[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CamelCase issues

Michael Neumann

10/21/2004 9:12:00 AM

Hi,

For method names that contain up to two words, I really prefer the
underscore-case (e.g., has_key?, method_missing). But if the method name
contains more than two words that starts to look ugly IMO. It even looks
strange (IMO) if you use underscore-case very often in your program
(everything is small, no contrast for your eyes):

c.form.url("foo").with {
c.table {
c.table_row.id("myrow").with {
c.table_data.align_top.col_span(3).with("Hello world")
}
c.table_row_with_data {
c << "Foo:"
c.text_input.value(myobject.foo).callback(myobject, :foo=)
}
}
}

Versus:

c.form.url("foo").with {
c.table {
c.tableRow.id("myrow").with {
c.tableData.alignTop.colSpan(3).with("Hello world")
}
c.tableRowWithData {
c << "Foo:"
c.textInput.value(myobject.foo).callback(myobject, :foo=)
}
}
}

(and if you know that there's a class TableData, shouldn't the method be
named tableData instead of table_data ?)

I know that underscore-case is the perfered way in Ruby.

Some more examples:

render_content_on <-> renderContentOn
render_table_header_on <-> renderTableHeaderOn

Which one would you prefer? Thanks.

Regards,

Michael


29 Answers

Robert Klemme

10/21/2004 9:30:00 AM

0


"Michael Neumann" <mneumann@ntecs.de> schrieb im Newsbeitrag
news:20041021091218.GC983@miya.intranet.ntecs.de...
> Hi,
>
> For method names that contain up to two words, I really prefer the
> underscore-case (e.g., has_key?, method_missing). But if the method name
> contains more than two words that starts to look ugly IMO. It even looks
> strange (IMO) if you use underscore-case very often in your program
> (everything is small, no contrast for your eyes):
>
> c.form.url("foo").with {
> c.table {
> c.table_row.id("myrow").with {
> c.table_data.align_top.col_span(3).with("Hello world")
> }
> c.table_row_with_data {
> c << "Foo:"
> c.text_input.value(myobject.foo).callback(myobject, :foo=)
> }
> }
> }
>
> Versus:
>
> c.form.url("foo").with {
> c.table {
> c.tableRow.id("myrow").with {
> c.tableData.alignTop.colSpan(3).with("Hello world")
> }
> c.tableRowWithData {
> c << "Foo:"
> c.textInput.value(myobject.foo).callback(myobject, :foo=)
> }
> }
> }
>
> (and if you know that there's a class TableData, shouldn't the method be
> named tableData instead of table_data ?)
>
> I know that underscore-case is the perfered way in Ruby.
>
> Some more examples:
>
> render_content_on <-> renderContentOn
> render_table_header_on <-> renderTableHeaderOn
>
> Which one would you prefer? Thanks.

I'd stick with underscore style. IMHO readability is not really improved
with camel case (might depend on screen, font and coloring though) and the
only advantage is that you save some chars.

It might be different for you but I have to use more than three
identifiers separated by a dot very rarely; so from my personal experience
the example you showed seems to be rather exceptional than regular - YMMV
though. I don't know the classes of your example so I don't know whether
these chains *have* to be there because all invocations create new
instance. If not, i.e., if some of those methods just return self, I'd
rather resort to multiple lines with individual invocations.

My 0.02EUR...

Kind regards

robert

Michael Neumann

10/21/2004 10:01:00 AM

0

On Thu, Oct 21, 2004 at 06:34:20PM +0900, Robert Klemme wrote:
>
> "Michael Neumann" <mneumann@ntecs.de> schrieb im Newsbeitrag
> news:20041021091218.GC983@miya.intranet.ntecs.de...
> > Hi,
> >
> > For method names that contain up to two words, I really prefer the
> > underscore-case (e.g., has_key?, method_missing). But if the method name
> > contains more than two words that starts to look ugly IMO. It even looks
> > strange (IMO) if you use underscore-case very often in your program
> > (everything is small, no contrast for your eyes):
> >
> > c.form.url("foo").with {
> > c.table {
> > c.table_row.id("myrow").with {
> > c.table_data.align_top.col_span(3).with("Hello world")
> > }
> > c.table_row_with_data {
> > c << "Foo:"
> > c.text_input.value(myobject.foo).callback(myobject, :foo=)
> > }
> > }
> > }
> >
> > Versus:
> >
> > c.form.url("foo").with {
> > c.table {
> > c.tableRow.id("myrow").with {
> > c.tableData.alignTop.colSpan(3).with("Hello world")
> > }
> > c.tableRowWithData {
> > c << "Foo:"
> > c.textInput.value(myobject.foo).callback(myobject, :foo=)
> > }
> > }
> > }
> >
> > (and if you know that there's a class TableData, shouldn't the method be
> > named tableData instead of table_data ?)
> >
> > I know that underscore-case is the perfered way in Ruby.
> >
> > Some more examples:
> >
> > render_content_on <-> renderContentOn
> > render_table_header_on <-> renderTableHeaderOn
> >
> > Which one would you prefer? Thanks.
>
> I'd stick with underscore style. IMHO readability is not really improved
> with camel case (might depend on screen, font and coloring though) and the
> only advantage is that you save some chars.

I usually agree. Hmm strange, now the example with underscores starts to
look better ;-)

