Hope Julia can use some shorter key words!

I guess most programmers don’t want to type many words while fewer can make things clear.

So I highly suggest Julia directing board to use some shorter key words, for example the function(), could we just use fn() or even func()?
Could we not use the end key word for each block? The Fortran already abused me for a long time before, do I need to be abused again and forever with this new language?

I am not saying the syntax of the language should be too short to influence the clearity of the presentation, but those are really not necessary!!!

I hope Julia can do some changes, 1.2 version is not still too late to do these kinds of changes.

Hope my suggestion can be saw and seriously considered by the directing board!!

If you agree with my points, please say something here, lets’ make sure this suggestion can be seen by them! Thanks.

Here are my takes:

About function: You can use short-form function syntax f(x) = 2x if you want, and you can even do f(x) = begin #= 10000 lines... =# end or const f = x -> 2x (but please don’t do those things). Short keywords are cool but you’re talking about breaking literally all user code here.

About end: The alternative is whitespace-sensitivity? No thank you :upside_down_face:

15 Likes

well, white space sensitivity is not good, I agree, How about just use {}?

why prefer to conflate the iconography of type information
f(x::Vector{Int}, y::Union{Maybe, Int}) and blocks?

Julia software an unusually effective medium for collaboration and transferring understanding of and the proper use of domain specific solution methods. To compress the tokens would vitiate an easy clarity.

2 Likes

I totally disagree with this. Julia is just using English keywords, which are very easy to understand even for kids.
You can use TAB in your IDE (like Juno) or REPL to auto-complete the keywords.

You can create your own code snippet’s keywords in Juno. See this snippets that I added to my juno-toolbar-plus package for example:
https://github.com/aminya/juno-toolbar-plus/blob/538c9dc47085f15d34cdd12db5d6fc6384e1c4d2/snippets/julia_snippets.cson#L61

I used doce to quickly write a lot of code. You can do the same for anything.

11 Likes

At the beginning of my undergrad I found Python’s indentation rules and no ‘end’ keyword as something very elegant. Now I just find it clearer to use the end keyword. I also vote against.

Additionally, 1.2 is definitely too late to bring this kind of changes. If it were done, It could only be for a 2.0 release as this is definitely a breaking change.

edit: typo

17 Likes

Note that the bar is really, really high for changes in surface syntax at this point: because this would break all existing Julia code, the improvement would have to be huge. This is doubtful in this case, so a suggestion like this is most likely to be ignored.

12 Likes

Yeah, I agree!

Hi @LarkyJulia, I suggest spending a good bit of time working with the language before worrying too much about which parts need changing. I think that with experience you will find Julia has a lot of syntactic sugar which allows you to write very concise code. The short-form function syntax mentioned already is one such example but there are many others including uniform broadcasting syntax, multidimensional array comprehensions, custom string literals, fancy indexing, block-like closures (do syntax) etc etc.

10 Likes

Or, just have a look into this thread. It proves something of Julia which is quite adorable…

1 Like

This has to be the most warm and welcoming programming community. I really look upward all of you who had the patience to answer the new commer’s suggestion this constructively. Thank you. You are good human beings.

13 Likes

:grinning:Yes, Thank you everyone!!!

Technically, one does not actually ever need to use the function or end keywords in julia. For instance, here’s random chunk of julia code I had laying around which uses a wide range of language constructs:


function f(p=0,q=1)                  # define the function
    if rand() < 0.5                  # flip a coin. 
        if p < (q - 1)               # if the coin gives heads, check if p < (q - 1)
            while gcd(p+=1, q) != 1  # increment p while the greatest common divisor or p+1 and q is not equal to 1
            end             
            return f(p, q)           # recursively call f(p, q) (where p has been incremented)
        else
            return f(1, q+1)         # if p is not greater than q - 1, we recursively call f(1, q+1)
        end
    else
        return p//q                  # If the coin flip gives tails, we return the Rational number p//q
    end
end

let
    data = [f() for _ in 1:10_000_000]
    for frac in [(0//1), (1//2), (1//3), (2//3), (1//4), (3//4), (1//5), (2//5), (3//5), (4//5), (1//6), (5//6)]
        freq = count(x -> x == frac, data)/length(data)
        println("P($(frac)) ≈ $freq")
    end  
end 

Now here is me rewriting it without using function or end and I’ll let you be the judge of whether this is preferable:

eval(Expr(:macro, Expr(:call, :while, :cond, :body), :(nothing; esc(Expr(:while, cond, body)))))
eval(Expr(:macro, Expr(:call, :while, :cond       ), :(nothing; esc(Expr(:while, cond, nothing)))))
eval(Expr(:macro, Expr(:call, :for,   :iter, :body), :(nothing; esc(Expr(:for,   iter, body)))))

eval(Expr(:macro, Expr(:call, :let, :body), :(nothing; esc(Expr(:let, Expr(:block), body)))))

f(p=0,q=1) = 
    (rand() < 0.5 ?               # flip a coin. 
     (p < (q - 1) ?               #   if the coin gives heads, check if p < (q - 1)
      (@while(gcd(p+=1, q) != 1); #     increment p while the greatest common divisor or p+1 and q is not equal to 1          
       f(p, q))                   #     recursively call f(p, q) (where p has been incremented)
      : f(1, q+1))                #   if p is not greater than q - 1, we recursively call f(1, q+1)
     : p//q)                      # If the coin flip gives tails, we return the Rational number p//q

@let((data = (_ -> f()).(1:10_000_000);
      @for(frac = [(0//1), (1//2), (1//3), (2//3), (1//4), (3//4), (1//5), (2//5), (3//5), (4//5), (1//6), (5//6)],
           (freq = count(x -> x == frac, data)/length(data);
            println("P($(frac)) ≈ $freq")))))

The eval expressions at the beginning were for creating the macros @while, @for and @let which allowed me to create while, for and let blocks without using the end keyword.

If you don’t like the keywords while, for and let, you could call them @w, @f, and @l.

It should go without saying that writing this sort of code is not a good idea if you want to share it with or get help from anyone who doesn’t share your sensibilities, but I just wanted to demonstrate that this is actually not too hard to do in julia.

4 Likes

I like the fact that function is the keyword for introducing a function, and that end is the keyword for ending a block. Straightforward, explicit, simple :slight_smile:

13 Likes