Don’t know if appropriate create this thread here, anyway, i am quite newbie for crystal, and still learning, following is some confusing things(and maybe improvement advice) for now.
- i consider following code should not a valid syntax.
# a blank space added between new with left parenthesis
SomeClass.new ("String") # this is bad, i propose this is a invalid syntax.
SomeClass.new("String") # this is good
Anyway, unified format is better (as go), we don’t want to write another rubocop
for crystal, just for change those bad syntax habit, right?
- getter :name, should not accept symbol as argument, we prefer to use only one form(as python) to do same things, right?
getter :name # => bad
getter name # => good
- What the
Int
in the method parameter type stand for?
# following code just work
def fact(n : Int) : Int32
p typeof(n)
if n < 0
puts "n must be positive!"
exit
end
n == 0 ? 1 : n * fact(n - 1)
end
# But follow declare not work.
x : Int; # => can't use Int as the type of variable yet, use a more specific type
i am so curious, why we can use Int as a alias
for Int32 in parameter, but, can not use
it for declare, and in fact, change to following code not work too.
def fact(n : Int) : Int
p typeof(n)
if n < 0
puts "n must be positive!"
exit
end
n == 0 ? 1 : n * fact(n - 1) # no overload matches 'Int32#*' with type Int
- This more like a question, for curious, what is the real type of the tuple key? why we can visit the value correctly use both String or Symbol?
foo = {aaa: 100} # => what is the key type?
p foo["aaa"] # => 100
p foo[:aaa] # => 100
- because
crystal run "$@"
is the default ofcrystal "$@"
,
e.g.
$: crystal run test.cr
$: crystal test.cr # same as above
There is almost no arguments supported when use crystal without sub command, except -h and -v, so, can we pass all arguments of crystal run --??
to crystal --??
?
e.g.
$: crystal run test.cr --error-trace # this work
$: crystal test.cr --error-trace # this not work, --error-trace was ignored
Showing last frame. Use --error-trace for full trace.
...
Error ...
Thank you.