Live data from Hacker News

Response to “Literate programming considered harmful”

johnwshipman.blogspot.com

51–60 of 68 posts

Re: Response to “Literate programming considered harmful”

#51
post #13

Earlier quoted context omitted.

> The trend in programming lately seems to be less to no comments and less to no documentation; and it is killing the joy I take in programming. Without comments the only way the next guy has a chance to understand the code is if you stick to lowest common denominator patterns and frameworks. You can't do anything that hasn't been done before. Enter Golang... a language smaller than even ANSI C. It's readable because…

> It's readable because if you've worked with Golang for more than a week, you basically know every language construct you'll encounter. If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed? > I can usually just go to the source code if I'm trying to figure out how to use a library I just pulled in from clojars. Will a cursory read of t…

> If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed?

Oh, come on... BF was specifically/pathologically designed to be unreadable.

> Will a cursory read of the source code either tell you how the library deals with corner cases, or convince you that such corner cases don't exist?

Um... no, not really (at least not a cursory glance), but readability certainly helps track down issues later when you do run into an unforeseen corner case. Language choice is all about trade-offs -- if things like this are what is most important to you, perhaps you would be happier with something like Haskell or Ada.

Re: Response to “Literate programming considered harmful”

#52

The trend in programming lately seems to be less to no comments and less to no documentation; and it is killing the joy I take in programming. Without comments the only way the next guy has a chance to understand the code is if you stick to lowest common denominator patterns and frameworks. You can't do anything that hasn't been done before. I think this is related to the proliferation of frameworks. I can't come up…

Completely disagree. I'm not going to summon up simple scarecrow arguments, but for software that makes money, I do not want your clever pattern with comments that saves a microsecond behind a 60 millisecond latency api. I want a simple for each loop. Where I want comments is where code gets hairy for a reason . For example, extra crafty SQL on some summary metrics page, sure, go ahead and comment that. But I don't w…

> I'm not going to summon up simple scarecrow arguments, but for software that makes money, I do not want your clever pattern with comments that saves a microsecond behind a 60 millisecond latency api

Is that not a strawman argument?

Re: Response to “Literate programming considered harmful”

#53
post #50

Earlier quoted context omitted.

I haven't figured out literate programming with a large group yet, but I do use it (with org mode) for my own projects (solo or small group). A nice thing, at least with org-mode, is that I can choose whether or not to export a particular bit of content. * This headline won't export :noexport: These are some comments for the user and maintainers of this document. Describing our formatting and practices. * This headli…

That is reasonable for a solo project, which naturally has a common style readable to the author. In my (maybe skewed) experience though once 2 or more people start adding comments on the same place of code things can get very confusing quickly -- with mishmash of different styles, commented out comments, multiple copy-paste, etc., so the only way to understand what is going on is to delete the whole Kunstkamera and…

NOTE: The plain text mode here doesn't do the org-file content I've included justice. Copy it into emacs and switch to org-mode to see how this'd actually look and work. And I agree, right now I've only figured out how to do this with myself and one or two other people. I use this for both work and side projects. I also tend to work on smaller code teams (max 3 people) so that helps if I want to use this at work on a specific project. You also have to get buy in on the tool (emacs and org-mode, in this case, which is a hard sell these days). I imagine there are ways to make this scale, but I've not figured it out yet. It'll require more tooling and finer-grained access for editing. Merging with this in git could be a pain in the ass with more than a couple people.