> It might be different for you but I have to use more than three
> identifiers separated by a dot very rarely; so from my personal experience
> the example you showed seems to be rather exceptional than regular - YMMV
> though. I don't know the classes of your example so I don't know whether
> these chains *have* to be there because all invocations create new
> instance. If not, i.e., if some of those methods just return self, I'd
> rather resort to multiple lines with individual invocations.

No, these chains are not exceptional! And yes, they return self most of
the time. It's a port of Seaside2's new Html rendering scheme.

> My 0.02EUR...

Thanks.

Regards,

Michael


George Moschovitis

10/21/2004 10:05:00 AM

0

> Then, how about file names? Do you prefer underscore-style, too?
> For example:
> session_store.rb vs.
> SessionStore.rb
>
> Shouldn't they be named after the class (camelcase)?

I prefer session-store.rb (like many filenames in the standard Ruby
dist). There is no reason to use SessionStore. A Ruby source file
may contain multiple Ruby classes.

George

--
www.navel.gr | tel: +30 2106898050 | fax: +30 2106898437

Navel does not accept liability for any errors, viruses or omissions in
the contents of this message. The full corporate policy is available on
our site.

have fun: www.joy.gr

Michael Neumann

10/21/2004 10:06:00 AM

0

On Thu, Oct 21, 2004 at 06:34:20PM +0900, Robert Klemme wrote:
> > Which one would you prefer? Thanks.
>
> I'd stick with underscore style. IMHO readability is not really improved
> with camel case (might depend on screen, font and coloring though) and the
> only advantage is that you save some chars.

Then, how about file names? Do you prefer underscore-style, too?
For example:

session_store.rb vs.
SessionStore.rb

Shouldn't they be named after the class (camelcase)?

Regards,

Michael


Robert Klemme

10/21/2004 11:03:00 AM

0


"Michael Neumann" <mneumann@ntecs.de> schrieb im Newsbeitrag
news:20041021100547.GF983@miya.intranet.ntecs.de...
> On Thu, Oct 21, 2004 at 06:34:20PM +0900, Robert Klemme wrote:
> > > Which one would you prefer? Thanks.
> >
> > I'd stick with underscore style. IMHO readability is not really
improved
> > with camel case (might depend on screen, font and coloring though) and
the
> > only advantage is that you save some chars.
>
> Then, how about file names? Do you prefer underscore-style, too?
> For example:
>
> session_store.rb vs.
> SessionStore.rb
>
> Shouldn't they be named after the class (camelcase)?

Hm, never though of that much. But I'd say, if a file contains only one
class, name it after that class, otherwise choose the name that seems most
appropriate (whatever that is :-)).

Kind regards

robert

Austin Ziegler

10/21/2004 12:19:00 PM

0

