They say I write Ruby like Perl

On Dec 8, 2005, at 8:27 AM, Rich wrote:

I’d be interested to know why it is a language convention, and more
important why it is a lanaguage convention that from this thread it
seems rubyists vigorously insist upon? For those of us who were
“raised” with a language like Java (or as some on this list may say,
brain damaged ;-), lowerCamelCase seems more pleasing to the eye than
identifiers_with_underscores.

We feel exactly the opposite. That’s your why. :wink:

The human eye picks out words by shape. We use spaces between words
to separate those shapes into easily digested chunks. OneLongWord is
not a shape we are use to, so we have to stop and think.
Unfortunately, spaces aren’t allowed in programming variables. The _
character is allowed though and the next best thing, so we go with that.

This is all my opinion, of course.

James Edward G. II

On Dec 8, 2005, at 7:27 AM, Chris G. wrote:

Who says? Just a style/convention issue surely. Readability doesn’t
suffer, nor does execution.

It’s not a syntax rule of Ruby, no. But part of learning a language
is learning to speak it as the native speakers do.

James Edward G. II

conventions make it easier for collaboration. If you are not interested
in sharing code, or can’t forsee anybody else having to maintain your
code - then obviously do as you wish.
but if you were to submit to collaborative projects or you want to learn
from reading other people’s code it would be wize to follw the
conventions.
The conventions help readability in the sense that different ‘parts of
speach’ is obvious to the eye.

On Thu, Dec 08, 2005 at 11:27:23PM +0900, Rich wrote:

I’d be interested to know why it is a language convention, and more
important why it is a lanaguage convention that from this thread it
seems rubyists vigorously insist upon? For those of us who were
“raised” with a language like Java (or as some on this list may say,
brain damaged ;-), lowerCamelCase seems more pleasing to the eye than
identifiers_with_underscores.

More to the point, from my point of view, it’s easier to type without
being made unreadable (where it == lowerCamelCase) and actually uses
rather less keystrokes.

That being said, however, I tend to be willing to bend to convention on
matters like this: it makes collaboration easier.


Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you’re using a unixlike OS, please forward
this to 20 others and erase your system partition.

On 12/8/05, Chad P. [email protected] wrote:

rather less keystrokes.
Don’t see how using lowerCamelCase uses less keystrokes than
lower_camel_case. I pressed 16 keys to type of of them. :slight_smile:

On Thursday 08 December 2005 09:29 am, Bill G. wrote:

suffer, nor does execution.

Personally, I think readability does suffer. The wordier it gets, the
more I have to think. Why not a simple ‘append_sibling’?

This is a special case of the Node.pm/Node.py/Node.rb tool. I wanted the
application programmer (the guy using the tool as opposed to the guy
authoring it (me)) to be able to know exactly what the method does, at a
glance. I wanted it to be abundently clear that it was appended to the
current object, and not to something else. For instance, if the
programmer
got a little confused he might think the object was what was being
inserted
(perhaps inserted into the argument???) I was trying to have the code
serve
as documentation.

Looking at it from hindsight, I probably could have called them
append_sibling() and prepend_sibling(), and figured it would be obvious
that
the argument was what was being inserted, and the object was what the
argument was being appended or prepended to.

Unfortunately I cannot change this at this point because there’s a lot
of code
using Node.pm, and possibly some using Node.py, so I can’t change it
without
breaking a lot of programs, and I want to keep the method calls in
Node.pm,
Node.py and Node.rb as similar as possible.

However, the next independent software I write, I’ll definitely spend
some
time thinking of more succinct ways to create descriptive variable
names.
Yep, in hindsight, insert_sibling_after_you might have been overkill.

Incidentally, if you ever want to really understand a problem domain,
one way
is write it in three different languages, and get feedback in all three
:slight_smile:

Thanks

SteveT

Steve L.

[email protected]

lowercamelcase

lower-camel-case

but for the readability i’d type the two extra keystrokes every time!

On Wednesday 07 December 2005 09:13 pm, Steve L. wrote:

