Home > Articles > Web Development

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Step 2: Understand the Intent

So you've got some code. Great!

It's tempting at this point to go line by line through the code, looking up equivalent calls in your chosen new language. This approach will be useful shortly, but please refrain from actually writing anything new! Your new language may offer powerful alternatives to the code you're examining. Moving from C to C++ offers an obvious example: In C, you would write your own data structures, but C++ gives you access to the Standard Template Library (STL), a very fast and well-written set of standard data structures (among other things). See whether your hand-coded data structures can be replaced. For the code snippet I've chosen, we're going to add support for exceptions. Don't just "port" your code—upgrade it!

To do this, however, we need to understand what the chosen code is trying to do. Valuable clues include the obvious—comments, function and variable names, documentation—and the not-so-obvious, like the last 10 versions of that very same code. Dig into the product's source control system—it's a valuable tool for tracking the intent and evolution of a piece of work. For this example, we don't have anything from source control (it's just a snippet found on the web), and comments are sparse. So instead we go out and look up the bits of code that are in there.

Ah, excellent. This code is pretty simple: The user is passing a drive letter and a network location to us, and we're using a Windows API call to map the drive. Whew. So all we need to do is write our new code, right? Oh, wait. Where are we going to write it?

  • + Share This
  • 🔖 Save To Your Account