T
T
theNorthWind2020-02-18 13:03:30
OOP
theNorthWind, 2020-02-18 13:03:30

How many lines is normal for a class?

How many lines do you think is acceptable for one class in C++ and maybe not shitty code? Is it ok to make a class of about 300 lines?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2020-02-18
@theNorthWind

As many as necessary to code the logic of the behavior of objects of this class.
And the logic put into this class is a matter of the project architecture (not the project code!).

M
Maxim, 2020-02-18
@myks92

I read somewhere that about 500-1000 lines for business logic.
But:
1. The number of lines cannot depend on the quality of the code. You can have 500 lines of bad code that even the author can't figure out. But if you have code at least according to DDD, then it is easier to live with such code. And if there are still tests, then doubly better.
2. You may have 1500 lines of code due to the detailed documentation of the code. Or a lot of lines are obtained due to the large number of parameters passed in the methods. And such a method has to be transferred - each parameter is 1 line. Example .
3. Do not focus on the number of lines. If the code is easy to maintain and read, then don't bother. If difficult - refactoring.
In general, I advise you to write code so that it can be read like English text. Choose the name of variables, methods, interface classes, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question