code-cleanup

How do I initialize classes with lots of fields in an elegant way?

删除回忆录丶 提交于 2019-11-29 21:07:54
In my application, I have to instantiate many different types of objects. Each type contains some fields and needs to be added to a containing type. How can I do this in an elegant way? My current initialization step looks something like this: public void testRequest() { //All these below used classes are generated classes from xsd schema file. CheckRequest checkRequest = new CheckRequest(); Offers offers = new Offers(); Offer offer = new Offer(); HotelOnly hotelOnly = new HotelOnly(); Hotel hotel = new Hotel(); Hotels hotels = new Hotels(); Touroperator touroperator = new Touroperator();

Formatting Clear and readable SQL queries

瘦欲@ 提交于 2019-11-29 10:47:26
问题 I'm writing some SQL queries with several subqueries and lots of joins everywhere, both inside the subquery and the resulting table from the subquery. We're not using views so that's out of the question. After writing it I'm looking at it and scratching my head wondering what it's even doing cause I can't follow it. What kind of formatting do you use to make an attempt to clean up such a mess? Indents perhaps? 回答1: With large queries I tend to rely a lot on named result sets using WITH . This

Remove unused source code files

落花浮王杯 提交于 2019-11-29 08:37:44
In Visual Studio 2010 I have a large solution that contains number of .cs files that are no longer used (not referenced in .csproj), but still present in code repository (ClearCase). Do you know of any tool / extension / script that would find all such files? One could write a script that goes through all projects' directories, takes all files that are checked in and than compares against content of a project file. In it is not there, than we have a candidate for deletion. It is not too exotic, so I wonder whether such a script already exist. Otherwise it will be a good occasion to get dust

How to remove extra empty lines from XML file?

谁说胖子不能爱 提交于 2019-11-28 19:36:30
In short; i have many empty lines generated in an XML file, and i am looking for a way to remove them as a way of leaning the file. How can i do that ? For detailed explanation; I currently have this XML file : <recent> <paths> <path>path1</path> <path>path2</path> <path>path3</path> <path>path4</path> </paths> </recent> And i use this Java code to delete all tags, and add new ones instead : public void savePaths( String recentFilePath ) { ArrayList<String> newPaths = getNewRecentPaths(); Document recentDomObject = getXMLFile( recentFilePath ); // Get the <recent> element. NodeList pathNodes =

Finding dead code in large python project [closed]

雨燕双飞 提交于 2019-11-28 18:12:41
问题 I've seen How can you find unused functions in Python code? but that's really old, and doesn't really answer my question. I have a large python project with multiple libraries that are shared by multiple entry point scripts. This project has been accreting for many years with many authors, so there's a whole lot of dead code. You know the drill. I know that finding all dead code is un-decidable. All I need is a tool that will find all functions that are not called anywhere. We're not doing

Is there any way to find unused CSS in a website?

点点圈 提交于 2019-11-28 04:24:57
Is there any way to find unused CSS in a website? I'm trying to clean up a project I just inherited. Sampson Dust-me Selectors is a Firefox plugin that finds unused selectors. I just ran into this and remembered your question: http://github.com/geuis/helium-css Chrome 59 has built-in coverage display for CSS and JavaScript since 2017-04: https://developers.google.com/web/updates/2017/04/devtools-release-notes#coverage You can enable it by opening the dev tools, then the command menu ( Cmd+Shift+P on Mac or Ctrl+Shift+P on Windows and Linux), and then type "show coverage". Wex There is so much

How to call a function by its name (std::string) in C++?

喜夏-厌秋 提交于 2019-11-27 06:34:44
I wonder if there is a simple way to call a function from a string. I know a simple way, using 'if' and 'else'. int function_1(int i, int j) { return i*j; } int function_2(int i, int j) { return i/j; } ... ... ... int function_N(int i, int j) { return i+j; } int main(int argc, char* argv[]) { int i = 4, j = 2; string function = "function_2"; cout << callFunction(i, j, function) << endl; return 0; } This is the basic approach int callFunction(int i, int j, string function) { if(function == "function_1") { return function_1(i, j); } else if(function == "function_2") { return function_2(i, j); }

How to remove extra empty lines from XML file?

我的梦境 提交于 2019-11-27 01:21:58
问题 In short; i have many empty lines generated in an XML file, and i am looking for a way to remove them as a way of leaning the file. How can i do that ? For detailed explanation; I currently have this XML file : <recent> <paths> <path>path1</path> <path>path2</path> <path>path3</path> <path>path4</path> </paths> </recent> And i use this Java code to delete all tags, and add new ones instead : public void savePaths( String recentFilePath ) { ArrayList<String> newPaths = getNewRecentPaths();

Is there any way to find unused CSS in a website?

ぃ、小莉子 提交于 2019-11-27 00:24:09
问题 Is there any way to find unused CSS in a website? I'm trying to clean up a project I just inherited. 回答1: Dust-me Selectors is a Firefox plugin that finds unused selectors. 回答2: I just ran into this and remembered your question: http://github.com/geuis/helium-css 回答3: Chrome 59 has built-in coverage display for CSS and JavaScript since 2017-04: https://developers.google.com/web/updates/2017/04/devtools-release-notes#coverage You can enable it by opening the dev tools, then the command menu (

How to project clean in android studio?

拈花ヽ惹草 提交于 2019-11-26 13:46:29
I am new in Android studio so I face some problem with it. so please anyone can give me a way how to project clean in Android studio. In Eclipse Project -> clean -> OK but I don't know how it is done with Android Studio. You can clean your project doing this Build > Clean Project or Build > Rebuild Project Also you can do the gradlew clean As @Kellogs commented : Manually delete the [project]/.gradle as hidden folder as that one is the main culprit for large cleaned projects sizes. Cleaning an android project is quite simple just follow these steps 1. Click on Gradle pane,found in the top