Remy Porter

Computers were a mistake, which is why I'm trying to shoot them into space. Editor-in-Chief for TDWTF.

Jan 2013

Reusable Code

by in CodeSOD on

Code reuse is one of the key steps to maintainability. There are many ways a developer might make their code reusable. For example, Steve’s co-worker wrote this block, which generates 1000 log entries:

int next = 0;  

List<FeedSearchTransactionLogResult> allDataSimulated = new List<FeedSearchTransactionLogResult>();  

allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
//SNIP skip 995 lines…  
  
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));

Scheming Schema

by in Feature Articles on

Adam worked for a moving company. When he joined up, it was a regional enterprise with several locations and a surprisingly large fleet of trucks. One day, he came to work to learn that he now worked for a much larger, national company, called ConHugeCo. Nobody was getting fired, but now Adam had to get their data integrated with ConHugeCo’s.

ConHugeCo had a fat middleware tier built in WebSphere MQ. Like any true enterprise solution, everything was glued together by XML, and that meant Adam built many small programs that pulled data from legacy systems and spreadsheets and mashed it into XML files, which were then shipped off to the MQ system. Adam had the HR and insurance data synced within a few days, but when it came time to sync their loadouts for moving large items, things started to get weird.


The Sysadmin's PC

by in Feature Articles on

“Hey, can you give me a hand? This computer I built won’t boot.”

Alexander sighed, and went to see what Nicholas had done now.


Comments

by in Coded Smorgasbord on

Comments are a vital part of making code readable, but they’re more than just documentation. They’re communication between one developer and another. They tell us what the code does, but also how we feel about it.

Scott found this, which conveys a most fervent hope for this block of code:


InsertSql()

by in CodeSOD on

Data-driven applications need to generate SQL from time to time. Usually, we leverage things like stored procedures or ORM tools to keep our code sane, but from time to time, we might hard code our SQL statements. You sacrifice some flexibility for some transparency into what your code actually does to the database.

Sometimes, however, writing SQL is just too darn readable. Adam’s co-worker has a better way:


Check the Check Printer

by in Feature Articles on

There was nothing unusual about an unusual ticket. Matt worked helldesk at an assembly plant, and not a week went by without some confusing brain-bender from his users. He didn’t blink when he received this ticket:

We’re having an issue with our check-printer. Every time a user logs on, it prints out an inventory of electrical parts dated from 1984. On our checks. This is causing some accounting issues.