Coded Smorgasbord: Classic WTF - Sweet Mysteries of Life |
Check out a Classics republish of one of our most read articles from 2014. Enjoy!
When you read a lot of bad code, you start to get a sense of why the code exists. Often, its ignorance- of the language, of the functional requirements, of basic logic. Sometimes, its management interference, and the slavish adherence to policy over practicality. Other times, its just lazy or sloppy work.
And sometimes, the mysterious logic that gave birth to a WTF is just that- a mystery.
Timo cant help but wonder why this method exists:
public DataModel getEditionModel() {
if ( true )
throw new IllegalArgumentException( "You shouldn't be here" );
return editionModel;
}
Angela is still puzzling over this one:
String timeStampLength = " ";
int lengthOfTimeStamp = timeStampLength.length();
Can you imagine a clearer way to express a numeric length?
Dennis found some code that needs to check the length of an array, so it does this:
function countDocuments() {
var count = 0;
for ( var i = 0; i < user.documents.length; i++) {
count++;
}
return count;
}
If only there were a built-in method that could tell us the length of an array...
And finally, Andrew sends us this example of defensive programming, thats about as safe as we can make it:
Private Sub ImageList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ImageList.DataBound
Try
Catch ex As Exception
If TypeOf ex Is ArgumentOutOfRangeException Then
Throw New Exception("item not found in the list...")
End If
End Try
End Sub
http://thedailywtf.com/articles/classic-wtf-sweet-mysteries-of-life
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |