[erlang-questions] erlang-questions Digest, Vol 24, Issue 11

John Haugeland <>
Mon May 4 16:42:12 CEST 2009


>
> > In the "programming rules"
> > http://www.erlang.se/doc/programming_rules.shtml#REF32551
> >
> >
> > ---snip--------------------------------------
> > Use tagged return values.
>
>  My $0.02 is that this advice is, and always has been, hogwash. It is
>  a rare function that can return several valid answers. So, the
>  default should be to return a valid answer, i.e. one that can be
>  used directly, or throw an error.
>
>  My theory is that the people who wrote this "programming rule" were
>  (good) C programmers, and thus felt a need to check if the value
>  returned was ok before they dared use it.
>

Your theory is incorrect.  The reason keysearch returns tagged result values
is that the thing you're searching for might have a value of false.  Tagged
results are the only way to return a value such that any value is legal;
otherwise you need a placeholder value for "nothing found", which is not a
tolerable admission in basic datastructure behavior.  There is no way to
guarantee that every legal value in a datastructure can be unambiguously
fetched without tagging.

Manual advice is correct.  It's generally a bad idea to call the advice in
the manual hogwash when you're still guessing about the reason it was
there.  This is honestly pretty 101.







> > Another question,
> >
> > Is there any function for showing the source code that is being
> > refered to along with its comments?
>
>
> You mean like literate programming?
>

Literate programming has nothing to do with showing source code, nor is it a
fancy way to refer to source-extracted documentation.  If you haven't read
the Knuth book, you shouldn't be using this term (and it's fairly obvious
that you haven't read the Knuth book.)

Literate programming is the practice of writing out what you expect to code
as natural language in comments, then filling the code in behind it.
Literate programming has nothing to do with the end result code; you can
remove all comments from code and still have literate code as long as it was
built according to the guidelines in the book you didn't read.  The comments
are of course encouraged to be left behind, but if you'd bother to read what
the guy who invented the term says, or learn to use cweb, it's really quite
clear that he had no intention of describing documentation extraction.
Literate programming is expressly designed for the purpose of guiding the
human mind through complex algorithms by forcing their framing in natural
language.  There are several chapters about why this works.  Please read
them before using the term again.

It's unfortunate that people name-drop so easily; this is the same thing
that robs people of their ability to understand object orientation, simple
construction patterns like model view controller, et cetera.

No, he does not mean literate programming.

To the original poster: no, but you can get at the abstract syntax tree.
That isn't good enough for humans in most cases, but if your intent is to
use software to back up the interpretation of the function, then it's
actually better (for example, this is how I've begun my purity prover.)
There's a flag 'debug_info' that you can pass to the compiler; if you do,
one of the many results will be that the abstract syntax tree created by
compiling your module will be included in the module as a module attribute.


You can see some examples of working with this in scutil in the sc_pure and
heckerl modules; see http://scutil.com/ .  MIT license, because the GPL is
evil.






GuaranteedVPS.com - bandwidth commitments and root starting from $12.98/mo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090504/515408c0/attachment.html>


More information about the erlang-questions mailing list