error:- "regex literal in condition"

Z

Zach

I know the current naming standards of the language. My curiosity is
how many programmers prefer it.

Prime example given by a few: snake_case is preferable to Japanese Readers.

-Zach
 
W

William James

Zach said:
Alrighty,

I've another question I'd like to pose the Ruby community. Coming
from a Java background, so I'm rather used to "camelCase" as opposed to
what looks to be the standard "ruby_case". (For those who don't know, If
a method is java was named "DoSomething" it would be called
"doSomething" in Java, and likewise "do_something" in Ruby.)

Arguments I've personally witnessed against Camel Case is Acronyms. If I
have an "ABC" in Camel Case it I'd have to would be to break up the
acronym like "aBC" if it appears at the beginning of the word. A lot of
people try to push the word to the end, others say to have the whole
acronym as lowercase "abc", but I think that is just a workaround for
the problem not a solution.

aBunchOfStuffIWantToSave

is less readable than

a_bunch_of_stuff_I_want_to_save

If your language allows the underscore, use it!
 
A

ara.t.howard

This is an ignorant question to pose, but here I go anyway.

Does anyone see advantages to using Hungarian Case to variable names in
Ruby, or do you think it may hinder as some people call "accidental
abstraction" [Bill Davis] ? Since Ruby is big with "Duck Typing", would
using Hungarian Case be more of a verbal obstacle than a more descriptive
variable. What about varying degrees, such as for integers, doubles,
strings, and o for Objects, but not exhaustive?

(For those who don't know about Hungarian typing, it would similar to an
integer you would name "counter" being named "iCounter" or a variable you
would normally name "duck" be "oDuck" because it is an object)

I know this is a rather old topic to be bringing into a newer technology,
but I'm curious on what your all's take is on this.

i think everyone, even the people who strongly object to hungarian naming,
actually do this to varying degrees:

n_bins = 42 # clearly this is a numeric variable

lines << line # clearly/probably lines is an array/container a line is an element of it

x_i, x_f, x_s = x.to_i, x.to_f, x.to_s # no explanation needed

if it helps you read your own code i don't think it would really put anyone
off. however, i'd strongly reccomend using

counter_i vs. iCounter

also

CamElcaseForVARIAbleNameSisDefiNtelyNotRUby ;-)


the standard library certainly prefers encoding type info at the back of the
variable, not the front:


harp:~/build/ruby-1.8.4/lib > egrep '^\s*[^\s\.#]+_hash\>' *rb
resolv.rb: config_hash = Config.parse_resolv_conf(filename)
resolv.rb: config_hash = {}
resolv.rb: config_hash[:nameserver] = nameserver if nameserver
resolv.rb: config_hash[:search] = [search].flatten if search
resolv.rb: config_hash
resolv.rb: config_hash = Config.default_config_hash
resolv.rb: config_hash = Config.parse_resolv_conf(@config_info)
resolv.rb: config_hash = @config_info.dup
resolv.rb: if String === config_hash[:nameserver]
resolv.rb: config_hash[:nameserver] = [config_hash[:nameserver]]
resolv.rb: if String === config_hash[:search]
resolv.rb: config_hash[:search] = [config_hash[:search]]
un.rb: opt_hash = {}
un.rb: opt_hash[s.delete(":").intern] = val
un.rb: yield ARGV, opt_hash



harp:~/build/ruby-1.8.4/lib > egrep '^\s*[^\s\.#]+_io\>' *rb
irb.rb: back_io = @context.io
irb.rb: yield back_io



harp:~/build/ruby-1.8.4/lib > egrep '^\s*[^\s\.#]+_string\>' *rb
cgi-lib.rb: url_encoded_string = CGI::escape("string")
scanf.rb: attr_reader :re_string, :matched_string, :conversion, :matched
scanf.rb: @re_string, @handler =
scanf.rb: @re_string = '\A' + @re_string
scanf.rb: @matched_string = @conversion.to_s
scanf.rb: width_left = c_or_cc_width && (matched_string.size < width)



harp:~/build/ruby-1.8.4/lib > egrep '^\s*[^\s\.#]+_file\>' *rb
debug.rb: binding_file = file
debug.rb: line_at(binding_file, binding_line)
debug.rb: binding, binding_file, binding_line = @frames[frame_pos]
debug.rb: binding, binding_file, binding_line = @frames[frame_pos]
logger.rb: age_file = "#{@filename}.#{postfix}"
pstore.rb: new_file = @filename + ".new"
pstore.rb: tmp_file = @filename + ".tmp"
pstore.rb: new_file = @filename + ".new"


of course this isn't strictly hungarian, but it's pretty much the same idea in
many cases. in the end anything that helps you read your own code and maintain
it is good - as the brits say: suck it and see.

cheers.


-a
 
G

Gabe Boyer

------=_Part_15779_13592843.1137803529796
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I tend to prefer to adopt the stylistic conventions of the language I am
working in. Rather than try to hold on to some cross-language personal
preference, I find having my code match the style of the libraries that I a=
m
using to be the most aesthetically pleasing.

Gabe

I know the current naming standards of the language. My curiosity is
how many programmers prefer it.

Prime example given by a few: snake_case is preferable to Japanese
Readers.

-Zach

------=_Part_15779_13592843.1137803529796--
 
B

Bill Kelly

From: "Zach said:
I know the current naming standards of the language. My curiosity is
how many programmers prefer it.