You can get code only views, no deletion necessary. Run tangle, which will spit out all the source files (which is part of the compilation/execution step anyways), or use (org-mode specific): C-c C-v C-v (org-babel-expand-src-block). The latter gives you the expanded (this assumes you're using something like noweb[0]) view of the code in a read-only buffer.

Org uses optional noweb notation to include blocks of code in other blocks:

  #+NAME: print_hello_world
  #+BEGIN_SRC c
    printf("Hello, World!\n");
  #+END_SRC

  #+BEGIN_SRC c :noweb yes :tangle hello.c
    #include
    int main(int argc, char** argv) {
      >
      return 0;
    }
  #+END_SRC
> will be substituted with the contents of the other block. The expand-src-block will give you a view with all substitutions made. C-c C-v C-t (org-babel-tangle) will generate hello.c (could be prefixed with a directory, my preferred way, so it'd be "src/hello.c").

A more useful case than the above, I have a switch/case statement. Each case gets broken into its own source block with documentation around it like:

  * Handling different message types
  #+BEGIN_SRC c :noweb yes
    switch(msg.type) {
      >
      >
      >
     }
  #+END_SRC
  ** Message 101
  Documentation
  #+NAME: msg_101
  #+BEGIN_SRC c
    case 101:
      // handle 101
      break;
  #+END_SRC
  ** Message 102
  Documentation
  #+NAME: msg_102
  #+BEGIN_SRC c
    case 102:
      // handle 102
      break;
  #+END_SRC
  ** Default case
  Documentation
  #+NAME: default
  #+BEGIN_SRC c
    default:
      // handle default
  #+END_SRC

Re: Response to “Literate programming considered harmful”

#54
post #19

Earlier quoted context omitted.

If your problem is unique and requires creative solutions, and you work in an anti-documentation team, that's when things get truly nasty.

Elsewhere known as "Academia" ;)

Which also can create documentation without code :-)

Re: Response to “Literate programming considered harmful”

#55

Earlier quoted context omitted.

Completely disagree. I'm not going to summon up simple scarecrow arguments, but for software that makes money, I do not want your clever pattern with comments that saves a microsecond behind a 60 millisecond latency api. I want a simple for each loop. Where I want comments is where code gets hairy for a reason . For example, extra crafty SQL on some summary metrics page, sure, go ahead and comment that. But I don't w…

> I'm not going to summon up simple scarecrow arguments, but for software that makes money, I do not want your clever pattern with comments that saves a microsecond behind a 60 millisecond latency api Is that not a strawman argument?

You are right, that isn't worded the way I intended (not the least because I misremembered the name). I meant to say code examples. For example:

    # double the counts.
    counts.map! { |count| count *= 2 }
Is the type of strawman I intended to avoid.

Re: Response to “Literate programming considered harmful”

#56
post #51

Earlier quoted context omitted.

> It's readable because if you've worked with Golang for more than a week, you basically know every language construct you'll encounter. If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed? > I can usually just go to the source code if I'm trying to figure out how to use a library I just pulled in from clojars. Will a cursory read of t…

> If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed? Oh, come on... BF was specifically/pathologically designed to be unreadable. > Will a cursory read of the source code either tell you how the library deals with corner cases, or convince you that such corner cases don't exist? Um... no, not really (at least not a cursory glance), b…

> Oh, come on... BF was specifically/pathologically designed to be unreadable.

I was just exposing a flaw in your “readability” criterion. Another example: you can learn the rules that govern a given cellular automaton in 5 minutes, yet be completely unable to predict what said automaton will do when run.

> readability certainly helps track down issues later when you do run into an unforeseen corner case.

I'd rather not have issues, and always be sure that I've handled everything. Only applied formal logic can help.

> Language choice is all about trade-offs

Normally, understandability trumps all else. The only exception is when it's too badly in conflict with performance.

> if things like this are what is most important to you, perhaps you would be happier with something like Haskell or Ada.

Nah. GHC Haskell and Ada are both ginormous languages that I don't believe anyone could fit into their heads in their entirety. In particular, with GHC Haskell, I don't feel confident saying “this code does exactly what I want and nothing else”, because someone might enable an extension I haven't accounted for, and then hilarity ensues.

(And nobody uses the language specified in the Haskell Report.)

Re: Response to “Literate programming considered harmful”

#57

Earlier quoted context omitted.

> It's readable because if you've worked with Golang for more than a week, you basically know every language construct you'll encounter. If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed? > I can usually just go to the source code if I'm trying to figure out how to use a library I just pulled in from clojars. Will a cursory read of t…

