ruby style question

J

Joe Van Dyk

Browsing through the Rails code... I see a lot of lines over 80
characters there!

I always thought that it was good to keep line length below 80
characters as it helps readability on different devices/screens. But
I've found that it's difficult to keep that small a line length
sometimes.

Your thoughts?
 
W

William James

Joe said:
Browsing through the Rails code... I see a lot of lines over 80
characters there!

I always thought that it was good to keep line length below 80
characters as it helps readability on different devices/screens. But
I've found that it's difficult to keep that small a line length
sometimes.

Your thoughts?

What makes you think it's difficult?

puts "Tom Tidler's Ground".scan(/[TG](r)?([aeiou])/).\
flatten.compact.join
 
P

Pit Capitain

William said:
Joe said:
I always thought that it was good to keep line length below 80
characters as it helps readability on different devices/screens. But
I've found that it's difficult to keep that small a line length
sometimes.

What makes you think it's difficult?

puts "Tom Tidler's Ground".scan(/[TG](r)?([aeiou])/).\
flatten.compact.join

In this case you can even omit the backslash. Because of the last dot
Ruby knows that the statement isn't finished yet.

Regards,
Pit
 
G

Gavin Kistner

--Apple-Mail-2--140845119
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

I always thought that it was good to keep line length below 80
characters as it helps readability on different devices/screens. But
I've found that it's difficult to keep that small a line length
sometimes.

I frequently find it really hard to keep lines below that limit
without heavily altering the code I want to write (such as wrapping a
single statement in a if ... then rather than a post-line
conditional). When I find myself wasting time reformatting my code to
try and meet an arbitrary limit that is nowhere close to what my own
screen and comprehension impose, I try to stop and say "It's alright,
leave it be."

I think it's a nice initial goal, but I personally don't fret if half
my lines are 100 characters long, and the occasional line tops 130 or
more.

--Apple-Mail-2--140845119--
 
K

Kirk Haines

On Tuesday 16 August 2005 6:27 am, Gavin Kistner wrote:

[talking about 80 character lines...]
I think it's a nice initial goal, but I personally don't fret if half
my lines are 100 characters long, and the occasional line tops 130 or
more.

I generally try to keep my lines less than or close to 80 lines, as well, but
it's not over any great concern about whether or not the lines will fit on
someone else's screen. Just as processor speeds climb and storage media
capacities soar, screen resolutions have also increased, and with them, the
usable line length has changed, too. I used to believe that the 40 character
wide Apple ][+ lines were perfectly reasonable, for example. Technology is
no great limit, unless one is coding on or reading code on a palm-sized
computer.

My reasoning for generally trying to stay at 80 characters are that by
sticking to some arbitrary limit, it helps me to think about how the code and
the comments do look. Comments that stick to an arbitrary limit are nicer
looking and easier to read, and often if I have a line of code that is
growing well beyond that arbitrary 80ish character limit, it's a signal to me
that there might be a simpler approach or that I am probably writing a
Faulkner style sentence when a Hemmingway style paragraph would probably be
easier to read. Like that sentence you just finished reading. Sure, it's
fine, but turning it into multiple sentences would be better for most
readers.

It is just a general rule, though, and I violate it all the time. For
instance, if I am creating a chain of several method calls or doing something
similar, it may be easier to understand a single long sentence instead of a
paragraph of short sentences.

As with so many style issues, it comes down to personal taste. Do what makes
sense for you and your audience.


Kirk Haines
 
J

James Edward Gray II

My reasoning for generally trying to stay at 80 characters are that by
sticking to some arbitrary limit, it helps me to think about how
the code and
the comments do look.

Well put.

The eye gets lazy when it has to follow those long lines. I figure
I'm trying to be too cute, when my line soars past 80 characters and
I rethink what I'm trying to accomplish.

Also, I'm of the opinion that it eases the inclusion of code in other
mediums: email, web pages, and books. This can be pretty important
in Ruby where a wrapped line can change the meaning of the program.

James Edward Gray II
 
M

Mark Volkmann

On Aug 16, 2005, at 7:58 AM, Kirk Haines wrote:
=20
=20
Well put.
=20
The eye gets lazy when it has to follow those long lines.

Right. There's a reason why newspapers wrap lines in articles the way
they do. It's easier for us to read. I think the same applies to
reading source code.

--=20
R. Mark Volkmann
Partner, Object Computing, Inc.
 
K

Kirk Haines

Right. There's a reason why newspapers wrap lines in articles the way
they do. It's easier for us to read. I think the same applies to
reading source code.

Though one should not follow print media guidelines too closely. People
generally have their eyes farther away from their monitors than they do from
print media that is being read, which means that the natural scan arc of the
eye can take in a wider line on a monitor than on book or newspaper. Of
course, confounding that is the fact that paper has a clarity and crispness
advantage over monitors.

I did a project for a Catholic priest this spring, helping compile a
historical archive, and we went round and round more than once on the fact
that formatting online content like a print manuscript looks funny; the
columns are too narrow.


Kirk Haines
 

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
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top