8

Why do programming languages, especially C, use curly braces and not square ones?

This post has generated very rapid close/reopen votes along with an extended discussion in the comments. I have cleaned up the comments, but brought some relevant points here, attributing them to the author. Please use this Meta question to discuss the merits and appropriateness of this question.

I have cleaned up the extended discussion as well as the low-quality answers to the post. Please resume discussion here.

The only person who can answer this is Dennis Ritchie and he's dead. A reasonable guess is that [] were already taken for arrays. – Dirk Holsopple

@SomeKittens: Sorry, but the fact that you are curious about it doesn't make the question on topic here. As you can see from the answers nobody knows and it's just a discussion of options, what we mostly avoid on this site. – thorsten müller

@thorstenmüller MichaelT makes good observations though, and that looks almost like an answer. I'm not experienced enough on programmers.se to judge what is on topic but it looks like an interesting question to me. – dystroy

Voting to close. See Are programming-related history/trivia questions acceptable on P.SE? That, along with the fact that this doesn't seem to be related to a real problem, makes this off topic and not constructive. – Caleb

@SomeKittens It's still difficult to see how this is an actual problem. If you find reaching for the shift key tiring, there's no shortage of software on any major platform to help you remap your keyboard. Indeed, one has to wonder why you're looking to change what you type to suit your (archaic) keyboard rather than changing your keyboard to suit what you type. But I don't think that's a terribly constructive question either -- just do whatever suits you. – Caleb

6
  • 6
    I like the question, and think the top answer makes it a great history question for this site. Can you unlock it so I can vote to reopen it? :)
    – Rachel
    Feb 26, 2013 at 21:19
  • @Rachel as far as I can tell, the lock is temporary ("timed locks"). I expect it to time out and go away auto-magically
    – gnat
    Feb 26, 2013 at 21:33
  • 1
    @Rachel The question will be locked to let the community discuss the question. If the community reaches a decision before the lock expires, I (or one of the other mods) can unlock it sooner. Otherwise, we have a week to talk about it and figure out if it's good.
    – Thomas Owens Mod
    Feb 26, 2013 at 22:11
  • 3
    @Rachel A great answer doesn't make the question great. A great answer will probably save a closed question from getting deleted, but that's about it. If the question was crap to begin with, it remains crap even with one or more great answers. And just to not be misunderstood, I am not saying the question in question is crap.
    – yannis
    Feb 27, 2013 at 1:00
  • 3
    I find it odd that the nay-sayers on the post can be so sure of their correctness. You're sure Dennis Ritchie is the only one who knows? Maybe he told someone, or wrote it down. You're sure there are no real answers actually exist? You're sure it's not constructive? This type of absolutism just doesn't compute for me.
    – Daniel B
    Feb 27, 2013 at 6:26
  • My cursory take: it doesn't need to be deleted, but it doesn't need to be reopened either. Save the trivia questions for Yahoo Answers. The topicality of [history] questions is not really relevant here. Feb 27, 2013 at 21:19

5 Answers 5

5

Voting to close. See Are programming-related history/trivia questions acceptable on P.SE? That, along with the fact that this doesn't seem to be related to a real problem, makes this off topic and not constructive. – Caleb

The history of questions has had a confused history in Programmers.SE. Closing because this is a history question based on one particular meta post may not capture the full scope of the history tag's history.