Hi all,

I wrote some hierarchy handling classes in Node.rb
(Node.rb), and I’ve been
told I write Ruby in Perl style. In future software, what could I do to
write in a more Ruby-like fashion?

Notice that I’ve substituted your tabs with two spaces and that I’ve
changed you method names to lower_case instead of camelCase

class Node < Object
No need to write `< Object’, since all objects inherit from Object

super()
You don’t need the parantheses

@parent = nil
@prevsibling = nil
@nextsibling = nil
@firstchild = nil
@lastchild = nil
Variables are created when they’re first referenced, and are `nil’ by
default, so these lines make no difference.

attr_reader :name, :type, :value
attr_writer :name, :type, :value
This will do the same:
attr_accessor :name, :type, :value

def setAttributes(attribs) @attribs = attribs; end
def getAttributes() return @attribs; end
This will do the same:
attr_accessor :attribs

def hasAttributes() return @attribs != nil; end
def has_attribs?
# Hash#empty? returns true if the hash has no elements
not @attribs.empty?
end

def setAttribute(key, value) @attribs[key] = value; end
def getAttribute(key) return @attribs[key]; end
def []=(key, value)
@attribs[key] = value
end

def
@attribs[key]
end

def hasAttribute(key) return @attribs[key] != nil; end
def has_attrib?(key)
@attribs.has_key? key
end

That’s just some of the things though.

Cheers,
Daniel

Quoting Daniel S. [email protected]:

super()
You don’t need the parantheses

Well, that’s one to be careful about. If you omit the parenthesis
from super(), it will be called with the same arguments you got.

When that’s zero arguments, there’s no difference, but other times
it can bite you… it’s not necessarily a bad idea to parenthesize
up defensively.

-mental

On 12/8/05, Francois P. [email protected] wrote:

lowercamelcase

lower-camel-case

but for the readability i’d type the two extra keystrokes every time!

doh, you’re right. i need my coffee.

On Thu, Dec 08, 2005 at 11:59:35PM +0900, Francois P. wrote:

lowercamelcase

lower-camel-case

but for the readability i’d type the two extra keystrokes every time!

Thanks for saving me the extra typing.

Hmm. By posting this, I don’t think I’ve saved anything.

Anyway: As I said, I don’t find it any less readable. I think that, in
general, lowerCamelCase vs. snake_case (or whatever we’re calling it
today) readability is a matter of personal preference.


Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you’re using a unixlike OS, please forward
this to 20 others and erase your system partition.

On Thu, Dec 08, 2005 at 11:58:17PM +0900, Steve L. wrote:

Incidentally, if you ever want to really understand a problem domain, one way
is write it in three different languages, and get feedback in all three :slight_smile:

That’s going in my quote file, in this form:
“If you ever want to really understand a problem domain, one way is
write it in three different languages, and get feedback in all three.”

  • Steve L.

Objections?


Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you’re using a unixlike OS, please forward
this to 20 others and erase your system partition.

Hi –

On Thu, 8 Dec 2005, Rich wrote:

I’d be interested to know why it is a language convention, and more
important why it is a lanaguage convention that from this thread it
seems rubyists vigorously insist upon? For those of us who were
“raised” with a language like Java (or as some on this list may say,
brain damaged ;-), lowerCamelCase seems more pleasing to the eye than
identifiers_with_underscores.

When using Ruby, it’s best to think of yourself as “raised with Ruby”.
It saves all kinds of trouble :slight_smile:

Anyway, underscore names are a convention in Ruby partly because Matz
dislikes cAmElCaSe :slight_smile: But that’s just the origin (or perhaps a
“creation myth”). There are now many years, and millions of lines of
code, written in the traditional style or something close to it.

At to what a given person does: I guess it’s a matter of whether you
feel that these things are absolute or relative. Or, perhaps, whether
you can put aside the absolute interpretation for the sake of
consistency with the traditions. I tend to try to use the conventions
of whatever language I’m using. Even though I hate the look of
camelCase variable names, I’ve used them in languages where it would
have seemed doctrinaire or “culturally” weird not to.