Personally, I like Ruby's naming standards. I prefer snake_case to
camelCase in general, so that helps. But an important point is, I think,
that it's better to adopt the naming standards of whatever language
I'm coding in. In Java, I follow Sun's naming conventions. We've seen
posts from Ruby programmers who stick with their own style, regardless
of language. That's their prerogative, but if one is writing library code
to share with the Ruby community, I think it's especially important to be
willing to adopt the Ruby naming conventions. It's always a sinking
feeling (for me anyway) to download what might be a nice open source
Ruby library, and find the author was either unaware of the Ruby
naming conventions, or decided to disregard them, thereby putting
unnecessary burden on all users of the library. Makes me want to
scream, "Oh! You inconsiderate miserable b****rd!!!!" - but that is
always tempered by, "But, thanks for the free code!" <grin>

Anyway, "When in Rome, ..." etc.


Regards,

Bill
 
J

John W. Kennedy

Hungarian notation has never been useful except in C code before C
compilers started doing a reliable job of identifying type mismatches,

That's not entirely true. It can be /very/ clarifying in complex cases
of pointers to pointers, etc.

But I agree it's a bad fit with Ruby.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
G

Gregory Brown

It's always a sinking
feeling (for me anyway) to download what might be a nice open source
Ruby library, and find the author was either unaware of the Ruby
naming conventions, or decided to disregard them, thereby putting
unnecessary burden on all users of the library. Makes me want to
scream, "Oh! You inconsiderate miserable b****rd!!!!" - but that is
always tempered by, "But, thanks for the free code!" <grin>

Nicely put! I too prefer to use the conventions of the language I am
working in.
I used to use camelCase everywhere when I first got into Java. That
angered a few people. I learned ;)
 
M

Mark Probert

hi ..

James said:
If you have a variable that refers, say, to an instance of a class
representing a hotel reservation, name it as such:
current_hotel_reservation. Not hr_curr or the like.
Personally, I think that there is a place for short names as I find them
much more readable. Verbosity can be a real impediment to readability.
 
J

James Britt

Mark said:
hi ..


Personally, I think that there is a place for short names as I find them
much more readable. Verbosity can be a real impediment to readability.

Well, readability and communication are key.

James
 
K

Kevin Olbrich

James said:
Well, readability and communication are key.

James

An interesting concept for functional apps (or system) Hungarian in
Ruby. It would be pretty easy to set up the missing_method function to
extract out certain tags from a variable name.

For example,
assume you have a model with an attribute called 'Text'

you could set up missing_method to pick up 'iText' and return
'Text.to_i' or 'hText' could return 'h(Text)' etc...

NOTE: I'm not advocating that this is a good idea, I'm just pointing out
that you could use Hungarian notation in Ruby and actually have it do
something.

_Kevin
 
D

dblack

Hi --

An interesting concept for functional apps (or system) Hungarian in
Ruby. It would be pretty easy to set up the missing_method function to
extract out certain tags from a variable name.

For example,
assume you have a model with an attribute called 'Text'

(A class with an attribute called "text"?)
you could set up missing_method to pick up 'iText' and return
'Text.to_i' or 'hText' could return 'h(Text)' etc...

Why not just call to_i or h in the first place? :)


David

--
David A. Black
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
K

Kevin Olbrich

Kevin said:
NOTE: I'm not advocating that this is a good idea, I'm just pointing out
that you could use Hungarian notation in Ruby and actually have it do
something.

David A. Black said..
Why not just call to_i or h in the first place? :)

In most cases I expect that it would be better that way, and that would
be my preference as well. I suppose it might be useful for porting
code.

_Kevin
 
J

James Edward Gray II

An interesting concept for functional apps (or system) Hungarian in
Ruby. It would be pretty easy to set up the missing_method
function to
extract out certain tags from a variable name.

For example,
assume you have a model with an attribute called 'Text'

you could set up missing_method to pick up 'iText' and return
'Text.to_i' or 'hText' could return 'h(Text)' etc...

How are you going to assign a variable (iText = ...), and then
convince Ruby to treat it as a method (to trigger method_missing())?

James Edward Gray II
 
J

James Britt

Hi --

On Tue, 24 Jan 2006, Kevin Olbrich wrote: ...


(A class with an attribute called "text"?)



Why not just call to_i or h in the first place? :)

Aesthetics? Encapsulation? Hiding implementation details? Amusement?

I've seen code that takes find_by_foo( bar ) and converts it into find(
:foo => bar ) or some such thing. Is this to save typing (he asked
rhetorically)? Expression of intent? Slickitude factor ("Ha! Try THAT,
Java droids!" )? (Still rhetorical; please, no flames.)

I showed this as part of a Ruby demo, and at least one person didn't
see what that bought you. Fair enough. I tend to like it, though.

hText (though h_text or text_h looks more Rubyish) is just another
example of embedding code in message names.

But it can teeter toward DSL: domain-specific logorrhea.

foo.baz_then_bar_unless_bif_equals_47

James Britt

--

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools
 
K

Kevin Olbrich

James said:
How are you going to assign a variable (iText = ...), and then
convince Ruby to treat it as a method (to trigger method_missing())?

I just tested this with a quick one and found that if you do something
like

object.iTest=5

Then method_missing will get 'iTest=' as the symbol, and 'n' as an
argument. Then it's a simple matter of trimming the 'i' off the front
and returning the result of '(test=n).to_i'.

_Kevin
 
J

James Edward Gray II

I just tested this with a quick one and found that if you do something
like

object.iTest=5

Then method_missing will get 'iTest=' as the symbol, and 'n' as an
argument. Then it's a simple matter of trimming the 'i' off the front
and returning the result of '(test=n).to_i'.

Gotcha. I thought you were talking about using local variables. I
understand now. Thanks.

James Edward Gray II
 

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

Forum statistics

Threads
474,298
Messages
2,571,539
Members
48,274
Latest member
HowardKipp

Latest Threads

Top