14 ms·
It's all about style. Which is what makes it really interesting. In your implementation you used string interpolation, a different kind of shortcut. And in my e
by bphogan 15y ago
It's all about style. Which is what makes it really interesting. In your implementation you used string interpolation, a different kind of shortcut. And in my example, I used + to make it more readable for the parent poster who said they weren't familiar with Ruby.
Interesting how "more readable" is somewhat objective, isn't it?
- randomdata 15y agoI chose interpolation in this example because I found the lack of any break character between the method and the variable to not read well. puts k + " " + v Does that execute as puts(k) + " " + v, puts(k + " ") + v or any other combination? While those of us familiar with Ruby know the answer, I would still argue that it takes greater cognitive resources to evaluate over the single string, especially in the presence of a syntax highlighting editor who clearly defines the string boundaries in colour. You are right that it is definitely subjective. Coding is user interface design, but we don't usually have the luxury of processes like A/B testing to validate our work like other interface designers do. It would be interesting to put both of our code samples along with some other variations in front of an audience and see how they are received.
- bphogan 15y agoI've done some of that in my teaching - people get the string addition right away since that's how people write in JS and other languages they already know. I immediately show how string interpolation works (by showing how it automatically calls .to_s to handle type issues.) When I've tried to jump right into string interpolation, people don't quite get what's going on, which resulted in me having to backtrack and do addition anyway. But that's just my experience.