Keeping the syntax and the need to memorise syntax simple

I think most IDEs, and even simpler editors, take care of some of these already. To take your examples: In VS Code, Atom, Sublime etc. <cmd+/> toggles line comment, for any language supported by the editor. You should also have a for snippet that expands on tab by just typing for. And many more.

Check out snippets in your favourite editor. Some are already there, and you can add others. I particularly like snippets in LaTeX, which is so full of boilerplate.

BTW: What’s up with the flagging of some posts in here? It doesn’t seem like anything is in violation of guidelines, right?

4 Likes

Yeah, the posts are just fine — the flags were erroneously applied by an overzealous spam-catcher bot and immediately dismissed.

8 Likes

Different languages target different use cases so it makes sense that their syntax is not the same. Also, with fixed templates, innovation is harder and one can not improve upon mistakes made in the past, catch up to changing times etc.

I think in most places, Julia does use syntax that is also used by at least a few other languages, but maybe not each individuals favourite language.

2 Likes

We keep excruciatingly detailed institutional history, in the form of the git commit log and issues: https://github.com/JuliaLang/julia. There’s a lot of it, but that’s how much thought and effort has gone into the language you get. Explaining all the design decisions that have gone into Julia would take more time and energy than anyone has to spend. The manual does some of this explaining already.

9 Likes

I personally find the assignment operator <- in R to be far more offensive than any Julia syntax. Period.

17 Likes

@mthelm85: That operator is EXACTLY why I stopped using R. Python’s syntax was a relief, but Python is too slow. Matlab is expensive. So Julia was something I was really looking forward to…until I saw some of the syntax :slight_smile: I had been considering posting this topic for many months, and finally did so. Glad to see that many of y’all share the same opinion.

1 Like

Maybe I’m misunderstanding your conclusion there, but Julia has nicest syntax of any language I’ve seen, with only a few minor blemishes (I never liked where {T}). For example, I prefer the current syntax to the ones proposed in the OP.

12 Likes

Julia definitely has the nicest syntax I have ever seen; it uses my favourite keyword end to terminate blocks, so you don’t have to use curly braces, and yet don’t have to rely on the abomination that is syntactic indentation. This is in common with Ruby, another language I really like.

It uses -> to define function, which is awesome, because that is how you write functions in math (and with a font such as Fira Code or the smoking hot JuliaMono -> and other digrams are turned into ligatures that makes your code look even more like math).

Parametric functions (which is called generics in Java and templates in C++) are fantastically transparent and nice in Julia; since e.g. C++ templates are Turing complete, there is no end to how awesome/horrifying your code can get (and I actually like(d) C++). Compiler errors due to C++ templates are magnificent (in a horrible way). Julia compiler errors due to parametric types are verbose (less so in 1.5), but always logical.

(EDIT: I should note that of course, no programming language has better syntax than LISP, but that’s because LISP does not have a syntax :stuck_out_tongue:, since you program the abstract syntax tree directly.)

11 Likes

I actually like the <- assignment operator.

Consider the following Julia code:

julia> x, y = 1, 2;

julia> z = x == y
false

Which of the following do you think is easier to understand?

z = x == y

or

z <- x == y

?

At some point I suggested allowing the use of for assignment; this is common in computer science texts.

I agree that it is clearer, in that it avoids overloading the meaning of the “=” sign.

A nice alternative would be :=.

8 Likes

Yes, that is definitely a nice feature of the arrow assignment. It clarifies the difference between equality and variable assignment. If you try to read the statement x = x + 1 as a mathematical statement, it makes no sense.

Another nice thing is that in R you can also use -> for assignment. This can be handy in a pipe:

c(4, 7, 3) %>% sort %>% rev -> x
1 Like

That is almost nice – except for the horrible %>%

9 Likes

I really dislike <- for assignment, it just looks like the wrong kind of operator, like it does something completely different.

:= would be fantastic, it’s just right. Anyway, too late now, I’m just glad it’s not <-.

3 Likes

Perhaps an unintended side effect is that mutability is not the first thing engineered into methods. Often it’s nice to have stuff be immutable. Just a reason why pop! is good syntax.

4 Likes

fortunately you can just use = and it works fine in basically all cases

2 Likes

Sorry, can you clarify, an unintended side effect of what?

The first one. = is the assignment operator in almost every lang, while <- is very esoteric and makes me feel there might be some magic going on. Also, the readable way to write that is z = (x == y). Not following good style can make any syntax hard to read.

Now that we are on hacking Julia to type less, is there a way to call a function without () or @ (i.e., no macro call either)? A zero-arg operator kind of thing. It’s nice for impure functions that don’t need input, and don’t need to be passed around as an object themselves.

I’m not sure what’s so esoteric about a left arrow, but oh well, I guess I can’t convince people to like arrow assignment.

The point is that if you use the arrow for assignment, then you don’t need the parentheses to clarify the syntax.

No, that’s impossible – how would Julia know to distinguish between “the function f” and “the result of calling the function f”? There has to be some indication in the syntax.

1 Like