Proposal - enforce lower_case for variables and methods

Ruby does already enforce CamelCase for class/modules.

‘camelCase’ for variables/methods is easy to confuse with
ClassNames. Its hard to distinguish for newcomers if they
should use ‘under_score’ syntax or ‘camelCase’ syntax. If
the person has a Java background it may be natual though
(but being friendly to Java persons may hurt Ruby).

However I don’t use ‘camelCase’ and I tend to avoid
libraries which uses forces me to it. Luckily many of them
provide underscore aliases.

In Ruby2 it would be nice to get rid of ‘camelCase’, so
that ‘under_score’ naming is enforced by the language.

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

···


Simon Strandgaard

Simon Strandgaard wrote:

Ruby does already enforce CamelCase for class/modules.
#-- Begin example —
class Not_camel_case
def foo
puts “Hello.”
end
end

Not_camel_case.new.foo
#------- End -----

This works fine for me. Where is CamelCase enforced?

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

First submit an RCR for required indentation and significant white
space. I’d feel the same way about that. :slight_smile:

There are various cases where I want to map some string from the outside
world to a method invocation. For example, when stream processing XML.
Any restrictions on naming makes this harder, particularly if I don’t
control the naming conventions for the source XML.

I want fewer syntax restrictions, not more.

James

class No_not_really
end

no_not_really = No_not_really

no_not_really.new

···

Simon Strandgaard (neoneye@adslhome.dk) wrote:

Ruby does already enforce CamelCase for class/modules.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Simon Strandgaard wrote:

Resistance ? any good reasons to use camelCase ?

Imagine a workplace where the dominant language is Java and hence people are used to using camelCase … and it’s probably specified in a coding standard, if one exists.

In such an environment, being forced to use a different convention could easily be the thing that stops people from adopting Ruby for some of their work.

Personally, I dislike this sort of forced conformance. So long as there’s consistency within a given piece of code, I don’t see it’s really a huge problem what the approach is. I believe people tend to overemphasise the importance of these kinds of conventions.

Put it this way, if someone wrote the Ruby “killer app” library and they didn’t follow whatever convention you considered to be “correct”, would you seriously just ignore that code?

Just my AUD0.02 worth.

H.

Simon Strandgaard wrote:

Ruby does already enforce CamelCase for class/modules.

‘camelCase’ for variables/methods is easy to confuse with
ClassNames. Its hard to distinguish for newcomers if they
should use ‘under_score’ syntax or ‘camelCase’ syntax. If
the person has a Java background it may be natual though
(but being friendly to Java persons may hurt Ruby).

However I don’t use ‘camelCase’ and I tend to avoid
libraries which uses forces me to it. Luckily many of them
provide underscore aliases.

In Ruby2 it would be nice to get rid of ‘camelCase’, so
that ‘under_score’ naming is enforced by the language.

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?


Simon Strandgaard

I would probably prefer most library code to have similar conventions,
but I generally chafe against restrictions which seem reasonably
arbitrary like this one. It’s one of my chief reasons I never learned
python that they had arbitrary rules like this.

Charles Comstock

Simon Strandgaard wrote:

Ruby does already enforce CamelCase for class/modules.

‘camelCase’ for variables/methods is easy to confuse with
ClassNames. Its hard to distinguish for newcomers if they should
use ‘under_score’ syntax or ‘camelCase’ syntax. If the person has a
Java background it may be natual though (but being friendly to Java
persons may hurt Ruby).

However I don’t use ‘camelCase’ and I tend to avoid libraries
which uses forces me to it. Luckily many of them provide underscore
aliases.

In Ruby2 it would be nice to get rid of ‘camelCase’, so that
‘under_score’ naming is enforced by the language.

Should I submit an RCR about this ? Resistance ? any good reasons
to use camelCase ?

– Simon Strandgaard

I would consider this a very bad idea.
OTOH, I’m not sure that the suggestion of making case, and perhaps
underscored, non-semantic isn’t a good idea. I.e.,
Item === item === ItEm === i_T_e_M
But probably the special nature of the first letter should be
retained. Everybody is alreay aware that, e.g., Polish isn’t the same
as polish. OTOH, NASA === N.A.S.A === nasa.
Analogies with natural languages are always slippery, but perhaps this
is a reasonable one.

Still, if the decision is to forbid camelCase, I won’t loose any sleep
over it. I just think it a poor, and somewhat arbitrary, idea. You
could even go all lispish, and use internal asterisks for markers if
you wanted. I’d think it a poor idea, but I could live with it.

Tim Sutherland wrote:

In article pan.2004.03.24.04.02.22.303009@adslhome.dk, Simon Strandgaard
wrote:

Ruby does already enforce CamelCase for class/modules.

