Phobos packages a bit confusing

Roman Ivanov isroman at km.ru
Mon Nov 30 12:40:20 PST 2009


retard Wrote:
> Java isn't that bad IMO - you just have to remember the buffer:
> 
> BufferedReader input = new BufferedReader(new FileReader("foo"));
> try {
>   String line = null;
> 
>   while (( line = input.readLine()) != null) {
>   }
> }
> finally {
>   input.close();
> }

One of the important factors in API quality is feature discoverability. That is, the amount of time you need to find a sane way to do something, provided that you know the language. Java has very low discoverability. The code above is extremely unintuitive, because the abstractions you are required to use have nothing to do with the task at hand. FileReader? BufferedReader?

Compare that with C#:
string[] readText = File.ReadAllLines(path, Encoding.UTF8);

Or PHP:
$file = file_get_contents($path);

Yes, the alternatives store the entire file in memory. That's perfectly fine for 95% of use cases.

Good APIs provide several levels of abstraction. If 95% of the people don't care about the way a file is read, then a good API would provide a simple function that just works for those people. Nobody stops it from providing a low-level API with finer control as well.

> > 
> > These are common, simple I/O operations that just about everyone needs
> > fairly often.  It's ridiculous if I have to use three different modules
> > or whatever it takes to accomplish something so simple.
> > 
> > I'm convinced that this is one thing that turns a lot of people off to
> > programming if they get past the first hurdle of understanding variable
> > assignment.  File I/O is required for almost any program complicated
> > enough to be worth writing.  When a beginner who doesn't necessarily
> > even understand the concept of a class hierarchy well sees a huge
> > overengineered API for basic file I/O, he/she is bound to think
> > (wrongly) that programming is much harder than it really is and that
> > he/she is just inept at it.
> 
> Well, that's not the only problem a novice meets during the first 
> minutes / hours with a new language.

I'd say most of the programmers learn new APIs all the time. If every one requires you to jump though hoops, you will end up with a significant and constant overhead.



More information about the Digitalmars-d mailing list