3 ms·
There's an old joke about if you write code as cleverly as you are able, then you won't be clever enough to debug and maintain it. I sometimes code out "in lon
by simonblack 3y ago
There's an old joke about if you write code as cleverly as you are able, then you won't be clever enough to debug and maintain it.
I sometimes code out "in long' if I feel it is necessary. That is, I deliberately add extra lines to 'show my working'. As in, perhaps:
variable = foo( bar( baz( stuff )));
might possibly be laid out as
bazzed = baz ( stuff ); /* comment one */
barred = bar ( bazzed ); /*comment two */
variable = foo ( barred ); /*comment three */
to show how and why a particular result is generated, if I feel the original code is too abstruse to see quickly why it is so.
Yes, there is a (usually) negligible time cost in the running of the program that might even be fixed by an optimising compiler. But I will save a lot more time than that for myself and any other programmer in the future when maintenance time comes around.
- extasia 3y agoInteresting. I'm quite the opposite in that I'll try pretty hard to avoid unnecessary allocations. In the case of your example I'd do something like: variable = foo(bar(baz(stuff))); // baz stuff // then bar the result // which we finally foo. I primarily write python which can't optimize out the allocations so that might influence this.