# How to add in programming languages

This is a tongue-in-cheek attempt to expose programming language expressiveness.

## 1. Scheme

```(+ 1 2)
(+ 1 2 3 4)
```
• Characters needed to add n digits: + 3
• Prefix notation allows passing in multiple operands
• Prefix notation is not popular

## 2. JavaScript/Python/Ruby/Octave/Matlab

```1 + 2
```
• Characters needed to add n digits: + (n – 1)
• Very simple and generally accepted
• Infix form requires two operands leading to (n – 1) operators

## 3. Java/C#

```// CSharp
class Program
{
static void Main(string[] args)
{
Console.WriteLine(1 + 2);
}
}
```
• Characters needed to add n digits: N (where N is a largeeeeeeee number :) )
• Too verbose – you need a class to add two numbers

## 4. SQL

```SELECT 1 + 2;
```
• Characters needed to add n digits: + 8
• Simple but not popular
• Declarative nature can impact clarity

Do you know of any other language examples? Feel free to share in the comments!

Here are a couple of other posts you might also like:

## 13 thoughts on “How to add in programming languages”

1. Prolog:
X is 4+8.
Characters needed to add n digits: At least n + (n-1) + 4
Declarative nature

Like

2. Ralph Trickey says:

Forth would be 2 1 + for 2 numbers and 2 1 3 + + or 2 1 + 3 + for 3 numbers. Each operation pops x operands and returns the result pushed onto the stack like the old HP calculators. I haven’t used it in years. It’s a stack oriented programming language.

Like

1. Interesting, never heard about stack-oriented programming. I found out that Factor is touted as Forth’s replacement; do you do a lot of programming in FORTH?

Like

3. Baribal says:

Python: 1 + 2
Just like JavaScript. Added Con for both:
* If the order of evaluation might matter, you better know it.
* You better know how types interact and which types result, because 2/3. = 0.6666666666666666, but 2/3 = 0

Like

4. Paul Childs says:

The differences are largely according to infix, prefix, or postfix. The latter two were come upon as a way to avoid having to use parentheses. The LISP family of (scheme is one of it’s descendants) use prefix (also known as polish) notation as well as a few others like Tcl. Makes it sound a lot like the Celtic and Semitic languages (VSO). The postfix form (SOV) is like the turkic languages and postscript is probably the most commonly known example.
Lets not forget about adding using boolean gates, which is happening behind the scenes:
sum=1^2^c
c’=(1&2)^((1^2)&c)

Like

1. Brilliant insight Paul!

I absolutely love the way you related this to real human languages and the the subject-object-verb placements. I love languages too but didn’t think of this connection.

Yes most of the differences come from the infix, prefix and postfix notation and there are a other of syntax changes too. All the same, great feedback!

Like

1. Thanks! I find the / operator interesting however it is quite similar to Scheme as they both follow the prefix notation.

Like

5. Scala in the REPL is “1+2” will be in category 2. Outside the REPL, it’ll be category 3.

Like

1. The fan kicks on and the lights dim either way. Maybe we should measure in watts instead of lines of code.

Like

6. I haven’t done assembler in so long I forget the details, but in some simulated variety of assembler:

MOV R1, #1 !! store a 1 in register 1