Skip to main content
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
  • 13.1k
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
  • 20k
40 votes
Accepted

Why is array access not an infix operator?

The answer to "why" questions is often partly historical - unless there is a good reason to be different, following existing conventions helps limit a new language's "strangeness budget&...
IMSoP's user avatar
  • 2,458
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,991
31 votes
Accepted

Why do relational comparison operators never short-circuit?

The saving is rare The benefit of short-circuiting is that you don't have to compute the second operand. But there is only one value the first operand can have where short-circuiting is possible ─ ...
kaya3's user avatar
  • 20k
31 votes

Why is array access not an infix operator?

There are a couple of arguments in favour of the x[y] syntax for arrays, over an infix operator. One is that we want array access to bind the left operand more ...
kaya3's user avatar
  • 20k
21 votes

Why is array access not an infix operator?

it is, sometimes In Haskell, array access is the binary operator !!. In APL, one of the ways of doing array access is the dyadic function ...
RubenVerg's user avatar
  • 1,641
20 votes
Accepted

What are the syntax options for implementing a ternary "if" operator?

Here are some options (including the ones you mentioned): C-family languages (e.g., C, C++, Java, JavaScript): Syntax: condition ? ifTrue : ifFalse Advantage: ...
The Thonnu's user avatar
  • 1,528
19 votes

What syntax could be used to implement both an exponentiation operator and XOR?

Demote xor Unless you're in C or a similarly low-level language, you're not going to be doing a lot of bit-level manipulation. So the bitwise operations really don't need to be using up those juicy ...
Silvio Mayolo's user avatar
18 votes

Why add an increment/decrement operator when compound assignments exist?

While x += 1 may be replaced by ++x, x++ is special in that it is essentially temp = x, x += 1, temp. I am making a C-like which ...
Nuoji's user avatar
  • 1,115
17 votes
Accepted

Why are expressions in languages so prone to integer overflow?

Overflow checking has a (small) cost The hardware will always overflow. It doesn't care. In order to check if an overflow happened, you need extra instructions (typically just a single ...
Rydwolf Programs's user avatar
16 votes

What syntax could be used to implement both an exponentiation operator and XOR?

Double star Many languages have a ** operator for exponentiation. This is reasonably intuitive, as exponentiation is just the hyperoperation after multiplication. <...
CPlus's user avatar
  • 8,513
16 votes

What syntax could be used to implement both an exponentiation operator and XOR?

I think most of the problem comes from functions being in the form op(a, b), which is verbose and doesn't read well when expressions get complicated. So why not use ...
BoppreH's user avatar
  • 1,441
15 votes

Prior art on pipelines of function calls

There are several different traditions for this in real-world languages. Many of them have colonised previously-unused punctuation, rather than having a strong design ethos to them. The semantics also ...
Michael Homer's user avatar
  • 13.1k
14 votes

Advantages/disavantages of including the comma operator?

The benefit of the comma operator is that it allows you to include a sub-expression for its side-effects only. In languages without a comma operator, there are often ways around this ─ suppose ...
kaya3's user avatar
  • 20k
14 votes
Accepted

Ternary operators other than ?:

Wikipedia lists the following ones, which I let here operate on arguments a, b and c: The ...
Glorfindel's user avatar
  • 1,503
14 votes

Why add an increment/decrement operator when compound assignments exist?

C isn't a language that comes with fancy iteration constructs like foreach or map. This means programmers need to increment ...
Eldritch Conundrum's user avatar
13 votes

What are the syntax options for implementing a ternary "if" operator?

There's always the Smalltalk postfix form. result = condition ifTrue: [ ... ] ifFalse: [ ... ]. This has the benefit of not even being special syntax. It's just an ...
Silvio Mayolo's user avatar
13 votes
Accepted

What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?

I wouldn't store them as arrays, but you can certainly implement such a syntax efficiently. If you translate x[0] to x & 1 ...
ruarq's user avatar
  • 146
13 votes
Accepted

Unambiguous syntax for a ternary comparison operator

There are several plausible approaches here, some of which work with the ambiguity and some sidestep it entirely. Some imply significant semantic choices about the language more broadly. A function, ...
Michael Homer's user avatar
  • 13.1k
12 votes

What alternatives are there for C++ operator overloading syntax?

Using names instead To rectify this problem, you can use names instead of symbols for the names of operator functions. For example, take a look at Kotlin: ...
Seggan's user avatar
  • 2,743
12 votes
Accepted

What alternatives are there for C++ operator overloading syntax?

Rust-style traits In Rust, operator overloading is implemented using core traits built into the language, which allow the operators to be named, without conflicting with methods which have the same ...
Rydwolf Programs's user avatar
12 votes

Why add an increment/decrement operator when compound assignments exist?

The ++ and -- operators aren't really necessary. There are languages that get along just fine with ...
dan04's user avatar
  • 1,969
12 votes
Accepted

How do you correctly compile the chained comparison operators like ones that exist in Python (`a < b < c`), if `b` might have side-effects?

The trite answer is that if evaluating b twice is wrong, then it should only be evaluated once... Disclaimer: I don't know AEC, so I'm going to make up syntax. ...
Matthieu M.'s user avatar
  • 3,133
11 votes
Accepted

Distinguishing modulo (Euclidean division) from remainder

Given the usefulness of a proper modulo operator to wrap an integer into a range [0, n) e.g. for an array index or generating a random integer in this range, I find ...
kaya3's user avatar
  • 20k
11 votes

What are pros/cons of ternary conditional operators?

Pro: Readability While plenty of people talk about the readability problems with misused ternary operators, there are also situations where using a full if/...
Rydwolf Programs's user avatar
11 votes

What are the downsides of supporting chained comparison operators?

One thing I think Python got wrong in this regard, is that they made this work with too many "comparison operations". Sure, x < y < z is common to ...
kaya3's user avatar
  • 20k
11 votes

Why add an increment/decrement operator when compound assignments exist?

(Yes, I'm writing another answer to this question.) Sometimes i++ really is what you need. Here's an example where it shines. Consider the following code fragment: <...
Eldritch Conundrum's user avatar

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