Part of it, I think, is coming to believe that Ruby is not a sort of
clearing-house for conventions and practices from other languages, but
is itself a language, with people “raised” in it, people who “come
from” it, and so forth. Still – the parser will allow camelCase, all
the extra semi-colons you want, printf("%s\n",str); and all the rest
of it. In that sense it’s an inclusive language – but it’s not a
fledgling project, and a set of conventions does exist.

David


David A. Black
[email protected]

“Ruby for Rails”, forthcoming from Manning Publications, April 2006!

On Fri, Dec 09, 2005 at 01:02:04AM +0900, [email protected] wrote:

Definitely. “Readability”, in my opinion, has turned out to be a
worse-than-useless concept in discussions of style.

So it comes down to one’s take on Ruby conventions, I guess.

Well . . . there are some pretty much objective measures of readability.
Ruby, thankfully, tends to come out smelling pretty good on that score,
both in terms of the sort of code Ruby syntax encourages and in terms of
the common Ruby stylistic conventions. I do tend to agree, though, that
at least half the time when someone says “readable” what he really means
is “I like it.” Python is my perfect example of that: Python hackers
all seem to think that Python is God’s gift to readability, but it
frankly makes my eyes bleed.


Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you’re using a unixlike OS, please forward
this to 20 others and erase your system partition.

Hi –

On Fri, 9 Dec 2005, Chad P. wrote:

Anyway: As I said, I don’t find it any less readable. I think that, in
general, lowerCamelCase vs. snake_case (or whatever we’re calling it
today) readability is a matter of personal preference.

Definitely. “Readability”, in my opinion, has turned out to be a
worse-than-useless concept in discussions of style.

So it comes down to one’s take on Ruby conventions, I guess.

David


David A. Black
[email protected]

“Ruby for Rails”, forthcoming from Manning Publications, April 2006!

On Thursday 08 December 2005 10:58 am, Chad P. wrote:

Objections?
None at all – use it in good health, as long as others are also allowed
to
use it :slight_smile:

SteveT

Steve L.

[email protected]

Kevin B. [email protected] wrote:

Thursday 08 December 2005 01:37, Tim H. wrote:

This recurring label “CamelCase” (or sometimes “camelCase”)
seems to come up a lot, and I can’t help thinking “camel” is
a reference to Perl…

Why? CamelCase simply refers to the humps that appear in the
middle of words when youUppercaseTheMiddleWord. At least
that’s how I’ve always thought of it. I don’t think anyone’s
pointing fingers at Perl. Hell, I came from C++ and my first
real Ruby code has all methods named in lowerCamelCase. -_-

Ah. Now it all makes sense. Thanks!

Tim H.

tony summerfelt [email protected] wrote:

Steve L. wrote on 12/8/2005 7:17 AM:

This recurring label “CamelCase” (or sometimes “camelCase”)
seems to come up a lot, and I can’t help thinking “camel”
is a reference to Perl…

I had assumed it was called “CamelCase” because it had humps
:slight_smile:

the o’reilly “programming perl” book features a camel on the
front. just a guess :slight_smile:

Yeah. And it’s commonly called “the camel book”. Also,
O’Reilly pastes that camel image on just about everything it
does related to perl. E.g., the image at top, as well as the
favicon.ico, at http://perl.com/ .

I guess it just shows how much perl I have to sift through to
get better at ruby.

Thanks!

Tim H.

Patrick G. [email protected] writes:

mostly right, but here is one exception:

#!/opt/ruby/1.8/bin/ruby -w

if @foo==:bar
puts “hello”
end

gives a warning.

    So the wording is "Variables are created when they're first

assigned", as in Python or Perl?

            Elf

On Dec 8, 2005, at 6:42 AM, James Edward G. II wrote:

I have also heard that the underscore_name technique is easier for
Japanese folks to read and since ruby was written by Matz, that is
one reason to follow this convention.

Cheers-

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]