5 ms·
synonyms in ruby seem to be a mistake. Searching code for certain usage patterns ends up needing more complicated regular expressions taking into account all s
by cma 6y ago
synonyms in ruby seem to be a mistake. Searching code for certain usage patterns ends up needing more complicated regular expressions taking into account all synonym variations.
If you've seen a method one way many times while learning, then see a synonym, you end up having to search up docs to make sure there isn't some subtle difference.
- the_other 6y agoI find it really valuable to have different patterns of similar tokens to express different intent. My canonical example is early returns in JavaScript. Function f () { if(errorCindition) return if(normalBehavior) { return 1 } else { return 2 } } (I know, my use of braces and lack of semi-colons will cause flame wars!) The error condition looks different from the rest, so when I’m scanning quickly, I know where I am. My eyesight’s rubbish, so the shape of the code has a marked impact on me. I don’t have to read the whole thing to orient myself. I thought it was nuts when I read the title, but reading the examples had a noticeable “easing” effect on my reading. So I’m very excited by this addition to Ruby. It could lead to some neat, expressive patterns.
- nitrogen 6y agoshape of the code This is an undervalued aspect of development. The tactile shape of a block of code conveys some aspects of intent, and overly aggressive linting tools destroy that intent.
- dragonwriter 6y agoThere almost invariably is a subtle difference (very commonly, in precedence), and that's usually a key part of the motivation for the (near) synonym.
- cma 6y agoThat makes it confusing when there isn't a difference (I think map and collect?).
- dragonwriter 6y agoOh, I was thinking of (nearly) synonymous alternate syntax. It's true that Ruby has lots of true synonyms in method names.