By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

I'm very disturbed! Sherlock H. HELP

P: n/a

Within the following construction
switch (expression)
{
int i;
i = GetArgs() //return 2

case constant-expression:

if ( 2 == i )
{
//statement 1
}
else
{
//statement 2
}

break;

case constant-expression:
....
break;
}

(the switch block is nested within a try using catch
block)

I get execution of both statements!!!!. I thought I was
an experienced c++ programmer (10y+) migrating to C# but
I can't see what I'm doing wrong. If I take the code
snippet and puts it over in another project it works
fine, hence the syntax is ok. If I instead of ( 2 == i )
writes ( true ) it also works fine.

Please advise
best regards Jesper

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
100
Hi John,
[You do know that posting private emails is incredibly bad netiquette
by the way, don't you? Please don't do it again.] I'm really sorry about that. I' ve never had the idea to make it private
conversation, but I did. And I brought it back to the thread by mistake. I'm
really, really sorry and I'll make sure that this will never happen again.
And based on my experience - in software companies in North America the most are not.


Pardon?

Sad, but true.

.........

I really thought it might be interesting to the others in the group. It
appears to be not. So now it looks like we are just teasing each other. You
are one of the persons, which posts I almost always read and I've found that
it is like you love to drill down the details, which in many cases are not
relevant to the question (like this one with "const ==var").
Maybe you read the source code like you read books. I don't know this and
I'll never know. But I read source code in the way I read a .... source
code.... I mean engaging my brain. It might be the reason why I don't have
problems with either.
I would suggest that the same is the case for many programmers out
there, given how rarely one sees if (2==x) outside C/C++ where it's
used to avoid bugs.
The reason is that many programmers never thought about it. And it looks
like they don't read books named "Writing solid code". The prefered titles
are "Learning *something* in 24 hours". Or they think "Why should I read a
book where the examples are in c++ if I'm a Java programmer.
Why not? If my code is primarily going to be read by people who have
English as their first language ???????????
(my colleagues, for a start) then why
should I not make the code as readable as possible for them? Like it or not, I *do* think in English, where your way of expressing a
comparison is unnatural. I like it frankly. I think that many problems could be solved if we speek
and think one language. English or not, it doesn't really matter. Back to
the reality, we (non English) don't think in english, though.
You claim it doesn't hurt the readability. I *know* it does, for me. Yes, I can see, for you it does.
In that case I suggest you go back to C/C++ with the "freedom" of
memory leaks etc. Frankly I think you'll find you're in the minority if
you believe that the lax if(...) compiler rules in C/C++ are a benefit.
It is strange that you bring up the qestion of the memory leaks. Reading the
groups for .NET I have seen so many post about memory leaks in the
framework. That many I've never seen in any c++ group. Believe me or not I
have never had problems with memory leaks.
In .NET and Java, I think, lot of objects stay in the managed heap
unreferenced awaiting for the GC to collect them undefined amount of time.
Some thimes they stay there until the precess ends, when eventually they get
freed. This in c++ we called memory leak. In .NET and Java it is called
managed heap.

C/C++ guys looks like more flexible that the JAVA ones. I'm not afraid to
learn and work in any other language. And I'd love to go back to c++ some
time. Even I cen do some Java programs. Why not...
Way to make a post unreadable... you do realise that anyone trying to
follow this who *hasn't* read our previous two emails is now utterly
confused by now, don't you?
I already made my appologies to you. Now I would like to apologize to the
others.
Even if there is 0.01% chance anybody to use them I don't want to take it
and I'll insist the member of the team to use such a "tricks". So you'll prevent someone from writing code they (and other team
members) might find more readable, just because it might just, some
day, create one bug? That's really bad team leadership, IMO - you'll be
creating more bugs just by making them have to do more mental
translation when writing and reading the code. "Mental translation" - sounds so complicated for so easy thing.
Let's just hope I never have to work with you... I'd like to work with you. I feel like you can hardly work with
*non-english*, but we can find a way around this, I believe.
but comparing one boolean with the value of a method is pretty rare
too, in my code Sounds senseless to me.
I'm not saying I never use cut-and-paste. I'm saying I try to use it as
little as possible. Being able to cut and paste between different
languages is almost entirely unimportant for me, and whenever I *do*
cut and paste I have enough sense to check what I'm doing - because
cutting and pasting without examining the code afterwards is going to
cause far more bugs than using if (i==5).

