There was a function…

Ibe Agwu
3 min readMay 2, 2018

--

Long ago in the Land of my program, there lived a function that could solve a problem; I knew it could solve a problem but I didn’t know how it did that or when to use it. Even though I used C#, I still couldn’t see sharp!…

yeah, this happened to me

Writing code that is readable is important for any application that needs to be maintained for any period of time, even if it’s a [simple] GPA calculator program. Code that is well written for human understanding should generally be simple and easily modifiable.

There are many practices that reduce code readability. Poor variable names, especially short, unrelated names, can make it difficult to know the purpose of a variable.
Long classes and long methods are much difficult to understand and follow than short ones, and often end up with a lot of conditional complexity that can take some effort to understand.

Ideally your functions should do one thing, their name should reflect what they’re doing, and they should live in a class that is small and related to the function. Short functions within small classes are generally easy to understand, provided there is actual computation going on in these functions.

Consistent coding conventions, not just for variable naming but also casing (pascal, camel, etc.) of elements, indentation and line break styles, etc. can also have an impact on how easy it is to quickly understand what a program is doing. I would say that a more appropriate statement would be “Programs are meant to solve problems!”.

In order for them to do that they need to be :
- executed by computers, and
- readable by humans (we would still write everything in assembly if we didn’t want other people to be able to contribute to our programs and share knowledge in this space; not to mention how difficult it would be to re-read your program days/months/etc. after writing it if it wasn’t in a humanly readable friendly format). [exactly what happened to me!]

No comment in code was ever intended to be executed by the computer. No variable name was ever intended to be executed by the computer (the computer would be happy with every variable being named k, _iei, ols, wss, namis etc., it doesn’t care). We give variables meaningful names for humans to read [Imagine things like firstNumber, age, dateOfBirth etc… they are all cool variable names].

We give classes, procedures, database tables, etc. readable names for humans to read. Most languages don’t use symbols for things like loops, instead they use readable strings like “for” or “if” which are only there for humans to read (except for strange languages like BrainFuck). The computer is going to reduce all those to 1’s and 0’s no matter what we do.

simple code in Brainfuck, Really ?
bad code sample in python

Finally, I’ll advice every programmer should name a variable using the same care with which you name your first-born.

And to myFunction(), I’ll keep remembering you !

Thanks for reading.

--

--