The thing about computer programming is that it’s a complete pain in the ass when you’re trying to figure out the problem, yet when you finally solve it, when you finally have that aha moment, the feeling of accomplishment is unlike anything you’ve felt when you’ve accomplished something. You think holy shit, I can make technology work, and that feeling is totally worth the long stretch of hours or even days when computer programming feels like a pain in the ass.

7+1 tips for coding…

I had this post sitting on my drafts for a few weeks, so I decided to make it pretty and post it. Enjoy!

Based on what my teachers told us.

1. Think before coding.  →  Take 10 minutes, 20 or even 30, whatever you need and think about which design pattern (if any) is appropriate for what you are going to code. Really think about it, you’ll be glad for those “wasted” minutes when you have to change or add something on the code and it only takes you 30 minutes instead of 5 hours.

2. Comment your code. →  Seriously, there’s nothing worse than check your own code two months later and don’t remember what it does. Comment everything important, avoid really obvious things.

3. Write clean code →  Indentate. Use spaces. Separate your code in blocks by functionality.  Read Clean Code by Robert C. Martin, it’s really useful. Also, follow whatever convention/standard the code has (like the Java Code Conventions), especially if it’s a shared code.

4. Refactoring is your friend. →  Nobody likes those looooooooong methods with tons of lines. Usually (almost always), that means you’re mixing functionality. Separate the code in more manageable methods. It also helps to make the code more reusable… which lead us to 5.

5. DO NOT COPY AND PASTE CODE.   →  If you have the same chunk of code twice or more times, you’re probably doing something wrong. Read no. 4.

6. Use meaningful names. →  It’s always funny to name your int variable “elligent” or your char, “mander”; but that doesn’t say anything about what it is for.

7. Test your code. →  Test, TEST, test, tEST. Also, test as you code. Don not wait until you’re done with the program to test it or you’ll regret when you find a giant bug you don’t even know where it came from.

7b. Automated testing is usually worth it. It also helps to save a lot of time with retesing and regression testing.

7+1. Learn to debug. →  In my first year, I used to think that I could manage without knowing how to do it and by printlning every time I had a problem. Wrong. Sometimes, I wouldn’t even find the bug and checking for “lost” println is a waste of time.