[TUHS] Clever code (was Re: Re: Stdin Redirect in Cu History/Alternatives?
Steve Nickolas
usotsuki at buric.co
Mon Dec 12 12:44:20 AEST 2022
On Sun, 11 Dec 2022, Bakul Shah wrote:
> Agree that clear code is preferable to complicated code. But in practice
> people sacrifice clarity for performance improvement all the time. Look
> at the kernel code of any modern os. Everybody pays lip service to this
> but most anything other than toy programs ends up getting needlessly
> complicated over time. As an example, building "Unix as a service" as
> user processes on top of a small microkernel could provide the same
> functionality using much clearer and much less code but it would be
> slower so we don't do it. Plan9 sort of went in that direction and it
> is much simpler (but that could also be because it is not hacked on so
> much).
>
> I do prefer clever/smart design to locally clever/smart code. For example,
> using Schönhage-Strassen algorithm for multiplying very large numbers.
> Or transforming a problem to use a much more efficient data structure
> or making equivalent transforms which may be more efficient to compute.
> Such code may not be immediately clear but with proper documentation
> it is not difficult + you can solve much larger problems. But agreed
> these come up much less often.
My attitude is: if I'm doing an ugly on nonobvious hack, I'll drop a
comment saying what it does.
Most recently I wrote code that set a "magic flag" - and the comment
explained why the flag was set (so that it would be immediately altered,
forcing a redraw).
-uso.
More information about the TUHS
mailing list