Derrick Pallas

Mar 2007


by in CodeSOD on

Recently, time has been an issue on the minds of many people. Unfortunately, as far as I can tell, only about half of them installed the software required to deal with the new Daylight Saving schedule. This means that for about three weeks, people trying to share appointments and events will have trouble, at least sometimes.

The real problem is that these intermittent issues will probably only last three weeks and will thereafter be forgotten. Until October. Then, no one will be expecting it. As the poet should have written, time is not on my side.

Checking Your Digits

by in CodeSOD on

Since the invention of the printing press made dime-store novels a commodity, as intended, distribution has always been a problem. With places like "The House" on "The Street" in "The Empire" on which "The Sun" never sets, postmen have their work cut out for them. Luckily, postmen are very clever and have come up with systems for describing how to route mail.

Like programmers, postmen are also lazy; they'll give you discounts for making their job easier if you utilize the cleverer parts of their system. For instance, in the United States, you can make postal workers happy by printing a simple barcode on your item. This barcode includes a check digit.

Refactoring History

by in CodeSOD on

Refactoring is a trick that managers play on us, to waste our time and break our spirits. Just because they can't wrap their tiny minds around large chunks of similar code doesn't mean that you are unable to wield these weapons. Sometimes, however, we are forced to do things we don't want to do. If you have to refactor: do it late and infrequently.

As a case example, take the code John is being forced to slice into mortal-sized chunks for managerial consumption. It's "classic ASP" and the decision to refactor was made at a critical tipping point: 4381 lines of code, most of it in a single procedure.

The Insanity Defense

by in CodeSOD on

Those Internet folks just don't get it: content is valuable, but with all this hippie talk about "openness" and "collaboration" and "cooperation," they forgot to build in content rights management! For anyone that does run a website with valuable content, it's inevitable that pirates will come after your work and you'll need the best defenses to protect it.

Now Fran's website definitely has valuable content and they've been protecting it for years, only allowing known customers with fixed IPs to access it. "How," you may ask, "does their code stop the pirates?" A secret buried deep in ASP, they're now ready to share this technology with the world.

Third Time's a Charm

by in CodeSOD on

Starting a new job is usually exciting but also frightening. Adjusting to a new code base --- styles, idioms, and all --- can be daunting. Luckily, for Sam, all the important code is kept in a single file: MyStuff.asp. Despite the name, the functions in that file belong to everyone.

Weighing in at only 1k lines of code, it's included by every script on the company website and contains a treasure trove of helpful functionality. It contains just about anything a web developer could want. If what you want to do is not in "The File" and it might be useful for other developers, add your function at the end. It's that simple.

Another Brick in the Wall

by in CodeSOD on

Compilers are just too picky: on one hand, they'll accept just about anything; this encourages us to feed them just about anything. On the other hand, they complain ceaselessly. Luckily, you can just pipe away your troubles to /dev/null and everything is sunshine and lollipops again. (Or fluorescent basement lighting and Pop-Tarts, take your pick.)

All is not well for AJ, however. In his world, they discovered the -Wall and --- instead of shying away --- actually use it. What's more, they actually fix warnings, like the following "unused variable warning."

Special Coders

by in CodeSOD on

Recently, Craig was digging through some "old 3D code," intending to chop it up and port it to some foreign language. What he found was some very special code, written by a very special coder; and folks, when you come across something like this, it's a crime against humanity to do anything but put it in a museum.

We are that very special museum. Step up, one and all! On to the exhibition!

Net Shift

by in CodeSOD on

As far as I'm concerned, both Al Gore and Vint Cerf can be fathers of the Internet; it's just that they can't get married in most states. This crazy bastard child we all know and love really did cause a paradigm shift by shrinking the world. When it comes down to it, the Internet is a pile of money and equipment combined with a bunch of standards and peering agreements; if that's not love, I don't know what is.

However, all is not well. Equipment gets old and money dries up. Bugs and clever coding can stop standards in their tracks. Peers don't always play nicely. Some people might blame the Internet's family, but it has a lot of baggage.

Unique Ways to Play Catch

by in CodeSOD on

Normally, we don't write up submissions that come from code websites or open source projects. This policy is partially because F/OSS projects are supposed to already have many eyes and partially because I don't want to get beat up. When the submitter is afraid of getting fired, anonymity kicks in. As for code websites that take themselves seriously, I just feel sorry for the people that write those.

That's why Alvin should be ashamed of himself, especially because this code and its coder aren't hurting him in any way. However, the snippet he sent in was just too good to pass up. I won't mention where the code came from but I have faith y'all'll figure it out.

The Pyramid of Error

by in CodeSOD on

The ancients knew the power of pyramids. Placed on power points around the globe, they allow mankind to channel mysterious, transcendental energy from across the void. Now, the wise folks that figured this out also realized that much of this power is derived from mystery; thus, they made sure that the power of the pyramid would evade any attempt to quantize or otherwise capture it as data.

This power is still with us today. You might that this would prevent these forces from interacting with computers, which are all about quantization and data, but this is not the case. It is said that Kernighan and Ritchie first channeled the C specification at one of these points of power under a blue moon. This, perhaps, is why a portable assembly language has been so successful.

