| Richard 2006-03-09, 6:55 pm |
|
Frank Swarbrick wrote:
> You're right. As I said, I couldn't recall if =3D=3D would compare string
> values or just their references. In C# it compares values.
It may, or may not, compare values depending on what is defined for
that class and what has been overloaded.
For example it may be that if you had:
if ( stringobject =3D=3D 23 )
This may compare the length of the string with the integer, such is the
wonder of overloaded operators. The point being that you cannot tell
what it is going to be doing without looking at the class or
documentation for it.
Which is why I dislike overloading of operators.
> I don't know Python, really, other than a little reading. Can you show me
> how you might code the equivalent of a case statement?
Just a series of if .. elif .. elif .. else. In python the =3D=3D operator
does compare strings so:
if ( control =3D=3D =A8one=A8 ):
one()
elif ( control =3D=3D =A8two=A8 ):
two()
else:
thisdefault()
> I think that one is much more likely to forget a 'break' statement than o=
ne
> is to comment out a single COBOL statement and having it drop through.
That may depend on how experienced one is in the various languages and
how easily one switches from one to the other. I can=B4t recall the last
time that I forgot a break, but I do recall having done it when I
started with C.
> Which is not to say that there isn't a third, better, way. Such as,
> maybe...
But why not just be explicit about what you actually want with:
if ( this =3D=3D =A8one=A8
or this =3D=3D =A8two=A8 ):
do_one_or_two()
elif ( ...
> Just off the top of my head, but this might be just as flexible and less
> prone to mistakes.
If it is _different_ then it will lead to mistakes. Java is fine for C
programmers _because_ it is the same.
> Yep. As I said in a previous message, I don't like this. It seems to me
> I'm much more likely to want to do a "value" compare than a "reference"
> compare, so to me the "value" compare should be the "basic" compare. Just
> my opinion, obviously.
Then don=B4t use Java or C. In C one would use if ( strcmp(string1,
string2) =3D=3D 0 ) or similar to compare two strings. If ( string1 =3D=3D
string2 ) compares the two addresses. It is the way that the language
works, if you don=B4t like it then choose another. Personally, I have no
trouble switching to use what is provided by the language I am using at
the time.
|