5 ms·
"This is a perfectly reasonable solution, but it's a whopping 11 lines of code. Further, it feels like we're using the wrong tool for the job: why are we using
by hfsktr 13y ago
"This is a perfectly reasonable solution, but it's a whopping 11 lines of code. Further, it feels like we're using the wrong tool for the job: why are we using Ruby iterators and conditionals to get at DOM nodes?"
Is it really that bad to have 11 lines in Ruby?
Initially I didn't get the wrong tool part but after reading it all that did make more sense. I haven't used XPath more than a few times and they were pretty simple so can't complain. Just something I'll have to keep in mind.
- jpatokal 13y agoAgreed. I find the 11 lines of Ruby a lot more readable/obvious than that fairly convoluted XPath. Although I'd probably have opted for RSLT instead: http://hackpackers.lonelyplanet.com/2013/03/05/XML-Transformation-With-RSLT.html http://hackpackers.lonelyplanet.com/2013/03/05/XML-Transform...
- steveklabnik 13y agoMost Rubyists try to keep methods between 5-10 lines long. 7 is the number for a Rails controller.