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