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

S

scooterm

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
 
J

James Gray

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?
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. :)

James Edward Gray II
 
J

Jean-François Trân

2008/1/16 said:
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?

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

See : http://pastie.caboo.se/139710

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

-- Jean-Fran=E7ois.
 
A

ara.t.howard

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(/\w*o\w*/)

dog
mouse
gorilla

;-)

a @ http://drawohara.com/
 
K

Karl von Laudermann

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.

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.
 
C

Chad Perrin

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.
 
W

Wincent Colaiuta

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
 
M

Michal Suchanek

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.

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();

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
 
C

Curt Sampson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top