Code Cloning an example

Code Cloning an example

Some parts of code cloning are bad. In contrast to my other post this is supposed to be entertaining and something you can do before breakfast. Find the difference yourself and draw the conclusion. This code is from qmailstore.cpp from the qtopiamail library. This is not to pick on any developer at Trolltech but to highlight how code review and discussion could create a better Qtopia product.

    d->checkComparitors(key);

QString sql = "SELECT id FROM mailfolders";

if(!key.isEmpty())
sql += " WHERE " + d->buildWhereClause(key);

if(!sortKey.isEmpty())
sql += " " + d->buildOrderClause(sortKey);

QSqlQuery query = d->prepare(sql);

if(query.lastError().type() != QSqlError::NoError)
qLog(Messaging) bindWhereData(key,query);

if(!d->execute(query))
qLog(Messaging) checkComparitors(key);

QString sql = "SELECT id FROM mailmessages";

if(!key.isEmpty())
sql += " WHERE " + d->buildWhereClause(key);

if(!sortKey.isEmpty())
sql += " " + d->buildOrderClause(sortKey);

QSqlQuery query = d->prepare(sql);

if(query.lastError().type() != QSqlError::NoError)
qLog(Messaging) bindWhereData(key,query);

if(!d->execute(query))
qLog(Messaging)

Comments are closed.
© 2024 Strong Leaf