To read all comments associated with this story, please click here.
You'll learn to love them; like the most of us
You can start flamewars just because of mentioning where the curly braces should be!!
I actually prefer writing:
int main()
{
}
to
int main() {
}
but, apart of feeling it more natural and making easier to see where a block starts and ends, I do not have any excuse to prefer it over the other one.
Not just a matter of aesthetics; it also depends on the tools you use.
With XEmacs, when the cursor is at a closing brace, the line with the matching opening brace is shown in the status bar.
With this setup, it is advantageous to place the opening brace and function definition on the same line for quick reference.
I also think it depends on the language you are writing in where you should put it.
e.g.
If it is JavaScript Douglas Crockford recommends the opening brace should be on the first line, because of JavaScript semi-colon insertion mechanism.
Java is the same due to convention. Microsoft recommend you use opening brace on the following line as you do when writing C# and is the visual studio intellisense default.
Personally I somewhat agree with the OP and I have had a gutful of C style syntax.
Same, Allman style is the best!
Especially when programmers tend to have atleast 1200 pixels of height on their screens (well atleast I hope programmers are smarter than average consumer and don't give in into 16:9 fad just because it's cheaper for Samsung to make 23" 16:9 than 23" 16:10...).
Edited 2013-01-16 11:04 UTC
Please, be my guest :
http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid...
Especially check my CSkinProgress and WaterMarker source code : space instead of tab, 2 space indent, hungarian notation, one instruction per line, etc...
Kochise
One thing that struck me is the part about where to put the braces. Personally, braces just look messy to me, so I'd rather use a language without them. IMHO, having a terminating statement like 'END IF' is a lot more elegant than having braces all over the f**king place.
And don't even get me started on semi-colons
I'll agree with you on the semicolons and I do like Python's indent-based block syntax, but using words rather than curly braces is one of the reasons I've never tried to learn Ruby and refer to it as the bastard child of Java, Perl, and BASIC.
(Though by no means the only reason. The standard library and core language syntax are full of caveats, the Unicode support is inferior to Python's, it's not used much outside of Rails and apps based on it, etc.)
Agreed. The only thing that stands out more is probably the indenting itself.
You can start flamewars just because of mentioning where the curly braces should be!!
I actually prefer writing:
int main()
{
}
to
int main() {
}
but, apart of feeling it more natural and making easier to see where a block starts and ends, I do not have any excuse to prefer it over the other one.
Seeing all that wasted vertical space just drives me nuts. (Partly because it means more scrolling, more time spent repositioning my Vim cursor when scrolling drags it along for the ride, and more time reacquiring my train of thought when scrolling sometimes disrupts it)
...not to mention it doesn't fit as nicely with my Python-originated mental model that an indent level (syntactic block) is generally associated with the first line prior.
In fact, I'm sure that, in some places, I've been guilty of writing slightly less than ideal code using things like the ternary operator (PHP, mostly) and list comprehensions (Python) in order to vertically-compact my code.
Edited 2013-01-15 23:59 UTC
I personally think list comprehensions are a cool feature and should be used more, not just in Python. It may be harder to figure out what it does, but at a glance, at least you can tell what kind of things are in the list.
Yeah... The beauty of indent-controlled blocking in languages like Python and Coffeescript is that it kills multiple birds with one stone:
1. It eliminates a lot of noise.
2. It makes something that everyone does anyway for readability actually mean something.
3. It effectively kills most styling arguments (not all, but most).
Anyway, I'm quite fond of it.
Having programmed in both, I they both have pros and cons.
The real problems are:
1: badly formatted code,
2: lack of naming conventions,
3: and bad program design
1
--
Badly formatted code will make even the most readable of languages a struggle to follow.
2
--
It doesn't matter how well you format your code, if your function / variable names are badly chosen (eg abbreviated names that mean nothing to anyone but the developer) and there's no clear naming convention, then it can be a tough job understanding what the routine does.
I will also add, overly verbose names are bad too (I have one colleague who uses entire sentences in their function names. While it's helps explain what the function does, it makes code readability more challenging).
3
--
Bad program design is a more subjective topic. Most (if not all) developers roughly agree on indentation; and naming conventions only have to be readable, concise and consistent. Not everyone agrees on the specifics of naming conventions, but as long as those 3 criteria are met, then anyone new to the code can quickly understand the standards applied to that particular project.
However bad program design is about the code design of the code - when to you objects, functions, iteration and so on. Sometimes application performance is paramount, which often means writing clever routines in a manner that isn't ideal for a human reading back. Other times you'll be writing a program which isn't going to tax the processor much, so you can afford to opt for readability over performance (Sometimes you're lucky and the optimised code is also the most readable code).
Then you have people using obscure language features or unpopular features (goto is a great example of that. But thankfully there's very few occasions when a goto is the better method of writing a routine).
And after all that, you have the topic of code separation (eg using MVC's in web development to keep server side code separate from HTML).
----------
At the end of the day, it doesn't really matter whether your language uses English words or braces - a good developer can make their code readable.
But also, a lot of it comes down to practice. If you've never spent any time developing in C-derived languages, then the C syntax will naturally look a mess. But most developers get used to it and even come to love braces (that certainly happened to me).
No, no it's not. You try to maintain someone else's VB.Net app... "End If"'s (and "End ..." blocks in general) are complete crud. Braces are only complicated if you don't line them up correctly.. but most modern IDE's don't even make that hard. I far prefer '}' to working out which flavour of 'End ...' is missing in a VB method that some idiot made span 3 or 4 screens. Dometimes life is too short to not refactor, and moving VB code to C# is not all that hard. In fact, the last time I did that I fixed about 3 or 4 obscure bugs that VB introduced due to it's utter shit syntax (and this is with Option Explicit and Option Strict on.)
Having come from a Pascal background (but having done a lot of C++ in my BeOS days, ADA at university and BASIC before that), the "begin .. end" block teaches you much better practices than C's braces. There are plenty of places I will use a block where other programmers will not, mainly because it saves time in the long run.
The semi-colon is a fairly unambiguous end of statement marker. If that is hard to understand, you are pretty much doomed.
I use both punctuation (C) and verbose (ADA) languages and tolerate both well.
The solution is a syntax colouring editor with very different colours for keywords and plain identifiers (not black and dark blue...)
The begin/end stuff becomes colorful patches surrounding black code.
Normally most formatting problems can be sorted with the IDE.
TBH a lot of the problems you describe are more to do with the way the applications have been written and not the language itself. I am sure I can point you to some of the atrocities I have seen in C# (my favourite being the INullObject interface I recently found).
Personally I like VB.NET, while the syntax is odd you can write code pretty quickly. My main issue with the language is that it is difficult to see the difference at a glace between an array and a procedure/function.
A lot of newer developers especially those coming from Python or Ruby find the use of a semi-colon slightly arduous. There was recently a flame war between Douglas Crockford and one of Twitter Bootstrap developer over whether you should make of the JavaScript semi-colon insertion mechanism.
Edited 2013-01-16 13:16 UTC





Member since:
2005-11-13
This is going to be a post about personal preferences ...

Being the novice programmer that I am, some of it was over my head, but other parts of it I could comprehend.
One thing that struck me is the part about where to put the braces. Personally, braces just look messy to me, so I'd rather use a language without them. IMHO, having a terminating statement like 'END IF' is a lot more elegant than having braces all over the f**king place.
And don't even get me started on semi-colons