Completely depends on how often you need to write boilerplate code, and how error-prone it is.
After writing hundreds of instances of ‘fetch this from the server and show an error if it doesn’t work’, I finally wrote a helper for that. It took 2 hours, shouts at me if I use it wrong, and instantly makes my classes easier to read because all the boilerplate is gone. As an added bonus, the invocation is so small that Copilot can write it error-free, which it couldn’t before.
So fetching things is now a thing of a few seconds instead of one minute with a chance of making a mistake. I say it’s worth it.
DRY is usually helpful if you don’t use it in situations where you have like 2 semi-different things. If they’re actually the same and you have 3 or more then the level of abstraction is worth it almost always.
To me, there are two classifications of DRY - one I find harmful, the other very useful.
First one resembles mathematical extractions, essentially you never allow a single chunk of code to be written twice and you create massive amounts of global util junk. This also creates some bad tight coupling.
The other is more logical, where you only extract logic in places you want to always change together. Simple and effective.
This sounds just extremely dumb to me, as in “do something manually for 2 minutes or spend 2 days automating it”
Also, DRY in 90% of the cases is a sham
Completely depends on how often you need to write boilerplate code, and how error-prone it is.
After writing hundreds of instances of ‘fetch this from the server and show an error if it doesn’t work’, I finally wrote a helper for that. It took 2 hours, shouts at me if I use it wrong, and instantly makes my classes easier to read because all the boilerplate is gone. As an added bonus, the invocation is so small that Copilot can write it error-free, which it couldn’t before.
So fetching things is now a thing of a few seconds instead of one minute with a chance of making a mistake. I say it’s worth it.
DRY, but also pre-optimization and dependency hell are bad.
DRY is usually helpful if you don’t use it in situations where you have like 2 semi-different things. If they’re actually the same and you have 3 or more then the level of abstraction is worth it almost always.
To me, there are two classifications of DRY - one I find harmful, the other very useful.
First one resembles mathematical extractions, essentially you never allow a single chunk of code to be written twice and you create massive amounts of global util junk. This also creates some bad tight coupling.
The other is more logical, where you only extract logic in places you want to always change together. Simple and effective.