On Thu, 21 Oct 2004 19:05:54 +0900, Michael Neumann <mneumann@ntecs.de> wrote:
> On Thu, Oct 21, 2004 at 06:34:20PM +0900, Robert Klemme wrote:
> > > Which one would you prefer? Thanks.
> > I'd stick with underscore style. IMHO readability is not really improved
> > with camel case (might depend on screen, font and coloring though) and the
> > only advantage is that you save some chars.
> Then, how about file names? Do you prefer underscore-style, too?
> For example:
>
> session_store.rb vs.
> SessionStore.rb
>
> Shouldn't they be named after the class (camelcase)?

In this case, I would simply call it:

sessionstore.rb

In other words, I deal with filenames that contain a single class (or
the main class, even) as class.to_s.downcase for the filename.

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
: as of this email, I have [ 5 ] Gmail invitations


Nikolai Weibull

10/21/2004 12:33:00 PM

0

* George Moschovitis <gm@navel.gr> [Oct 21, 2004 12:20]:
> > Then, how about file names? Do you prefer underscore-style, too?
> > For example:

> > session_store.rb vs.
> > SessionStore.rb

> > Shouldn't they be named after the class (camelcase)?

> I prefer session-store.rb (like many filenames in the standard Ruby
> dist). There is no reason to use SessionStore. A Ruby source file
> may contain multiple Ruby classes.

definitely,
nikolai

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


T. Onoma

10/21/2004 5:28:00 PM

0

On Thursday 21 October 2004 05:12 am, Michael Neumann wrote:
| Hi,
|
| For method names that contain up to two words, I really prefer the
| underscore-case (e.g., has_key?, method_missing). But if the method name
| contains more than two words that starts to look ugly IMO. It even looks
| strange (IMO) if you use underscore-case very often in your program
| (everything is small, no contrast for your eyes):
|
| c.form.url("foo").with {
| c.table {
| c.table_row.id("myrow").with {
| c.table_data.align_top.col_span(3).with("Hello world")
| }
| c.table_row_with_data {
| c << "Foo:"
| c.text_input.value(myobject.foo).callback(myobject, :foo=)
| }
| }
| }
|
| Versus:
|
| c.form.url("foo").with {
| c.table {
| c.tableRow.id("myrow").with {
| c.tableData.alignTop.colSpan(3).with("Hello world")
| }
| c.tableRowWithData {
| c << "Foo:"
| c.textInput.value(myobject.foo).callback(myobject, :foo=)
| }
| }
| }

Not every single word need to be divided. There is a balance I think:

c.form.url("foo").with {
c.table {
c.tablerow.id("myrow").with {
c.tabledata.aligntop.colspan(3).with("Hello world")
}
c.tablerow_with_data {
c << "Foo:"
c.textinput.value(myobject.foo).callback(myobject, :foo=)
}
}
}


| (and if you know that there's a class TableData, shouldn't the method be
| named tableData instead of table_data ?)
|
| I know that underscore-case is the perfered way in Ruby.

Actually I would like to see Ruby move away from the significance of
capitalization if possible.

T.




Stefan Schmiedl

10/21/2004 8:45:00 PM

0

On Thu, 21 Oct 2004 18:12:23 +0900,
Michael Neumann <mneumann@ntecs.de> wrote:
> Some more examples:
>
> render_content_on <-> renderContentOn
> render_table_header_on <-> renderTableHeaderOn
>
> Which one would you prefer? Thanks.

Actually, I'd prefer

content.render_on and
table.header.render_on

but I'm not sure if that's an answer to your question :-)

s.

Michael DeHaan

10/21/2004 9:18:00 PM

0

> > Some more examples:
> >
> > render_content_on <-> renderContentOn
> > render_table_header_on <-> renderTableHeaderOn
> >

To add more confusion to this thread ...

A user of this API might have a question. Does render_content_on
change a value or return the current one, based on whether it has
parameters? It's hard to tell.

To clean this up, I'd be apt to use attr_reader and attr_writer, while
overriding the render_content= function.

Trivial accessor and mutator methods are not something I'm a fan of,
I'd like to keep field syntax when things are simple. I mean, we
could write a render_content? kind of query function, but what would
be the point?

Let me know if that's totally evil, I'm new here :)

--MPD