Help sorting an array

J

Jeremy Bopp

hello,
i have my first (of what may be many) really dumb questions: why is it advantageous to be able to distinguish aVariableName from avariablename?

Are you asking why identifiers are case-sensitive?

-Jeremy
 
R

Robert Dober

thanks,
doug

I would not say it is advantageous. Maybe one could argue about
a_variable_name vs. AVariableName (bad example for camel case I guess)
It is a matter of taste, ... [computer! erase the last sentence!]
It is a matter of style and convention, Ruby has chosen the former
style and about everybody I know sticks to it. Note that camel case is
used for constants and that helps us to distinguish those two;)

thus in Ruby it is my_variable and MyConst. in Java it would be
MyVariable and MYCONST
I believe the Ruby style is more readable but that might be because I
read almost infinitely more ruby code than Java code :p.

Cheers
Robert
 
R

Robert Klemme

why is it advantageous to be able to distinguish aVariableName from avariablename?

So you basically ask why Ruby's identifiers are case sensitive. It's
that way in many (most?) programming languages. I suspect that what to
us humans looks like simple (identifying both variants as the same
variable) is more difficult for computers: case handling is highly
dependent on the encoding used and may actually be difficult to compute.
For a machine it is easier to just test for binary identity.

Good news is: you can actually get used to this. :)

Kind regards

robert
 
D

Doug Stone

WWVzLCB0aGFua3M6IEkgd2FzIGFza2luZyB3aHksIHdoZW4gZGVzaWduaW5nIGEgbGFuZ3VhZ2Us
IHdoeSBtYWtlIGlkZW50aWZpZXJzIGNhc2Ugc2Vuc2l0aXZlLiAgT25lIGxpc3QgbWVtYmVyIHJl
c3BvbmRlZCB0aGF0IHRoZXJlIHdvdWxkIGJlIGFuIGV4dHJhIG92ZXJoZWFkIGludm9sdmVkIGlu
IGVxdWF0aW5nLCBzYXksIGFWYXJpYWJsZU5hbWUgd2l0aCBhdmFyaWFibGVuYW1lLiAgT3Zlcmhl
YWQgY29uc2lkZXJhdGlvbnMgYXNpZGUsIEkgdGhpbmsgaXQgd291bGQgYmUgZGVzaXJhYmxlIHRv
IGhhdmUgaWRlbnRpZmllcnMgYmUgY2FzZS1pbnNlbnNpdGl2ZS4uLiA/DQoNCi0tLS0tT3JpZ2lu
YWwgTWVzc2FnZS0tLS0tDQpGcm9tOiBKZXJlbXkgQm9wcCBbbWFpbHRvOmplcmVteUBib3BwLm5l
dF0gDQpTZW50OiBUaHVyc2RheSwgRGVjZW1iZXIgMDIsIDIwMTAgOToyNCBBTQ0KVG86IHJ1Ynkt
dGFsayBNTA0KU3ViamVjdDogUmU6IG5ld2JpZTogdmFyaWFibGUgbmFtZXMNCg0KT24gMTIvMi8y
MDEwIDExOjA3IEFNLCBEb3VnIFN0b25lIHdyb3RlOg0KPiBoZWxsbywNCj4gaSBoYXZlIG15IGZp
cnN0IChvZiB3aGF0IG1heSBiZSBtYW55KSByZWFsbHkgZHVtYiBxdWVzdGlvbnM6IHdoeSBpcyBp
dCBhZHZhbnRhZ2VvdXMgdG8gYmUgYWJsZSB0byBkaXN0aW5ndWlzaCBhVmFyaWFibGVOYW1lIGZy
b20gYXZhcmlhYmxlbmFtZT8gIA0KDQpBcmUgeW91IGFza2luZyB3aHkgaWRlbnRpZmllcnMgYXJl
IGNhc2Utc2Vuc2l0aXZlPw0KDQotSmVyZW15DQoNCg==
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

Yes, thanks: I was asking why, when designing a language, why make
identifiers case sensitive. One list member responded that there would be
an extra overhead involved in equating, say, aVariableName with
avariablename. Overhead considerations aside, I think it would be desirable
to have identifiers be case-insensitive... ?
As an extremely visually oriented person, I think I would incur a mental
overhad as well if you could talk about the same variable/method in
different places, but have the method name look different in each of them.

Interestingly, in JRuby, when dealing with Java libs, you can call methods
with either snake_case, or camelCase, and both will work just fine.
 
J

Jeremy Bopp

