I was reading up some things about how to design a library or API well, and stumbled across Joshua Bloch's great talk at Google Tech Talks. Now although I am nowhere near a professional API developer, I think programming a bunch of classes/functions is a similar, although much scaled-down version of the same thing - clear-cut separation of actions, ease and pleasurable use, encouraging clean code, etc.
I was going through some widely used open source Java code and got this idea (nothing new, but just putting it up lucidly...)
Let us take an example pseudo code (or maybe some dialect of BASIC):
1. new label
2. set name 'hello world'
3. set color 'blue'
4. show 'topmost'
5. on click hide
Now inspired by the Java code I would want to be able to do something like this:
1. Label l = new Label()
2. .setName('Hello World')
3. .setColor('blue')
4. .show(zindex.top);
5. l.onClick = l.hide() ;
My question is this:
Does anyone else design APIs starting from pseudo-code like this?
Is it a good idea for something small? Say upto 10 classes each with maybe 10 methods, each method not more than than 5-6 lines code inside it. That is obviously just a rough set of numbers to to show the size of the classes to be designed - nowhere close to a full API and not just a hobby project - a professional package that does something small but does it well.
Has anyone found any serious drawbacks to this approach?
I think the one real benefit is that it forces you to write down your use-cases first.
The other thing is that the nouns and verbs stay simple, enabling your final product to dodge the MultiPhraseAbstractParadigmDesignPatternImplementor syndrome :-D