When I'm coding something and I've already done a desired algorithm elsewhere in the code, I'm often tempted to copy/paste it to the new location and directly adapt it to that case. It's very quick and I immediately feel good how fast I got things done (instant gratification).
-
Näytä tämä ketju
-
Often the better (but slower) approach is to refactor the algorithm into a function and parametrize it so that it can handle both the old and new use case. It takes more time to add in the extra variables/logic, but if it generalizes nicely, it saves me time down the road.
1 vastaus 0 uudelleentwiittausta 8 tykkäystäNäytä tämä ketju -
Once I figured this out, I went to the other extreme and started refactoring everything, even when I haven't really generalized the case, but merely stuck two cases together with a bunch of if statements. It took time to get the feel what is worth abstracting.
1 vastaus 0 uudelleentwiittausta 7 tykkäystäNäytä tämä ketju -
One thing I did pick up going through these stages is to not define functions in advance. I implement things once for a specific case and only when I need the same thing performed elsewhere, I refactor. Similarly to how I never do premature optimization. OK, story time over.
3 vastausta 0 uudelleentwiittausta 14 tykkäystäNäytä tämä ketju -
Vastauksena käyttäjälle @retronator
On the flip side: When I can, I try to make as many functions as is reasonable. Even if it's just one line. In my experience, GCC at -O3 is usually smart enough to inline things without explicit hints, and being able to read code prosaically is a huge help when I come back later.
1 vastaus 0 uudelleentwiittausta 1 tykkäys
Even just a few lines of code can become as opaque as a brick in just a few days, and I'd rather see get_rampdown_frame_count(channel_index); than whatever is in the function itself.
-
-
Vastauksena käyttäjälle @TheMogMiner
I write comments everywhere for that same reason.
0 vastausta 0 uudelleentwiittausta 0 tykkäystäKiitos. Käytämme tätä aikajanasi parantamiseen. KumoaKumoa
-
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.