help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does "lacks a prefix" mean?


From: Yuri Khan
Subject: Re: What does "lacks a prefix" mean?
Date: Tue, 14 Jul 2015 12:23:55 +0600

On Tue, Jul 14, 2015 at 5:47 AM, Emanuel Berg <embe8573@student.uu.se> wrote:

> If you are to muck around with old code, which seldom
> is a good idea but sometimes necessary (?),

Why the (?)? Mucking around with old code is necessary every time you
want to add a feature or debug a failure.

> then doing
> so will be helped to an unfathomable degree if the
> "let* style" has been applied when the code was
> originally written, as computation is stepwise
> performed and each step is named and put neatly into
> a nice looking column!
>
> It is, on the contrary, the "let style" with
>
>     (let ((entity (computation_1 (computation_2 ( ... )))))
>        ... )
>
> which is much more difficult to write, not to mention
> read, debug, and later maintain and modify.

You’re putting out a strawman by comparing a “let* style” where small
expressions are given names and arranged in a total order with a “let
style” where few names are bound to independent but huge expressions.


The ultimate degree of the “let*” style you describe is code compiled
to assembly. (For the sake of argument, let’s assume a machine with
ten thousand registers, so that we don’t have to argue about register
reuse.) Expressions are very simple but it becomes hard to give them
meaningful names. Additionally, evey modern compiler worth its bits
will interleave independent evaluations if it will help saturate the
CPU pipelines. The resulting code is very complicated — the code is
doing several things at once and one has to unscramble it in order to
reason about it.

The ultimate degree of the “let style” you describe is the UNIX shell
pipeline. Its two main problems are: (1) lack of names for
intermediate values, (2) each unnamed intermediate value can only be
used once. As soon as you want to reuse the result of a subexpression,
you need to give it a name.


As in most things, there is a golden middle where the expressions are
not too complex, names are meaningful enough, and related computations
are clustered together. When structured like this, code is a pleasure
to work with.


> "Variable dependencies" is all schoolbook stuff -
> forget about it, the sooner the better, because it
> doesn't work like that. It doesn't increase
> "complexity", whatever that is.

Schoolbook stuff? No, we were not taught about dependencies at school.
We were taught recipes. Here is how you add, subtract, multiply and
divide; this is how you use standard library functions; this is how
you define your own functions. Oh actually in <this particular
language> you can’t define your own functions; too bad, you’ll have to
make do with subroutines and instead of returning a result assign it
into a global variable.

This is where complexity comes from: people knowing recipes and
applying them out of scale until the code is too complicated to fit in
one head. Especially, code written by a person with an exceptionally
big head will not fit in an average head.

Maybe you can keep 15 named variables and 60 unnamed intermediate
values in your head and reason about them freely. I cannot. I need
devices that help me in that. These devices can be embedded in the
code (meaningful names, auxiliary functions, and/or an occasional
comment) or I can work it out on a sheet of paper, throw it away when
done and have to redo it again the next time.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]