Let no good deed go unpunished--why you can't be too careful with C#DecimalParse NumberStyles

G

Göran Andersson

raylopez99 said:
I assumed that the default would include "AllowDecimal", in other
words, that the flags would be more inclusive rather than all-
inclusive.

If you mean the default used by the overload of the method where you
don't specify a NumberStyle, it does.

If you mean the default value of the enum, the default value is always
zero. For that to allow a decimal, the flag would have to be DenyDecimal
rather than AllowDecimal. That would be awkward as all the other styles
are allowing rather than denying.
 
R

raylopez99

I see. Because you believe things that plainly are not true... That's
not a very good reason.

Well Göran Andersson, since you are such the expert programmer, I will
give you a quick quiz, taken from an excellent book by Scott Meyers,
written over 10 years ago (Scott was the Jon Skeet of the 1990s--he's
coming out with a new book, but I was surprised he only wrote three
books, all three of which I own; btw Meyers does not believe in on-the-
spot language quizzes given to job applicants, since they are too
stressful and don't prove much; better to rely on source code the
candidate has written, but I digress):

Quiz Question: (from Item #7 of "More Effective C++")

in the statement from this code: "char *p; /*...*/ if ((p!=0) &&
(strlen(p) > 10)) ... "

does the second expression, strlen(p) > 10, get executed?

Answer:

~
~
~
~
~

since char *p is a null pointer, then only the first expression is
executed and the second expression is never even considered, since it
is irrelevant in Boolean Algebra. In fact, if the second expression
was considered, you would crash your program since strlen cannot take
a null pointer.

Now, how does that affect your Boolean Algebra? Shows that x&&y is !=
y&&x, at least in "if" expressions of this kind! Try reversing these
expressions, so that it's written: if ((strlen(p) > 10) && (p!=0))
and watch your program crash. Meyers goes on to say that in fact
programmers often specifically write statements in the above specific
order, so that only the first expression is executed, knowing this
rule, and thus if the language were to be redefined so that both
expressions were automatically considered always, it would break a lot
of existing code.

Put that in your Boolean pipe and smoke it! :)

RL
 
M

Marc Gravell

Put that in your Boolean pipe and smoke it! :)

&& and || (logical) are completely different operators to & and |
(bitwise)

Seriously, every time you come back with stuff you look more
ridiculous...

Marc
 
M

Marc Gravell

He's got you guys all on his line,  hard.  :)

What you say is true; and you're right - the "respectful for short
periods of time" is getting old. I'm coming over to your "just ignore
him completely, even if he is pretending to be genuine" approach....

Marc
 
R

raylopez99

Since the only question here is the actual result of the expression, it's 
valid to describe the operators as commutative and associative, whether  
one's talking about the boolean operators or bitwise operators.

Yes. This was my point, that you, Peety, in a backhand way have
grasped. Both Boolean and Bitwise operators are completely the same
when it comes to the Karnaugh Map Truth Table. And this C# "shortcut"
means that the associative property of X =Y, Y=X does NOT hold
(because of the shortcut). Actually I didn't know C# had this
shortcut until you confirmed it, but I suspected it did.

That was my point--order matters in C#, like in C/C++. I realize &&
is not &.
I guess that depends on one's perspective.  I have a hard time imagining  
him looking any more ridiculous than he already does, if one considers the  
totality of evidence.

Good point, I take that to mean I'm not looking any "MORE" ridiculous,
that the rate of change of ridiculousness has gone to zero. Thanks.
I will take you out of my virtual .kill file for that (Google Groups
via a web browser does not have an actual .kill file, unlike most
newsreaders, so you kind of have to remember whose in your virtual
killfile--for a while, you were in it, but not now).

RL
 

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

Top