According to Wikipedia, Eric S. Raymond said that one of the 17 Rules of Unix is the "Rule of Generation", stating that:

Developers should avoid writing code by hand and instead write abstract high-level programs that generate code. This rule aims to reduce human errors and save time.

How is this rule to be interpreted in a modern context of languages that abstract away memory management (ex. Java's GC) or other low level bit-twiddling tasks? Does this rule still apply?

  • 5
    Isn't coding in Java an application of that rule? – MetaFight Jun 23 '15 at 13:14
  • The 'code' in the phrase 'high-level programs that generate code' is ambiguous in my opinion. Does that mean code = machine code or code = byte code or code = source code in another language? If 'code' means machine code then I'd say yes, Java would be an example. However, in 2003, there was a huge variety of interpreted and compiled languages that could run on Unix. C, C++, Java, Python, Ruby, Perl, bash, zsh...all of them ran on Unix. – Green Jun 23 '15 at 13:19
  • 1
    I thought that too but it struck me as odd that ESR would say that because of the many many options for not writing assembly/machine code in 2003. Very few people write production assembly code for funzies. There's just better ways to write code. – Green Jun 23 '15 at 13:53
  • 2
    Have you ever used an IDE that generates Java getters and setters for you? Do you use Project Lombok? Does your IDE generate a project skeleton? – Jörg W Mittag Jun 23 '15 at 14:10
  • 1
    @JörgWMittag I have used an IDE to generate getters and setters but the scope of that kind of code generation seems really limited compared to the broad scope of the other Unix Rules. Project Lombok looks really cool. I haven't heard of that one before. – Green Jun 23 '15 at 15:04

He doesn't mean little IDE utilities that create boilerplate for you, which you must modify. He's referring to more comprehensive code generation that you shouldn't have to touch. You make changes to the higher level and regenerate.

The canonical Unix example would be Yacc, which uses a high-level grammar to generate complex parsing code. Other examples:

  • An SQL query.
  • A domain-specific language, like many web frameworks use for route handling.
  • A GUI builder.

The basic idea is to write in as high an abstraction level as possible, as close to the natural representation as possible.

  • 1
    So ESR is expressing a preference for DSLs and 4GLs wherever possible as way to work at the highest level of abstraction? That makes sense. Thank you. – Green Jun 23 '15 at 20:04
  • An other example would be Model driven development where you define your model in xml (or other domain-specific language) and have code generators that create classes, sql and gui elements from it. – k3b May 16 '17 at 13:46

In “modern” C++, the manta “don’t write code — use algorithms.” is the same general idea. The “generation” is done with templates and reuse, so you don’t touch manual looping and elementary code slogging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.