‘camelCase’ for variables/methods is easy to confuse with
ClassNames. Its hard to distinguish for newcomers if they
should use ‘under_score’ syntax or ‘camelCase’ syntax. If
the person has a Java background it may be natual though
(but being friendly to Java persons may hurt Ruby).

However I don’t use ‘camelCase’ and I tend to avoid
libraries which uses forces me to it. Luckily many of them
provide underscore aliases.

In Ruby2 it would be nice to get rid of ‘camelCase’, so
that ‘under_score’ naming is enforced by the language.

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

There are libraries which provide a bridge between Ruby and e.g. Java, .NET
and Python. For example, you can have Ruby call a Java method. If the Java
method is called someJavaMethod' then you will want your Ruby code to say foo.someJavaMethod(123)`.

there’s also a .NET bridge, the .net libraries capitalize their method
names… should we allow foo.SomeDotNetMethod(123)? this is not an
argument either way, just a question.

···


dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap

Hi –

(posting through my Usenet provider, hoping the gateway will
work in this direction…)

Simon Strandgaard neoneye@adslhome.dk writes:

In Ruby2 it would be nice to get rid of ‘camelCase’, so
that ‘under_score’ naming is enforced by the language.

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

I dislike camelCase variables in Ruby as much as anyone, not only for
their visual incongruity with conventional Ruby but also because I’m
uncomfortable with everything rooted in the idea that
[Java,Perl,C++,…] conventions should have priority in Ruby so that
[Java,Perl,C++,…] programmers (rather than Ruby programmers) will
feel good. I honestly believe that people’s quite genuine love of
Ruby often manifests itself in a kind of language inferiority complex.
I’ve never understood why. Ruby itself makes people feel good. We
should trust it :slight_smile:

Anyway… While I certainly root for traditional Ruby style, I don’t
think actual under_score enforcement is appropriate. I think it’s
better for people to learn from the standard library, Matz’s
explicitly expressed preferences, and the bulk of practice.

David

···


David A. Black
dblack@wobblini.net

Simon Strandgaard wrote:

Ruby does already enforce CamelCase for class/modules.

Well, it enforces a leading capital, CamelCase is just a convention.

‘camelCase’ for variables/methods is easy to confuse with
ClassNames. Its hard to distinguish for newcomers if they
should use ‘under_score’ syntax or ‘camelCase’ syntax. If

Are you sure it is confusing to newcomers? Most natural languages use a
leading capital to distinguish different types of things. Nouns/proper
nouns vs. other parts of speech, beginning of sentences,etc.

In Ruby2 it would be nice to get rid of ‘camelCase’, so
that ‘under_score’ naming is enforced by the language.

Have you ever used a wiki where links are created when you enter words
in a particular version of CamelCase? It’s pretty restrictive. For
example, the one I’ve used recently won’t let me use a link named
CProgrammingTips, because it has two adjacent caps. Instead I have to
use the potentially confusing name CeeProgrammingTips. Because of this,
I think it’s a bad idea to enforce something like this unless it’s
really necessary to the parser.

I also think it’s a bad idea to auto-translate between snake_case and
camelCase. What happens when a newbie is reading someone’s library and
see things declared in snake_case, but the code using that library uses
camelCase? It also makes it hard to grep for usage of a particular
method/variable.

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

Good reasons to use camelCase: to distinguish between
variable-like-things and subroutine-like-things.

Take “run_once”. Is that a boolean flag saying that something should
only run once, or is it a method that does one run of a multi-run
action? What about “skip_whitespace”. Is that a method that skips over
whitespace or a flag that indicates whether whitespace should be
skipped? What about “read_buffer”? Is that a buffer where data you
read is stored, or a method to extract something from a buffer?

If we see something named “ReadBuffer” we know that it’s a class. We
also can make some educated guesses about how it’s used, what it does, etc.

Using camelCase allows you to see at a glance whether a given token does
something (subroutine-like), or whether it returns something
(variable-like). For years, I’ve used the convention that
subroutine-like-things use camelCaseWithLeadingLowercase and
variable-like things use snake_case_with_all_lowercase. Constants are
UPPERCASE_WITH_UNDERSCORES and classes are CamelCaseWithLeadingCaps.

In C, this convention is particularly helpful in understanding code that
passes function pointers into other functions. If I see a line of code
like this:

sort(data, alphaSort);

I can tell at a glance that alphaSort is a function that sort will call
as it works. I can tell it isn’t a constant that indicates the type of
sort to use. I can also tell it isn’t a variable, even though most
things passed to functions are constants or variables.

I don’t think that every function needs to have an uppercase letter in
it somewhere, it’s pretty obvious that ‘sort’ is a function/method. I
also don’t think that every variable / accessor needs to have an
underscore. Person.age is almost certainly not a method to cause a
person to get older!

