|
Fabio Franco wrote: That's specially useful when you need to constantly comment in and out some of
the conditions to find the right records. Without that you'd have
to worry to every time replace the AND for a WHERE and vice-versa.
For that, I use TRUE , e.g. in SQL:
WHERE TRUE
AND X=Y
AND A=B
You can then comment in / out the real conditions without any worries about whether a leading AND is needed or not or even if any conditions remain. e.g.
WhereClause = "WHERE TRUE "
& ( test1wanted ? "AND X=Y " : "" )
& ( test2wanted ? "AND A=B " : "" );
|
|
|
|
|
Same thing, except "1=1" is only three characters long
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
----
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
My apologies! I had misread your previous comment.
|
|
|
|
|
No need to
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
----
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
As a variation on that, you could do something like this:
if ('l' == '1')
{
Abort();
}
Just to play with people who would use fonts that don't distinguish the two well...
|
|
|
|
|
|
I have seen that code in a VB6 app and it was a convenient way to get an empty but initialized (containing columns you were interested in) RecordSet from the database that you could then populate with data and save.
|
|
|
|
|
Just make sure they do not come up with PrintLibel() and this._Libel.
|
|
|
|
|
I frequently use
select * from tbl where 1 = 2
when I'm trying to figure out the columns in a table.
|
|
|
|
|
My favorite that I have seen is this...
if variable < 24 And variable > 26 then
end if
|
|
|
|
|
Ah, variable is surely of type MagnitudeNumber, yes? With a value of -50? It is both less than 24 (because it's negative) and its magnitude is greater than 26.
The comparison operator obviously checks both the signed and unsigned number, and returns true if either satisfy the condition.
|
|
|
|
|
Uhhhh... sure!
Just kidding. The programmer at the time just probably forgot that they checked the same variable twice. Maybe it was supposed to be another variable. I have no clue what the intention was, but its still active in the program. I don't have the heart to comment it out because of how funny the goof is.
|
|
|
|
|
int main (){
long variable = -1;
long var24 = 24;
unsigned long var26 = 26;
if( variable < var24 && (variable > var26)){
printf("%ld, is a magic number, %lu, %ld, %ld", variable, variable, var24, var26);
}
return 0;
}
I was just wondering if this could come up somewhere in the code and still be funny.
-JD
|
|
|
|
|
it could be a 'typo' for an Or
|
|
|
|
|
That was my thoughts exactly. However, there are many other instances like the example I posted. The worse I have seen are many goto statements.
|
|
|
|
|
if (this == null)
{
Environment.Exit(-1);
}
I cannot remember the exact code block, but it was something along those lines. And yes, somehow, that condition happened. And 'this' was the actual keyword, not some redefinition of it. I still don't know how that one happened.
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
your object was finalized before the time, probably it had a unmanaged reference, when it had no more managed references, the GC collected it...
Forgeting to pin a object is really a PITA, especially when it's the first time you are doing P/Invoke
(i was speaking of me, not sure if this is your case)
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
This wasn't my code, it was from one of my friend's projects. I cannot remember what the actual class did, but most of the projects code files were naive (and buggy) implementations of classes in the framework. I did show him the documentation, and his reply was "Cool! How did you know this existed?". Me:
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
PEBKAC
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
I think it was more of an ID-Ten-T error. Either that or a BrainNotFoundException .
He has decided to become an English Major with Anthropology and History minors.
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
well, can't say i haven't found such cases...
there was a guy on my class who left to become a surgeon... I hope I never have to be operated by him
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
Zac Greve wrote: Environment.Exit(-1);
Way back in the 1980's, I was using Sun 3 workstations running UNIX. We had FrameMaker, back before Adobe got ahold of it. On UNIX, there is a command called "strings" that attempts to extract all the ASCII strings from a file. If you ran it over FrameMaker.exe, one of the strings you got was...
"Evacuate now? In our moment of triumph? I think you overestimate their chances."
There is no way to tell what error case causes this message to print, or just what happens right after, but I really want to know.
|
|
|
|
|
Which language is that? Java?
|
|
|
|
|
A professor of Computer Science -- a world-renowned expert on PL/I -- once wrote the following:
if ((i != 1) || (i != 2))
...
else
...
(Yes, the above is in C. I can't remember the PL/I syntax.)
He spent most of a day trying to figure out why the "else" branch was never executed. A graduate programming assistant had to point it out to him.
(This message is programming <i>you</i> in ways you cannot detect. Be afraid.)
|
|
|
|
|
if (my $thisScriptHasBecomeSkynet) {
die;
}
|
|
|
|