View unanswered posts | View active topics It is currently Mon Dec 11, 2017 8:00 pm



Reply to topic  [ 30 posts ]  Go to page Previous  1, 2, 3  Next
examples of bad code (and why) ? 
Author Message
LQFP112 - Up with the play
User avatar

Joined: Thu Sep 10, 2009 9:23 am
Posts: 244
Location: Dayton, OH
thats what I'm talking about .. I would have even never though to look there. I never touch db stuff.

any bad code you've seen out there ? I'm going to go out and hit some random oss sites and do some pure browsing for a couple of hours.


Sun Apr 18, 2010 12:57 am
Profile
LQFP144 - On Top Of The Game
User avatar

Joined: Mon Mar 31, 2008 12:47 am
Posts: 568
Location: New Zealand, land of the long white burnout
EssEss wrote:
something new to ponder:

Code:
/**
 * @public
 * @brief turn on load indicator
 */
static inline void loadLEDOn( void ) {

}


I name funcs like this: [things]+[action]() -> [loadLED]+[On](), but I notice the conflict with how I 'naturally describe it' in the comment.

As I just typed this out moments ago (literally), I remember that Fred pointed this out to me before, but I dont know which way he leans .. or what most people prefer.

btw: this is in a header, hence the @public, even though I marked it static

opinions ?


Personally, when using an acronym in a CamelCase method/var name, I would switch to First letter uppercase only, for example in this case loadLedOn - seems to make things much nicer to read.

_________________
Owner / Builder: 1983 Mazda Cosmo 12at (1200cc 2-rotor turbo) coupe [SPASTK]
165hp @ 6psi standard - fastest production car in japan Oct 82


Mon Apr 19, 2010 11:04 pm
Profile WWW
LQFP112 - Up with the play
User avatar

Joined: Thu Sep 10, 2009 9:23 am
Posts: 244
Location: Dayton, OH
EssEss wrote:
thats what I'm talking about .. I would have even never though to look there. I never touch db stuff.

any bad code you've seen out there ? I'm going to go out and hit some random oss sites and do some pure browsing for a couple of hours.


this is harder than I thought.

sry_not4sale wrote:
I would switch to First letter uppercase only


thanks for the camelcase tip!


Mon Apr 19, 2010 11:26 pm
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14908
Location: Home sweet home!
Yep, he's right, and I don't follow it! :-o Maybe I'll go about fixing that at some point. The official Java std is as Aaron said.

_________________
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 Apr 20, 2010 12:42 am
Profile WWW
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14908
Location: Home sweet home!
More gold, via nhtshot, courtesy egor, written by a "now unemployed paki" LOLOL

Code:
bool variable;
if(variable.tostring().length==4){}


Stunningly bad! :-)

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!


Wed May 19, 2010 5:18 pm
Profile WWW
LQFP112 - Up with the play
User avatar

Joined: Tue Jan 15, 2008 5:31 pm
Posts: 166
Dallas semiconductors had a real pot of gold in their one-wire sample application... The routine for reading the data stream had something like 15 nested if-then-else statements. It was pretty horrible to debug. I don't have the source code at hand, but I think you can imagine it...


Thu Jul 08, 2010 10:43 pm
Profile
LQFP112 - Up with the play
User avatar

Joined: Thu Sep 10, 2009 9:23 am
Posts: 244
Location: Dayton, OH
I found a great place: http://thedailywtf.com/


Mon Aug 23, 2010 3:23 pm
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14908
Location: Home sweet home!
LOTS of shit wrong here, and in so few lines. Readers, see if you can spot some. I'll come back post wrist healing to fill gaps.
Code:
int aircor_eq(int mat)
{
    signed int cor;
    signed char ccor;
    // returns air density correction from equation in % (100 is no correction)
... <snip> ....

        cor = 529700 / (mat + 4597);
// Changed for 3.0.3w to ignore this (unused) setting always use degF internally.
//    }
//    else  {                          // deg C
//        cor = 293200 / (mat + 2732);
//    }
    if (flash5.airden_scaling) { // only if non-zero
        ccor = (unsigned char)cor - 100;    /// <<<<<<< this shouldn't be cast to an unsigned char !!!
        cor = ((signed int)(ccor * flash5.airden_scaling)) / 100;
        cor = cor + 100;
    }
    return (int)cor;
}

Source: http://msextra.com/forums/viewtopic.php?f=91&t=45364

_________________
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 02, 2012 10:02 am
Profile WWW
LQFP144 - On Top Of The Game

Joined: Tue Dec 27, 2011 5:37 am
Posts: 268
This reminds me of when I first started coding, and I'd get compiler errors about assigning doubles to ints and such. This is when I didn't know the difference between the variable types, and my attitude was fuck you compiler I'll just typecast that shit. Why are they typecasting cor as an int in the return statement? It's already a signed int, and I'm pretty sure typecasting only temporary changes the data type in the previous calculations. I'd hate to see their code after paying good money to install their system on one of my engines.

Code:
#define PWND 2
#define FAIL 1
#define SUCCESS 0
unsigned char aircor_eq(int matF, unsigned int *correctionValue) // The air density correction value should never be negative. Neither should temperature, but their comments say they're working in F so matF. Although I would prefer matK or matR.
{
    unsigned int cor;
    // returns air density correction from equation in % (100 is no correction)
... <snip> ....
    if(matF != -4597){  //As far as I know their MAT calculation code could send me all kinds of strange shit, so we won't be dividing by 0 here. It should probably be limited to realistic values.
        cor = 529700 / (matF + 4597);
    }
    else{
        *correctionValue = 100; // No correction, because something bad is happening somewhere else.
        return FAIL;  // To be handled improperly by MS people.
    }
    if (flash5.airden_scaling_that_returns_an_int) { // only if non-zero
        cor = (((cor - 100) * flash5.airden_scaling_that_returns_an_int) / 100) + 100;  //Integer division, but I'm going to argue that more significant figures is outside the accuracy of our measurements.
    }
    if(cor > 200 || cor < 50){ // Should be optimized(narrowed) to realistic values.
        *correctionValue = 100; // No correction, because something bad is happening somewhere else.
        return PWND; // Used by MS people to crash the system, this way your engine isn't completely ruined.
    }
    *correctionValue = cor;
    return SUCCESS;
}


Quote:
In MS3 we already changed the 'correction' curve to 0.1% steps. In a future code release we'll likely merge the built-in calculation and the correction curve.

James
I guess I was wrong about assuming that we don't need more than 1% accuracy for air density. lmao

_________________
:-p


Sat Jun 02, 2012 5:12 pm
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14908
Location: Home sweet home!
Peter wrote:
Code:
#define PWND 2
#define FAIL 1
#define SUCCESS 0
return SUCCESS;

LOL @ all of that, but, the last bit would throw an "unreachable code" error ;-)

Quote:
Quote:
In MS3 we already changed the 'correction' curve to 0.1% steps. In a future code release we'll likely merge the built-in calculation and the correction curve.

I guess I was wrong about assuming that we don't need more than 1% accuracy for air density. lmao

^ this is another story and another fail, but for different reasons. Discussing it may help them do something right (for a change), so I discourage that :-p

_________________
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 02, 2012 6:56 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 30 posts ]  Go to page Previous  1, 2, 3  Next

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.