If people don’t find my arguments convincing, and want to continue using
lowercase_with_underscores for both methods and variables, that’s fine
with me. I’ll have to work a bit harder to understand your code, but as
long as you don’t start using CamelCaseWithLeadingCaps for variables,
classes, methods and constants then I think I can figure things out.
But please, don’t force me to make my own personal code less legible for me.

Ben

Simon Strandgaard wrote:

Ruby does already enforce CamelCase for class/modules.
#-- Begin example —
class Not_camel_case
def foo
puts “Hello.”
end
end

Not_camel_case.new.foo
#------- End -----

This works fine for me. Where is CamelCase enforced?

initial letter must be upcase. Neither lowercase nor underscore.
Mild degree of enforcement :wink:

ruby a.rb
a.rb:1: class/module name must be CONSTANT
cat a.rb
class im_a_class
end
im_a_class.new

···

On Wed, 24 Mar 2004 13:34:06 +0900, James Britt wrote:


Simon Strandgaard

“Charles Comstock” cc1@cec.wustl.edu schrieb im Newsbeitrag
news:c3r7ov$3g7$1@newsreader.wustl.edu…

I would probably prefer most library code to have similar conventions,
but I generally chafe against restrictions which seem reasonably
arbitrary like this one. It’s one of my chief reasons I never learned
python that they had arbitrary rules like this.

How about a command line option for warnings? Or someone provides a
Ruby-Lint that takes care of that. I’d vote against hard enforcement
though. It’s not rubyish. :slight_smile:

robert

Tim Sutherland wrote:
[snip]

There are libraries which provide a bridge between Ruby and e.g. Java, .NET
and Python. For example, you can have Ruby call a Java method. If the Java
method is called someJavaMethod' then you will want your Ruby code to say foo.someJavaMethod(123)`.

there’s also a .NET bridge, the .net libraries capitalize their method
names… should we allow foo.SomeDotNetMethod(123)? this is not an
argument either way, just a question.

Interesting idea. That could be useful. Unfortunatly as Anders points out,
it doesn’t work with .net.

Is this really the way people wants to interact with non-ruby packages ?

···

On Wed, 24 Mar 2004 13:18:31 +0100, Anders Borch wrote:


Simon Strandgaard

Anders Borch wrote:

there’s also a .NET bridge, the .net libraries capitalize their method
names… should we allow foo.SomeDotNetMethod(123)? this is not an
argument either way, just a question.

We already allow that. See this code:

irb(main):001:0> def FooBar(arg = :none); arg; end
=> nil
irb(main):002:0> FooBar(1)
=> 1
irb(main):003:0> FooBar 2
=> 2
irb(main):004:0> FooBar()
=> :none
irb(main):005:0> self.FooBar
=> :none

But also note this:

irb(main):006:0> FooBar
NameError: uninitialized constant FooBar

Regards,
Florian Gross

=> 1

···

On Wed, Mar 24, 2004 at 09:19:28PM +0900, Anders Borch wrote:

there’s also a .NET bridge, the .net libraries capitalize their method
names… should we allow foo.SomeDotNetMethod(123)? this is not an
argument either way, just a question.

Kernel.Integer(“1”)

Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Software is like sex; it’s better when it’s free.
– Linus Torvalds

Simon Strandgaard wrote:
[snip]

Should I submit an RCR about this ?
Resistance ? any good reasons to use camelCase ?

First submit an RCR for required indentation and significant white
space. I’d feel the same way about that. :slight_smile:

One of the first language I programmed in was AMOS for the amiga500
(multimedia Basic clone). Its editor enforced many things, uppercase for
somethings, lowercase for others, it enforced the indention level, and it
enforced how chunks of code could be folded. Though I don’t know how much of
it were enforced by the language.

It didn’t gave me any choice, users of that language didn’t have
to worry about such details. Maybe because all such ackward problems were
cut away, kickstarted my programming carrier even though I hardly
understood any english at that point.

Its about breaking as much as possible in the transition to Rite,
somebody has to raise the nasty questions, and this question is in
paticular about religion.

There are various cases where I want to map some string from the outside
world to a method invocation. For example, when stream processing XML.
Any restrictions on naming makes this harder, particularly if I don’t
control the naming conventions for the source XML.

sounds cludgy.

I want fewer syntax restrictions, not more.

Too much freedom may turn into anarchy. :wink:

···

On Wed, 24 Mar 2004 13:34:06 +0900, James Britt wrote:


Simon Strandgaard

It seems a lot of people find Ruby so much closer to perfect than any other
language they’ve run across that they tend to think “If only Ruby did
such-and-such it would be perfect” , and then rush out to create an RCR.
I’ve done it myself :->

