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: n + 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 + (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 + 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: n + 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:
Prolog:
X is 4+8.
Characters needed to add n digits: At least n + (n-1) + 4
Declarative nature
LikeLike
Great! I have never tried prolog, do you use it a lot?
LikeLike
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.
LikeLike
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?
LikeLike
Python: 1 + 2
Just like JavaScript. Added Con for both:
* If the order of evaluation might matter, you better know it.
Added Con for Python:
* You better know how types interact and which types result, because 2/3. = 0.6666666666666666, but 2/3 = 0
LikeLike
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)
LikeLike
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!
LikeLike
APL:
+/1 2 3 4
n + 2
LikeLike
Thanks! I find the / operator interesting however it is quite similar to Scheme as they both follow the prefix notation.
LikeLike
Scala in the REPL is “1+2” will be in category 2. Outside the REPL, it’ll be category 3.
LikeLike
Cool! I guess it should have its own distinct category then; maybe 2.5? :)
LikeLike
The fan kicks on and the lights dim either way. Maybe we should measure in watts instead of lines of code.
LikeLike
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
ADD R1, #2 !! add a 2 to register 1
Of course, this assumes you can then make use of the result out of R1, rather than having to spend more cycles moving it somewhere.
LikeLike