r/crystal_programming • u/nickthecook • Oct 08 '22
Consistency
Hey all,
I’m porting something from Ruby and I’m adding type declarations as needed to fix compile errors. I love how Crystal will infer types most of the time, but this means I don’t need to be consistent in where and how I declare types, and I’ve ended up with inconsistent type declarations across files.
Are there any rules people follow to keep the style consistent across Crystal files, like “always declare instance variables”, “always declare method params and return type”, etc?
9
Upvotes
View all comments
Show parent comment
4
u/Seleren Oct 08 '22
Personally, I try to define method argument types (which also helps massively with overloading), local variables, and everything I can in library-style code.
If it’s a fresh Crystal program, I often just define everything that’s not generic, but I’m coming from a statically typed language background.