code-cleanup

git - trim whitespace

你离开我真会死。 提交于 2019-12-03 07:01:42
问题 I've accidentally put some whitespace in my initial commit - it shows up red in git diff --color . What's the best way to get rid of the existing whitespace and how can I avoid this happening again? I am not necessarily looking for a built-in git command. Any external program available for free on Ubuntu would also be welcome. 回答1: To trim trailing whitespace on all files in the current directory, use: sed -i 's/[[:space:]]*$//' * To warn about future whitespace errors (both trailing spaces

git - trim whitespace

半腔热情 提交于 2019-12-02 20:37:00
I've accidentally put some whitespace in my initial commit - it shows up red in git diff --color . What's the best way to get rid of the existing whitespace and how can I avoid this happening again? I am not necessarily looking for a built-in git command. Any external program available for free on Ubuntu would also be welcome. Zaz To trim trailing whitespace on all files in the current directory, use: sed -i 's/[[:space:]]*$//' * To warn about future whitespace errors (both trailing spaces and spaces before tabs ), and to fix whitespace errors in patches, add the following code to your

Sublime Text 2: Trim trailing white space on demand

蹲街弑〆低调 提交于 2019-12-02 14:00:18
I know that Sublime Text 2 can delete the trailing white space on files upon saving. When working in a team and commiting a change to a file this tends to produce huge diffs which make peer code review more cumbersome. For that reason I prefer to only do the white space cleaning when I'm commiting huge changes to a file anyway and leave whitespace as it is for the minor changes. I would like to know if there's any command for executing the trimming of the white space on demand on a file, other than "Activate trimming on save > Save file > Deactivate trimming" . Searching in the Documentation

why is the use of return a bad habit in scala

◇◆丶佛笑我妖孽 提交于 2019-12-02 07:00:29
问题 I am doing scala through the functional programming course on coursera. I noticed that the automatic style checker tells me that the use of 'return' is a bad habit. Why is that? To me it seems like the use of return would make the code more readable because any other programmers can instantly see that and what the function is returning. Example, why is this; def sum(xs: List[Int]): Int = { if( xs.length == 0){ return 0 }else{ return xs.head + sum(xs.tail) } } Considered to be worse than this;

why is the use of return a bad habit in scala

人走茶凉 提交于 2019-12-02 06:27:32
I am doing scala through the functional programming course on coursera. I noticed that the automatic style checker tells me that the use of 'return' is a bad habit. Why is that? To me it seems like the use of return would make the code more readable because any other programmers can instantly see that and what the function is returning. Example, why is this; def sum(xs: List[Int]): Int = { if( xs.length == 0){ return 0 }else{ return xs.head + sum(xs.tail) } } Considered to be worse than this; def sum(xs: List[Int]): Int = { if( xs.length == 0){ 0 }else{ xs.head + sum(xs.tail) } } I am used to

Organizing code files/XML files for Android SDK

核能气质少年 提交于 2019-12-01 05:04:33
Can someone provide some strategies as to organizing my project so that it is clean? Say I have a bunch of activities; is it good to place them all into a separate package, while putting other classes (such as custom Adapters) in another package to separate "logic" better? Also, when creating XML files for layouts, how would I separate the layout XML files logically if I have some layouts that are for certain activities and other XML layout files for custom "rows" (to use with an Adapter) I don't want to just throw them all into res/layout -- it would become such a huge hassle when the project

Removing unused code in Visual Studio

两盒软妹~` 提交于 2019-12-01 02:05:36
In relation to this question: " Remove unused references (!= "using") ", I would like to know if there is a tool for removing unused classes, structs, delegates, etc from a Visual Studio solution. Scenario: I have an unorganised Visual Studio Solution which consists of 1000's of: Native method imports Structures Delegates Enumerations Rather than trawling through each file clicking "Find All References" and determining if the code is being used somewhere, is there any mechanism by where I can simply remove redundant code files easily? Example: //This class contains a method called

Removing unused code in Visual Studio

巧了我就是萌 提交于 2019-11-30 21:27:36
问题 In relation to this question: "Remove unused references (!= "using")", I would like to know if there is a tool for removing unused classes, structs, delegates, etc from a Visual Studio solution. Scenario: I have an unorganised Visual Studio Solution which consists of 1000's of: Native method imports Structures Delegates Enumerations Rather than trawling through each file clicking "Find All References" and determining if the code is being used somewhere, is there any mechanism by where I can

Formatting Clear and readable SQL queries

强颜欢笑 提交于 2019-11-30 08:10:21
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? With large queries I tend to rely a lot on named result sets using WITH . This allows to define the result set beforehand and it makes the main query simpler. Named results sets may help

Finding dead code in large python project [closed]

安稳与你 提交于 2019-11-29 22:37:29
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 anything fancy with calling functions based on the string of the function name, so I'm not worried about