It’s Bugging Me – Debugging in Unknown Languages

Debugging-in-Unknown-Languages

I’ll admit it, for one reason or another, I never really learned .NET. I think it just wasn’t very popular when I started my career and none of the places I’ve worked at have needed it.  It somehow never crept into my list of languages to learn, so here I am. For the record (and to keep the comments nice) I have nothing at all against .NET.

Everyone has languages that they just never got around to learning (if this doesn’t describe you, tweet me, I have a job waiting). If you work in the services side of your company like me, from time to time, these gaps in your knowledge can really have you scrambling to see why something’s not doing what it should. Hopefully, there’s a friendly coworker available to help, but not always. What if, you’re the coworker people go to for help. What can you do then?

Thankfully, there’s hope. You probably even know what to do, just not how to do it. I’ve put together of few of my go to tools and approaches in hopes of helping out the next person in this situation.

Stack Overflow

Despite what my generation may have been told when we were younger, no one is special. Everything you break has been broken before. Go read how other people fixed their problems. I’m sure everyone is already doing this, so let’s just move forward.

Formatting

I’m the type of programmer that wants everything on my page aligned (and a tab is always four spaces). However, not everyone seems to care about this as much as I do. That’s fine. It’s their code, they can keep it however they want.

But, you don’t need to work with it like that. Lets look at a very simple function:

I can more or less work out what’s going on, but I shouldn’t need to work so hard to read a basic print function. If you spend a bit of time, you’ll end up looking at this

  puts “The the program was written #{a1}”

  puts “The program was written by #{a2}”

end

Ahhh, much easier. But, I know Ruby. How do you clean up languages you don’t know? Most languages are based on C (or ALGOL) so there are some some things you can usually do across languages. First, look for any “;” or “END” If you add a line break at all of these, you’ll at least be on the right track. Next, look for other words you’re accustom to seeing indented. Things like fun, if, while, do (you get the point) will help you identify where to add some indentation.

Count the Parentheses and Make sure Everything is Terminated

I wish this didn’t solve as many problems as it does, but seriously, do a quick for {, { and ( and then do the same for }, } and ). If the numbers aren’t the same, you found the problem.

Make sure every function is somehow ended. For .NET, that means I need to look for

End Function

Just google Basic <Language> function example to find what you’re looking for.

Comment out…EVERYTHING!!!!!

Comments are the best. Nothing better than getting some legacy code that’s well commented. I’m pretty sure in my entire professional life, this has happened about three times. There is a school of thought that states code should be self-documenting, meaning that methods should indicate what they do and why they are there. In my experience, self documenting code is great in theory, but requires a dedication often falls short near line 700.

Assuming you’ve done the previous step, you’ll be looking at something along the lines of this-

Giving it a quick once over, I see a few things I recognize, but I just want to find where my problem is, so I’ll comment out pretty much everything just to make sure the using statements pass the mustard (this is when I start wishing every language had multi-line comments).

This is good! Now we have a better idea of what’s causing this issue.

You can imagine the next few steps (hopefully) so I’ll save some space and point it out directly – line 20:

Should be:

Debuggers will not help

When I’m writing my own code, I love using tools like ruby-debug. But, it’s only helpful because I already know Ruby. If this were an unfamiliar language, I’d need to learn how to use the tool, which would require learning the language. We’ll save that for a weekend project.

So, if you’ve done everything listed above and you’re still getting no where, look for a part of the code you can figure out. Usually, it’ll be something like a while loop, but get a good entry point and just try and follow the flow as long as you can. That may mean leaning heavily on Google in this situation.

Summary

Above all else, just use your analytical thinking. At the end of the day, what you’re doing is the same in every language. It’s just the means you can do it in that are slightly changed. Keep plugging at it, and eventually you’ll get it to a point where you can see some light.