The world of development methodologies with its various schools of thought is an interesting place. At its core code is a tool - a means to an end - almost comparable to a blacksmith's anvil and hammer. Yet every blacksmith will own a wide and varied collection of hammers and set their work against an anvil they have chosen.
But it is not the hammer the blacksmith sells but the forged item and likewise lines of code are not the goal when creating software. This analogy is now wearing thin so I suggest watching blacksmiths at work if you have never seen one.
The fundamental goal of software is representing and manipulating data. This drives biggest aspect of development to me: data structures. With the right choice in structure the rest of the code will fall into place almost naturally. When the wrong choice of structure is made then every requirement and change becomes a herculean challenge.
Unfortunately picking the right data structure is still only the first hurdle to be overcome. It won't write the rest of the code for you, but it's a good place to start!
There are no end of rules to choose from when creating software which vary from general ideals "Don't Repeat Yourself" to specific minutia "Five lines per function". Each rule is an expression of a goal e.g. changes should only need to happen once (DRY) or each function should not be complex (5 lines).
Yet there are times when you will come across code that is currently the same and think "can I combine these". Now you must understand the intent behind the rule: combine code that has the same goal. The rule appears to say combine them: the code is repeating, but the goal tells us not: one will change without the other.
Expand your knowledge of rules so that you may understand the principles behind them. Let those principles guide your code and not the letter of the law.