The title is a bit hyperbole. But is reaction to something I meet in my everyday programmer’s life. Reaction to trend of de-humanized code. What to do better and how? My recommendations:
If you are a junior programmer, just learning how to solve specific assignments by code, don’t bother. Continue learning and don’t waste your energy targeting too much objectives. When you are experienced enough, strong in coding, consider this. After you finish your individual assignment, go through your code once again and check following points
- pay great attention to naming of identifiers. Identifiers of classes, objects, methods, properties, etc. Their names should be accurate, concise and truthful. Opposite of vague and misleading. Identifiers are keywords of the story your code tells, they are bricks building your system. Vague identifiers mean soft bricks. Try to imprint maximum (or rather optimum) of domain information in them. On the contrary when declare auxiliary local variable with scope of couple lines and with no significant meaning, like loop index or so, use simple and possibly vague naming. Like i, k, index or so. Within short code snippet such a naming is perfect, because it’s meaning is clear from context and longer name in this case would make the code overcomplicated
- think about interfaces you create (on both classes and interfaces). Particularly interfaces exposed publicly. Making interface following some formal criteria is not enough. Interface must be intuitive, must be handy, must be selfexplanatory. Must contain everything important and contain nothing redundant or misleading
- write algorithms not like technical solution combining elements a way they give desired result, but make them story told in human language, story explaining the solution
- remove from your code everything redundant and misleading. I mean everything what is not relevant. Everything what you just ‘think will be useful in future’. It is myth. These predictions don’t work. Code what is needed only, not your phantasies. Never leave rubbish in your code, irrelevant elements which emerged during your algorithm shaping. On the other hand, obsolete code and commented code (deactivated by putting into comments) are not necessarily this case. Should be removed when no perspective for them at all, but no big priority. Really. Problem is not something relevant and obsolete. Problem are programmers’ phantasies and confusions
- simplify, simplify, simplify. Everything, what could be simplified to get shorter and more synoptical, structures and algorithms, should be simplified. Remember, all the live code will be read again and again by programmers (includinig you) in future, to be understood, maintained and extended. Simple means handy. Complicated means attacking it’s limits.
Added on 23.3.2019: It is why I don’t like var clause in C#. Definitly it is a good approach in linq expressions where explicit data types are too complicated. But using var everywhere I find misusing this approach. I admit it is my personal prefference and mass usage of var is not principally wrong. But I like seeing declaration separate from assignment. Declaration for me is something significant and explicit and I like seeing variable’s data type on it’s spot.
Added on 5.4.2019: Remember, there is always something you can do with your code to make it more readable, more understandable, more human oriented.
Added on 16.4.2019: Something more to ‘var’ clause. This declaration form is even worse when used in combination with a method call or generally expression. Such a usage I personally find really inappropriate.
Programmer’s Blog využívá WordPress MU a běží na Blog.zive.cz. Vytvořte si svůj vlastní blog
Sledování přes RSS: články
a komentáře