3 ms·
> it's a whopping 11 lines of code. If you think 11 lines of code is a lot, you're overly focused on concision at the expense of readability. I've never (read
by d23 13y ago
> it's a whopping 11 lines of code.
If you think 11 lines of code is a lot, you're overly focused on concision at the expense of readability. I've never (read: never) worked on any Ruby code, yet I find the posted example more readable than the supposedly more valuable xpath.
At the very least, they're the same. If you're writing code in Ruby, 11 lines is nothing. If you're writing code in Ruby and xpath is used nowhere else in the project, that single line of super-compact xpath might as well be 1000 lines of Ruby -- it doesn't matter.
If you're trying to compact 11 lines of code you're probably doing it wrong.
- GuiA 13y agoI may or may not agree with you- but one could make the argument that xpath is likely heavily tested and proven, and will handle unexpected corner cases that arise in the future, which those 11 lines of ruby will not. In that case, using xpath lowers the amount of future headaches with that code.