Readability: It’s all in the name
Hello all you cool cat….wait that’s not me, What’s up everyone! Today I am wanting to talk to you about Readability, I want to talk about how important it is, why it matters, and most importantly how it helps others.
So imagine, you are working late one night, pounding out some serious code, everything is looking beautiful, the clock has stopped, the night has frozen and everything is working perfectly, but in the midst of everything working so well, you didn’t want to take the time out to make good names for variables, functions, objects and your code file is starting to resemble the word files in your documents folder. Now fast forward 6 months, you have rested, ate some Doritos(not a paid advertisement, looking at you Doritos!!), and got a few others interested in your project, so you decide to pack it up, throw it on Github and send it to some people to help build out features, only when they open it, they see things like
And they have no idea what you are doing, so they spend hours more just reading through your code, testing things, to see what each piece does. Horrible right? Now imagine if you were paying that person by the hour, or if you were waiting for them to get through to take the project further. Imagine this was a work project and there was a deadline(yes code like this happens at companies) I mean there are so many situations where this could be an issue, remember that time is a valuable resource, and for a lot of people time is money, time wasted is something you can’t get back, so it goes back to the wonderful saying that I have heard multiple times, when it comes to code, don’t write it for you, write it for the next person to work on it.
It used to be considered bad to have long names, but with so much computing power, there are really no instances where it should affect you in a bad way, I am sure there are some that would debate this, some that think we should get it to be as compact as possible, but there has to be a middle line, and in defense, I think we can sacrifice space for longer names, and lessen comment space, what I mean is, if you have well-named pieces of code, then you do not have to spend as much real estate explaining things through comments, so a function name like addsThIngs(which I have seen used) causes issues because what are they adding, anything? Everything? Some things? I mean we could solve this confusion by adding a long comment, or we could solve the issue by using a better naming system, such ass addFirstAndLastNames() and as you can see, we really do not need a comment whatsoever. This name is self-explanatory, it says what it does(because functions should have a sole responsibility) and it makes it clear. Which in the long term, frees up some space by cutting back on the comment real estate.
So, the next time you are sitting there, writing some awesome code, think about the future, the future you, a future coworker, and take those few extra seconds on naming so you don’t lose a few hours later on. Remember to have fun and Happy Coding to everyone.