Skip to content

Instantly share code, notes, and snippets.

@hzhou
Last active March 4, 2017 20:06
Show Gist options
  • Save hzhou/f6a86d62811d1a2833921fb1b97ada45 to your computer and use it in GitHub Desktop.
Save hzhou/f6a86d62811d1a2833921fb1b97ada45 to your computer and use it in GitHub Desktop.
Merit of libraries

Libraries (such as libpcre and libreadline) are just like products such as microwaves and toast ovens. And as typical consumer products, they are supposed to be simple, and they are:

#include <pcre.h>
pcre* re;
re = pcre_compile(pattern, 0, &err_msg, &err, NULL);
int offsets[30];
pcre_exec(re,	NULL,	s, n, 0, 0, offsets, 30);

#include <readline/readline.h>
s = readline("> ");

That's it. Simple as an oven.

The point is, that should be the only form using libraries. However, the current practice of making libraries is to provide tons of options. With options, the idea is that, the consumers do not just buy one simple oven, they buy ovens that have all possible features. That is stupid.

So with the library only provide one style, what if the user need a different style? -- buy or have engineers build a different library of course, with the same simple intuitive interface. The user don't need understand how one style transforms into another style, all they need know is how to use the typical style and use all the library the same way. Just like toast ovens!

What about code reuse? Consumers don't reuse anything. They just buy new products. Engineers reuse ideas and components all they time. They don't reuse another product of course. They reuse ideas and components. That is what majority of reusable code should be: in form of documentation, paper, prototype and pseudo code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment