
Why do programming languages use curly braces? - RKoutnik
http://programmers.stackexchange.com/q/188455/54164
======
jgrahamc
_and why not something more reasonable, like [], which doesn't require the
shift key at least on US keyboards_

The OP is assuming the current US keyboard layout. C was developed on the
PDP-11 which would likely have used a DECwriter II for the keyboard/output.

On that keyboard [ ] are on the same key (non-shift is [, shift is ]). Thus [
] were not 'easier' on it. Similarly, { } were on the same key with non-shift
being { and shift being }.

C's predecessor BCPL used { } although it was developed on a machine without a
keyboard and so typing those characters was just as easy as any other
character. The developer might have had access to an IBM card punch with a
keyboard but the keyboards on those were odd (IBM layout) with no [] or {} and
$( was used in place of {.

~~~
limmeau
On German (and I think also Dutch) keyboards, {} are on AltGr-7 and 0, which
is a pain to type (and the reason why I switch every computer to US keyboard).
I wonder if that's why Python uses indentation and not braces for blocks...

~~~
sjmulder
Dutch people use US International layout keyboards almost exclusively (@ above
2). The Dutch layout (# above 2) is very very rare.

~~~
walshemj
Out of interest how do dutch keyboards handle the IJ

~~~
Someone
Typically: not. Historically, I don't think there were character sets that had
it as a character. Unicode nowadays has it, but discourages its use.

<http://www.unicode.org/versions/Unicode6.1.0/ch07.pdf>: _"Another pair of
characters, U+0133 latin small ligature ij and its uppercase version, was
provided to support the digraph “ij” in Dutch, often termed a “ligature” in
discussions of Dutch orthography. When adding intercharacter spacing for line
justification, the “ij” is kept as a unit, and the space between the i and j
does not increase. In titlecasing, both the i and the j are uppercased, as in
the word “IJsselmeer.” Using a single code point might sim- plify software
support for such features; however, because a vast amount of Dutch data is
encoded without this digraph character, under most circumstances one will
encounter an <i, j> sequence."_

But don't take my word for it; I used Google to see what a Dutch keyboard
layout is supposed to look like because I don't think I have ever seen one in
real life.

There were typewriters with a ij ligature. That makes sense because that is
about the worst kerning pair you can get in a monospaced font (but as a
monospaced ligature, it is fairly tight with those large vertical stretches
both at the left and at the right)

------
cgrubb
Features of BCPL (Martin Richards, 1967):

    
    
      * used { } instead of BEGIN and END keywords
      * single type called WORD
      * declared variables with LET
      * used // style comments like C++
    

Features of B (Ken Thompson, 1969):

    
    
      * used = instead of := for assignment
      * variables could be declared AUTO or STATIC
      * semicolons as statement terminators
      * ++ and -- incrementors/decrementors in prefix and postfix position
    

Features of early C (Dennis Ritchie, 1970)

    
    
      * two types: int and char
      * struct introduced in 1973
      * /* */ style comments from PL/I
      * && and || operators with short-cut semantics

~~~
pjmlp
Sadly proper arrays and strings were left somehow along the way.

~~~
kps
BCPL vectors seem to be the same as C arrays, no?

dmr wrote at <http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.html> that “C was
invented in part to provide a plausible way of dealing with characters when
one begins with a word-oriented language. [...] BCPL later found a solution
better, on its own terms, by providing an operator (%) analogous to its !,
such that v%i designates the i-th character in a vector. However, the earliest
BCPL applications tended not to process packed characters in vectors, but to
spread them out early into one character per word, process, and then pack them
again if necessary.”

~~~
pjmlp
I meant about the design decision to ignore what other system programming
languages were already offering on those days.

Algol and PL/I already offered what I consider proper arrays and string types.

The performance argument about bounds checking is stupid, because any proper
compiler offered the possibility to disable bounds checking for code regions.

Sadly the decision taken was another one with the security consequences
everyone was to endure with software written in C. At least C++ offers a way
out for the developers that embrace STL and similar libraries.

------
pmelendez
[Slightly off topic] It's just me or now a lot of very interesting threads in
SO are being closed as "not constructive"

Should we start to looking for a place to start this kind of discussion
without lose the Q&A format? Reddit and HN might work but just a few of 'Ask
HN' posts actually make the front page and, in my opinion, answers on Reddit
don't have the same quality in comparison with SO.

~~~
manaskarekar
Simple answer: [http://meta.stackoverflow.com/questions/110350/why-are-
usefu...](http://meta.stackoverflow.com/questions/110350/why-are-useful-
questions-on-stackoverflow-being-closed-as-non-constructive)

Not a fan of this myself. When there is a pool of thousands of smart people
who are willing to answer in a certain format, hundreds of thousands who are
looking to read those answers in that format, outright banning that format is
a little unfortunate in my opinion.

If you want to maintain a certain style for SO, then perhaps there's some
outlet for these "discussion format" style questions on there that could be
marked as such.

To disallow smart people from solving problems because they don't adhere to
one strict format is a tragedy.

~~~
jiayo
They already split off "programmers" from the main StackOverflow site to
address this exact issue, and history is repeating itself. Now it seems we
need individual sites for programmers-offtopic, programmers-trivia,
programmers-history. Make those, and as time goes by, each one will be
moderated more and more heavily until they form their own spinoffs.

~~~
rtkwe
It's spin offs all the way down.

------
lelandbatey
This is _very much_ a side comment, but I've noticed that there are a lot of
these kinds of questions on StackExchange, but it seems like a lot of them are
closed (this one was closed within an hour of it being opened) because they
don't fit within the goals of StackExchange.

My question is: is there somewhere else where these kinds of questions (not
totally on topic but still relevant to what programmers do) can be asked? I'd
love to see more of them!

~~~
thoughtpalette
<http://programmers.stackexchange.com/>

"This is a collaboratively edited question and answer site for professional
programmers interested in conceptual questions about software development."

~~~
smackfu
You would think, but the same question was closed there as Not Constructive:

[http://programmers.stackexchange.com/questions/188455/why-
do...](http://programmers.stackexchange.com/questions/188455/why-do-
programming-languages-especially-c-use-curly-braces-and-not-square-ones)

Very common on StackExcahnge. A bunch of high rep users swoop in and close
questions that don't meet this weeks version of the rules that were decided in
the Meta site that only the high rep users read. It reminds me a lot of
Wikipedia.

~~~
Turing_Machine
It reminds me a lot of any human organization that develops a "manager" class.
There are a lot of people whose goals in life have more to do with controlling
what other people do and making sure that the rules are followed, rather than
contributing actual work.

You can see the process on a small scale with homeowner's associations.

(I put "manager" in quotes because there _are_ good managers out there. Oddly,
they're often the ones who are willing to break the rules when they don't make
sense).

------
k3n
Tokens of a bygone era.

I wish more languages were like Python and didn't require so many cruft
characters.

~~~
cobrausn
The first time I ran into the spaces vs. tab problem I wanted my curly braces
back.

~~~
k3n
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.

~~~
tobiasu
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.

~~~
pekk
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.

------
buster
I always wonder why so many languages are sooo bad to use on a non-us
keyboard.. I'd love if language designers would consider other keyboard
layouts more often.. :(

~~~
dlitvakb
Most programmers often write their programs in english anyway, to be easy to
share or to review by others (even in closed source software), so it makes
sense for programming languages to mostly care about English keyboard layouts.

Anyways, if the keyboard layout is a blocking problem for you, consider
changing it to what it suits you the best, or use multiple layouts for
different tasks. Every operating system has a keystroke to swap layouts.

~~~
buster
It's not about writing english per se. How often do you need to write {[]}<>
in a letter?

Those keys are really easy on US layout but horrible to type on a german
keyboard layout. Holding alt-gr and press 7 or 8 or 9 or 0 is surely not
impossible to type but compared to US layout it's much more worse, imo.

Fortunately Python does away with the overabundance of curly braces at least.

~~~
TylerE
Why is Alt+9/0 so much worse than Shift+[/]

 _slightly_ worse I'll grant, but MUCH worse?

~~~
ygra
It's AltGr, which is on the right side. And that makes it quite awkward to
use. I either break half my hand or need both hands. Or resort to Ctrl+Alt on
the left side which isn't optimal either ...

~~~
buster
Wow.. now i'm wondering how quickly (if ever) i can adopt to using ctrl+alt
instead of that awkward (and hated) AltGr. You never stop learning...

~~~
TylerE
Couldn't you remap your keys so normal (left) Alt is AltGr and right Alt is
"normal" Alt? Alt key bindings are pretty rare.

~~~
ygra
They are? Every time I want to access a menu or a control in a dialog by
keyboard I need Alt. Also in Far Alt+typing searches which I use frequently to
get around the file system. Sure, one could get used to doing that with the
other hand, but at least for me it's not that little muscle memory that has to
be retrained.

~~~
TylerE
Really? Every program I've ever used uses Ctrl as the primary modifier.

~~~
ygra
Shortcuts, yes. Access keys, no.

------
Thrall
I sometimes wonder why languages use sequences like "->". This is clearly
meant to represent an arrow, so why has noone ever taken the time to make sure
an arrow character is defined, make sure it's possible to type it in most
keyboard maps and use it in programming languages.

It can't be because physical keyboards wouldn't have the key, because my
keyboard doesn't display a # symbol, but that is widely used.

I can only guess that the character sets and "what characters are easy to type
into a computer" became standardised early on, and no individual language has
been able to push such a change (Early in development a language has few
users, thus no influence; Later in development, the language has been using
"->" itself for a while, so it's less easy to change).

Also, proper languages like lisp use parentheses (), not curly braces. :p

~~~
kps
Several early programming systems did use custom character sets (custom type
bars) as well as typewriter-oriented notations like overstrikes, half-line
motions for superscripts (powers) and subscripts (indexes), and colour (red
half of the ribbon for comments)¹. Except for APL, which had IBM behind it,
these tended not to escape their original research environments.

Relatively large-scale production required I/O devices to share a common
character set. These tended to be based on pre-computer character sets
(teletypes, punched cards) and were limited in size both by the I/O devices
and by storage requirements (don't forget how small and expensive memories
were). A lot of work went into choosing character sets.²³⁴

1963 ASCII had an up arrow ‘↑’ dropped in 1967 in favour of ^ (because
furriners wanted accents), and a left arrow ‘←’ dropped in favour of ‘_’.⁵⁶

¹Jean Sammet, _Programming Languages: History and Fundamentals_ 978-0137299881
²Charles E. MacKenzie, _Coded Character Sets: History and Development_
978-0201144604 ³<http://www.trailing-edge.com/~bobbemer/SURVEY.HTM> ⁴R W
Bemer, _Design of an improved transmission/data processing code_
<http://dx.doi.org/10.1145/366532.366538 > ⁵ _American Standard Code for
Information Interchange_
<http://www.wps.com/projects/codes/X3.4-1963/index.html > ⁶ _Revised U.S.A.
Standard Code for Information Interchange_
<http://www.wps.com/J/codes/Revised-ASCII/index.html >

------
dangoldin
A meta comment: It's pretty awesome that we're already having lore discussions
about our craft 50 years later. I wonder what they'll be discussing in a 100
years about our languages now and why certain decisions were made.

~~~
pjmlp
We will discussing how it was possible that C could endure for so many years
delaying the use of safer languages for systems programming along the line of
Modula-2 and Ada.

~~~
alan_cx
Modula-2 ????????

Is that serious language then? We learned that back at University when I was
doing my CS degree. Other students were scathing about it, going on about why
we weren't doing C. But it was used as a simple introduction to programming
techniques to prepare for C, Java etc. I understood its value back then as an
introduction, but I never realise it had a use beyond that. I have to say, I
quite enjoyed using it, and I was a little disappointed to move way from it to
"proper" languages at the time.

So, it is used in anger, as it were, now? If so, what can it be used for? Part
of me would love to pick it up again for something vaguely serious.

~~~
pjmlp
It used to be a serious language back in the day (up to early 90's).

The Lillith operating system was written in it. A fully working operating
system with what could be considered a kind of GUI environment on those days.

It was used at Zurich's university and a few others around the world.

You can have a look at it here:

<http://www.youtube.com/watch?v=ob0lznzkykc> (Lilith Comdex Demo)
<http://weblog.hansotten.com/?p=490> (Emulator)
<http://www.modulaware.com/mdlt52.htm> (Some background history)

There were a few companies selling commercial Modula-2 compilers like Garden's
Point and Excelsior. There was a UNIX system that had it as part of their
compiler suite, I cannot remember which one now.

It failed to fully replace Pascal, because eventually Mac/Turbo Pascal came
along and most Pascal compilers had extensions that made them compatible with
Mac/Turbo Pascal. Since those Pascal extensions were similar to what Modula-2
offered and many companies already had an investment in Pascal code, many kept
using Pascal instead of moving into Modula-2.

When UNIX gained much of the space in the enterprise world, C was the language
to use if you didn't want to justify why you were using something else, so
that was like the final nail in Modula-2's coffin.

It is very hard for a systems programming language to gain market share if it
isn't the official language used by the operating system's vendor.

The language is quite powerful, when compared with C, with the added benefit
of proper modules, strings and arrays. Not the pointer everywhere from C which
leads to security exploits by design, so to speak.

Its time has passed, now a proper replacement would be something like Oberon,
when looking at Wirth's family of languages. You can use it to program
embedded systems, <http://www.astrobe.com/default.htm>.

------
calinet6
Well... why not?

\--Edit: No, seriously, why not? There are only a few different opening-
closing character pairs on a keyboard: [], (), <>, {}, /\, etc. It's not
_that_ different to type any of them.

So why is this even a question? It's because we used the others up and that
was next on the list, and it looks somewhat logical as a container of things.
So again, wholly and completely, the answer is in the question: "why not?"

~~~
jonascopenhagen
Because on non-English keyboards curly braces are a pain to type. E.g. in
Danish it requires Alt + Shift + 8 (on a Mac), and if you look at the comments
above you'll see that the problem is the same for many other languages.

------
restlessmedia
I wonder what percentage of questions with the highest hit rate on SO and SE
have "closed as not constructive by x" on them.

My 3 groats here says lots.

------
dragonwriter
> and why not something more reasonable, like [], which doesn't require the
> shift key at least on US keyboards

[] are used for indexing, which is probably used more. So regardless of the
historical reason, it makes sense to use something visually distinct for
blocks.

------
abecedarius
Smalltalk uses [] for blocks, and somehow it just looks jagged and unpleasant
to read, to me: [[[]]] doesn't nest nicely like ((())) or {{{}}}. I don't
propose this as an explanation of anything; but I'm glad it isn't [].

------
DodgyEggplant
The "what question is interesting enough to reach HN front page so we can
close it" watch is alert and active, thank you

