Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Could Dart use this solution, which Python uses and Oil shell now uses?

This works well for Python, because the following causes IndentationError:

    x = 1
      + 2
In a language without significant indentation, would this be two statements, an assignment and a separate unary `+` expression? Is that OK?

If not, one possible solution would be to disallow arbitrary expression statements. AFAIK this is what Go does.

> JavaScript has some weird rules, the common gotcha seems to be `return \n {...}`

Disallowing expression statements also fixes this particular example, but it doesn't solve the `return` problem in general. It's not practical to disallow standalone function calls, so `return \n f()` still has the same issue.

Lua solves this by enforcing that a `return` must be the last statement in a block.



> It's not practical to disallow standalone function calls

If your language structurally differentiated procedures (i.e., void-returning functions) from (other) functions, it would be practical to disallow standalone functions (not procedures), though you might have a modifier to explicitly discard the result of a function that allows it to be standalone.


> you might have a modifier to explicitly discard the result of a function that allows it to be standalone.

ocaml does this and i find it very annoying, even though i know it's theoretically saving me from accidentally not consuming a return value.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: