- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The thing is that it's a noun, not a verb.
Admin
I have been signing posts like that since I first got on the Net ten years ago.
Sincerely,
Gene Wirchenko
Admin
I came up with all the ideas for Sesame Street.
Sincerely,
Richard Nixon
Admin
Pissing off Dick Nixon is just gravy.
Admin
Which is why my code looks like this
No useless braces, no useless keywords...
2spaces can go fuck itself.
Admin
this is f-in hilarious
Admin
if (wtf) { ++lol; }
is my personal preference. It's legal in Java (and other languages which require braces) and it saves vertical space.
Admin
Whenever I deal with XML, my fingers automatically type out ":set shiftwidth=2", but code is definitely done with 4.
Admin
Generally I don't need to preserve horizontal space. Why would I sacrifice readability to preserve a resource that isn't scarce? However, when I see more of the method on one screen, I can more quickly comprehend the code.
Now, If I was using a 40 column display your argument might have merit...
Admin
Just for your personal culture, it's also valid in languages that don't use braces.
Python example:
Ruby example:
And you get rid of the parenthesis on top of the braces and semicolon, AND the code looks like plain english.
Admin
I wholeheartedly agree, provide the body of the block is fairl trivial or corresponds to a well known idiom. I won't do this with important logic.
Admin
Et tu, Brute?
Sincerely,
Richard Nixon
Admin
If that was the only problem this forum had... <sigh>
HEY! My "delete key" now functions! WOOOHAAAA!
<damned, promised myself not to post again to boycott this forum until it is fixed>
Admin
If you still go by what standard console screens require, you should be using an amber CRT screen at 640x480 with no GUIs. That's a non-argument if I ever saw one.
Since you use SciTE (which I use as well), you can turn on the whitespace and indent lines. The editor uses very unobtrusive glyphs for the whitespace, and the indentation is very easy to follow, even set at 2 spaces.
Admin
Actually, the optimal space saver would be
lol+=wtf?1:0;
Admin
Except I'm not advocating saving horizontal space either. I was just pointing out that people who claim putting an opening brace on its own line is bad because it wastes (vertical) space still often waste (horizontal) space by using large indents. I.e. the wasting space argument is not particularly consistent.
Another inconsistency in the opening-brace-on-same-line argument is that I haven't seen anybody advocate putting the closing brace on the same line as the last statement, like so:
if (myIndent.sucks()) {
System.out.println("My indent sucks");
System.exit(1); }
instead of the standard
if (myIndent.sucks()) {
System.out.println("My indent sucks");
System.exit(1);
}
Mung Kee claims the braces are essentially pointless for readability, and that it's all about indentation and not wasting vertical space for braces. If that's true, then you should close your braces on the same line as the last statement. Otherwise, the argument makes so sense whatsoever.
Admin
I hate arguing religious issues, but that's spurious nonsense -- the closing brace provides the indent-level match, which is a definite aid to readability. The opening brace adds nothing but an extra line, since the indent level is already provided by the statement preceding it. I write K&R generally because I'm an old fart who's set in his ways, but I can work with any of them. Just not on a 640x480 or 24 line, 80 column monitor (remember when VGA was a huge leap in display technology?).
Kids today. They don't know how good they've got it.
Admin
The point RevMike tried to make (but you kinda whooshed past it) was that you only save a scarce resource, there is no point in saving something you have plenty of... aka you'll try to save (and optimize usage of) sunlight in the Grönland, but you won't even try to save on ice usage. Similarly, you'll try to save on water consumption in the Sahara but probably won't give a damn about the sunlight usage.
Horizontal space is a resource that most screens are plentiful in, the regular 4/3 has room for twice the characters horizontally as it has vertically (with most fonts) and i'm not even talking about widescreen types here.
Vertical space is a scarce resource, as I said 1280*1024 I merely get 50 lines with a very stripped down editor while i get more than 150 characters horizontally.
There is no point in saving horizontal space since you have more than enough, there is a point in saving vertical space (to an extend).
Admin
Curly brace on same line
I can see more of the code in one screenful without losing readability
I can scan up from the closing brace to see what it corresponds too
Exception -- if a method has more parameters than are easily viewable in one line
Always use braces, even if there's only one line in the body
Consistency -- no matter how many lines are in the body my constructs always looks the same
If I need to add or remove lines later, it's easy and all I have to do is add or remove lines
Tab size = 2
I can see more of the code in one screenful without losing readability
If you are using real tabs instead of spaces, everyone can have it their way
Admin
That is irrelevant. You're arguing that it's silly to be conservative with your apples if you're going to eat your oranges without any thought of conservation.
I remain unconvinced of your point.
Sincerely,
Richard Nixon
Admin
Totally misquoted. I meant what I said, not what you perceived. If you're going to refer to my comments, get them straight. See my quote from a previous post below.
Notice I didn't say it's "solely" about indentation.
The implication here is that the closing curly brace is as important as ever, since it is used to line up the first character of the scope block. It's the open curly brace that doesn't matter. Take your example for instance. In the "standard" you mention in the second if statement, the closing curly brace is lined up with the "i" in "if". That is precisely the point I was making. The "open scope marker", the "i" in "if" in this case, doesn't need to be an open curly brace, so why give it it's own line? You line the close curly brace up with the "i" and you have your scope. As I also said in a previous post, mentally processing this would actually be <marginally> faster since your brain doesn't care what character it is that opens the scope, so long as it falls in the same vertical line.
Admin
Actually I remember those days. Two colors, 24 lines, 80 columns, no mice, very limited usability. Linux today is almost as good!
Admin
Then you must be blind. It's very clearly at the end of the statement that beings the block, which is the first statement at a lesser indentation level.
Frankly, I don't care where the brace is as long as the code is indented properly and all if, else, while, for and do expressions use braces instead of single statements.
I also like Python, in which the block open character must occur at the end of the previous line, and code doesn't work if it's not indented properly.
Admin
Personally I prefer keeping my opening brackets on the line that is responsible for the code block
while (someCondition) {
__doThis();
__doThat();
}
continueOn();
just works for my eyes better. I am sure its 99% percent personal preference. As for all the people who got so upset over someone using 8 character indents, why would your first assumption be they are hard coding 8 spaces? Its notepad, its 1 tab...even if they liked large indents, I'd rather they use 8 via a single tab, than drop 4 spaces in with the spacebar.
Anyway, all this bracket fighting is killing the love - can't we call come together and ridicule Jed's code as one? I mean, thats a guy who managed to take exception handling's lovely "no cost when not used" methodology and actually track every single possble exception throwing condition long after it was obvious the function would never execute, even though he would never report any specifics about all the errors - then of course screw up on actually reporting the errors.
And here we are bickering over brackets, its things like this that made Baby Jesus cry. :(
Admin
Honestly, who gives a flip about formatting? Any developer worth his/her salt will use a tool to do all the formatting automatically (this also allows a department to standardize on the formatting conventions very easily, too). Anyone who still aligns code by hand is about at the level of a 5cr!pt k!ddi3 in terms of skillz and wasted time.
Your boy “Jim” is definitely a WTFer for wasting time reformatting the code—and getting paid cash to waste time like that, too!
As for the other part, definitely a WTF.
Admin
I recall even smaller screens... writing BASIC on a C64.. 25x40 screensize. But then again - I had 16 colors.
[pi]
Admin
The One True Brace Style War has been going on ever since braces were used for the first time in a programming language. It probably won't stop before C, C++, Java and C# are all dead.
The sooner the better, if you want my take on it
Oh BTW the so called "windows indent style" is actually Whitesmiths, from a PDP-11 C compiler, and the most fucked up style is probably the GNU one (Lisp syntax is already tough in Lisp, but writing Lisp in C/C++ is quite fucked up)
Admin
I beg to differ. Pico is pretty f-ed up.
Admin
I should have known I'd generate such passion for asking this question. I don't know whether to laugh or apologize. :-)
And I should have known Wikipedia would have an article on this. Thanks! ("Whitesmiths style"? That's interesting. I discovered it in Durant, Carlson & Yao(1988).)
Let me try to explain why I like this format so much:
First, I see a compound statement as consisting of the keyword, conditional, and block. The block is a package of statements that are subordinate to the keyword & conditional - their child, almost. So it makes sense to me that it should be set off visually with the curly braces, and that the curlies should line up with each other. In BSD style they are aligned, but then the text in the block is sitting out there in whitespace all alone. When I scan code like that, it's harder to make the connection between the block & the statement that controls it. In Whitesmith style at least the curlies line up & tie the block visually to the conditional. Also, if you run your eye down the left side of a block, you see at a glance what kind of statements make up the block. In this case, an assignment, if, and else. Without the curly braces sitting next to the if, else, while, etc., they stick out prominently.
BTW, as for taking up less space, sometimes if the block is 1 stmt long I'll put it immediately after the opening curly.
Well gee, I'm just happy to see that I'm not the only one who uses this style anymore. Group hug! [:D]
(I guess I won't ask if anyone else prefixes their function parameters with "p_"... [8-)])
Admin
Amen :-)
Admin
Useless hungarian at its best [:)]
Admin
hahahha.. I work with a similar person, if only I could describe the hundreds of "WONDERFUL" ideas he has... some people can be such asses. [Y]
Admin
Nope, I prefix my function parameters with a_, because that is what our @$#%%$*^%#^@% coding standard requires. At least for c++ the standard works and and is consistent, even if sometimes annoying.
Don't get me started on our python coding standards. Suffice to say that there is a section on how to format switch/case (python does not support switch/case), and many other area where it is clear the cheif programmer has never worked with the python community, nor did he care.
Thankfully the author of the above WTFs is no longer here.
Admin
Yuck. I've never seen that until and hope I never do again. That is making baby Jesus cry because his eyes are hurting so bad trying to read it.[;)]
if ( !poNode ) {
return DOMNodeUnk;
} else {
eOldType = poNode->GetType();
eRet = poNode->SetType(eNewType);
return eOldType;
}
Ahh. Much better
I forgot to mention I consider a space before and after the paranethesis on if/while/for mandatory.
I also detest not having the two braces on the else and else on the same line.
Admin
its te start up for atitd.com u fools
Admin
There's a big contradiction here. If the indentation is enough to see the scope block going down, what do you need the closing brace for? The end of the block is clearly delimited by the return to the previous indentation level.
if (you.suck()) {
whine();
magicNumbers.use();
hex.setKnown(false);
code.bungle(); }
System.out.println("This is the next scope");
etc.
You could make the exact same argument about my position: mentally processing the scope block delimited with a brace on its own line on each side of it is faster since all your brain has to do is look for a brace (which is always the same) and not abstract away from what character is the first to be indented, and because the layout is symmetrical, which has processing advantages.
At any rate it's really about personal preferences, not about "logic" or whatnot, and all I was trying to do is to rile you and others up. Seems like I succeeded. :)
* rogthefrog goes off to submit his own code for consideration as WTF of the year
Admin
indentation... check this out for sucky indentation ( saw this when editing a mates code at uni<FONT face="Courier New">)</FONT>
<FONT face="Courier New">function phpFunctionOfSomeSort</FONT>
<FONT face="Courier New">{ </FONT>
<FONT face="Courier New"> somecode here</FONT>
<FONT face="Courier New"> some more code here</FONT>
<FONT face="Courier New"> if (condition) </FONT>
<FONT face="Courier New"> {</FONT>
<FONT face="Courier New"> lets have even more line breaks</FONT>
<FONT face="Courier New"> }</FONT>
}
so not only is it a gammy style (K+R is the best ever, obivously) but there was a linebreak between _every_line_of_code!
Admin
GNU is baaaaaaad. Pico is nasty. But Whitesmiths is just terrible.
Admin
In C#:
1
3
as I expected.
I take your word for it that not all compilers/platforms act the same, but it suprises me highly.
Admin
Let's be honest. The BSD/Allman style is the only true style; with 3 spaces and none of that mucking about with tabs (a pain in the arse when transferring stuff between systems with bad codepage convertors). After all, all the best programmers use vi on an 80x24 terminal screen.
The BSD style gives you vital contextual information - rather than disassociated blocks like the GNU style. The Whitesmiths style just looks ugly.
Also the BSD style leaves you a convieniant place for a comment:
if (foo == bar)
{ // flange the grobble
...insert code here
}
Hungarian notation is never acceptible.
Admin
I disagree. Hungarian notation is acceptable if it provides actually useful information beyond the datatype. I don't care if it is an integer. I might care that it is an integer that holds a handle to something else in the application. Or I might care if it is an integer that is used to store a set of bit flags.
Admin
I think there is not only one true style. Any style is good as long as you're consequent. I like to keep my code as compact as possible without loosing it's readability, so I use the K&R style:
if(foo==bar) {
DoSomething();
}
or in this case, I'd prefer:
if(foo==bar) DoSomething();
1 line instead of 4 and still very readable...
Hungarian notation is off course acceptable. Why would anyone have invented it? It's just from another time period when there was a limited amount of types (primitives of objects). I think you should not use it anymore in modern OO languages!
Admin
12 is a satanic number in jeds world?
Admin
Apparently they are unaware of the IF ELSIF Structure?
Admin
ehhhh no!
But in the old code you never throw 12 exceptions at the same time.....
Admin
The problem with K&R is in dealing with multiple line conditionals:
if (test1() && test2() && test3()) { action1(); action2(); action3(); }
... in that the conditions are not obviously separated from the body of the statement, without hunting for the '{', which may be a long way off if the test has a long name.