Ruby annoyances ... mine is line continuation, what's yours?

Just thinking how really smart Ruby is in most areas makes it all the
more surprising when some of its “warts” start showing. Admittedly,
the ones that appear are pretty minor, but still a tad irritating
nonetheless.

Line continuation is probably the biggest annoyance for me so far.

Consider:

puts ‘cat :: dog :: elephant :: mouse :: gorilla’.
split(’::’).
map{|str| str.strip() }.
select{|str| str[‘o’]}.
join("\n")

If you ask “why is this an annoyance” … it’s because you have
to put the period at the end of each item, even though some
prefer to put it at the beginning. Why? Because it makes it easier
to remember to put in the code, you dont have to scan a bunch
of varying-length lines to see if you remembered to put the
dot at the end, … and don’t even think about adding “line
continuation escapes” like a backslash … they’re ugly and
they suck.

Anyone else have an annoyance they want to share? … or better
yet, a fix for this one? Speak up, get it off your chest.

–salutations

On Jan 16, 2008, at 1:44 PM, [email protected] wrote:

prefer to put it at the beginning. Why?
Anyone else have an annoyance they want to share? … or better
yet, a fix for this one?

Ruby 1.9 allows the period at the beginning of the line, so cheer up,
your complaint has already been fixed. :slight_smile:

James Edward G. II

Don’t all sentences end with punctuation?

On Jan 16, 2008, at 12:54 PM, Joshua S. wrote:

Don’t all sentences end with punctuation?

Not the incomplete ones

TwP

2008/1/16, [email protected] [email protected]:

If you ask “why is this an annoyance” … it’s because you have
to put the period at the end of each item, even though some
prefer to put it at the beginning. Why? Because it makes it easier
to remember to put in the code, you dont have to scan a bunch
of varying-length lines to see if you remembered to put the
dot at the end, … and don’t even think about adding “line
continuation escapes” like a backslash … they’re ugly and
they suck.

Anyone else have an annoyance they want to share? … or better
yet, a fix for this one?

You can insert spaces before or after the dot, so for instance,
you can format your code to make the dots vertically aligned.

See : Parked at Loopia

So it’s easy to check if a dot is missing.

– Jean-François.

On Jan 16, 2:41 pm, “[email protected][email protected]
wrote:

to put the period at the end of each item, even though some
prefer to put it at the beginning.

When splitting a long line across an operator, I’ve always preferred
to put the operator at the end, because it makes it obvious that the
line isn’t finished. Not just for the Ruby interpreter, but for the
user as well. Even in Java, I prefer to write:

int val = Foo.someLongThing() +
Bar.otherLongThing();

even though Sun’s official Java style guide dictates putting the + at
the start of the second line.

On Jan 16, 2008, at 12:44 PM, [email protected] wrote:

puts ‘cat :: dog :: elephant :: mouse :: gorilla’.
split(‘::’).
map{|str| str.strip() }.
select{|str| str[‘o’]}.
join(“\n”)

have fun debugging that one - the stack trace from any error on any
of those lines will come from the same line. fine for quick hacks,
but deep method chaining is evil if there is even a remote chance
that the error will bubble up to a logfile somewhere for some poor
soul to grok. anything that makes crazy line chaining even easier
would probably annoy me

btw

puts ‘cat :: dog :: elephant :: mouse :: gorilla’.scan(/\wo\w/)

dog
mouse
gorilla

:wink:

a @ http://drawohara.com/

On 16/01/2008, Karl von Laudermann [email protected] wrote:

Bar.otherLongThing();

It depends on the operator. +' is quite easy to see but a .’ is not.

Note that in writing it is customary to put the operator both on the
line end and on the beginning of the next line so that it’s clear
wherever you start reading. Indentation usually can serve that purpose
in electronic form so the operator at the start is less important for
understanding the program. However, you would need an editor that
automatically and correctly adjusts indentation to detect the missing
operator.

Thanks

Michal

On Thu, Jan 17, 2008 at 04:54:20AM +0900, Joshua S. wrote:

Don’t all sentences end with punctuation?

The case being discussed is not of a sentence ending with punctuation,
but a linewrap ending with punctuation.

On Jan 16, 10:04 pm, Chad P. [email protected] wrote:

On Thu, Jan 17, 2008 at 04:54:20AM +0900, Joshua S. wrote:

Don’t all sentences end with punctuation?

The case being discussed is not of a sentence ending with punctuation,
but a linewrap ending with punctuation.

Would you write in English like this:

Well, the unit was tall
, thin, blue, and had
, well, how would you say
? anomalies which were, er
, rather disturbing.

Or like this:

Well, the unit was tall,
thin, blue, and had,
well, how would you say?
anomalies which were, er,
rather disturbing.

W

On 2008-01-17 20:00 +0900 (Thu), Wincent C. wrote:

Would you write in English like this:

Well, the unit was tall
, thin, blue, and had

No. But we’re not discussing writing English, we’re discussing writing
computer code.

cjs