|
Re: The Problem of Overspecification
|
Posted: Jul 21, 2006 7:04 AM
|
|
Marcin: > Note that a sufficiently smart C++ compiler is allowed to perform this summation in parallel. The C++ language specifies only the observable effect, not the way the program is implemented. It isn't likely in practice I'm afraid: compilers aren't that smart today. Same for Cat.
There is a key difference here. C++ normally won't optimize a for loop, for example, even if the order of the sequence it travels doesn't matter, because it has a very tough time determining if the order is relevant. It is not specified by the user, so it is much safer to just let it be.
Here, with Cat, this is explicitly specified, so as to say "yes, travel me any which way you desire". The optimization can always be made, and if it doesn't work out, that is the developer's fault for saying something is what it isn't.
Morgan: > Having just reread Java Concurrency in Practice, I'm beginning to thing that overspecification is GOOD. What if some other thread might be adding values to the end of the array? Then you want to go in order.
Well that is what design is all about. You're supposed to know whether you'll be appending before you write the code that specifies if there will be concurrency or not. In almost all cases, realizing you need to be doing something differently than you originally intended requires some code rewrite, and this would be no exception.
Harrison:
You made me think of this: C++ or Java can probably do reduce even better than Cat (perhaps a question of opinion?) by simply making a method similar as std::accumulate. Fine, this new implementation would not be STL, but that doesn't matter, since it is still easy and clear to do. In Cat, at least in this example, it seems like there needs to be a keyword ("reduce") in the language to do this operation, rather than give the user direct control over the control flow, which seems really limiting.
|
|