|
Of course it is impossible to future version to change default value (or behavior) - that will break applications in an instance...You not even ca nto introduce a new meaning for null, as it is today interpreted as false and changing that will also break applications...
If you are aiming to future options, you have to use enum, and add new values for new features...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
That's fine, if you bother to document what the null actually means.
Without that, its a bug waiting to happen.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: obviously the default for a bool (at the end of the day) will be false, if not stated otherwise...And if stated otherwise, than it should be part of the
IMO, this is the most significant statement in this thread.
The thing that drew me into this thread was its subject, which made me wonder how a bool could be considered nullable. When I see the word "nullable," I assume that the context is an object, rather than a primitive type such as bool, int, long, uint, ulong, double, etc.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
It means not set. It can trigger an auto-discover method, an error or a default behaviour.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
|
|
|
|
|
Exactly...So the question remains...Why to use it in this code, where nothing happens and NULL interpreted as false...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
|
Which is there to aid cases of data bound control and required filed...but in the code above NULL simply interpreted as false and not as missing value...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id)
{
try
{
int len = ProjectCode.Length + id.Length;
int rem = 10 - len;
switch (rem)
{
case 1:
ProjectCode = ProjectCode + "0" + id;
break;
case 2:
ProjectCode = ProjectCode + "00" + id;
break;
case 3:
ProjectCode = ProjectCode + "000" + id;
break;
case 4:
ProjectCode = ProjectCode + "0000" + id;
break;
case 5:
ProjectCode = ProjectCode + "00000" + id;
break;
case 6:
ProjectCode = ProjectCode + "000000" + id;
break;
}
}
catch (Exception ex)
{
}
return ProjectCode;
}
|
|
|
|
|
I have to compliment the author on writing bulletproof code - the catch all is awesome!
/ravi
|
|
|
|
|
"What? It errored? Where? I don't see any errors? I'm sure I covered/hid all the errors..."
|
|
|
|
|
I had to go back and look. Yes, it's awesome, and about as enlightened as ignoring the return code of a method or function. Catch exception and throw it away. Why even bother with naming it?
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
ProjectCode should be camelCased , other than that I don't see what's wrong with it
|
|
|
|
|
Sander Rossel wrote: I don't see what's wrong with it
The only bit that's wrong is the stuff between the first and last bracket...
|
|
|
|
|
Is the original author still around? umm not that wou'd want to hunt him/her down and hurt them or anything....
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
No, they left long ago. What confuses me the most is how you can know enough code to be able to write something like that, but not enough to know how to do it without the ridiculous switch statement. It's like a weird ignorance knife-edge.
|
|
|
|
|
Nothing like beautiful legacy code, very beautiful indeed.
|
|
|
|
|
The missing default handling and error handling (len >10) the mean exception handling shows me that some Visual Basic coder was on the loose.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
It's friggin C# code and you STILL have to bash VB?
Sounds to me like a C# dev who can't admit there are actually really very bad C# coders out there.
C# coders who are, if I dare say so, even worse than a lot of VB programmers out there
And that comes, of course, from an ex-VB coder, who has seen crap code in both VB and C# (and both make you want to spoon your eyes out)
|
|
|
|
|
I'd post a legacy code snippet but I'd be sharing all the production connection strings they hardcoded at every single db connection.
I seriously wished I could build a terminator to go back in time and shoot the coder in questions parents.
|
|
|
|
|
Woah! I saw 'rem' and started reading it as a comment!
"Go forth into the source" - Neal Morse
|
|
|
|
|
This post is trending on my Facebook:
The other day a "hacker" stole all the money from my bank account. I sent him a message saying "I am a security expert at Microsoft, you can check my profile, and I can screw up your life if I want... So, I will believe that you are a security expert doing a training when my money comes back... I will not send the police after you and, it doesn't matter if you are really a security expert or not, you will be in the right path."
Some hours later, all my money came back and I received the picture of a nice lady on my phone.
On a completely different matter, if you want to show this to Kids... or if you want to check it out...
It requires a keyboard:
Game of Life - Philosophical approach for kids[^]
Adding the content - Looking for a Really Bad Fight! With Death! Seriously!
Click here![^]
modified 27-Apr-16 23:14pm.
|
|
|
|
|
Certainly weird, but I'm not sure about the wonderful bit
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
To me the Game of Life is wonderful....
Try playing it after drinking lots of vodka and you will see it.
|
|
|
|
|
I got me thinking about numbers, conventions and things like that.
I remember talking to some people about it, but maybe I was imagining it. Anyways...
The number one is a very interesting number.
I was thinking how all the base systems give a 10 when we use the actual base as the number. That is, 2 in binary is 10. 3 in a ternary system is 10. 10 in our decimal system, is 10. 16 in the hexadecimal system, is written as 10.
By "convention" we could say that 1 in the base 1 would give a 10...
But then we hit our first crash... or we found infinity... or whatever.
Let me explain: The binary system (base 2) only sees the 0 and the 1. A "base 1" system would only see the 0, and nothing else.
So, it would be impossible to have a "10".
But we may think about it diferently. The value for all base systems can be discovered by dividing the value we want by the base value, and we keep dividing until the value reaches zero.
That is, we could divide 1 by 1. It will result in 1, but we will still have one. So, we keep dividing one by one, and we always have an extra one. To infinity!
So, by trying to divide one by one, we are actually only making the one become bigger and bigger... or should I say that we discovered the true value?
An interesting thing is that many basic languages consider the true value to be -1 (actually, all bits set to one)... while other languages consider true to be only 1 (not a lot of ones).
I also don't know if a teacher really told me that... or if I simply imagined, but one of the rules was that it doesn't matter if we want to multiply or divide one by one... we end-up always having half of it.
Let me explain:
1/1 = 1
1*1 = 1
So, we had 2 ones on one side and, on the other side, we ended up with a single one. So, half the ones, right?
But to my perception, we only multiplied the number of ones by doing this. We had 2 number ones... then, after the equals sign, another one appeared. In the end, we have 3 number ones.
That is, by trying to either divide or multiply one by one, we always get a kind of clone. A new one!
Where am I going with this?
No idea. I simply considered it funny that multiplication or division of one by one may end-up in multiplication or division of the ones... and it is only a matter on how you look at it. Are you looking at the result (after the equals sign), are you looking at the image? Are you simply counting how many ones appeared?
Funny isn't?
Don't try to think about this under the effect of drugs. It may halt your brain! I know it kinda did it to mine... everything went white, with a really high pitched sound!
Remembering: I don't do drugs. People drugged me and tried to screw up my mind... they kinda succeeded on it.
|
|
|
|
|
All's I know is that One is the loneliest number that I'll ever do.
|
|
|
|