yujiri.xyz

Software

Why code readability is important

When I was new to programming, I didn't worry about readability at all. Instead I valued compactness to such an extent that I'd remove all spaces that weren't syntactically necessary and write things like:

And I hope I can persuade some beginning programmers to part from this practice after less time than I did. If by any chance you're a beginning programmer and you *don't* puke at seeing the above code, please let me argue for why you should, even if you're sure no one else will ever read it.

The benefits of readability are reaped unnoticed.

An incredibly dominant fraction of time spent "writing" code is actually spent *reading* code. I think even a beginner will have experienced this and realize it on reflection. Being able to parse it faster saves you an enormous amount of time over the hours, but because it's such a subtle, gradual benefit, it tends to go unnoticed.

You don't know what readable code is like until you see it

I was quite convinced when I programmed that way that because I could read my code "fine" I obviously wouldn't benefit from more readability. Of course, I thought that because I'd never worked with readable code, so having to stare at a line for 5 seconds to figure out what the hell it was doing felt like "being able to read it fine" to me. But when I started writing more readable code, I found that I *was* able to read it more easily, faster. Nowadays I write readable code and I can't describe my nausea when I look back at some of my old projects.

This same thing happened to me with font sizes. I had a phase in my teenage years where I set my font size to as small as I could possibly read it because "being able to fit more text on the screen at once makes me more productive". Despite my denial I eventually noticed I *was* straining to read it sometimes, and when I upped the size by 1 and got used to it, I found it much better.

If you don't think anyone else will ever read it, you are probably not correct.

Almost any time you write non-throwaway code, it's a good idea to have it posted on a code forge (eg. Gitlab / Github), personal website, or somewhere else where people can see your accomplishments. I had several projects in my early years that I told myself no one would ever read and I turned out to be wrong. I had them published on the internet for some time but later unpublished them because I became absolutely embarrassed about the quality of my code.

A future you is also the most likely "other person" to end up reading it! Just because you can understand your code now doesn't mean you will be if you leave it and come back to it after a month. It's not the same when you didn't just write it yesterday. Again, if you think that won't happen, you're probably wrong.

contact

subscribe via RSS

Proxied content from gemini://yujiri.xyz/software/readability.gmi

Gemini request details:

Original URL
gemini://yujiri.xyz/software/readability.gmi
Status code
Success
Meta
text/gemini; lang=en
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.

What is Gemini?