News for hackers. Stuff that matters.
Re:Why do programming languages use curly braces? by cobrausn on Tuesday February 26, 2013 @11:07AM (#5286353)
The first time I ran into the spaces vs. tab problem I wanted my curly braces back.
Re:Why do programming languages use curly braces? by k3n on Tuesday February 26, 2013 @11:43AM (#5286656)
That's an issue you run into once, set your editor, and then never have to worry about it again.

On the other hand, curly braces will plague you as long as you use C-inspired languages. An editor will only help you to more easily produce the cruft, it won't absolve you of the responsibility.

Re:Why do programming languages use curly braces? by cobrausn on Tuesday February 26, 2013 @12:01PM (#5286792)
You run into it again when you start working with other developer's code.

And once you learn to use curly braces, you don't forget that either. I haven't been plagued by curly braces since college - I work with C / C++ / Lua / Ruby on a daily basis. I seriously don't see how it's any different than remembering to indent your python code. An editor certainly doesn't absolve you of that responsibility either.

I'll put it this way - when I look at a block of code with braces (or begin / end), non-rendered characters don't affect the correctness of it.

Re:Why do programming languages use curly braces? by k3n on Tuesday February 26, 2013 @12:25PM (#5286962)
I just think they're redundant.

Indention in non-Python code is 100% aesthetic; it doesn't affect program behavior, we just do it because it helps us non-compilers understand the code. And if you follow most any sane coding standard, indention will always be congruent with braces.

So, you're essentially attempting to convey the same concept -- program structure -- via 2 different mechanisms: tokens (curly braces) and indention, where of course the former is required, while the latter is the fodder of more flame wars than anyone cares to count. The sad thing is, these flame wars over code formatting are the most contentious to humans and yet the least meaningful to the compiler.

One solution would be to remove the indention -- hey, we already have the tokens informing us of the lexical code boundaries...but this produces unreadable code. The other solution is to remove the tokens; since we as humans will naturally structure our code in block paradigms, then we can piggyback on a behavior that is already innate to programmers.

Re:Why do programming languages use curly braces? by qu4z-2 on Wednesday February 27, 2013 @12:21AM (#5290822)
I agree with you. It seems odd that we have the structural information in our program twice: Once for humans, and once for computers. The computers are perfectly capable of understanding the human construct, so let's use that.
Re:Why do programming languages use curly braces? by pekk on Tuesday February 26, 2013 @01:32PM (#5287402)
Enforcing a convention (like go fmt) will also take care of the issue.

However, this doesn't end up being really different from what Python does by rejecting mixed tabs and spaces. So.

Re:Why do programming languages use curly braces? by tobiasu on Tuesday February 26, 2013 @12:26PM (#5286967)
Until you refactor some python code and the indentation gets messed up without you noticing... Been there, done that.

And unlike languages with explicit begin/end markers, an editor can't re-format it or warn about it, because there is no information to work with.

Re:Why do programming languages use curly braces? by pekk on Tuesday February 26, 2013 @01:31PM (#5287393)
Perhaps you didn't understand, but that doesn't happen when you set up your editor.

Anyone who actually uses Python spends 0% CPU thinking about soft tabs because the editor is already set up to deal with this and almost everyone uses soft tabs, as suggested by PEP8.

Re:Why do programming languages use curly braces? by qu4z-2 on Wednesday February 27, 2013 @12:23AM (#5290832)
There's no reason an editor can't reformat most cases. If you copy a block of text out of one indentation-level and into another, you simply need to adjust the leading indents by a fixed amount.

Obviously if you're changing which statements are or are not part of a block and thus need to re-indent things per-line you'll need to do it manually, but you'd also need to manually move the braces around, and it'd be less obvious if you forgot.

Re:Why do programming languages use curly braces? by Someone on Tuesday February 26, 2013 @02:12PM (#5287703)
Technically, you don't have to type any { or } to write C code. ??< and ??> will do 'fine' as replacements, as do <% and %> (http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C)
Re:Why do programming languages use curly braces? by papsosouid on Tuesday February 26, 2013 @11:59AM (#5286770)
>That's an issue you run into once, set your editor, and then never have to worry about it again.

HN needs /. style comment ratings for things like this. You deserve your "+1 funny" for that.

>curly braces will plague you as long as you use C-inspired languages

Curly braces don't cause (potentially hard to find) errors like mixed invisible indentation does. You can't be "plagued" by them at all, they are harmless. And they even let your code be completely unambiguous so you can use tools to reformat your code as you please/need.

Re:Why do programming languages use curly braces? by qu4z-2 on Wednesday February 27, 2013 @12:20AM (#5290816)
Much as I like the /. "semantic rating" system, I'm glad HN doesn't have it, so we don't get these sorts of passive-aggressive ratings.

Regarding your second point, curly braces do cause potentially hard-to-find errors, specifically when the indentation and the curly braces don't match up. Admittedly it's very easy to get into a set of habits where you don't do that, but the same can be said for the mixed indentation issue.

Re:Why do programming languages use curly braces? by papsosouid on Wednesday February 27, 2013 @09:53AM (#5292600)
Except that there is no potential for ambiguity, so tools can easily highlight indentation that doesn't match braces as an error for you, and tools like "indent" can automatically indent the code correctly based on the braces.
Re:Why do programming languages use curly braces? by qu4z-2 on Wednesday February 27, 2013 @05:21PM (#5295381)
But those are both ways to keep your two different notations for structure in sync. If you only have one structure, you don't have that problem in the first place.
Re:Why do programming languages use curly braces? by rejschaap on Tuesday February 26, 2013 @11:34AM (#5286586)
Invisible cruft! The worst.

Also, Python is crufty by convention with its __init__ and __new__.