Here are some real life examples of bad programming. Of course, similar code was all over the place copy/pasted in 100 places. Guy got fired, but I've heard that he got a nice job again. Enjoy:
a)
if (! TableObject.loadList("sql condition").isEmpty()) {
List<TableObject> myList = TableObject.loadList("sql condition");
...
}
b)
public static Type getInstance() {
if (instance == null) {
return new Type();
}
return instance;
}
c)
getForeignKeyObjectProperty1() {
return ForeignKeyObject.loadByPrimaryKey(foreignId).getProperty1();
}
getForeignKeyObjectProperty2() {
return ForeignKeyObject.loadByPrimaryKey(foreignId).getProperty2();
}
...
getForeignKeyObjectPropertyN() {
return ForeignKeyObject.loadByPrimaryKey(foreignId).getPropertyN();
}
d)
public boolean isHasImage() throws SQLException {
StringBuilder query = new StringBuilder();
query.append("select user_name");
query.append(" from user");
query.append(" where has_image = 1");
query.append(" and user_name ='"+getUserName()+"' and user_image is not null");
Connection c = Database.getInstance().getConnection();
Statement st = c.createStatement();
try {
ResultSet rs = st.executeQuery(query.toString());
if (rs.hasNext()) {
return true;
} else {
return false;
}
} finally {
st.close();
}
}
If you make this kind of code, stop programming. If you don't see anything strange in this code, stop programming. Otherwise you aren't bad, so you even might be good :)
EDIT: To answer comments: I got job before graduating, and this guy already had few years of programming experience. He got fired few months after I got employed so I wasn't in position to tutor anyone. Examples above were just from top of my head - every peace of code he touched was flawed in various and imaginative ways. Most of the stuff started to creep out after he went from the company, because only then other people saw some parts of the code. He is generally a nice guy, pleasant to talk with etc. but he will NEVER be a good programmer, just as I will never be a good painter or a writer or whatever.
To contrast this with another example, guy who came to replace him was also undergrad at the time. He studied college more famous for management then programming. He isn't too geeky in a sense that he programmed anything for fun or would sit home and read about java or programming, yet he is doing just fine. He adjusted quickly and started producing useful and maintainable code. Some people can do that, other can't - just ask dailywtf.