Good Code Matters

You have heard it before and you will not stop hearing it, as long as any part of your school or future work experience will involve programming, writing clean and good code is important. I’m not going to go through all the details about writing good, reusable code because there’s a lot of material out there (that I recommend you seek out) that would help you extensively with this. I’m only going to go through the most basic things that I think might be relevant and helpful to some since I have come across many people who have questions about why they need to go the extra mile of writing “good code” if their program already works. As a student starting out, programming can be daunting and that’s understandable but it’s equally important for you to invest time into learning how to write good code because it will only pay off well. There’s no demerit, that I know of, that will come as a result of learning how to write good code. On the other hand, there’s not enough time and space for me to write about the downsides of writing bad code. Always remember that time spent writing good code is never wasted time. 

Why good code matters:

  1. For your own well being and sanity. There’s nothing more frustrating than looking at your own code days after writing it and not knowing what’s going on in the whole program. And it happens all the time even to the best of us if you don’t have well-written code. When you take the time to write appropriately commented, well-chosen variables names and well-indented code (insert many other things that comprise of good code), you spend less time debugging and your code becomes easily reusable if you ever need it in the future.
  2. It will save you so much time when you go to TA office hours when you need help with debugging your code. Well-written code is so much easier to read and also easier for someone else to follow what your program is doing. This saves you so much more time because the faster they find the bug, the faster you finish your programming assignment, the more time you get to play! 
  3. If you ever work in a team at an internship or full-time job, good code is vital because your eyes will not be the only ones that see your code. Good code makes collaboration much easier and in general, helps people understand what you are doing collaboratively and increases productivity in team projects. An important question to ask yourself when writing code is this “If someone else read the code I’ve just written, would they be able to understand what this code is doing?”
  4. Most interviews for internships or full-time positions require that you have a technical interview where you exhibit your programming skills. Your interviewer will most likely judge you based on the quality of the code you write and your thought process behind it. If your code isn’t clear enough and your interviewer has to spend a lot of time asking you questions about what your code is doing and not on the concepts that are relevant to CSE or CE, then that might hurt your chances of getting hired. So always write clean code that is easy to understand and follow.

How to write good code:

Do not start writing any code if you don’t know what you are going to write. Let me put this way, if you can’t fully explain to someone else/yourself what your code is supposed to do at each step, then you shouldn’t start writing it. First, computers are dumb machines that only do what you tell them to. Not what you want them to do or hope for them to do. Only what you tell them. So if you intricately don’t understand what you want the program to do beforehand, you will not get the results you expect from your program when you start coding.

Think of it this way, when you get into a car to go to the beach, you don’t just start the ignition and start driving to random directions and hope that somehow the car will get you to the beach. What happens is you plan your route in advance and only start driving when you have an established plan about the direction you want to take.

If it never makes sense for you to start driving before planing the direction you should take, the same applies to code, it should never make sense to start coding in your IDE before planning out exactly what you are going to tell the computer to do. 

As with driving routes, things can change, you may learn of a road accident that requires a detour or think of an alternative route that might be shorter than the one you initially planned so you make some adjustments on your journey. That is perfectly fine. It happens in code too. Along the way, you might discover that there are better ways of implementing something than what you had initially written out and so you tweak your program accordingly. Just remember, there won’t be anything to tweak if you never had a plan, to begin with. So I’ll say it again, always plan out your code before opening your coding environment.  

If you are at the point where you are thinking “Okay, I get it. I need to plan before writing any code, but I don’t know how to plan, where do I start?” That is a perfectly good place to be and the right question to be asking. If you go ask your TA’s or professor about how to approach this, they would be willing to teach you ways on how to plan your code. The worst place to be is a place where you don’t know you need to plan. But that’s not you now. So ask for as much help as you can get, you are on the right track!

In conclusion, read as many books as possible on programming, it will help you improve your skills. One of my favorite books on good programming practices is Clean Code by Robert Cecil Martin, give it a try, it might help. Of course, there are many books out there and if you have any resources that you think might be useful for this topic that I haven’t talked about, please leave them in the comment section below.

I hope you have a great rest of the week! 

Note: Because we want Engineer’s Loungue to be a useful resource to you the students, please send an email to nekesame@buffalo.edu about any questions / topics you would like to hear more information about that you feel would be helpful for you during your college experience as a CE & CSE major. We will try our best to point you to resources that would be helpful and also in cooperate more topics in the articles about things you would like to learn about. The goal is to get as much help to you guys as possible during the course of your programs that would allow you to be successful.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.