4 ms·
The problem with Ruby isn't static typing per se, it is the terrible handling of `nil`. Ruby either has to make nil more evaluatable, or assure unexpected nils
by specialp 8y ago
The problem with Ruby isn't static typing per se, it is the terrible handling of `nil`. Ruby either has to make nil more evaluatable, or assure unexpected nils never come with options. For instance calling `each` on `nil` should have the effect of calling it on an empty enumerable like Clojure does would make it more evaluatable and stop the dreaded "No method found each on nilclass".
I've been programming in Ruby for 10 years and I have to say after writing Clojure for a bit I really enjoy the fact that nil behaves as an empty value, and is enumerable. It is not the purest CS interpretation of nil but it makes it way easier. If someone is really concerned to check to see if something is nil there is still .nil?
When have you had errors like Oh this is String [][]{} vs Int[][]{}? That kind of static typing gets in your way more than it saves you. Pretty much all my errors that would be saved with type checking involve nil and that could be handled as I stated above.
- wes-k 8y agoNot perfect, but ruby 2.3 introduces the safe navigation operator (&.), so you can do foo&.each or foo&.bar
- kwillets 8y agoI'm at best an intermediate-level rubyist, but I was quite surprised when more experienced people didn't recognize that operator after I started using it. It seems like one of the most significant upgrades. I got really into it and started using it with operators, eg num_objects&.> 0
- ezekg 8y agoI didn't even think of using it with operators. Awesome.
- freehunter 8y agoOh lord the number of lines of code I've had to put in to check for nil is unbelievable. Seriously my only complaint about Rails is handling nil.
- thirdsun 8y ago> For instance calling `each` on `nil` should have the effect of calling it on an empty enumerable And I thougt it was only me. I love Rails, but when I started learning it this was so confusing to me. Well, I understood what was happening, but I always expected an iteration or a method acting on nothing to simply return an empty result instead of an error.