This is a question that's been on my mind for a while. Recently I've been checking out concurrent languages like Haskell or Go or Erlang.
From my point of view, they have huge benefit in performance as opposed to languages like C++ or Python because of the way they handle functions in parallel.
My question is: Why is the syntax for languages like C++ or Python so much different (and IMO simpler) from those of concurrent languages, even though most concurrent languages are executed on runtime (and therefore they have more possibility in simplifying the syntax)?
Here is an example, consider Go's sqrt
:
// Package newmath is a trivial example package.
package newmath
// Sqrt returns an approximation to the square root of x.
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * z)
}
return z
}
Now for the Python counterpart (ported this myself based on the Sqrt
example from Go):
def Sqrt(x):
z = 1.0
for i in Range(0, 1000):
z -= (z*z-x/2*z)
return z
Now as you can see go has a syntax like ":=" for assignment, If you take a more complicated examples, the syntax will look more like what I am trying to point out.
And Go is just the least "weird-looking" language. If you consider Erlang it's looking even weirder:
%% qsort:qsort(List)
%% Sort a list of items
-module(qsort). % This is the file 'qsort.erl'
-export([qsort/1]). % A function 'qsort' with 1 parameter is exported (no type, no name)
qsort([]) -> []; % If the list [] is empty, return an empty list (nothing to sort)
qsort([Pivot|Rest]) ->
% Compose recursively a list with 'Front' for all elements that should be before 'Pivot'
% then 'Pivot' then 'Back' for all elements that should be after 'Pivot'
qsort([Front || Front <- Rest, Front < Pivot])
++ [Pivot] ++
qsort([Back || Back <- Rest, Back >= Pivot]).
Parts that caught my eye were "++ [] ++", '<-' and '->'
I am convinced these languages look like this for a reason, but I can't help but think: Can't it be simpler? Why are concurrent languages like this? Why if they use a runtime like Python and JavaScript, are they still type-safe?
I know type-safe languages have an advantage of their own to not mix up variable types, but still, there's gotta be somebody who made a concurrent language that didn't have type-safety, if possible right?
It seems like almost all concurrent languages have one thing in common: a bigger list of possible / valid syntax.
I hope I've explained my question well enough.
x = y
never means "assign the value of y to x", it's a statement of equality.sqrt
andqsort
!