Answer the question
In order to leave comments, you need to log in
Functions by "Clean Code" - is it necessary?
Reading "Clean Code" by Robert Martin.
What confuses me is that he calls to create a function for any sneeze.
It is clear that small functions are easier to read than large ones.
But pack each operation into a separate function?.. Why, when you can write a few (understandable) lines of code without resorting to creating new functions? Is it really necessary?
I had no experience as a developer, and it's hard for me to judge, so I'm asking for the opinion of those who managed to fill the bumps.
Answer the question
In order to leave comments, you need to log in
Depends on the situation.
But it is better not to let people occupying fanatical-categorical positions into your head.
Take McConnell's Perfect Code. There is more about reality and less holivar.
This is some kind of cargo cult. Short functions are clear - so all functions should be short. No, they, or rather, the entire code should be understandable.
If a few trivial lines of code are clearer than three single-line functions, then there is no need to rewrite them, just because this principle has been introduced.
Read on. The book lucidly describes how all paradigms and practices in programming are aimed at managing the complexity of change. You can't know how your code will need to change tomorrow, but what's certain is that small functions will be easier to repackage. Naturally, all this makes sense if you have something more complicated than hello world.
Only the Sith make everything absolute. If you think that some advice, even in a publicized book, is contrary to common sense, then it is not necessary to blindly follow it. Develop critical thinking.
Not quite so, it means to create functions for all business structures. For example, you need to take a hash from something, you can do it with one language construct, but when you need to change the hashing mechanism in the future, you will need to edit in many places. Therefore, you wrap it with a function and all calls in the code only refer to it. And the question is not only edits, you have better control over the code, knowing that only a specific function does this, and not just how and how anyone wanted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question