Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
scroll top