Seeing Sextuple
by in CodeSOD on 2014-04-29(Read to the tune of "The Way We Were")
Bitmaps Clog the corners of my RAM Giant, duplicated bitmaps of the memes that were
Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.
(Read to the tune of "The Way We Were")
Bitmaps Clog the corners of my RAM Giant, duplicated bitmaps of the memes that were
The First Rule of Enterprise Software is: don't talk about enterprise software. The Second Rule of Enterprise Software is: when you do talk about enterprise software, make references to stylish dramas from the '90s starring Brad Pitt and Edward Norton to make it seem more exciting. However, the most important rule of enterprise software by far is Rule Number Three: Even the simplest little things can't be simple. Arthur was reminded of Rule Number Three on a recent trip into his employer's company-wide database.
The codebase Arthur maintained had a method for just about everything. "Hah!" You're probably thinking. "I bet it doesn't have a method that returns an array containing the letters of the English alphabet!" Well, Hah! yourself: stumbling across a call to GetAlphabetForHouseCombinedPortfolios
in the bloated, inappropriately-generic UploadingTool
class, Arthur was curious. Would it contain a hard-coded list of letters? A complex mathematical formula dependent on the current date that would baffle everyone by returning Hebrew when the clock switched out of daylight-savings time? No, like all proper enterprise solutions, the method invoked a stored procedure in the database. And that's why Arthur is proud to present sp_UploadingToolGetAlphabetForHouseCombinedPortfolios
:
We've all had that feeling before. We see something happening in front of us, yet because the sight doesn't conform to the worldview held within our brain, we just can't believe our own eyes. Dogs playing poker. Cats wearing panty hose. Politicians telling the truth. You get the idea. And depending on your personal threshold for incredulity, you might experience this feeling as a double take, a spit take or a psychotic break. If you happen to be prone to psychotic episodes, then I'm going to have to ask you to move on. Wait for tomorrow's WTF. Or maybe pet some kittens. Here's a picture to help you get started.
Feeling calm and relaxed? Good. Now let me tell you a story about Steve. Steve is what you call a 'skeptic' (which is scarily close to septic, but I digress). He questions absolutely everything he encounters. He walks with overly firm footfalls to make sure that the ground won't open up under him. He carries two watches to act as verification for the clock on his smartphone. He even checks his own pulse to make sure he's alive.
Trevor spent a huge amount of time writing a 2,000,000+ PHP/JavaScript/HTML system for an e-commerce company. Like a few other I'm-Special geniuses in our field, he believed that he could do it better than everyone else. For this reason, he came up with his own way of doing things. Database queries. Date-time logic. You name it.
The Java-based application that Dan M. supports does something that is frequently accomplished by applications the world over - based on the value of a passed string containing a valid date, convert it to datetime. Simple stuff. Java even has built-ins to make this task even easier.
Well, the developer behind the below code decided to take the idea of date conversion using Java's built-ins and run with it ...way off of the reservation.
JH supports web-based property management software, which is exactly as exciting as it sounds. We've all been there: obsolete tech—their database was running SQL Server 2000 long past its sunset date—and outsourced development. The Indian office had a problem to solve: they'd already written a database function to return all completed work orders for a given tenant's unit, but since notifications were only sent once a day, the client wanted to scoop up any work orders from the previous day that were completed after that day's notification was sent. JH could have modified the function to look back at the previous day in five minutes, but then his company would have missed out on the incredible cost and efficiency gains of offshoring. Instead, JH was tasked with reviewing the code. The first thing he noticed was that, instead of just comparing the work order dates to the current date using SQL Server's GETDATE()
function, the technician did this:
where datediff(day, @asofDate, wo.DTWCOMPL) between -1 and 0
One of the The Architect's developers laid the egg that is this round-robin connection pooling code. He discovered this when he noticed that his connection was getting incorrect responses under load.
public class RoundRobinConnectionContainer { private static final Logger LOG = Logger.getLogger( RoundRobinConnectionContainer.class ); private int useNext = 0; private List<BehaviorEngineConnection> connections = Collections.synchronizedList(new ArrayList<BehaviorEngineConnection>()); // Find the index of the next connection to try public int getNextIndex() { if (useNext > this.connections.size() - 1) { useNext = 0; } return( this.useNext++ ); } public void addConnection(BehaviorEngineConnection connection) { connections.add(connection); } public BehaviorEngineConnection getConnectedConnection() { int size = this.connections.size(); while (size-- > 0) { BehaviorEngineConnection conn = connections.get(getNextIndex()); if (conn.isConnected()) { return conn; } LOG.error("No connected connection available!"); return null; } } }