Hacker News new | ask | show | jobs
by stabbles 1057 days ago
> Python arguments are evaluated when the function definition is encountered

This is a giant pain. Easy to miss. Sometimes forces you to deal with Optional[Something] instead of just Something.

Compare with Julia where default arguments are evaluated ... very late:

    julia> f(a, b, c, d = a * b * c) = d
    f (generic function with 2 methods)
    
    julia> f("hello", " ", "world")
    "hello world"
that's really neat.
1 comments

Probably one of the benefits I gained from writing JavaScript before ES5 (although have worked with many languages, I've only used a few that were dynamic - PHP, JS, and old VB). I write my functions as early as possible, having remembered hoisting rules from JavaScript (and trying to only rely on OOP with Python where it naturally makes sense).

Looking at your Julia example, this seems much more friendly and less surprise and error-prone.