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

It just so happened that every week I learn something that you can implement in your personal project. Here is something that mast HEV, the result is forced to pererabatyvaya, edit, or improve everything.

Example, I learned about what is necessary to get rid of getters and setters, especially in DDD. Because they violate basic principles. I had to rewrite the kernel, all of the methods was renamed, it became more readable, Yes, the logic is improved.

Now much more clear what's going on, although the code became more so as instead of 2 methods, get and set, now 2-7+ pieces of methods that perform logic 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, Yes? Now I understand that where, why and how it works, all logic in a single point, and not scattered throughout the application.

So, is there any way to avoid this or at least control it?
June 7th 19 at 14:38
3 answers
June 7th 19 at 14:40

1) instead of rewriting everything every week should be a time to take and spend this week reading 1-2 books like "Code Complete or The Pragmatic Programmer: From Journeyman to Master". This will allow you to broaden your horizons and give some basic principles of "good code". This in turn will lead to the fact that you initially will write more good code and rewrite all have less.
Then with experience comes the understanding that not every article on Habre is the ultimate truth and it is not necessary to run headlong into and Choteau to implement. Will understand why you need this change. To develop their own point of view. All cease to be black and white. Every architectural question will become "philosophical" and so and so. But it is with experience, while that will have to be rewritten
2) if you are a student in this process, in principle there is nothing wrong.
if you're talking restless perfectionist - it sucks, rewrite you don't finish never. or until you gain the necessary experience (see point 1)
3) if you do it in the commercial development of something really bad
from the point of view of any business, absolutely no matter how brilliant, simple and podderzhivaem Your code. If there are no obvious bugs then it will work in the General case exactly the same. And what do you - a waste of resources (time and money)
For wisdom says - "while you're asleep - the enemy is swinging"
If translated into our language - while you're for the hundredth time rewriting the same competitors are already nerovnosti long ago took away our customers. So I would advise to take into account such a factor is "is this change right now." If you do not burn - do it when sunbathing, now you need to quickly into a production to go out and carry developments to investors.

A little chaotically written
If in brief:
- first, learning more and more about what you write
- perfectionism there is no limit
- right prioritizing their work
- wash your hands before eating
thank you - jaycee commented on June 7th 19 at 14:43
June 7th 19 at 14:42
To maintain uniform inter-unit integration will help interfaces.
Also, check out design patterns.
thank you - jaycee commented on June 7th 19 at 14:45
June 7th 19 at 14:44
Wonder Why user 7 methods associated with the rating?
About to rewrite. Business as usual learning something new begin to push it everywhere. Where necessary and where not necessary. A sense of proportion comes only with time.

Find more questions by tags ProgrammingIT education