expecting keyword_end
I’ve been working on a tool to import communities from Google+ into Discourse on behalf of several Google+ community owners. This means learning Ruby, a bit of Rails, some ActiveRecord, etc.
I disliked ending everything with end
while writing the script,
and now that I’m actually trying to run it, I understand why. With
Python’s whitespace-delimited control flow, you can see the control
flow directly. With C and family’s {...}
around blocks of code,
you can match braces in the editor. But when every conditional is
terminated with end
it is not obvious where an end
was left out,
and so the last line of code has an error message attached to it
without any clue of where the end
is really missing.
syntax error, unexpected end-of-input, expecting keyword_end
I suspect that most real Ruby developers use syntax-highlighting editors that make this clear, so I’m just not the target audience.
My solution was to use binary search, deleting methods from roughly
half the file, then half of that, and so forth, until I found the
one method that failed; then I saw the if
that was missing its
paired end
.
Certainly, this was PEBCAK and my fault, but an equivalent error would have been almost impossible in Python and easy to diagnose in any C-family language.
I’ve been enjoying Go at work and Ruby sure isn’t going to displace my preference for Go. On the other hand, Ruby is certainly an improvement over PHP or Perl! I glanced through the tutorial ten days ago and started trying to write code five days ago. Could be worse! So this isn’t really a rant, just an instance of confirming my preference for the Python or C styles.