[en]About size of code

Polish version

Good code is short code. What I mean is that if you can implement the same feature in 500 or 100 lines of code, 100 will be better. Main reason is shorter = containing less elements = less complex = easy to understand. Situation, when programmer don’t know what his code do is not funny. Also less code is less probability of making bug.

But some people use approach, that only seemingly reduces amount of code.

Libraries

If you use library instead of writing code yourself, you have less your’s code. But code inside library is still code, and it runs in the same way that code written by You. Moreover, publicly available libraries are adjusted to many use cases and contains lot’s of features You don’t need.

Don’t get me wrong, I’m not saying, that using libraries is wrong. I mean more situation, when I have working 20-30 line function, and other developer want me to delete it and use external library.

But library with big community has less chance of having bug.

Yes, but there is risk, that lib would do something you aren’t aware off, which can cause bug.

Couple years ago I worked with project that had used jQuery. Sometimes happened situation, that after clicking some button exception inside jQuery’s code was thrown, but after F5 problem disappeared. I spend lots of time to find cause.

Problem was, that in some other view I added event listener, but instead of handler method there was undefined. JQuery didn’t get any problems with this, but throwed exception while handling event, even if I switched view and this event handler wasn’t necessary.

But library has better quality of code

Maybe yes, maybe not. You need to remember, that not only ninja senior developers publish to github, so not everything there is good quality.

Also you need to remember, that main reason for making software is to work correctly. Good code quality is a means, not an end.

Microservices

Personally I think, that microservices architecture is only for the most experienced developers. I, having over 5 years of commercial experience, still feels too small for microservice.

Temptation for using microservices can be, that insead big monolith with lots of code you have small projects, that are simple to understand. Problem is, that one microservice is not a whole program. Even if there are separated, maybe on other servers, maybe written in deferent programming languages, only set of services makes something useful.

And in microservices you need to add logic for handling sending requests to other services, which always will be more complicated, that calling method in other class.

I’m not against microservices, but if you want to use them, you should have better reason why. If you want to keep order in code, split in to classes, namespaces, maybe libraries, but run it inside one process.

One thought on “[en]About size of code

Leave a comment