And the source code doesn't tell you why something was done. Why is this message expected to be only 42 bytes long or less? Is there a specification for it? I can see that someone grabs two adjacent bytes, pulls out 12 bits from them and puts them into a variable called "version": version = ((data[0] & 0x0F) But why ? Is this still correct with the current specification of the message format? Who knows! And this is a…

My thoughts exactly.

Re: Response to “Literate programming considered harmful”

#58
post #47

I recently ran across this piece, "Literate programming: Knuth is doing it wrong", whose author contends that > the ends are insufficiently ambitious by focusing on a passive representation [0] After practicing literate programming seriously for over a year on a large project, I believe that our notion of documents themselves is insufficiently ambitious, for the same reason. Computer-based media should not be limited…

What tools did you use for this?

Re: Response to “Literate programming considered harmful”

#59
post #51

Earlier quoted context omitted.

> If you've used Brainfuck for more than 5 minutes, you already know the entire language. Is it the most readable language ever designed? Oh, come on... BF was specifically/pathologically designed to be unreadable. > Will a cursory read of the source code either tell you how the library deals with corner cases, or convince you that such corner cases don't exist? Um... no, not really (at least not a cursory glance), b…

> Oh, come on... BF was specifically/pathologically designed to be unreadable. I was just exposing a flaw in your “readability” criterion. Another example: you can learn the rules that govern a given cellular automaton in 5 minutes, yet be completely unable to predict what said automaton will do when run. > readability certainly helps track down issues later when you do run into an unforeseen corner case. I'd rather…

Truly. I used Ada professionally for several years and wouldn't want to go back. Even though programs that compiled had a much higher probability of just working compared to other languages, programming with Ada was both dull (or maybe that's just an Aerospace industry thing) and frustrating (that type system, ugh).

One thing I found while messing around with Haskell is that while learning and writing vanilla Haskell is one thing, deciphering Haskell written by others is quite another, given the propensity of library authors to use language extensions and stuff like TemplateHaskell.

Re: Response to “Literate programming considered harmful”

#60
post #47

I recently ran across this piece, "Literate programming: Knuth is doing it wrong", whose author contends that > the ends are insufficiently ambitious by focusing on a passive representation [0] After practicing literate programming seriously for over a year on a large project, I believe that our notion of documents themselves is insufficiently ambitious, for the same reason. Computer-based media should not be limited…

What tools did you use for this?

How long do you have?

This was for a project called "willshake." The system provides a rough overview of itself [0].

I was using Org for documentation, and I decided to try migrating to a literate codebase.

It was clear immediately that I needed a "real" build tool. After some research, I decided that was Tup [1]. Tup is a strict, "functional reactive" build system with extremely fast incremental builds.

So I run the Tup monitor, and everything gets tangled as I write. Great.

But tangling through Emacs/Org was way too slow. So I wrote my own gawk-based tangle [2] that supports the subset of Org Babel's features that I needed, but would tangle any file in 20-50ms.

But usually I want to do something with the tangled code (you know, compile it, run it). So I also define build rules inside of the documents (for example, [3]). I just extract the rules from the documents and feed them to Tup.

Now I can just write whatever I want in a document, and stuff just happens as I write. This includes the removal of obsoleted build targets, which Tup handles. So I can "literally" remove a document file from the project and the feature is removed; return it, and the feature is restored.

But as the system grew, the build started to push 2 seconds. This is because Tup was reviewing thousands of rules whenever any file changed. So I decided (following Christopher Alexander), to treat directories of documents as isolated subsystems.[4]

So I can create features and subsystems with continuous builds ~250ms, using only Org files and directories.

It still sucks. I'm taking a detour to explore dynamic documents, which I think precedes considerations about "programming."

[0] https://willshake.net/about#more-about

[1] http://gittup.org/tup/

[2] https://bitbucket.org/gavinpc/willshake/src/default/bootstra...

[3] https://willshake.net/about/the_stylesheets#sec-4

[4] https://bitbucket.org/gavinpc/willshake/src/default/bootstra...

Post reply on HN