Cut and paste between languages? *hmmm* I've never thought about that. Does
anybody do that?
for (int i=0; i < 10; i++) NULL;
Is clear enough. Too many comments hurts readability as well. Obvious things don't have to be commented.


In that case reduce it to:

for (int i=0; i < 10; i++) {}

Maybe clear..., but ugly. I would prefer to stick with the 3-more-letters
one.

B\rgds
100
Nov 15 '05 #2

P: n/a
100

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
100 <10*@100.com> wrote:
> And based on my experience - in software companies in North America the > most are not.

Pardon? Sad, but true.


I meant pardon as in, please rephrase that, because currently it
doesn't make sense as a sentence.

I'll try one more time. Like it or not the most of the software companies
are situated in North America And in those companies most of the programmers
doesn't have english as a first language. And they don't think in English.
I really thought it might be interesting to the others in the group. It
appears to be not. So now it looks like we are just teasing each other. You
are one of the persons, which posts I almost always read and I've found that it is like you love to drill down the details, which in many cases are not relevant to the question (like this one with "const ==var").
Certainly. I'll pick up on just about anything :)

Try harder, Jon. I don't understand everything of your perfect anglish,
neither. I'm keep trying, though. Some times it takes me several times to
read one paragraph, but I never give up. I appreciate everything that you
say.
And the last I mean it.
Maybe you read the source code like you read books. I don't know this and I'll never know. But I read source code in the way I read a .... source
code.... I mean engaging my brain. It might be the reason why I don't have problems with either.
I engage my brain too, but I read both books and source-code at least
to a certain extent "out loud" in my head.


I would suggest that the same is the case for many programmers out
there, given how rarely one sees if (2==x) outside C/C++ where it's
used to avoid bugs.
The reason is that many programmers never thought about it.


You seem very sure of that.
And it looks like they don't read books named "Writing solid code".


Or maybe they understand why it's not an issue in Java or C#, or just
find it more readable as I do.
The prefered titles
are "Learning *something* in 24 hours". Or they think "Why should I read a
book where the examples are in c++ if I'm a Java programmer.


And where in fact it seems that at least some of the strategies
proposed aren't relevant. I'd suggest that "Effective Java" by Joshua
Bloch is a superb read for Java programmers, but certainly some of the
points made don't apply to C# (although some do).
Why not? If my code is primarily going to be read by people who have
English as their first language

???????????
Sorry, I forgot you are English.

What's surprising about that? My colleagues all have English as their
first language, as do I. Chances are that for any one bit of personal
code I write, I'm likely to be the person reading it most.
(my colleagues, for a start) then why
should I not make the code as readable as possible for them?
Like it or not, I *do* think in English, where your way of expressing a comparison is unnatural.
I like it frankly. I think that many problems could be solved if we speek and think one language. English or not, it doesn't really matter. Back to the reality, we (non English) don't think in english, though.


Sure - I don't have any problem with that. However, I'd be interested
to know which languages have a preference for comparisons like this,
and which way that preference works.


Hmmm. I prefer a programming language for expressing comparitions in my
programs. And I don't try to read it *out loud* in english it doesn't make
sense to me. I read it in C#, C/C++ or whatever language I use.

I have worked like that for a long time. And I'm wondering if you need to
write something in Perl let say. How can you manage to read it *out loud* in
english.
You claim it doesn't hurt the readability. I *know* it does, for me. Yes, I can see, for you it does.
In that case I suggest you go back to C/C++ with the "freedom" of
memory leaks etc. Frankly I think you'll find you're in the minority if you believe that the lax if(...) compiler rules in C/C++ are a benefit.

