Principles of least surprise (or astonishment), is one of cornerstones of Ruby. However, the language itself is dynamic, so take the end result with a pinch of salt: The language's OO syntax is beautifully simple, incredibly easy to structure into classes/mixins and have tons of useful libraries, to write code with. Not always so much for reading code, refactoring or discerning what REALLY goes on in a Rails application..
Re:Principle of Least Astonishment
by gregkerzhner on Monday April 06, 2020 @04:44PM
(#22797658)
I think there is a great middle line for a language that is easy to work with, and provides enough safety to be maintainable for a long time. Environments like C++ and enterprise Java miss this middle line by being too cumbersome. However, Ruby equally misses this middle line, just in the other direction - it's too simple and dynamic leading to lack of maintainability in the long run. The best solution will be somewhere in between.
In my opinion, Kotlin, C#, and TypeScript all come pretty close.
My pet-peeve in ruby:
'//'.split('/') # => [] instead of ['', '', '']
'/'.split('/') # => [] instead of ['', '']
''.split('/') # => [] instead of ['']
'//'.split('/', -1) # => ['', '', '']
'/'.split('/', -1) # => ['', '']
''.split('/', -1) # => [] instead of ['']
In comparison: "".split("/") # => [""] in javascript
"".split("/") # => [""] in pythonBut if "instead of" means "I expected," doesn't that also mean that Javascript and Python don't do what you expected?
JS & python both have:
'//'.split('/') => [ '', '', '' ] '/'.split('/') => [ '', '' ] '',split('/') => [ '' ]
so they indeed produce what parent expected.
[1] https://makandracards.com/makandra/46939-ruby-a-small-summar...