View unanswered posts | View active topics It is currently Mon May 01, 2017 1:34 am



Reply to topic  [ 30 posts ]  Go to page Previous  1, 2, 3
examples of bad code (and why) ? 
Author Message
LQFP144 - On Top Of The Game

Joined: Tue Dec 27, 2011 5:37 am
Posts: 268
Fred wrote:
throw an "unreachable code" error ;-)

I saw that, and for some reason I thought that you were commenting on misspelling or something. Then about 45 seconds later I got the joke. I think I've only actually seen that compiler error once.

_________________
:-p


Sat Jun 09, 2012 5:54 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
Having a slow day? :-)

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Sat Jun 09, 2012 2:01 pm
Profile WWW
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
I found this on the interwebs:

Code:
if (i<3 && b<0) {}

Bad variable naming, times two, plus magic number, times one, equals meaningless code.

Fred.

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Thu Oct 25, 2012 2:43 pm
Profile WWW
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
Pointless code:

Code:
for (int i = 0; i < 1; i++) {
    // Lots of code, none of which referenced 'i'
}

Whose code is this, you ask? Mine! :-o

How the hell that made it near a source file I have NO idea. Possibly auto-generated or possibly a hang over from a loop with more than 1 in it?

It's gone now...

Fred.

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Mon Nov 05, 2012 5:02 pm
Profile WWW
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
Not really bad code per se, but:

Code:
[WARNING] Messages.java:247: warning - @param argument "a" is not a parameter name.
[WARNING] Messages.java:247: warning - @param argument "the" is not a parameter name.

Tell me why I got these warnings? :-)

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Tue Dec 11, 2012 10:10 am
Profile WWW
LQFP144 - On Top Of The Game

Joined: Tue Dec 27, 2011 5:37 am
Posts: 268
z=x/++x

_________________
:-p


Fri Dec 21, 2012 8:03 pm
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
M$?

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Fri Dec 21, 2012 9:55 pm
Profile WWW
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
Code:
    try
    {
      // Make one-line call
    } catch (Throwable e)
    {
      throw new Exception(e);
    }


Catching a throwable, sometimes, maybe, OK, rethrowing as a checked exception, what? :-/

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Mon Mar 18, 2013 3:58 pm
Profile WWW
LQFP112 - Up with the play
User avatar

Joined: Fri Feb 01, 2013 4:18 pm
Posts: 143
Location: Jersey City, USA
I believe
Code:
a = a >> 1;

is bad code.

And some people do agree with me - http://stackoverflow.com/questions/2580 ... e-into-shi

There is the whole http://code-wtf.livejournal.com/ on this - I know it's a bit in Greek but most of it is code anyway :)

_________________
http://forum.diyefi.org/viewtopic.php?t=2070 http://www.rusefi.com


Mon Dec 30, 2013 3:16 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14566
Location: Home sweet home!
Working on some horrendous code at the moment. Most of it is fairly average and normal, but a certain person did some stuff to it in the past that has rendered it nearly unusable now. The only example that I can succinctly post here is the following:

Removed 770,000 rows from a db table, none of which were used. This took over an hour to achieve. The database has no forreign key constraints. WTF. I can't explain more, really, but the 770 were autogenerated rows with no value... bleh.

Fred.

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Mon Dec 01, 2014 8:38 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 30 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF. ColorizeIt.