Code That Scales

General Discussions
Post Reply
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

Code That Scales

Post by Shane » Sat Sep 19, 2009 5:31 am

In software development, you have to write awesome code! Code that scales! Bottom line, I love developers that write wicked code that scales, that functions to perfection, and that looks “Hot”! I just don’t understand people that think their super hero name would be “The Human Obfuscator”.

The Hot and Ugly of Software Development

You know the feeling of hot code! It’s so easy to read, things just seem to flow together, you get into this state of happiness that all is good with the world?

Don’t you hate that feeling in your stomach when you open up code, and there are no comments, and it’s impossible to read, nothing seems to flow, you get into this state of crying and anger!

I love asking white boarding programming questions in interviews, not so much because I want to make sure the guy can put together come code that will execute, but because I love seeing how pretty their code is. I look for things like separation of code, is the developer putting related pieces together?

Someone Else Will Look at What You Developed

As developers, we often forget that chances are, someone besides you will be touching your code, and they will be lost reading it if your code is ugly. You should always be thinking in the back of your mind “How can I make sure that people reading my code will say, “That’s Hot Code!”".

See I think successful software developers view writing code more like an art form, than a science. Sure there is a lot of science in software development, however, once science becomes so complex that it requires finesse to get it done, it becomes art.

Software Development Requires Comments

So much code out there is not commented at all. During software development, it seems some developers don’t see the importance of it. When I look at code, I would love a brief explanation of what you are trying to do, any code hacks you used that need to be cleaned up later, etc. Adding a nice description to functions is awesome. Adding smaller bits of comments when needed within the code itself is also awesomeness. However, be careful not to go overboard and add to much detail! Your code should use variables that make sense, should flow, etc. However even the prettiest of code needs comments to make everything flow together nicely!

Comment your code as you go about development. If it took you a few weeks to figure out an algorithm, or how you needed to make a certain recursive function flow, make sure you comment it for goodness sakes! I can’t count the amount of times as a software consultant that I was reading other peoples code, and wasted days trying to figure out what they were doing, simply because they refused to take 2 minutes to add a few simple comments.

I’ve also run into the other side of this coin where some developer made it his life mission to over comment everything! I’m talking every single line. “What I’m doing here is going into a case condition.”, “This is and If statement.”, or how about “I’m going to assign 5 to the integer i.”. I get it! Reading through this kind of code also takes forever, as it becomes almost as annoying as using Microsoft Bob, or dealing with Clippy saying “It looks like your writing a letter!”.

Develop Readable and Well Formatted Code

Have you ever heard the argument that you save bandwidth by not spacing things out, not tabbing, and using small variable names? Let me just save you trouble by telling you, do not hire anyone that believes this theory. Machines are the best at saving bandwidth, if you are concerned with bandwidth and file size, run compiled or compressed code on your web sites. People that write code like they are a human obfuscator perplex me. If you are out there and reading this, please explain your logic in the comments…

Make sure you use indentation and your margins correctly. It’s nearly impossible to read code that has poor indentation, or none for that matter. I mean sure it’s readable, but it cause massive migraines, and it’s just something that should not be dealt with if you are any kind of professional developer.

You know how in English glass the teacher explained how run on sentences were bad? The same applies to programming. Try and keep your lines no longer than 80 characters wide.

Also please make sure you use variable names that make sense! Booerns (This is a Simpson’s technical term) to using letters that mean nothing! Be creative and come up with some nice variable names that make sense. And don’t try and be the smart ass that creates variables that make the Great Wall of China seem like a tiny stretch.

Follow coding standards set forward in your organization. What you don’t have coding standards? Get some! While you’re at it make sure you add in some casing and naming standards!

Separate Logic

New developers do this all the time, they will create functions like “submitOrder”, and place every piece of logic into the “submitOrder” function, from sending the order, to calculating totals for the order, and even figuring out the taxes on the order. Instead, please do everyone a favor and create an “Ordering” class, and create functions like “getSalesItems” and “calculatePST” and “sendOrder”.

You really have to make sure you separate out your logic whenever possible as it will make unit tests, later bug fixes, and re-usability much easier tasks to accomplish. Even if you already have a huge function that does everything but flush the toilet, make sure you go back and re-factor the function.

Code Review

Probably the single best thing you can do to make sure your code is “Hot” is perform code reviews! This will force you to want to write readable code that everyone will want to look at, instead of code that makes developers want to run away screaming.

Final Thoughts

As you grow in your software development career, you will start to realize that very little time is spent writing new code, and a lot of your time will be spent looking at old code, and figuring out how to tweak it, and extend it. Make it easier on yourself, and the other developers that will have to look at your code, by writing “Hot” code!

At the end of the day, “Hot Code” is readable, maintainable, less bug ridden, artistic, and scalable.
Post Reply

Return to “General Discussions”