One of the earlier meta posts about history (September '10): How can historical questions be on topic? - with very few votes at the time (top voted answer has two as of this writing), there was no great consensus. There were two yes and two no.

One of the yes answers reads:

Yes. In general I don't see any reason why questions on programming history should not be acceptable here.

(That said, if the answer is simple enough to be found on a wikipedia page, I would possibly question it's merit from that perspective, but that would have to be judged on a case by case basis)


From July '11 Are programming-related history/trivia questions acceptable on P.SE?

The accepted answer by user8 (site moderator back then) reads

Any question that's trivia, by definition, would be any that ask about unimportant (i.e. trivial) facts and matters. Those would be prohibited and should be closed as not constructive:

You should only ask practical, answerable questions based on actual problems that you face. Chatty, open-ended questions diminish the usefulness of our site and push other questions off the front page.

That said, a question stops being trivia the moment an actual, solvable problem is defined: that is, if one tells us why you want to know X or how knowing X solves Y problem, the question is a whole lot more constructive.

This question includes a follow up comment:

I think it can be justifiable in some cases; for example in the foo/bar example, indicating that you keep seeing foo and bar in code you're looking at and wish to understand more about it is not that fundamentally different than indicating you keep seeing some particular coding technique in code you're looking at and wish to understand more about it. – Jeff Atwood♦ Jul 30 '11 at 6:43


In March of 2012, a question of a specific history question was raised in meta - Is the question about statements being terminated by semicolons appropriate for Programmers?

There is lots of text and comments which should be read to get the full scope of the post. It does have some useful quotes in referencing a chat from user2334 (aka user8).

Save for the accepted answer, I thought the semicolons question was pretty good. Programming history has always been an overlooked aspect of Programmers's scope.


More recently, in May of 2012, there was a contest that included a week dedicated to history questions.


Tangentially, word origin questions have had some meta posts. Most recently (Feb '13), Are word origin questions on-topic?


Examining my own votes on the various questions and opinions, I've been inconsistent in my opinions of history and origin questions. However, if I was to try to find a common thread to this it can be seen in a recent chat message:

The biggest problem that I perceive with it is a lack of research / utility. That is a difficult thing to fix.

@SomeKittens "Why" questions are especially challenging for historical things - that unless one is able to find documentation to state it one way or another, it is mostly speculation. Speculation can have a multitude of answers, all of which equally correct in speculation. That is difficult to fit into the SE Q&A format.

Questions that are likely to become speculation or don't demonstrate sufficient research (despite the interesting topic) I frown upon, while ones that show that they can be answered substantially should be open. I'd be fast to close and fast to reopen to let someone try to answer it substantially.

Closing because it is a history question I don't see as a justifiable reason.

4
  • Just to clarify...what is your stance on this particular question?
    – Thomas Owens Mod
    Feb 27, 2013 at 0:31
  • 3
    @ThomasOwens It is disappointing that there wasn't more research done by the asker initially. The disappointment isn't sufficient reason to close it. Its historical nature isn't reason to close it either.
    – user40980
    Feb 27, 2013 at 0:36
  • 1
    @MichaelT: The disappointment isn't sufficient reason to close it. -- Yes, it is. Feb 27, 2013 at 21:15
  • 3
    @RobertHarvey Some day, I would like to believe that the quality of writing and research done in a question meets the expectations I have. The realist in me says that this is unlikely to happen. I am disappointed with most questions (browsing the perl tag on SO is painful in the extreme), but most questions shouldn't be closed. My approval or disapproval alone is a poor metric to base closure on. Other factors need to be considered and as mentioned, this is a question that is conflicting - poor initial research but I know there was a real answer could be identified with sufficient searching.
    – user40980
    Feb 27, 2013 at 21:35
5

My answer to Yannis' question on historical questions led me to the conclusion that the braces question should be opened back up. I didn't start out intending to create a response for this question, but that's what happened.

Short version - the braces question has several similar characteristics as other historical questions that have provided some great answers. Those other questions are open, so logic would dictate we open the braces question.

However, I'm still not comfortable with two aspects of this conclusion.

  1. It doesn't make a distinction about other special characters. Lundin's answer in this question raises some very good points regarding the slippery slope this can present.

  2. The determination about "is this a good question" is relying upon an a posteriori determination which I'm not comfortable with for a number of reasons. I cling to the belief that a question should be determinable as "good for SE" by the question alone and not rely upon the answers.

2

It is a bad question because there is not necessarily any rationale behind the '{'.

When there is one, how likely is it that it is of great interest for the programming community? (One such answer could be "it was inherited from B that inherited it from BPCL, a language which has barely ever been used in the real world" etc etc)

And when there is no rationale, the only answer possible is a speculation. And there is likely no practical use of such knowledge either. If you know why { was used for blocks in C, how will that make you a better programmer?

You can take any aspect of the language and ask pointless questions in the same manner. Why is # used for the preprocessor? Why is ! used for logical NOT? Why is ^ used for XOR? And there you go, an endless flood of meaningless questions.

I think this falls under the "too broad" category, because most answers are likely going to be of a philosophical nature.

7
  • question (in its current form) certainly lacks references that would support an assumption that curly braces are somehow special. It could at least refer reader to Wikipedia article List of C-based programming languages and its statement "Broadly speaking, C-family languages are those that use C-like block syntax (including curly braces to begin and end the block)."
    – gnat
    Feb 27, 2013 at 14:28
  • @gnat This is a bit off-topic, but I don't quite see how a reference to a Wiki link, that in turn contains no links to any form of authority on the subject, adds any weight or value to the question.
    – user29079
    Feb 27, 2013 at 14:43
  • I do not insist that adding it would salvage the question, merely point that your answer made me understand that lack of justification why curly braces could be special compared to # ^ ! is a problem that would certainly make me vote to close the question. Whether justification would be sufficiently compelling to deal with this is a different matter, I need to think it through some more...
    – gnat
    Feb 27, 2013 at 15:11
  • 1
    For # for cpp (or @ for objective c) there are real design decisions that were made - that the character currently had no place in the language and thus prefixing a token with the character insulates it from future changes to the base language. Real language design decisions are based on this which can make it a practical question (even if just curious for the asker). Understanding that some decisions were arbitrary and others were thought out to address particular reasons. "Those who do not know history are condemned to repeat it" or something like that...
    – user40980
    Feb 27, 2013 at 16:14
  • I disagree . How do you know for certainty that there was no rational behind creating '{' ? Maybe there was some rational behind making the choices at that time. Maybe there was some rationale it was just not documented well. Unless you were part of that team that created that language how can you possible know such things ?
    – minusSeven
    Feb 28, 2013 at 12:59
  • @minusSeven I had a college class in compiler and language design that went over some of the decisions in languages. I've researched the history of some myself. And this one showed that it was an arbitrary shorthand that likely made its way into a language influenced by the language using that shorthand. That is a valid answer. One doesn't need the diary of Kernigan to show the chains of thought
    – user40980
    Feb 28, 2013 at 14:44
  • @MichaelT what about editing the question to add a sufficiently compelling justification for why it is substantial (not idle curiousity) and specific enough to show it's not too broad (to prevent NARQ)? Since question is currently locked, justification can be drafted right here, at Meta - and serve as a base to request moderators to unlock the question for editing. I did something like that in the past (Jon Lord FTW), works like a charm
    – gnat
    Feb 28, 2013 at 17:25
2

There is a whole group of people I call "ego voters" who have a basic philosophy that if they can't personally think of a good answer, it must be a bad question, that askers magically "should know" beforehand if there's any particular significance to a programming tradition or not, and that if there doesn't happen to be any particular significance, that information isn't worth knowing.

Even seemingly inane information can potentially improve a design. I'm reminded of How the width of a horse's butt determined the size of the space shuttle. This story is popular among engineers primarily because it humorously illustrates how some design constraints evolve out of seeming nonsense. However, to the guy who designs the next generation shuttle, not knowing the story could significantly impact their design for the worse. They might manufacture their parts on site, or ship by air or sea, and be artificially limiting the width of their design without being aware of the reasons why.

I see that artificially limited thinking all the time among software developers. A certain design principle was important in C, then gets passed from mentor to mentor until someone is doing it in a language where it doesn't matter. He has no idea why, but still defends the principle as gospel. They're letting a proverbial horse's butt dictate their software design for no good reason.

So what does that have to do with curly braces? Well, there might be some huge significance to them, based on lambda calculus or something. Or there might be no significance at all, besides there only being three kinds of braces on the keyboard and the other two were already taken. Either way, the asker cannot reasonably know before he poses the question, and even if there is no significance, you never know when you might be breaking an obsolete paradigm for the person who designs the next great programming language.

In summary, don't let the horse butts win :-)

4
  • 3
    I cannot disagree more with this. Your first paragraph is idle speculation; your second paragraph is a straw man which merely illustrates that some things are the way they are simply because they are. Not knowing whether or not a question might have significant answers cannot be used as justification to give sweeping permission for folks to ask trivial, bikeshed questions on the off-chance that someone might have a profound, meaningful answer to them. Feb 27, 2013 at 21:25
  • 2
    In the end, the OP is still going to have to use braces in his programs. Feb 27, 2013 at 21:32
  • +1 so true . You hit the nail in the head !
    – minusSeven
    Feb 28, 2013 at 16:49
  • 1
    I have a lot of trouble with the concept of deciding that a question is not answerable and using that as a reason to prevent posting of answers. Mar 1, 2013 at 3:21
2

I generally dislike "Why did/nt X do Y" type questions, and vote to close them with a certain level of aggression. They are asking about motivation, which can be very difficult to 'prove'. While its certainly possible there is some cite, somewhere, that says Ritchie chose curly braces because they looked like the bookends on his office shelf, or because they use 20% less moonbeam energy than square brackets... the reality is most of the answers to questions like this end up being speculation.

2
  • 2
    Should one close all questions that garner poor answers then?
    – user40980
    Feb 27, 2013 at 20:30
  • @MichaelT regarding closing strange attractors of poor answers, well, as long as these cause freakin' broken collider formula bring more hotness lemmings than community can reasonable handle, this can be considered as sort of protection from a broken popularity scoring system. Remember the key point from Shirky's article you taught me about, "protect your own users from scale... human interaction... doesn't blow up like a balloon..." - doesn't it apply in cases like that?
    – gnat
    Feb 28, 2013 at 7:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .