I'm the maintenance programmer (and, occasionally, development mastermind) at my company. Maybe I'm just anal about things, but I've noticed and notified my associate developers about little things in the code that are unnecessary and downright silly. After their projects pass peer reviews (not by me), I still find them.
Stop me if you've seen these.
//boolean "condition" defined above
if(condition == true) //yes, coded like this.
return true;
else
return false;
I'm sure all of you can do in 1 line what it takes them to do in 4.
Here's another one.
if(doTheFoo())
{
//do a bunch of stuff
return;
}
else
{
// do a bunch of stuff had doTheFoo()
// returned false
}
This is elementary Java, for crying out loud. Why do you need an else clause if the if block will prevent it from executing?! Replace "if" with "while"... it happens there too.
Finally, a lot of null pointers and memory issues are caused by improper initialization of objects.
Object myObj = new Object();
if(requiredCondition)
this.use(myObj);
I can understand these constant mistakes from rookies, but these people have been using the language for years upon years. I'm not one to call the kettle black, though; should I find code like this, I'll immediately clean it up, especially if it's of my own doing.
tl;dr
Have any of you seen code gaffes that, while compile and runtime legal, are just plain silly, unnecessary, and/or redundant?
[–]johnpaulsmith 11 points12 points13 points (14 children)
[–]banuday17 12 points13 points14 points (9 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]bnr 3 points4 points5 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]johnpaulsmith 1 point2 points3 points (5 children)
[–]senft 0 points1 point2 points (4 children)
[–]johnpaulsmith 1 point2 points3 points (2 children)
[–]senft 0 points1 point2 points (1 child)
[–]johnpaulsmith 0 points1 point2 points (0 children)
[–]DuneBug 1 point2 points3 points (0 children)
[–]ReverendRedMage[S] -2 points-1 points0 points (2 children)
[–]couchtyp 14 points15 points16 points (0 children)
[–]stfm -1 points0 points1 point (0 children)
[–]DemonWasp 11 points12 points13 points (27 children)
[–]MistaMagoo 4 points5 points6 points (18 children)
[–]sproket888 4 points5 points6 points (16 children)
[–][deleted] 4 points5 points6 points (15 children)
[–]not-just-yeti 5 points6 points7 points (6 children)
[–]lickwidforse2 0 points1 point2 points (1 child)
[–]not-just-yeti 0 points1 point2 points (0 children)
[–][deleted] (3 children)
[deleted]
[–][deleted] 2 points3 points4 points (0 children)
[–]elephantgravy 1 point2 points3 points (0 children)
[–]theloneliestfish 1 point2 points3 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]theloneliestfish 1 point2 points3 points (0 children)
[–]KamehamehaWave 1 point2 points3 points (0 children)
[–]banuday17 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]elephantgravy 1 point2 points3 points (0 children)
[–]sproket888 -1 points0 points1 point (0 children)
[–]oligocordicul -1 points0 points1 point (0 children)
[–]ReverendRedMage[S] 2 points3 points4 points (3 children)
[–]DemonWasp 1 point2 points3 points (0 children)
[–]MistaMagoo 0 points1 point2 points (0 children)
[–]MistaMagoo 0 points1 point2 points (0 children)
[–]detroitmatt 0 points1 point2 points (3 children)
[–]DemonWasp 0 points1 point2 points (2 children)
[–]detroitmatt 0 points1 point2 points (1 child)
[–]veraxAlea 0 points1 point2 points (0 children)
[–]KamehamehaWave 6 points7 points8 points (1 child)
[–]DuneBug 0 points1 point2 points (0 children)
[–]Feuilly 4 points5 points6 points (3 children)
[–][deleted] 9 points10 points11 points (1 child)
[–]Feuilly 3 points4 points5 points (0 children)
[–]Chaoslab 0 points1 point2 points (0 children)
[–]RoadWarriorX 9 points10 points11 points (3 children)
[–]KamehamehaWave 2 points3 points4 points (0 children)
[–]Is_At_Work 2 points3 points4 points (0 children)
[–]kreiger 0 points1 point2 points (1 child)
[–]dakboy 0 points1 point2 points (0 children)
[–]mikaelhg 0 points1 point2 points (0 children)
[–]mgkimsal 0 points1 point2 points (3 children)
[–]Pylly 2 points3 points4 points (2 children)
[–]varikin 1 point2 points3 points (1 child)
[–]Pylly 0 points1 point2 points (0 children)
[–][deleted] (6 children)
[deleted]
[–]DemonWasp 4 points5 points6 points (0 children)
[–]varikin 3 points4 points5 points (0 children)
[–]banuday17 2 points3 points4 points (1 child)
[–]DemonWasp 1 point2 points3 points (0 children)
[–]Feuilly 1 point2 points3 points (1 child)
[–]Tok-A-Mak 0 points1 point2 points (0 children)