Skip to main content
254 votes
Accepted

Syntax Design - Why use parentheses when no arguments are passed?

For languages that use first-class functions, its quite common that the syntax of referring to a function is: a = object.functionName while the act of calling that function is: b = object....
Nathan Merrill's user avatar
157 votes
Accepted

Why do languages require parenthesis around expressions when used with "if" and "while"?

There needs to be some way of telling where the condition ends and the branch begins. There are many different ways of doing that. In some languages, there are no conditionals at all, e.g. in ...
Jörg W Mittag's user avatar
89 votes
Accepted

Why does the type go after the variable name in modern programming languages?

All of the languages you mentioned support type inference, which means the type is an optional part of the declaration in those languages because they're smart enough to fill it in themselves when you ...
Ixrec's user avatar
  • 27.6k
70 votes
Accepted

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility? Without explicit points where a ...
amon's user avatar
  • 135k
69 votes

Why do languages require parenthesis around expressions when used with "if" and "while"?

The parenthesis are only unnecessary if you use braces. if true ++ x; For example becomes ambiguous without them.
Telastyn's user avatar
  • 109k
65 votes

Syntax Design - Why use parentheses when no arguments are passed?

Indeed, Scala allows this, though there is a convention that is followed: if the method has side-effects, parentheses should be used anyway. As a compiler writer, I would find the guaranteed presence ...
Robert Harvey's user avatar
46 votes

Why does the type go after the variable name in modern programming languages?

Why in nearly all modern programming languages (Go, Rust, Kotlin, Swift, Scala, Nim, even Python last version) types always come after the variable declaration, and not before? Your premise is flawed ...
Jörg W Mittag's user avatar
43 votes

Why do most mainstream languages not support "x < y < z" syntax for 3-way Boolean comparisons?

Why is x < y < z not commonly available in programming languages? In this answer I conclude that although this construct is trivial to implement in a language's grammar and creates value for ...
Aaron Hall's user avatar
  • 5,943
41 votes
Accepted

Why do most mainstream languages not support "x < y < z" syntax for 3-way Boolean comparisons?

These are binary operators, which when chained, normally and naturally produce an abstract syntax tree like: When evaluated (which you do from the leaves up), this produces a boolean result from x &...
Karl Bielefeldt's user avatar
39 votes

Programming language where every function call/block is done in a separate thread?

every function call/new block (if clauses, loops etc) will work in a separate thread. Read a lot more about continuations and continuation-passing style (and their relation to threads or coroutines) ...
Basile Starynkevitch's user avatar
37 votes

Programming language where every function call/block is done in a separate thread?

You may be interested in reading about the research into data parallel Haskell. If you search around on youtube, Simon Peyton Jones has given some interesting talks related to the subject as well. ...
Karl Bielefeldt's user avatar
37 votes
Accepted

Is i,j = 1 really misleading?

I think not, but that's not the point. The point is that i, j = 0 is very easily mistaken for i = j = 0, which does initialize both. Clarity is the most important requirement on source code next to ...
Kilian Foth's user avatar
29 votes

One-liners vs. readability: when to stop reducing code?

No matter what code you write, readable is best. Short is second best. And readable usually means short enough so you can make sense of the code, well named identifiers, and adhering to the common ...
Greg Burghardt's user avatar
27 votes

Why don't programming languages automatically manage the synchronous/asynchronous problem?

What you are missing, is the purpose of async operations: They allow you to make use of your waiting time! If you turn an async operation, like requesting some resource from a server, into a ...
cmaster - reinstate monica's user avatar
22 votes

Syntax Design - Why use parentheses when no arguments are passed?

This is actually a pretty subtle fluke of syntax choices. I'll speak to functional languages, which are based on the typed lambda calculus. In said languages, every function has exactly one argument. ...
gardenhead's user avatar
  • 4,747
22 votes

Why do languages require parenthesis around expressions when used with "if" and "while"?

Parentheses in an if statement do not have the same meaning as parentheses used within an arithmetic expression. Parentheses in an arithmetic expression are used to group expressions together. ...
Robert Harvey's user avatar
19 votes

Is colon in python blocks technically necesary?

The colon is not really necessary grammatically, had Python been designed in a different world, it's quite conceivable that the language designer might not decide to require the colon. And indeed ...
Lie Ryan's user avatar
  • 12.4k
19 votes
Accepted

What makes some things easier to parse than others?

This topic is very complex. You can google for parser algorithms and you'll get plenty of detailed material. In general: The fewer ambiguities must be resolved, the faster the parsing process. The ...
marstato's user avatar
  • 4,628
19 votes
Accepted

C++ - explicitly prefixing every member with public/private

This is what is invariably going to happen sooner or later: class Foo { private: int x; private: int y; private: int z; int w; int q; public: int getX(); public: int setY(int val); public: void ...
whatsisname's user avatar
  • 27.7k
19 votes

Why don't languages use the words "and" and "or" instead of "&&" and "||"?

In short It's historical reasons. The long history Many older languages created between the 50's and the end of the 60's, as well as used the logical operators that you like such as not or and and:...
Christophe's user avatar
  • 78.4k
18 votes
Accepted

What does 'syntax vinegar' mean

"Syntactic sugar" is a common term for syntactic constructs added to a language primarily to make certain constructs easier or more pleasant to use. "Syntactic vinegar" is the opposite, making the ...
Dave Sherohman's user avatar
16 votes

Why do languages require parenthesis around expressions when used with "if" and "while"?

As other have already partially pointed out this is due to the fact that expressions are also valid statements, and in the case of a block with just one statement you can drop braces. This means that ...
Bakuriu's user avatar
  • 291
16 votes

One-liners vs. readability: when to stop reducing code?

I don't think you will get a better answer than "use your best judgement". In short you should strive for clarity rather than shortness. Often, the shortest code is also the clearest, but if you focus ...
JacquesB's user avatar
  • 59.8k
16 votes
Accepted

Logically, is there a reason why ++i++ can not be a valid expression?

You are misinterpreting GCC's error message: <source>:5:8: error: lvalue required as increment operand ++i++; ^ Note where the error message is pointing: the postfix++ part. ...
Nicol Bolas's user avatar
  • 11.9k
15 votes

Programming language where every function call/block is done in a separate thread?

This is exactly what Erlang does. It handles rejoining the threads mostly by using queues. It`s a brilliant concept but a bit difficult to wrap your head around initially if your background is more ...
GenericJam's user avatar
14 votes

Why do most mainstream languages not support "x < y < z" syntax for 3-way Boolean comparisons?

Computer languages try to define the smallest possible units and let you combine them. The smallest possible unit would be something like x < y which gives a boolean result. You may ask for a ...
gnasher729's user avatar
  • 45.9k
14 votes

Syntax Design - Why use parentheses when no arguments are passed?

In Javascript for instance using a method name without () returns the function itself without executing it. This way you can for instance pass the function as an argument to another method. In Java ...
Florian F's user avatar
  • 1,127
14 votes

C++ - explicitly prefixing every member with public/private

It's a bad idea. As you say yourself: [The traditional way] is the idiomatic style when reading and writing C++ code. Always use the style of least surprise. When somebody else reads your code, ...
Sjoerd's user avatar
  • 2,946
14 votes

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Some do. They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a ...
Telastyn's user avatar
  • 109k
14 votes
Accepted

Which was the first language to allow underscore in numeric literals?

In absence of an answer of David Arno, who first emitted the hypothese, here a summary of the findings. It appears that the first programming language that offered underscores as digit separator in ...
Christophe's user avatar
  • 78.4k

Only top scored, non community-wiki answers of a minimum length are eligible