Yes, thanks: I was asking why, when designing a language, why make identifiers case sensitive. One list member responded that there would be an extra overhead involved in equating, say, aVariableName with avariablename. Overhead considerations aside, I think it would be desirable to have identifiers be case-insensitive... ?

I can't speak to the reasoning behind the design decision, but I see
potential problems with either methodology.

When using case-sensitive identifiers, you can make your program
confusing by purposely using capitalization differences between
identifiers in order to hold different values or carry out different
functions. In a scripting language such as Ruby, a simple typoed
identifier could cause hard to find bugs, especially if the typo was a
minor capitalization difference. It would definitely be worse if the
convention for most identifiers was camel case as that could easily hide
incorrect caps. Fortunately, I have never seen this to be a common
issue even within some outrageously bad code I've inherited over the years.

OTOH, one could get pretty sloppy with identifier names, perhaps
unintentionally, if capitalization is ignored and thereby make a program
a challenge for a human to read later. Maybe that wouldn't be a
frequent problem either though.

What would be the biggest advantage of allowing case-insensitivity in
your opinion?

-Jeremy
 
J

John Morrice

Overhead considerations aside, I think it would
be desirable to have identifiers be case-insensitive... ?

As Robert Dober said, in Ruby, constants (Upper case) are
different beasts than variables (lower case).

An unfortunately unpasteable example:

irb(main):001:0> Hello = "I am a constant!"
=> "I am a constant!"

irb(main):002:0> hello = "I am a variable."
=> "I am a variable."

irb(main):003:0> Hello = "Indeed, I am a constant."
(irb):3: warning: already initialized constant Hello
=> "Indeed, I am a constant."

irb(main):004:0> def access_variable_example
irb(main):005:1> puts hello
irb(main):006:1> end

irb(main):007:0> access_variable_example
NameError: undefined local variable or method `hello' for main:Object
from (irb):5:in `access_variable_example'
from (irb):7
from /usr/local/bin/irb:12:in `<main>'

irb(main):008:0> def access_constant_example
irb(main):009:1> puts Hello
irb(main):010:1> end
=> nil

irb(main):011:0> access_constant_example
Indeed, I am a constant.
=> nil

It is desirable for a language to have a syntax which reflects the
semantics. Capitalization is easy to see, easy to type, and
doesn't add any extra waffle.

Also, case sensitivity gives me more choice. I can have sockets and
Sockets and SOCKETS, and have them, individually, mean whatever I want
to.

Johnny
 
J

Jörg W Mittag

Robert said:
So you basically ask why Ruby's identifiers are case sensitive. It's
that way in many (most?) programming languages. I suspect that what to
us humans looks like simple (identifying both variants as the same
variable) is more difficult for computers: case handling is highly
dependent on the encoding used and may actually be difficult to compute.

It's actually impossible. My favorite example:

def maße; end
def masse; end

MASSE # Oops. Which one do I mean?

jwm
 
S

Stu

I worked with macromedia( now adobe) lingo which was case insensitive
pre internet days. Though it was a "feature" no one used it. That
language it was more common to use hungerian notation for naming.

The token parser would have to have some extra checks and some
conversions but once turned into byte code and cached the program
should run just as fast. in c a char is still sizeof(char) and an
integer is still sizeof(int).

I would imagine the 'design decision' would have more to do with
creating something that is useful as opposed to making a feature which
though interesting would never be used in a real world application.

Yes, thanks: I was asking why, when designing a language, why make identi=
fiers case sensitive. =A0One list member responded that there would be an e=
xtra overhead involved in equating, say, aVariableName with avariablename. =
=A0Overhead considerations aside, I think it would be desirable to have ide=
ntifiers be case-insensitive... ?
-----Original Message-----
From: Jeremy Bopp [mailto:[email protected]]
Sent: Thursday, December 02, 2010 9:24 AM
To: ruby-talk ML
Subject: Re: newbie: variable names

hello,
i have my first (of what may be many) really dumb questions: why is it a=
dvantageous to be able to distinguish aVariableName from avariablename?
 
P

Phillip Gawlowski

2010/12/2 J=F6rg W Mittag said:
It's actually impossible. My favorite example:

=A0 =A0def ma=DFe; end
=A0 =A0def masse; end

=A0 =A0MASSE =A0# =A0Oops. Which one do I mean?

This can get even worse if you have a font with an upper case =DF (these ex=
ist):

MA=DFE # Er...


That's also a good example why Unicode is a good thing, but can be
painful when using Unicode characters to name programming constructs.

--=20
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 

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

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top