Failing to understand the space, time, complexity, or readability aspects of the code they write and take advantage of algorithms and/or data structures that would significantly improve performance and/or readability/maintainability. Typically, they implement the most naive algorithms and data structures which are almost invariably slower and take more space than necessary, using code that is hard to read and/or maintain.
For example, my son (studying engineering and taking his first programming class) had an assignment to write a program to convert back and forth between two different units for each of temperature, speed, and distance. His first attempt used a series of nested if statements to select the proper conversion function. His second attempt (and what I imagine most of the class ended up with) was to use a switch statement. I suggested that the way I would go about it was to use a map of units to conversion functions. Retrieve the correct function from the map and simply go about applying it. The naive algorithm requires up to 5 comparisons for each operation. The map-based algorithm does a simple lookup to find the function.
EDIT: FWIW, here's my implementation using the "map". The problem specification indicates that the both values and units are given as numeric. For my purposes I assumed a mapping of 0 = Farenheit, 1 = Celsius, 2 = inches, 3 = cm, 4 = mph, 5 = kph. The C# implementation uses lambdas for the functions, but includes help and the ability to specify the full unit name instead of a number so it's a bit more complex. I know that it could use more error checking. :-)
#include <stdio.h>
double TempFToC( double f )
{
return (f - 32) * 5.0 / 9.0;
}
double TempCToF( double c )
{
return (c * 9.0 / 5.0) + 32;
}
double DistanceInToCm( double in )
{
return in * 2.54;
}
double DistanceCmToIn( double cm )
{
return cm / 2.54;
}
double SpeedMPHToKPH( double mph )
{
return mph * 1.609344;
}
double SpeedKPHToMPH( double kph )
{
return kph / 1.609344;
}
int main(int argc, char* argv[])
{
double value;
int units;
double (*converters[])(double) = {
TempFToC,
TempCToF,
DistanceInToCm,
DistanceCmToIn,
SpeedMPHToKPH,
SpeedKPHToMPH
};
char* labels[] = { "C", "F", "cm", "in", "KPH", "MPH" };
printf( "Input value and units: " );
while (scanf("%lf %d",&value,&units) > 0)
{
if (units < 0 || units > 5)
{
printf( "Invalid units. Try again.\n" );
}
else
{
printf( "%lf %s\n", converters[units](value), labels[units] );
}
printf( "Input value and units: " );
}
}
EDIT: Even better version for linear transformations
#include <stdio.h>
double transform( double original, double scale, double offset )
{
return original * scale + offset;
}
int main(int argc, char* argv[])
{
double value;
int units;
double factors[][2] = {
{ 0.555556, -17.777778 }, { 1.8, 32.0 },
{ 2.54, 0.0 }, { 0.393701, 0.0 },
{ 1.609344, 0.0 }, { 0.621371, 0.0 }
};
char* labels[] = { "C", "F", "cm", "in", "KPH", "MPH" };
printf( "Input value and units: " );
while (scanf("%lf %d",&value,&units) > 0)
{
if (units < 0 || units > 5)
{
printf( "Invalid units. Try again." );
}
else
{
printf( "%lf %s\n", transform( value, factors[units][0], factors[units][1] ), labels[units] );
}
printf( "Input value and units: " );
}
}