|
I understand your point of view, but still prefer my way of doing things. What I find more troubling is that after working on a bunch of javascript, I'm starting to prefer the old school C style brace layout.
|
|
|
|
|
Correct.
If you have a 'rule' which says, "(don't) use braces, except in these special cases", then you have to remember the special cases.
I'm in the braces-good camp for the reasons Chris supplied above. Missing them doesn't make your code noticeably more concise, and does make your code (and, more importantly, your intentions, when you've run away from this project and I'm trying to figure it out [or vice-versa]) noticeably more readable.
|
|
|
|
|
You beat me to it man. If it's hard to read then I use them. For simple things concise wins. +5
Jeremy Falcon
|
|
|
|
|
I have to {
disagree.
}
I prefer the verbosity and clarity that the braces bring to the code.
Jeremy Falcon wrote: Concise wins, unless it's hard to read.
Which is usually what happens. People that use the latter form also tend to be the ones that crush every line together so that you first have to separate to properly understand. Is there a lack of space on your screen?
In any case a method bigger than a screen is just plain fugly.
|
|
|
|
|
Karel Čapek wrote: I prefer the verbosity and clarity that the braces bring to the code. You should try VB then.
Jeremy Falcon
|
|
|
|
|
Heathen! Blasphemer! How do you even know that VB uses braces???
|
|
|
|
|
Ha. Well you see... I work for the devil, but it's only because I'm evil.
Jeremy Falcon
|
|
|
|
|
I both agree and disagree. My personal coding style is:
if (expr) {
doSomething();
}
else {
doAnotherThing();
}
I like using the braces so that adding an extra bit of logic to the execution block won't inadvertently change the program flow, and at the same time placing the opening brace on the same line as the if... and the else statements compacts the code a bit. To me the advantage with compact code is that you can see more of the program logic in a single screen which means less time scrolling up and down trying to follow the program logic. For that reason, I'm ruthless in eliminating blank line whitespace except to visually offset functions or methods.
Ron Christie
|
|
|
|
|
As much as I'm not a fan of that (even in JavaScript), that makes more sense than:
if (expr)
{
doSomethingForOneLine();
}
else
{
doAnotherThingForOneLine();
} You're version is at least concise, and no matter what some may say on CP, concise is important. Less is more. Always will be.
Jeremy Falcon
|
|
|
|
|
I personally prefer this convention:
if ((a cond b) conjunction
(c cond d) conjunction // Additional conditions always on separate line
(e cond f)) { // Always include opening brace
do .... something
} // Always closing brace
Or
} else { // Always closing brace..else..opening brace
do .... something else
} // Always closing brace
The same conventions and principles apply to loops (for, while, etc.) and other conditionals.
I strictly avoid NOT using braces under any circumstances.
I want to be able to see a complete thought, i.e., a block of code, in one intact, obvious section.
These are my thoughts based on years of chasing bugs, modifying other people's code, and having to debug somebody else's problem. Other people are welcome to use their own conventions, but I may not be able to help them efficiently.
Just because I can do something doesn't mean I should do it.
|
|
|
|
|
It's interesting that the older the programmer the more concision becomes important.
Ron Christie
|
|
|
|
|
If their functions are really long they can see more of it on one screen that way.
|
|
|
|
|
|
Cool, Religious war in the Lounge!!!
I'd rather be phishing!
|
|
|
|
|
What exactly is a peeve? and how do you train it?
I prefer the second method as a matter of style and space. To each his/her own!
New version: WinHeist Version 2.1.0
There's a fine line between crazy and free spirited and it's usually a prescription.
I'm currently unsupervised, I know it freaks me out too but the possibilities are endless.
|
|
|
|
|
In a coding standard that put's { 's on their own line I prefer this:
if (condition)
DoThis();
else DoThat();
If you're putting the { on the previous line, IMO they're easy enough to overlook that the explicit closing } is needed.
And if you're writing javascript the opening { is obligate and this:
if (condition) { DoThis();
} else {DoThat();}
or this:
if (condition) DoThis() else DoThat();
are obscenities.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
It's not laziness. The second one is quicker and easier to read IF the condition and the branched commands are short.
As soon as any of those lines gets the slightest bit complicated, or if there's any nesting at all, I add the braces.
|
|
|
|
|
Ian Shlasko wrote: As soon as any of those lines gets the slightest bit complicated, or if there's any nesting at all, I add the braces.
Jeremy Falcon
|
|
|
|
|
IMHO the latter is easier to read. I've recently had to resort to cheap reading glasses as { started looking like (! (even at 125%}
I don't always use {}, but when I do, I also prefer then on their own lines for readability.
"Go forth into the source" - Neal Morse
|
|
|
|
|
kmoorevs wrote: I don't always use {}, but when I do, I also prefer then on their own lines for readability. Click Me[^]
Jeremy Falcon
|
|
|
|
|
High five!
"Go forth into the source" - Neal Morse
|
|
|
|
|
The decision which to use is simple:
- follow the coding standard
- if you don't have it, use whichever style is used in file/project
- new project/file, use whatever you find more atheistically pleasing to you
Personal atheistic preference is one of very few arguments that I can accept as valid in this "debate" (like in any other debate on any kind of style).
The only argument that is supported by concrete numbers is saved on-screen space by the second style. All other arguments are largely unsubstantiated (maybe I'm wrong, but let me see some numbers)
So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious.
<edit>
My preference: ?: . What' you gonna do now?
<edit>
|
|
|
|
|
Mladen Janković wrote: So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious.
++Mladen.rep;
|
|
|
|
|
Mladen Janković wrote: it can make you look obnoxious.
But I am obnoxious
|
|
|
|
|
Well I can't argue with that
|
|
|
|