It is strange that you bring up the qestion of the memory leaks. Reading the
groups for .NET I have seen so many post about memory leaks in the
framework. That many I've never seen in any c++ group. Believe me or not I have never had problems with memory leaks.


But how much energy have you had to expend in getting that right?


Have you ever written programs in C++? I suppose you have. I don't thing the
GC is the biggest advantage in languages like c# and Java. It sounds more
like commercial. I dare to say that I've never seen a question in a c++
group "How to free the memory". There is a lot of questions about GC,
though. And memory leaks in .NET.
In .NET and Java, I think, lot of objects stay in the managed heap
unreferenced awaiting for the GC to collect them undefined amount of time.

Absolutely. However, they *will* be collected if the memory is needed. Why not when I don't need them anymore. I preffer to have control on that
instead of use *dispose design pattern*, which looks more like a patch.

Some thimes they stay there until the precess ends, when eventually they
get freed. This in c++ we called memory leak. In .NET and Java it is called
managed heap.


There's a big difference between "memory isn't reclaimed because
there's no pressure on memory, so the GC doesn't run" and "memory isn't
reclaimed and *cannot* be reclaimed".

C/C++ guys looks like more flexible that the JAVA ones.
I don't think any Java advocate would deny that C/C++ is more flexible
than Java. They're more likely to argue that flexibility itself isn't
necessarily a good thing - which is the view I take.
So you'll prevent someone from writing code they (and other team
members) might find more readable, just because it might just, some
day, create one bug? That's really bad team leadership, IMO - you'll
be creating more bugs just by making them have to do more mental
translation when writing and reading the code.
"Mental translation" - sounds so complicated for so easy thing.


Doesn't sound complicated to me. It's obviously got to happen at some
level - but I believe that making it larger than it needs to be just
because in a different language it would prevent possible bugs isn't a
good idea.
Let's just hope I never have to work with you...

I'd like to work with you. I feel like you can hardly work with
*non-english*, but we can find a way around this, I believe.


I'd certainly have a problem if I couldn't understand people's
documentation and naming, yes. I think any group of programmers who
didn't have a common (human) language between them would find it
difficult to work together.


Take a look at some North American companies. You can find Indians,
Russians, English, Polish, Chinees, you name it programmers working together
in one team and doing great job. I think MS is such a company.
There is no problem with the language and no one of them speaks english like
you.
So, If you can't work with programmers, which you hardly understand without
making any effort the problem is entirely in you.
but comparing one boolean with the value of a method is pretty rare
too, in my code

Sounds senseless to me.


What do you mean? I'm saying that I rarely have a situation of:

if (someValue==SomeMethod())

where SomeMethod returns a boolean.
I'm not saying I never use cut-and-paste. I'm saying I try to use it as little as possible. Being able to cut and paste between different
languages is almost entirely unimportant for me, and whenever I *do*
cut and paste I have enough sense to check what I'm doing - because
cutting and pasting without examining the code afterwards is going to
cause far more bugs than using if (i==5).
Cut and paste between languages? *hmmm* I've never thought about that.

Does anybody do that?


I thought you'd implied it earlier, but I can't find the reference now.

I've never said it.
for (int i=0; i < 10; i++) NULL;
> Is clear enough. Too many comments hurts readability as well. Obvious > things don't have to be commented.

In that case reduce it to:

for (int i=0; i < 10; i++) {}
Maybe clear..., but ugly. I would prefer to stick with the

3-more-letters one.


In what way is it ugly? I would say that introducing the extra concept
of "NULL" is ugly at this stage. Nullity has nothing to do with what's
wanted. What's wanted is a "do nothing" block or statement, which is
*precisely* what {} is.

Nov 15 '05 #3

P: n/a
100 <10*@100.com> wrote:
I meant pardon as in, please rephrase that, because currently it
doesn't make sense as a sentence. I'll try one more time. Like it or not the most of the software companies
are situated in North America And in those companies most of the programmers
doesn't have english as a first language. And they don't think in English.


Did you mean to write that most software companies are *not* situated
in North America?

