Recent Articles

Aug 2021

A Bit Overcomplicated

by in CodeSOD on

Lets say you have a 64-bit integer. You want the first 42-bits. Now, if your language has a bitshift operator, you'd be tempted to do something like largeNumber >> 22.

But what if your language also has all sorts of advanced stream processing and map functions? It'd be a shame to not use those. Tarah's shop uses Rust, and thus they do have all those exciting advanced stream processing. Her co-worker decided they just needed to be used:

On Error Goto Anywhere but Here

by in CodeSOD on

One of the big pieces of advice about using exceptions and errors is that they shouldn't be used for flow control. You catch an exception when an exceptional event happens, but you don't, for example, throw an exception to break out of a loop.

Unless you're Python, which throws exceptions to break out of loops. That's just how iteration works. But we're not here to talk about Python.

Changing Your Type

by in CodeSOD on

Alex sends us some Objective-C code which… well, let's just say that the code is suspicious looking, but there's nothing clearly bad about it.

+(const char*)st:(NSArray*)a a:(int)i { @try { return ([a objectAtIndex:i]==[NSNull null])?"":[[a objectAtIndex:i]UTF8String]; } @catch (...) { return ""; } }

Select Orders

by in CodeSOD on

Some time ago, Will started a new job- a four month contract to take an old, ugly DOS application and turn it into a new, shiny VisualBasic 6 application. "And," the new boss explained, "the new program is almost done anyway. It's just that the last guy left, so we need someone to take it over the finish line."

A key feature was that it needed to be able to fetch PDF files stored on a shared network drive. The order numbers were serialized, but the PDFs themselves were organized by year, creating file paths like I:\ORDLOG\2007\172.pdf. Now, in this particular block of code, one had access to both the ordnum and the ordyear, so constructing this path could be a trivial exercise. The previous developer did not take the trivial path, though.