Skip to main content
60 votes

Why do (or don't) languages forbid unreachable code?

Great question. I can tell you a bit about C# and why in C#, unreachable code is a warning, not an error. I'll start by briefly describing how reachability detection works, then what it is used for, ...
Eric Lippert's user avatar
  • 3,449
45 votes

Why do programming languages use the asterisk * for multiplication?

I believe the first language to use * for multiplication was FORTRAN, in its original specification in 1956 (with earlier drafts). None of the other symbols you ...
Michael Homer's user avatar
  • 13k
44 votes

Why do programming languages use the asterisk * for multiplication?

The other answers have covered the first uses of * in programming languages. To these I will add that the asterisk has been used as a symbol for multiplication in ...
kaya3's user avatar
  • 19.7k
43 votes
Accepted

Why did JavaScript choose to include a void operator?

The most compelling reason for having it in the language, seems to be for its use in javascript: URLs, such as in the href ...
kaya3's user avatar
  • 19.7k
39 votes

Why does MATLAB have left division/solve?

Non-commutativity of multiplication a/b calculates $a \cdot b^{-1}$, whereas b\a calculates $b^{-1} \cdot a$. Since matrix ...
xigoi's user avatar
  • 1,007
35 votes

Why do programming languages use the asterisk * for multiplication?

The fundamental reason is because neither true multiplication symbols × nor were (or are) common on US keyboards. Using ...
Jack Aidley's user avatar
34 votes
Accepted

Why do programming languages use the asterisk * for multiplication?

Maybe FORTRAN, maybe MATH-MATIC FORTRAN's Preliminary Report in 1954 anticipated using the × symbol for multiplication (and ×× ...
Pseudonym's user avatar
  • 4,726
29 votes

Why do (or don't) languages forbid unreachable code?

Because it's not uncommon to create unreachable code deliberately. Sometimes it's just temporary during incremental development, sometimes it's permanent. For instance, you might have code like ...
Barmar's user avatar
  • 1,901
26 votes
Accepted

Why does Haskell use the bind operation instead of Kleisli composition?

The original reason monads were introduced in Haskell was to implement I/O. This answer of mine discusses many of the details of that usage, including the way things are implemented internally. ...
Alexis King's user avatar
  • 8,721
20 votes
Accepted

What language was the first to treat null checks as smart casts to non-nullable types?

I don't think this design is as new as you're expecting, though practical languages designed from the beginning with this purpose in mind are more recent. For example, in 2002's Declaring and Checking ...
Michael Homer's user avatar
  • 13k
17 votes

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

One pass compilation C was originally (and, as far as I know, still is) designed to allow for one pass compilation. This means you tokenize, parse, and output, all in one pass, never building an ...
blueberry's user avatar
  • 2,465
14 votes

Why do (or don't) languages forbid unreachable code?

In languages that have a preprocessor, templates or macros, unreachable code often occurs without being an issue: Configuration options checked with #ifdef can ...
jpa's user avatar
  • 389
13 votes

Why does Haskell use the bind operation instead of Kleisli composition?

Two examples: Consider do notation: do a <- f x b <- g a h b This desugars to: ...
blueberry's user avatar
  • 2,465
10 votes

Why does MATLAB have left division/solve?

Solving linear systems is better than inverting The main reason is the one in xigoi's answer, noncommutativity, but let me add that a separate operator is handy to have for matrix operations: ...
Federico Poloni's user avatar
9 votes
Accepted

Why does C++ require private methods to be declared with public ones?

As also explained by the other answer, all member variables need to be declared in the header, because by themself all types in C++ are value types. This implies that the compiler needs to know their ...
chrysante's user avatar
  • 778
6 votes

The history of "finally" in exception handling?

This probably isn't a complete answer, but Microsoft introduced a nonstandard __finally mechanism in their Structured Exception Handling feature. It's a feature of ...
Greg Hewgill's user avatar
6 votes

Earliest implementation of pattern matching as a programming language feature

The SNOBOL series of languages were developed between 1962 and 1967. Pattern matching is one of its basic operations, and patterns are a first-class data type. There were other string-processing ...
Barmar's user avatar
  • 1,901
6 votes

Why did Objective-C remove `NSZone`?

Something else which should be mentioned is that Objective-C objects and methods suffer from overhead, because objects are reference counted and methods are dynamic (every call is a lookup) among ...
tarzh's user avatar
  • 3,924
6 votes

Why did Objective-C remove `NSZone`?

Someone thought it was a good idea, maybe it even was a good idea 30 years ago, and now it isn't anymore. That happens. In modern Objective-C, you just allocate memory, and it is either allocated ...
gnasher729's user avatar
6 votes

What prevented fopen() from utilizing macros/flags but not fseek()?

I agree that this API choice of using strings instead of some form of more structured data is maybe not great. But your question is about why should we expect a difference between these designs? For <...
Eric Lippert's user avatar
  • 3,449
5 votes

Why does C++ require private methods to be declared with public ones?

The private attributes may effect the position of public attributes. If you have a class like this: class A { public: int a; } Here, ...
mousetail's user avatar
  • 8,349
5 votes

The history of "finally" in exception handling?

MDL in 1977 The MDL Primer and Manual (PDF) from 1977 documents UNWIND. MDL is a slightly unusual variant of Lisp. Page 150, 16.6 ...
Rainer Joswig's user avatar
5 votes
Accepted

What is the difference between JS's map and Python's dictionary?

Background: I was an implementer of Microsoft's JScript engine in the 1990s and for a time a member of the ECMAScript technical committee. And if so, why they aren't called the same? Given that JS is ...
Eric Lippert's user avatar
  • 3,449
4 votes

Why do (or don't) languages forbid unreachable code?

I'll come at this from a primarily C perspective. In general, determining reachability is undecidable; however, that doesn't stop compilers from applying rules which can statically detect some but ...
bta's user avatar
  • 171
3 votes

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

In languages which require that all variable declarations within a code block start with a recognizable reserved word, and requires that initialization expressions be compile-time constants, a ...
supercat's user avatar
  • 1,812
3 votes

Why do programming languages use the asterisk * for multiplication?

FORTRAN I Based on some quick research, it appears that FORTRAN I was the first language to use * for multiplication. You can see a sample of FORTRAN I code here, ...
blueberry's user avatar
  • 2,465
2 votes

Why does Haskell use the bind operation instead of Kleisli composition?

All the above are neat answers. Just to add to the understanding of the importance of bind associativity and especially blueberry's answer, this article helped me understanding why bind is important ...
Gergely's user avatar
  • 363
2 votes

What is the difference between JS's map and Python's dictionary?

Python dicts and JavaScript Maps are broadly equivalent in role, though the APIs and precise capabilities do differ. The semantics of iteration, key identity, and various additional methods differ, ...
Michael Homer's user avatar
  • 13k
1 vote

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

There is a syntax for declaration, and a syntax for statement. In old C versions the contents of a block was zero or more declarations, followed by zero or more statements. In newer C versions it’s ...
gnasher729's user avatar
1 vote

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

It makes stack management easier, because you do stack layout and then you do other things in the body, but you do not have to deal with changing the stack layout in the middle of a function. This ...
feldentm's user avatar
  • 1,779

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