I always use the new line method, as for me its much more clear. But whenever I come across someones code and if they have done it the same way I wont change it, unless I am rewriting their code & then I will.
I think today with high resolution monitors, conserving whitespace is less of an issue. I like the new line approach because it looks clean, makes it easy to delineate exactly where a block begins and ends (just scan up or down the page looking for the brace in the same column), and also makes it easy to move code around (just cut/paste at the braces).
if (condition)
{
statement1; Whitesmiths Style
statement2;
}
</rant>
Yes I probably sound kind of pissy about this...
Thank you for the rant. I think code that follow the conventions of the language is the most readable.
By the way, try your style in JavaScript. You'll have a tremendous amount of fun with return statements and implicit semicolons![]()
This discussion was surprisingly rational and dispassionate until you showed up lol.
Thanks for the link. I'm still trying to figure out my own preferred coding style. I'm using Allman, but I'll give Whitesmith a try and see how it goes.
One style suggestion I've tried and really like is to use a space buffer inside the parenthesis used for syntax purposes, but to omit the space buffer for parenthesis used to control the order of operation. I got this tip from Uli Kusterer's article on coding style. If there are some nested function calls with parentheses used for order of operations mingled together, it lets me quickly see what belongs to what.
Without trying to be antagonistic (really!), this is a silly comment. Readability is not and cannot be a function of language conventions, given similarly structured languages (i.e. not considering odd stuff like lisp or APL, etc.) Code readability is what it is, for a given set of similar languages. That said, it's a topic that could, and probably should have much more formal study than it has.
Your statement might be reasonable if you substitute the term "likable" or even "desirable, in many cases" for "readable". Then it's a subjective thing, and allows for things like herd mentality and just going with a standard because it's better than chaos. Which is, sadly, true.
Nice try, but fail. I've written tens of thousands of lines of JavaScript in recent years, ALL using Whitesmith. And I've supervised other coders and developed corporate coding standards for multiple companies, over the past nearly 30 years. You're not going to win this argument, other than just saying nyah, nyah, I like my way better. And with that, I cannot argue!
ps. no idea what implicit semicolons have to do with this conversation, but if you worked for me and purposely used them in JavaScript with any regularity you would be looking for a new job.
return
{
status: true
};
return {
status: true
};
Curly braces is the least of this but when people don't follow conventions for the given language it scares me. I immediately suspect them of trying to write in the style of whatever language they first learned and not really bothering to learn the language they're actually coding in.
You're sort of proving my point here. I do enjoy a flame fest as much as the next guy, and if curly braces is your most important problem, I congratulate you. It isn't mine.
Regarding implicit semicolons and return statements, let me provide you with an example:
Code:return { status: true };
The above is what I'd imagine Whitesmiths style looks like in JavaScript.
Code:return { status: true };
I mentioned JavaScript because it is the only popular language I know of where the placement of curly braces is significant. Granted, this is because some of the designers of the language were clearly possessed by demons. Such evil cannot come about by mere incompetence.
In conclusion, I don't think I fail. (and I already have a job)![]()
I've changed my style over the years (I don't even think it was a conscious decision). I started out using a new line for everything. Now I'll sometimes use a newline for a switch statement and not for other control statements. Go figure!
Cheers,
Steve Kochan
if (something)
then
begin
// blah
end
I'm one of those weird pascal programmers that use defines to make C code look more like pascal:
Code:if (something) then begin // blah end
Do you work alone (as a private consultant)? Because, no offense, but that would piss off a lot of other programmers who had to work with the same code.
if (whatever)
do something;
else
do something else;
continue doing stuff;
if (whatever)
do something;
else
do something else;
continue doing stuff;
New Line. It's easier to tell that your {s all have }s to close them when they're at the same indent.
Other question, does anyone else write single line if()s inline?
Code:if(var) fun();
versus
Code:if(var) fun();
if (var1) function1a() else function1b();
if (var2) function2a() else function2b();
if (var3) function3a() else function3b();
if (var4) function4a() else function4b();
// ----- 8< -- snip snip -- 8< ---------
if (var19) function19a() else function19b();
if (var20) function20a() else function20b();
This made me smile. Let me slightly rephrase: When I see people stick up for K&R, (regardless of language) it scares me, I immediately suspect them of trying to write in the style they first learned, without bothering to consider that other styles can be better.
Of course the reality is that on many projects you are going to be restricted to some kind of corporate or group standards, and then you just have to suck it up and do what you need to do. But my recommendation to the OP (and to others who haven't succumbed to the herd mentality) was that if you have an opportunity to do so, be open minded, and you may be surprised.
Stepping back along that vector, another pet peeve: if people would learn to name their identifiers to allow others to infer their purpose, life would be so much better! Verbosity is a virtue! This can be taught, although it's harder than merely adjusting bracing/indenting style.
Of course the biggest problems are related to people who just can't organize their designs in concise and reasonably easy-to-follow ways. But that's very difficult to fix because it relates to how people actually think, and how organized they are.
Got it, the example makes your point clear. And makes me much more confident that you don't do silly things like using implicit semicolons on a regular basis! As if you care what I think...! LOL (FWIW, I wasn't looking at your username when I replied - I've read many of your posts, and they're generally very good; and the "you" at the end of my earlier post was supposed to be in the general sense, not you personally, although looking back it kind of reads that way)
New Line. It's easier to tell that your {s all have }s to close them when they're at the same indent.
Other question, does anyone else write single line if()s inline?
Code:if(var) fun();
versus
Code:if(var) fun();
if (cond) {
fun();
}
fun() if (cond)
fun() unless (cond)