Gool old Notepad2:
Auto strip trailing blanks option (File, Line Endings, Default)
zzz⦠I thought this post was going somewhere - but then it didnāt. I was wondering āwhat am i missingā and when the big reveal was some whitespace I died a little.
@lolatwood - funny
KDevelop has a setting to strip all trailing whitespace on saving. However this wonāt be visible in the IDE until you close and reopen the file. I like the idea of a code cleaning bot that runs via commit hook/cronjob and tidies up with simple rules like trailing whitespace, extra line break at the end of each text file, tabs to spaces etc.
Srsly kdiff3 can ignore whitespace. Iām sure any decent diff/merge tool can. Who cares?
To Nick: any difftool can ignore whitespaces I guess too, unfortunately ignoring whitespaces that arenāt at the end of lines can hide important changes and thus should perhaps not be done.
I might be wrong, but isnāt \s*?$ a non-greedy match to any number of trailing whitespace? Wonāt this always match exactly 0 characters of whitespace? Shouldnāt it be: \s*$
What whitespace at the end of the lines?
signed: the VB guy
(I know, I know⦠in the example above, also for VB guys the whitespace would not be trimmed)
I submit that an important part of being a nerd is knowing which things to obsess over and which things to let go. To paraphrase Dave Chappelle, pick your spots.
If youāre using a language in which whitespace is not significant, I recommend choosing something else to obsess over.
It is nice to know Iām not alone in my Code Whitespace OCD.
Locking? Surely you are joking, mr PRMan. I thought no one used locking version control since about the time fire was discoveredā¦
Ctrl+E,D
Guess Iām not one of you ⦠Thank goodness too 'cause otherwise Iād have to have myself committed for being overly anal.
Other than the fact that whitespace, like case (ā¦yes I said CASEā¦why should GROSSPAY, grosspay, GrossPay, or grossPay mean different things or be scoped differently? Why? WHY!? Okā¦I got off on a bit of a tangent. Sorry.) shouldnāt matter, it can cause problems.
I remember beating my head for two days over a piece of code that refused to compile. Iād stare at the line and tweak it one way or the other to no avail. Out of desperation I deleted the entire line and retyped it from scratch. It worked. Comparing the old and new code, I found ONE SPACE at the end of the line that didnāt work.
Itās hard to debug something you canāt see.
May be worth saying too that most companies (and here Iām thinking those situation where thereās more than one person committing to the repository) enforce the removal of trailing whitespaces on their code guidelines documentation.
This is also, as far as I know, a common guideline among open source projects.
Iām surprised however as to why Jeff ignored the setting on most editors used for coding (modern and old alike) that automatically remove these on save. This setting alone removes the need for his three proposed solutions.
But assuming such an editor feature wasnāt present or couldnāt be present for some reason, itās worth saying that most diff tools can also ignore trailing spaces at our request.
Iāve recently switched to tab formatting in designer HTML in Visual Studio, and the reason is simply payload size of the page. Using Jeffās example, the the 48 space characters (not including the offending trailing white space on Line 2) could be replaced with 6 tab characters (assuming the Visual Studio default formatting setting of 1 tab == 4 spaces) and still retain the same visual layout. That amounts to a 12.5% reduction in size just on formatting. Howās that for OCD?
Iād like to minify all my .as?x files, like Iām doing with all CSS and JavaScript files, as part of a build step, but havenāt built/found a tool for that yet.
What I find most shocking about this is that anyone gives a sh*t. Nothing better to do, I guess.
Just thought my captcha was amusing:
heinie but
Sounds to me like you are complaining about the symptoms, not the problem.
Here are the problems as I see them:
-
You are using a language with ASP-style syntax. Didnāt you get the memo that those suck? They eventually trend toward unmaintainable.
-
You are using a merging repository with 10 developers. You arenāt writing the freaking Linux kernel!!! You donāt need merging, it just causes all kinds of problems. Tried and true locking is the best solution when you can easily divide the work between modules. I love locking, because then I can just set Visual Studio to conform the code to the way I like, and the next guy the same. Ctrl-K Ctrl-D and itās all good.
-
Was your diff tool written in 1990? Because WinMerge has been ignoring whitespace, blank lines and CR vs CRLF for at least that long. Seriously, there are diff tools that canāt do this in 2009? I would have never guessed.
-
You are using an IDE which doesnāt do code cleanup for you. Set your style and have the IDE conform the code to it for you. Nice and consistent.
-
Somebody checked in a bunch of spaces at the end of a line.
You left out one option regarding what to do to solve the whitespace problem. When I code, I use the Home and End keys ridiculously often. If youāre like me, itās quite simple to see when you have some trailing spaces - chances are youāll see it by chance when youāre just navigating the code! A lot of IDEās have customized it by default to make the Home and End keys ignore whitespace - so Home will take you to the start of code -following- the indentation, and End takes you as far as the start of trailing spaces. Usually double-tapping Home or End will take you to the -real- start or end, though, so Iāve become rather accustomed to that as well.
Even at the start/end of scriptlets, we are inserting a new lines which are unnecessary. That costs us few bytes.