Opening as mentioned here: https://github.com/crystal-lang/crystal/issues/4372#issuecomment-298999533
I propose that we allow one-line defs, similar to what is done with abstract method definitions
# As used in abstract def
abstract def implement_me
# Also available in other types of method definitions
def initialize(@name : String)
This is a bit messy parser-wise.
Given the following:
def initialize(@x)
x = 1
is x = 1
supposed to be evaluated inside initialize
or at the class scope? Crystal wouldn't be able to know this at all without knowing whether or not there's an extra end
...somewhere. It's not indentation-sensitive, like Python is.
I do wish that we could just do def f end
without the semicolon, though...
Closing. Very unlikely to happen. The parser would have to recover on quirks (e.g. def
inside def
) and so on as @kirbyfan64 states. Is an end
keyword that ugly, noisy or boring to type (if not automagically inserted by your editor)?
I don't think it's that ugly, no. I just thought it might be better as one line, but I understand why it would be hard to do. Thanks for considering it
Most helpful comment
This is a bit messy parser-wise.
Given the following:
is
x = 1
supposed to be evaluated insideinitialize
or at the class scope? Crystal wouldn't be able to know this at all without knowing whether or not there's an extraend
...somewhere. It's not indentation-sensitive, like Python is.I do wish that we could just do
def f end
without the semicolon, though...