Standard Library Concerns (Phobos / Tango)

Robert Fraser fraserofthenight at gmail.com
Thu Feb 7 20:33:17 PST 2008


I think you misunderstood the point of Sebastian and bearophile's posts. 
Structured programming, as I'm sure you know, is about interface over 
implementation. You read the documentation of a function, or class, or 
whatever, which can gauruntee [I spelled that so bad the spell checker 
isn't suggesting the correct one...] a specific interface (here are my 
preconditions and postconditions), because in the vast majority of cases 
you shouldn't care how it's implemented, as long as it works correctly 
and at a reasonable speed. It's not a "don't look" philosophy at all, 
it's a "you shouldn't have to look". That's Tango's philosophy, as well 
as Phobos's, as well as most APIs over the last 20 or so years AFAIK.

If you want to look at the implementation, both Tango and Phobos are 
open source, so go ahead. It's not more difficult or taboo to look at 
Tango's source than it is to do so at Phobos's.

Demanding hundreds of benchmarks is slightly unreasonable IMO; there are 
already some benchmarks (I doubt there will ever be hundreds) showing 
that Tango's IO is faster than Phobos's, and Phobos has adopted the 
Tango GC, so there must be something to that. However, from an 
implementation/algorithmic standpoint, it makes sense that Tango's IO 
model would be faster since it attempts to reduce allocation by 
extensive use of memory slicing.

Your points on memory allocation, in particular, seem founded on 
incorrect assumptions. Kris could tell you a lot better than I could 
(since I don't even use Tango often, let alone develop it), but much of 
the IO model is based on avoiding allocation and GC usage whenever 
possible. While Tango has a couple more explicit "new"s in there, Tango 
does significantly fewer implicit allocations of buffers. This also 
leads to better cache locality.

Finally, while you make many valid points as far as heap-allocated 
memory go, what exactly does that have to do with object-oriented 
programming? D supports stack-allocated classes, and many Phobos 
functions do heap allocation (mainly of dynamic arrays). If you're using 
either library, or really any libraries written for a language with 
built-in garbage collection, it's rather difficult to avoid heap usage 
at all. If that's what you're trying to do, you're probably going to 
have to re-implement much of the functionality yourself anyway.

While I agree that you should use whatever library you're more 
comfortable with and suits your style, I believe you might be 
misinformed about some of the issues you bring up, in particular the 
amount of memory allocations performed in Tango and Phobos, and Tango's 
design philosophy.

Dan wrote:
> bearophile Wrote:
> 
>> Sebastian Beschke:
>>> Which is pretty much the point of OO.
> 
> The point of OO is to not know what you're doing?  Maybe that's why I'm so averse.
> 
>> I agree, but the lesson here is probably that some people don't understand OO well, or they don't want to use it everywhere, or it doesn't go well with their mindset, or they need to go faster and they want to program in a more C-style, etc. 
> 
> It's the mindset, apparently.  I have no preference for syntax.  It's what's inside that counts IMHO, and with OO you have no idea what's inside.
> 
>> Java has OOP only, but D allows other kinds of programming too, so maybe it may be better to not have a std lib that is fully OOP, so it can be used when you program differently (like functional-style). Tango doesn't need to be perfect for everyone, but probably there are ways to modify its structure enough to make it look good enough for most people :-)
> 
> Agreed, but I'm continuing to use Phobos as long as it's better for me, and at the moment it still is.
> 
>> I know very little about Tango still, but I have seen there are lot of people that think some changes may be in order before making it the D std lib :-)
>>
>>> If you want to understand something in Tango, you can still read the source code.
> 
> Yes, if I want to understand anything in Tango, I need to study.  I already understand Phobos because it's similar to what I already know.
> 
> You say that Tango presents better GC and IO?
> 
> I couldn't possibly allocate 16 consoles and iterate through them without an undefined number of cache misses - because I can't control where they exist.
> 
> I couldn't possibly define classes and use copy-on-write semantics to expand them during runtime; something that was key to my thinking in the Walnut 2.x project.
> 
> I couldn't possibly be informed about the memory footprint of my program, or understand how many mispredicted? branches are taken because of the possibly painful multiple-constructor system.  I also cannot partially instantiate an object if I only need part of it for some rare case.
> 
> I can keep going on the limitations of OO.
> 
> But essentially the point is that unless it's beautiful inside, I don't care how convenient your notation is.  If the insides on which your library is built is "don't look!" then I have trouble believing they're beautiful unless you have a whole slew (like, hundreds) of benchmarks to show me.
> 
> Regards,
> Dan



More information about the Digitalmars-d mailing list