Do nothing without doing anything
-
Just found in our codebase at work: a method where the entirety of the method body looks goes like this.
begin Exit; { inherited; } end;
This is Delphi code. The equivalent C# would be something like:
{ return; /* base(); */ }
It's not likely to actually introduce bugs, but I just have to ask, what was the original developer thinking when they wrote this?
-
what was the original developer thinking when they wrote this?
It was probably multiple developers.
When the first dev created the class, the IDE generated placeholder code that just called the base type. The second dev decided they would rather the method do nothing and so changed to what you have now. The second dev, like so many devs, never actually deletes any code, just comments it out.
-
Yeah, looks like legacy crap piled on top of legacy crap.
The other day, I almost left a bunch of code commented out "just in case".
But than I remembered stories like this, and deleted the fuck out of that garbage. Not on my watch, legacy code.
And it was all thanks to WTDWTF!
-
And it was all thanks to WTDWTF!
You'll be sure to attribute us when getting that promotion, right? :D
-
If you have code in comments around here, it won't get through code review. That's in the checklist. Delete it. Delete it all.
-
At least they're not hided in dead code.
I recently see code blocks that shows two way to do similar task, controlled by a flag in settings file.
What bugs me is that according to deployment script records, that setting is never deployed to client so everyone is using the default behaviour. So unless someone dares to deploy unapproved code to clients... the second routine have no use.
And we don't dare to remove it because we can neither prove or disprove noone is using the routine.
-
If that bit of haunted code is only executed infrequently you could add logging to both branches, that means you'll at least have more proof after a while.
-
You'll be sure to attribute us when getting that promotion, right?
Screw the credit, he owes us a share of his bigger paycheck!
-
Looks like the kind of stuff one would add to put a breakpoint in it.
Edit: No wait, I hadn't seen
base()
was commented out, I thought the function was simplyreturn base();
. So you're right, this is stupid.
-
Looks like the kind of stuff one would add to put a breakpoint in it.
The .NET Framework has something called
System.Diagnostics.Debugger.Break()
. It's revolutionary!
-
And JavaScript has
debugger;
for the same purpose
-
This post is deleted!
-
And we don't dare to remove it because we can neither prove or disprove noone is using the routine.
Odds are high that your support people have told at least one client about this. Said client relies one this. Support has no documentation they said so.
-
C++ has
DebugBreak()
and/orasm("int 3")
according to taste...
-
C++ has DebugBreak() and/or asm("int 3") according to taste...
Yeah, in Delphi you can do a manual breakpoint withasm int 3 end;
. It's useful for debugging stuff in a tight loop where setting a conditional breakpoint in the debugger would slow things down massively.
-
The other day, I almost left a bunch of code commented out "just in case".
But than I remembered stories like this, and deleted the fuck out of that garbage. Not on my watch, legacy code.
And it was all thanks to WTDWTF!
How to Refactor Code
- Comment the old code out.
- Write new code while using the commented code for reference.
- Forget to delete the commented code.
-
Hey, @tufty! Someone's stealing your avatar!
Well, it's a little different, but still!
-
@cartman82 said:
The other day, I almost left a bunch of code commented out "just in case".
But than I remembered stories like this, and deleted the fuck out of that garbage. Not on my watch, legacy code.
And it was all thanks to WTDWTF!
How to Refactor Code
- Comment the old code out.
- Write new code while using the commented code for reference.
- Forget to delete the commented code.
Why comment the code if you can wrap it in a
if 1 = 2. "old code goes here endif. "obsolete, delete later
statement?
For added benefits, you could use some constants instead of integers (magic numbers are bad, right?)
-
Yeah, we have a guy that uses this pattern:
#ifdef THIS_IS_THE_OLD_VERSION_THAT_WORKS_BUT_IS_REALLY_SLOW
-
Yeah, we have a guy that uses this pattern:
#ifdef THIS_IS_THE_OLD_VERSION_THAT_WORKS_BUT_IS_REALLY_SLOW ```</blockquote> followed by: ```cpp #ifdef THIS_IS_THE_NEW_VERSION_THAT_IS_REALLY_FAST_WARNING_DOES_NOT_WORK
-
Go has
runtime.Breakpoint()
.
-
The problem is, whenever we need to change that part of code, we need to change the code in "no man's land" accordingly too, and we have no idea whose maintenance contract to debt the mandays.
-
C has
*NULL
( :P )
-
I was always quite fond of
((void(*)())0)();
for that kind of thing.
-
If you have code in comments around here, it won't get through code review. That's in the checklist. Delete it. Delete it all.
The other week, I found a few hundred lines of commented out code, in a
#region
block calledCommented out code
. I'm so glad to be leaving this job
-
At least they're not hided in dead code.
A previous programmer liked being able to "collapse" code in his IDE, so the way he did that was wrapping functional bits in an
if (1) { ... }
. Yeah this is terrible. What is worse is the occasionalif (0) { ... }
. I did find oneif (2) { ... }
.And we don't dare to remove it because we can neither prove or disprove noone is using the routine.
YOLO!
-
The other week, I found a few hundred lines of commented out code, in a #region block called Commented out code. I'm so glad to be leaving this job
I can imagine that the first line within that region was
// DO NOT TOUCH !!!
.
-
The other week, I found a few hundred lines of commented out code,
Strip it, then self-review a checkin that has a comment "This is why we have source control"
-
-
Strip it, then self-review a checkin that has a comment "This is why we have source control"
Assuming you have test suite, run that as well, just on the offchance the code is actually used and the "commented out" comment is a lie...
-
This would be the most prudent of course. You never know if someone would load that file, uncomment everything and recompile it on the fly.
-
-
-
We had a lot of these, and thankfully these will be removed in every major version changes, which occurs every one or two years.
-
What is worse is the occasional if (0) { ... }.
These statements have the same effect in ruby:
if 0 then puts "Hello" end
and
if 1 then puts "Hello" end
-
These statements have the same effect in ruby:
if by "same effect" you mean "makes you feel guilty and dirty in a way that cannot be washed clean, because ruby" then.... yes, you are correct!
-
That quirk in ruby is funny.
And it lets you use the
||
operator like C#'s??
-
How does it work? At a guess, integer is not bool, so neither value is true and neither branch executes?
-
How does it work? At a guess, integer is not bool, so neither value is true and neither branch executes?
It's because in Ruby,false
andnil
are "falsy", while all other values are "truthy". Since integers (including 0) are notfalse
ornil
, you don't get the behavior you see in C whereif 0
is equivalent toif false
.
-
Static typing makes things so much nicer.
true
is truthy,false
is falsy and everything else is a compiler error
-
Static typing + type inference makes things so much nicer.
FTFY
Without type inference, static typing can be a PITA.
-
nil
I always chuckle when I see this. Were they too cool to use
null
or something?
-
[poll type="multiple" min="2" max="3"]
- NULL
- null
- nullptr
- nil
[/poll]
-
nullptr.... Is that when the computer hasn't been set to an instance of a computer?
-
nullptr.... Is that when the computer hasn't been set to an instance of a computer?
-
-
I don't understand what prompted you to select "nullptr" in particular for the joke. So, it ed over my head.
-
Go uses
nil
because it's illegal to dereference a null pointer, but some nil values can be used - for example, a nil slice is an empty slice with 0 capacity, and a nil channel never resolves. You can even define a pointer type that has methods that don't deference a null pointer when called, unlike languages like C++, C#, and Java.
-
-
C# recently gained the 'null-conditional' operator. And it's fucking brilliant: no more
NullReferenceException
s!**Unless they come from a shitty library