B
B
BonBon Slick2018-03-02 23:49:38
Programming
BonBon Slick, 2018-03-02 23:49:38

How to avoid or control constant rewriting and improvement of your code?

It just so happened that every week I learn something that can be implemented in my personal project. Here is something that must have, as a result, is forced to rework, edit, or improve everything.
Example, I learned about getting rid of getters and setters, especially in DDD. Because they violate the basic principles. I had to rewrite the core, all methods were renamed, yes, it became more readable, yes, the logic improved.
Now it is much more clear what is happening, although there is more code, because instead of 2 methods, get and set, now there are 2-7+ pieces of methods that perform logical operations.

class User{
...
public function getRating(){...}
public function setRating($rating){...}
//стало
public function showRating(){...}
public function addRating($rating){...}
public function substructRating($rating){...}
public function hasEnoughRating($rating){...}
public function compareRatings($rating){...}
...
}

More readable right? Now it’s clear what, where, why and how it works, all the logic is at a single point, and not scattered throughout the application.
So, is there any way to avoid this, or at least control it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pugachev, 2018-03-03
@BonBonSlick

Andrew Stark ,
1) instead of rewriting everything every week, you need to take and spend the same week reading 1-2 books like "Code Complete" or "The Pragmatic Programmer: From Journeyman to Master". This will allow you to expand your horizons a little and give you some basic principles of "good code". This in turn will lead to the fact that you will initially write better code and you will have to rewrite everything less often.
Further, with experience, the understanding will come that not every article on Habré is the ultimate truth and you should not run headlong and implement something. You will understand why exactly you need this change. Develop your own point of view. Everything will stop being black and white. Every architectural question will become "philosophical" and so on and so forth. But this is with experience, so far you have to rewrite it,
2) if you are still learning, then in principle there is nothing wrong with this process.
if a restless perfectionist speaks in you, then it sucks, you will never finish rewriting. or until you gain the necessary experience (see point 1)
3) if you do it in commercial development, then everything is very bad
from the point of view of any business - it doesn’t matter how brilliant, simple and support your code. If there are no obvious bugs, then it will work in the general case in exactly the same way. And what you are doing is a waste of resources (time and money)
For wisdom says - "
If you translate it into our language, while you are rewriting the same thing for the hundredth time, competitors have already coded and stole our customers a long time ago. Therefore, I would advise you to take into account such a factor - "is this change burning right now." If it doesn’t light up, we’ll do it when it does, now we need to quickly go into production and bring our work to investors.
I wrote a little chaotically
If in short:
- at first we study more than we write
- there is no limit to perfectionism
- correctly prioritize your work
- wash your hands before eating

S
Sergey, 2018-03-03
@red-barbarian

Here I think: Why does a user need 7 methods related to rating?
About rewriting. It's a common thing when you learn something new, you start to shove it everywhere. Where to go and where not to go. A sense of proportion comes only with time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question