Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a question that\'s been on my mind for a while. Recently I\'ve been chec

ID: 647247 • Letter: T

Question

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.

Explanation / Answer

You're a little confused about terminology and what factors are relevant, as people mentioned in the comments. Let me just address the syntax of Erlang, which is a functional language.

It has more operators because it does more. It needs a ++ because it was already using + for something else. It uses ++ instead of a word like concat because the language was intended to favor conciseness. For example, the code:

[Front || Front <- Rest, Front < Pivot]
Requires the following code in C++ (copied from here):

int partition(int* input, int p, int r)
{
int pivot = input[r];

while ( p < r )
{
while ( input[p] < pivot )
p++;

while ( input[r] > pivot )
r--;

if ( input[p] == input[r] )
p++;
else if ( p < r )
{
int tmp = input[p];
input[p] = input[r];
input[r] = tmp;
}
}

return r;
}
Although the same code in python using list comprehensions is just barely longer:

[front for front in rest if front < pivot]
Because of immutability and lack of side effects in functional programming, certain methods of processing lists have been adopted which make it easier. This includes pattern matching and destructuring. You might want to do some research on those, but my point is in order to gain the expressiveness and conciseness that things like pattern matching provide, you have to accept more complexity in your syntax.

Also keep in mind that C++ and python seem more natural largely because you learned them first. If you had learned erlang first, then C++ and python's syntax would seem limiting and excessively verbose.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote