examples of bad code (and why) ?
Re: examples of bad code (and why) ?
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.
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.
- sry_not4sale
- LQFP144 - On Top Of The Game
- Posts: 568
- Joined: Mon Mar 31, 2008 12:47 am
- Location: New Zealand, land of the long white burnout
- Contact:
Re: examples of bad code (and why) ?
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.EssEss wrote:something new to ponder:
I name funcs like this: [things]+[action]() -> [loadLED]+[On](), but I notice the conflict with how I 'naturally describe it' in the comment.Code: Select all
/** * @public * @brief turn on load indicator */ static inline void loadLEDOn( void ) { }
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 ?
Owner / Builder: 1983 Mazda Cosmo 12at (1200cc 2-rotor turbo) coupe [SPASTK]
165hp @ 6psi standard - fastest production car in japan Oct 82
165hp @ 6psi standard - fastest production car in japan Oct 82
Re: examples of bad code (and why) ?
this is harder than I thought.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.
thanks for the camelcase tip!sry_not4sale wrote:I would switch to First letter uppercase only
Re: examples of bad code (and why) ?
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!
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!
Re: examples of bad code (and why) ?
More gold, via nhtshot, courtesy egor, written by a "now unemployed paki" LOLOL
Stunningly bad! :-)
Fred.
Code: Select all
bool variable;
if(variable.tostring().length==4){}
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!
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!
Re: examples of bad code (and why) ?
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...
Re: examples of bad code (and why) ?
I found a great place: http://thedailywtf.com/
Re: examples of bad code (and why) ?
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.
Source: http://msextra.com/forums/viewtopic.php?f=91&t=45364
Code: Select all
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;
}
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!
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!
Re: examples of bad code (and why) ?
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: Select all
#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;
}
I guess I was wrong about assuming that we don't need more than 1% accuracy for air density. lmaoIn 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
:-p
Re: examples of bad code (and why) ?
LOL @ all of that, but, the last bit would throw an "unreachable code" error ;-)Peter wrote:Code: Select all
#define PWND 2 #define FAIL 1 #define SUCCESS 0 return SUCCESS;
^ 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 :-pI guess I was wrong about assuming that we don't need more than 1% accuracy for air density. lmaoIn 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.
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!
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!