Big Math, Little Snippet

by in CodeSOD on

Computer scientists have always been jealous of mathematicians. Much of the strife in this ancient conflict is derived from the fact that math guys take large numbers for granted. Silicon can't handle arbitrarily large numbers as elegantly as paper and many computer languages realize that only really bad programmers would ever need numbers that need more than 32-bits.

But computer science is not about judgement. Thus, good programmers condescend to help out by writing BigInt[eger] packages, usually as part of an undergraduate "Intro[duction] to Data Structures" course. To show our gratitude for their hard work, the rest of us should make every effort to use their code whenever we can.

Shooting XML

by in CodeSOD on

As we know from Brooks' essay, in software engineering there is no such thing as a silver bullet; at least, not one that doesn't come in a 12oz can. That's why XML is suspicious: no one should have spent the time to develop a single, consistent methodology for data interchange when any possible effort could only be in vain. It is unfortunate that this so-called panacea has caught on: it's so easy that companies feel like they can get away with hiring developers instead of engineers.

To take this article down another notch: engineers usually understand the project triangle: good, fast, cheap: pick two. If you don't understand what I'm talking about, just say "XML should work" when anyone asks you a question and you'll be fine. The real problem with XML is transforming it into something more usable. It'd be really nice if someone came up with a transformation language for XML, but I suspect that this would fail for the reasons stated above.

SQL Four Joy

by in CodeSOD on

When the CEO is the ex-developer of the company's flagship product, it probably means that the other developers were just hired to add features the CEO was now too busy to be bothered about. Obviously, it is impossible that the design of the system could be imperfect in any way. As technology changes, however, it sometimes becomes necessary to do drastic things like change software platforms.

As the product had grown --- "Organically, like a weed." --- more and more logic was shared between the SQL database and the application.That's where Trent came in: it was his job to discover and recreate all the nuances of this dance on the new platform.

Generating Secure P455w0rd5

by in CodeSOD on

It's tough to generate good passwords. Users can't remember the hard ones, anyone can figure out the simple ones. We live in a world where two of the most common passwords are abc123 and password.

That why we have tools to generate passwords for us. Take, for instance, the following PHP, sent in by Dmitriy.

Cabbage Based Authentication

by in CodeSOD on

Security is a big deal. The days of open mail relays and anonymous file upload sites are long gone. No one executes binaries they find in an email inbox. If only.

That's why when Gabriel was asked to take a look at a PHP application on which her school relies --- an application that stores student's name, grades, and social security numbers --- she expected top-notch security. Here's what she found.

The Counter of And

by in CodeSOD on

With all the shiny client-side browser toys out there, many people forget about the dark underbelly of the web. As neat as it is that you can make a web brower act like a windowing system, dynamic sites are still powered by back-end applications; which is to say, powered by evil.

Now there are different levels of evil. Ruby is normally elegant but resource intensive. PHP was designed as an example of how not to name functions. Perl has its own special circle, ancient and full of strange characters. If you want real evil, though, you have to find a web application written in C.

JavaScript Hacks

by in CodeSOD on

The advent of JavaScript has made it really easy to write web pages that interact with you. Really, it's insanely easy. The barrier to entry: way too low. It's not that all JavaScript is bad, just that most JavaScript is not written with simplicity, correctness, consistency, or completeness in mind.

The worst part is that many "Coder 2.0s" don't have a background in other languages so they don't know what sorts of functions to expect from their language. Maybe that's why I don't feel any sympathy for Piotrek, who was looking for calendar code on the web and found this really fantastic way to detect leap years.

Putting It All Together

by in CodeSOD on

When management caught on that one of their lead developers was only good at talking about being a good programmer --- not at actually being one --- he was let go and Jimmy inherited the orphaned code-base. In order to cope, they've put up a bulletin board on which they post code that should never have been born. All of it is from the wake of this single developer.

Here's one of Jimmy's favorites. While he doesn't explicitly mention what language it is, I only know of one widely used language that goes out of its way to insult variables by calling them "dim." From the submission: "The idea is simple. Prompt the user for a file to import; pass this filename to a callback that will load and parse the file."

Visual Basic Triple Play

by in CodeSOD on

Instead of reinventing the wheel, the company Ramirez works for decided to use a framework to build their Web Framework. Unfortunately, they may have made a poor choice. When they found out it does "crazy things" like saving reports as PDFs (which are stored locally) and then routing them through an IIS web service, they decided to take a closer look at the code.

Without giving too much away, Ramirez identified (in the following code) three reasons he drinks. Consider it a Rorschach test: what do you see?

Getting Better Sleep

by in CodeSOD on

Reporting from the field, Zak tells us the sad story of a sysadmin who has been forced out of his comfort zone. When your sysadmin writes a bunch of scripts in Perl and then your company decides to switch to .NET, the job of converting the scripts will almost certainly fall to none other than the sysadmin. This will be the case even if said sysadmin doesn't know .NET.

When this happens, you will learn two things. The first is that the new .NET code will be structured as though it were Perl code, even where inappropriate. The second is that some functions that the sysadmin is used to will be unavailable, in a different namespace, or otherwise renamed.