| Frank Swarbrick 2006-03-09, 6:55 pm |
| Richard<riplin@Azonic.co.nz> 03/08/06 6:09 PM >>>
>
>Frank Swarbrick wrote:
>
>
>Actually you probably must not do that as it is not likely to do what
>you intend.
You're right. As I said, I couldn't recall if == would compare string
values or just their references. In C# it compares values.
>
>No. Not nicer. I use Cobol to write Cobol programs. There is no case
>statement at all in Python and I don't miss it.
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?
>
>The 'breaks' are not 'silly'. They allow one to do:
>
> case 1:
> case 2:
> dopart1and2;
> break;
>
>or even drop through:
>
> case 1:
> dopart1only;
> case 2:
> dopart1and2;
> break;
>
>But the break, or lack of it, is one of the bug traps in C-like
>languges. In Cobol one of the bug traps is not having an imperitive
>statement after a WHEN, or commenting it out, and having this drop into
>the next action. Python eliminated the case statement exactly for the
>reason that doing so removes the opportunity to create bugs.
I think that one is much more likely to forget a 'break' statement than one
is to comment out a single COBOL statement and having it drop through.
Which is not to say that there isn't a third, better, way. Such as,
maybe...
switch {
case 1:
or 2:
or 3:
dopart1;
case 4:
dopart2;
fallthru;
default:
doallothers;
}
Just off the top of my head, but this might be just as flexible and less
prone to mistakes.
myString[color=darkred]
>
>An == operator will only compare primitives. Object references are
>primitives, so Object == Object is only true if the two object
>references are identical, ie they both reference the same object.
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.
Frank
---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
|