(I hasten to add that *I'm* not situated in North America too, by the
way.)

I'm quite happy to agree that most software engineers don't have
English as their first language. That's why I've asked whether/which
other languages have preferences like this.
Certainly. I'll pick up on just about anything :) Try harder, Jon. I don't understand everything of your perfect anglish,
neither. I'm keep trying, though. Some times it takes me several times to
read one paragraph, but I never give up. I appreciate everything that you
say.
And the last I mean it.
Thanks - that's much appreciated. Feel free to ask for further
clarification on anything I say.
Sure - I don't have any problem with that. However, I'd be interested
to know which languages have a preference for comparisons like this,
and which way that preference works.


Hmmm. I prefer a programming language for expressing comparitions in my
programs. And I don't try to read it *out loud* in english it doesn't make
sense to me. I read it in C#, C/C++ or whatever language I use.


I don't read it *literally* out loud, but I do "sound it out" in my
head, with appropriate translations for symbols etc. I don't know how
many other people do that. It may well be because that's the way I read
(and write) natural language too. In my head, I'm currently "hearing"
every word I'm typing.
I have worked like that for a long time. And I'm wondering if you need to
write something in Perl let say. How can you manage to read it *out loud* in
english.
Using appropriate mental translations. The translation doesn't
necessarily always keep absolutely all of the context, either - when
you end up in a situation with lots of casting etc, a lot of the
context goes, but you can always get that back by careful examination.
But how much energy have you had to expend in getting that right?


Have you ever written programs in C++?


Yes, some. Not vast amounts - I've written rather more C than C++, and
it amazes me every (rare) time I have to go back to it just how painful
it is to allocate and free memory all over the place.

In C++ I found similar but significantly diminished problems - it was
fine when it was absolutely obvious who "owned" a bit of memory, but
that wasn't always the case. I'll readily concede that I'm really only
a novice in C++.
I suppose you have. I don't thing the
GC is the biggest advantage in languages like c# and Java. It sounds more
like commercial. I dare to say that I've never seen a question in a c++
group "How to free the memory".
Sure - but that's because all C++ programmers are going to know how to
do that because you absolutely have to.
There is a lot of questions about GC, though. And memory leaks in .NET.
There are lots of questions about how to free/delete objects in .NET
because people assume they have to if they've come from a C/C++
background. Yes, there are questions about the operation of the GC,
because it's a reasonably complex thing - but I still believe it saves
a *heck* of a lot of developer time compared with mechanisms in C/C++.
Absolutely. However, they *will* be collected if the memory is needed. Why not when I don't need them anymore.
Because working that out in a deterministic fashion is basically
infeasible in any reasonable and robust way. There's a URL I can dig
out for you which gives some of the problems, if you want.
I preffer to have control on that
instead of use *dispose design pattern*, which looks more like a patch.
But why do you care when memory is reclaimed?
I'd certainly have a problem if I couldn't understand people's
documentation and naming, yes. I think any group of programmers who
didn't have a common (human) language between them would find it
difficult to work together.


Take a look at some North American companies. You can find Indians,
Russians, English, Polish, Chinees, you name it programmers working together
in one team and doing great job.


Do any of them not understand English though? I suspect you won't find
many US programmers who don't use English in their code, even if it's
not their first language for speaking.
I think MS is such a company.
There is no problem with the language and no one of them speaks english like
you.
I suspect all of them can communicate in English though, and I suspect
that that's the language they use for documentation, method naming etc.
So, If you can't work with programmers, which you hardly understand without
making any effort the problem is entirely in you.


I'm willing to make an effort, but if we literally didn't have any
language in common at all, I don't believe it would be a productive
relationship. It would be insane to have to consult a dictionary every
time either "side" wished to use a class that the other "side" had
written. Like it or not, English *is* the basic lingua franca of the
Net and of programming in general. In my experience, even companies who
aren't based in the US/UK/Australia tend to produce APIs in English,
regardless of how they document internally.

Can you name any significant international open source efforts which
have their primary documentation and API naming scheme in a language
other than English, for example?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.