
Nice syntax – Popular languages' syntaxes compared - areknawo
https://areknawo.com/nice-syntax-popular-languages-syntaxes/
======
c3534l
I find it really annoying that the author would write code in C#, C++, and
JavaScript differently even when the languages share the same syntax for that
area. For instance, even when the languages shared the same syntax for do-
while, in some versions he would write the while condition on a separate line
and others not.

I'm also not sure what Python is doing in there. It's not a very C-like
language. And if he wanted to show the diversity of different ways of doing
things, he seemed to have gone out of his way to only showcase a family of
languages that are unusually similar to each other (apart from Python).

Additionally, the comparisons fail to actually show where the languages are
different or the same. He claims that C# only has 3 types of loops: do, do
while, and for. Then he compares that to Python which he claims only has two:
for and while. The problem is that Python's for loop is actually C#s foreach
loop. This would actually be a very good way to illustrate that Python loops
are conceptually different from those in other languages and how generators
are built into Python. But he ignores that, while also ignoring other Python
constructions which are pretty unique to Python as a language. As far as I
know, C# doesn't have anything equivalent to Python's while-else or for-else
loops. I might go so far as to say that the information provided about loops
in these languages is incorrect.

My last criticism is that if we're meant to compare these snippets of code, it
would have been much more readable had they actually been placed side-by-side,
rather than lay out everything vertically.

------
mdhughes
This is using Python 2, which is end-of-lifed. Those bare print statements are
gauche. Python does have a variable keyword, `global`.

While JavaScript _can_ omit semicolons, it's an incredibly bad idea outside of
console/Node REPL. In particular it'll merge adjacent closures or constants,
and you'll have an incredible time trying to find that error. Semicolon
everything.

The arrow function as ()=>{} is clearer and less likely to suck up adjacent
terms.

There's no point in even showing C#, since it's just Java with the
capitalization swapped. Go, as well, but at least it's slightly different.

OP should learn some languages which aren't just FORTRAN-with-C-syntax, like
Scheme (or any LISP), Haskell, ML, etc.

------
Someone
If you like this, I think you’ll like [http://rigaux.org/language-
study/syntax-across-languages.htm...](http://rigaux.org/language-study/syntax-
across-languages.html) more.

~~~
phaedryx
Thanks for sharing; I found it more interesting than the article.

------
saagarjha
This article fails to bring up a couple of points I thought might be useful,
particularly when talking about C++ and Java. In particular:

* Talking about the C++ type system without mentioning templates is selling the language short.

* Both Java and C++ have some form of type deduction in newer versions of the language.

* Both Java and C++ have for loops that work on collections.

------
andyidsinga
This reminded me of language / library attributes that I've been delighted by
over the years ...here's a few:

C :

\- function pointers combined with structs.

\- Ability to use pointers to go anywhere on the machines address space (think
embedded, kernel code etc) and muck with registers, shared memory etc.

C++ :

\- smart pointers - shared_ptr and friends. I'm not a big C++ fan in general
but when I learned about smart pointers I was really impressed.

Java :

\- interfaces - after treading around C++ objects in the 90s, interfaces were
a dream

\- 'Runnable' interface and Thread class coupled with any object's wait(),
notify() and notifyAll() methods.

\- generics

Javascript :

\- async / await ..once I figured out how this worked i was really impressed.

\- object literal syntax. (Perl hashes were also pretty delightful years
before - but not quite as much as JS)

Python:

\- Iterators and the litany of looping and ranging constructs.

------
infinity0
[http://hyperpolyglot.org/](http://hyperpolyglot.org/)

------
barskern
This is a minor nitpick but I feel that the usage of the arrow function in
Javascript was overly verbose.

Instead of:

    
    
      const add = (a, b) => {
        return a + b;
      }
    
    

It could be written as:

    
    
      const add = (a, b) => a + b
    
    

Or functions can also easily be turned into curried functions by doing:

    
    
      const add = a => b => a + b
    
    

Which can be really powerful when used properly.

I felt it was worth mentioning, but I understand that the goal of the article
was not to provide a in-depth comparison.

------
pmoriarty
I've got to say that none of those are nice, because none of those are Lisp.