However, it seems like this is a temptation we should probably resist.
Everyone who likes Ruby has their own sense of values and priorities,
and it seems small changes, if necessary, are best.

Jim

···

On Thu, 25 Mar 2004 01:39:52 +0900 Ben Giddings bg-rubytalk@infofiend.com wrote:

If people don’t find my arguments convincing, and want to continue using
lowercase_with_underscores for both methods and variables, that’s fine
with me. I’ll have to work a bit harder to understand your code, but as
long as you don’t start using CamelCaseWithLeadingCaps for variables,
classes, methods and constants then I think I can figure things out.
But please, don’t force me to make my own personal code less legible for me.

Robert Klemme wrote:

“Charles Comstock” cc1@cec.wustl.edu schrieb im Newsbeitrag
news:c3r7ov$3g7$1@newsreader.wustl.edu…

I would probably prefer most library code to have similar conventions,
but I generally chafe against restrictions which seem reasonably
arbitrary like this one. It’s one of my chief reasons I never learned
python that they had arbitrary rules like this.

How about a command line option for warnings? Or someone provides a
Ruby-Lint that takes care of that. I’d vote against hard enforcement
though. It’s not rubyish. :slight_smile:

ruby-lint is a much better idea. I’d put my vote on a ruby-lint in
stead. We should have had a ruby-lint a long time ago, maybe I’ll have a
look at writing one :slight_smile:

···
robert


dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap

Simon Strandgaard wrote:

It didn’t gave me any choice, users of that language didn’t have
to worry about such details. Maybe because all such ackward problems were
cut away, kickstarted my programming carrier even though I hardly
understood any english at that point.

I (sort of) understand the value of programming with training wheels,
but i the long run it gets in the way and does not teach one to thinking
clearly about what the are doing, as so many options are simply unavailable.

There are various cases where I want to map some string from the outside
world to a method invocation. For example, when stream processing XML.
Any restrictions on naming makes this harder, particularly if I don’t
control the naming conventions for the source XML.

sounds cludgy.

It’s actually quite elegant, and takes advantage of much of Ruby’s
dynamic nature. Try it some time and see if you change your mind.

I want fewer syntax restrictions, not more.

Too much freedom may turn into anarchy. :wink:

You say that like it’s a bad thing.

I would suggest that those who want a restrictive or controlling
language have plenty of alternatives.

Arbitrary aesthetic controls are not a good goal.

James

Hi –

“James F. Hranicky” jfh@cise.ufl.edu writes:

If people don’t find my arguments convincing, and want to continue
using lowercase_with_underscores for both methods and variables,
that’s fine with me. I’ll have to work a bit harder to understand
your code, but as long as you don’t start using
CamelCaseWithLeadingCaps for variables, classes, methods and
constants then I think I can figure things out. But please, don’t
force me to make my own personal code less legible for me.

It seems a lot of people find Ruby so much closer to perfect than
any other language they’ve run across that they tend to think “If
only Ruby did such-and-such it would be perfect” , and then rush
out to create an RCR. I’ve done it myself :->

Or rush out to introduce non-traditional variable and/or method names
:slight_smile: Actually this is an unusual case because the potential RCR is
actually aimed at preserving a characteristic of Ruby (not a language
feature per se, but a widely agreed-upon practice), rather than
changing something.

As I said in another message, I’m not actually in favor of forbidding
camelCase at the language level, but I do agree that change should be
conservative – i.e., that Simon’s idea is right in spirit. I’ve
always found Ruby very clear (including code written by Matz and
others who use the traditional style of naming). I think that’s
actually one of the big draws of Ruby, not a problem awaiting a
solution.

David

···

On Thu, 25 Mar 2004 01:39:52 +0900 > Ben Giddings bg-rubytalk@infofiend.com wrote:


David A. Black
dblack@wobblini.net

Its about breaking as much as possible in the transition to Rite,
somebody has to raise the nasty questions, and this question is in
paticular about religion.

No, not religion, just politics:
Conservative: camelCasing hurts the economy, and besides, it’s deviant
behavior!
Liberal: camelCasers have as much right to program as you and I!
Besides, I kinda like it myself…
Libertarian: I may not be a camelCaser myself, but I’ll be damned if
I’ll let you guys strip away another freedom! (where’s my shotgun?!?)
Socialist: camelCasing is a cancer eating away at the heart of our
culture. We must burn it out!!!

I want fewer syntax restrictions, not more.

Too much freedom may turn into anarchy. :wink:

Oh yeah, that’s right:
Anarchist: camelCase? I program in BrainF**k, dude. Get real

okay, okay, I didn’t get much sleep last night :slight_smile:

–Mark

···

On Mar 24, 2004, at 5:59 AM, Simon Strandgaard wrote: