News for hackers. Stuff that matters.
Re:Elm for the Front End, Right Now by ggregoire on Wednesday November 23, 2016 @04:51PM (#13026054)
From what languages is Elm inspired? I've a Java/C#/PHP/JS background and I feel really uncomfortable with Elm syntax.
Re:Elm for the Front End, Right Now by agumonkey on Wednesday November 23, 2016 @05:31PM (#13026317)
Completely logical. Java, C, PHP are said to be algol descendants. In two words: curly braces. JS wasn't supposed to but ended up curly because social trends are that strong. Now imagine JS function being the only thing you use, then that language users and designers evolving a syntax for typed js-like functions, rince repeat, you get ML, Haskell, Elm.

In time your brain realigns, depending on how much you appreciate the functional style or not.

Re:Elm for the Front End, Right Now by striking on Wednesday November 23, 2016 @06:29PM (#13026667)
Not quite. ALGOL doesn't have curly braces, just BEGIN and END blocks.

  BEGIN
  FILE F (KIND=REMOTE);
  EBCDIC ARRAY E [0:11];
  REPLACE E BY "HELLO WORLD!";
  WHILE TRUE DO
    BEGIN
    WRITE (F, *, E);
    END;
  END.
I've heard it said that the languages you mentioned are inspired by C's syntax.
Re:Elm for the Front End, Right Now by agumonkey on Wednesday November 23, 2016 @06:38PM (#13026706)
Wow, couldn't be more wrong. It's indeed C family (BCPL, B). Thanks a lot for the note.
Re:Elm for the Front End, Right Now by mikekchar on Wednesday November 23, 2016 @07:36PM (#13026988)
Well, I wouldn't be so hard on yourself. IIRC (and I hope someone corrects me if I'm wrong), algol introduced block scoping. Whether you use BEGIN/END or {/} I think is a pretty minor point.

C has braces to introduce a new scope. The irony is that JS (until recently) didn't have block scope. It just has braces :-).

Now this is where it gets screwy. You are supposed to (but don't have to usually) add a semi-colon on the end of each statement in Javascript.

a = 52;

This has a semi colon because it is a statement. There is another construct called an expression. An expression is anything that can evaluate to a value. An statement can be an expression (the statement "a = 52;" is an example of that because it also evaluates to 52 and is thus an expression). But there are expressions that are not statements. Here is an example of an expression

(5 * 27)

It evaluates to a value, but doesn't do anything so it is not a statement. Usually in computer languages, if "statements" are actually expressions. So you can say

if (1>0) {"Yay"} else {"Boo"}

evaluates to a value ("Yay" in this case), but doesn't do anything in and of itself. The blocks in the braces may contain statements, but the if is an expression, not a statement. Note the lack of semi-colon. Again, presumably because it is an expression, not a statement.

You can try the above in Node and it will indeed return the value "Yay".

a = if(1>0) {"Yay"} else {"Nay"};

In this case the variable a should be assigned the value "Yay", because the if expression evaluates to a "Yay". For some strange reason (that I don't understand), Javascript (or at least Node, when I tried it) does not accept that. It gives you a syntax error. You can not use if "statements" as expressions in Javascript (which sucks quite a bit).

All of this to say that Javascript appears broken to me, no matter what geneology you assign to it :-D. I personally really like programming in JS (or actually CS), but it is a beast unto itself, I think.

I'd welcome comments illuminating this issue if I've made a mistake with the above! As I said, it's easy to do.

Re:Elm for the Front End, Right Now by agumonkey on Wednesday November 23, 2016 @07:54PM (#13027052)
True but my algol mention was strongly on syntax not semantics (big part of algol contribution).
Re:Elm for the Front End, Right Now by fnovd on Wednesday November 23, 2016 @08:35PM (#13027268)
>You can not use if "statements" as expressions in Javascript (which sucks quite a bit).

It does indeed, and it leads to some ugly code:

a = function() { if(1>0) { return "Yay" } else { return "Nay" } }()

Re:Elm for the Front End, Right Now by ziad-saab on Wednesday November 23, 2016 @09:27PM (#13027532)
You can also write:

a = 1 > 0 ? "Yay" : "Nay"

Re:Elm for the Front End, Right Now by redtuesday on Wednesday November 23, 2016 @05:06PM (#13026156)
Because I really like syntax like Haskell (the type signature is much clearer especially in generic code compared to Java or Scala etc. for example), I'm curious, what is so uncomfortable about the syntax?
Re:Elm for the Front End, Right Now by skybrian on Wednesday November 23, 2016 @05:22PM (#13026260)
The lack of parentheses around function calls makes it hard for people not familiar with ML-style languages to tell where the function calls are and what the arguments are to each function call.

There is a wide variety of syntax among mainstream languages, but basic function calls are pretty much all the same.

Take a look at Reason [1] for an example of how a functional language (OCaml in this case) can be made more familiar.

[1] https://facebook.github.io/reason/

Re:Elm for the Front End, Right Now by eastWestMath on Wednesday November 23, 2016 @05:37PM (#13026360)
Or maybe people could just become familiar with ML-style languages? The basic syntax shouldn't take more than an hour or two to pick up.
Re:Elm for the Front End, Right Now by skybrian on Wednesday November 23, 2016 @06:00PM (#13026487)
Well sure, but you could say the same thing about Lisp.
Re:Elm for the Front End, Right Now by eastWestMath on Wednesday November 23, 2016 @08:00PM (#13027084)
Well they're both the lambda calculus, Lisp just had parentheses.
Re:Elm for the Front End, Right Now by kazinator on Wednesday November 23, 2016 @08:22PM (#13027188)
Does lambda calculus have character strings, structures, exceptions, symbols, mutable variables, quoting code as data, macros and three different kinds of object equality?
Re:Elm for the Front End, Right Now by fbreduc on Wednesday November 23, 2016 @09:59PM (#13027667)
it does have symbols
Re:Elm for the Front End, Right Now by kazinator on Thursday November 24, 2016 @01:45PM (#13032011)
Does it really?

Some of the algorithms for reducing lambda expressions are symbolic, like, say, alpha reduction. But they are not done in lambda calculus itself, as far as I can see; they are done on lambda calculus (by the mathematician, or a machine for manipulating lambda calculus terms).

Analogy: just like ordinary algebra doesn't have symbols; but of course mathematicians work with symbols and so do computer algebra systems.

Since lambda calculus is Turing complete, it can of course represent lambda calculus manipulation (via Goedel numbering of lambda terms and then working with their arithmetic encoding as Church numerals, or whatever).

Re:Elm for the Front End, Right Now by ungzd on Thursday November 24, 2016 @07:46AM (#13030018)
Ruby has optional parentheses around function parameters (usually it's recommended to avoid parentheses if possible). Shells have no parentheses around command arguments. These languages are mainstream and no one complains about this.
Re:Elm for the Front End, Right Now by kazinator on Wednesday November 23, 2016 @08:24PM (#13027206)
Of course, if we adjust "mainstream" so that it refers to that set of languages which have pass-by-value, strictly evaluated arguments, with no implicit currying, then your point is nearly self-evident. :)
Re:Elm for the Front End, Right Now by redtuesday on Wednesday November 23, 2016 @06:33PM (#13026686)
Yes, I agree, that took me also some time to get used to when I dabbled with Haskell and I looked at more complex programs.
Re:Elm for the Front End, Right Now by salimmadjd on Wednesday November 23, 2016 @05:10PM (#13026184)
when I spoke with Evan (you can usually meet him at the Elm SF meetup) I believe he said Elm was inspired more by OCaml than Haskell. But since many people might have heard of Haskell more than OCaml, Haskell is a better general answer.
Re:Elm for the Front End, Right Now by kinkdr on Wednesday November 23, 2016 @07:38PM (#13026993)
The syntax is closer to Haskell than Ocaml.

Foe example types in Ocaml usually start with lower letter.

Also Elm has "Maybe", just like Haskell, instead of "option" of Ocaml.

Also in Elm, like in Haskell you would write "List Sometype", while in Ocaml it is "sometype list".

Re:Elm for the Front End, Right Now by masklinn on Thursday November 24, 2016 @10:40AM (#13030844)
Yeah the syntax is clearly Haskell, the semantics are more ML-ish.
Re:Elm for the Front End, Right Now by botexpert on Wednesday November 23, 2016 @04:51PM (#13026058)
Haskell, ML langs.
Re:Elm for the Front End, Right Now by bbcbasic on Wednesday November 23, 2016 @05:19PM (#13026248)
Haskell but is very reminiscent of F# with the >> amd |> operators (which I prefer to . amd $). Although you could name them that in Haskell too.
Re:Elm for the Front End, Right Now by jmcdiesel on Wednesday November 23, 2016 @05:04PM (#13026142)
Yeah, it seems like a step back in readability... It's not at all intuitive and once I figure out what its doing, I can't find a reason for it.. Lisps are hard to read, but there are at least a few reasons for the syntax (not that i like them) ... This just seems... weird and unusual for no reason...
Re:Elm for the Front End, Right Now by cnp on Wednesday November 23, 2016 @05:38PM (#13026365)
Have you spent much time with it? Like all things, you need to learn before you understand, and then it becomes clear.
Re:Elm for the Front End, Right Now by Latty on Wednesday November 23, 2016 @06:34PM (#13026691)
I've written a fair amount of Elm, and I still find it awkward. One issue is that I feel like I end up having to go back and add in brackets more than I would with the C-style syntax. I'm not sure if that's just the way I think thanks to being used to that, or an inherent problem.

The main issue really is that I think it's harder to read, as it's less clear what is being used where. The explicitness of the C-style makes it easier to see what goes where.

Re:Elm for the Front End, Right Now by jmcdiesel on Thursday November 24, 2016 @12:24AM (#13028363)
Thats kinda the point... with the vast array of languages out there, that are performant and powerful and very well established, why should anyone suffer through the learning curve? what value does the language offer to make that worth the effort?
Re:Elm for the Front End, Right Now by eastWestMath on Thursday November 24, 2016 @01:59AM (#13028717)
Well, evaluation in these languages is more transparent. The syntax is basically the lambda calculus, so once you've actually learned the language it makes a huge difference. I'd try reading up on "referential transparency".
Re:Elm for the Front End, Right Now by notduncansmith on Wednesday November 23, 2016 @05:13PM (#13026211)
One thing that can help with the discomfort is thinking about it as patterns. The = operator isn't for assignment, it's an assertion of equality. Reading the docs carefully helps immerse you in the syntax as well.
Re:Elm for the Front End, Right Now by kinkdr on Wednesday November 23, 2016 @04:51PM (#13026060)
Haskell
Re:Elm for the Front End, Right Now by q3r3qr3q on Wednesday November 23, 2016 @05:51PM (#13026436)
Yikes, you should branch out more.