The new, new phobos sneak preview

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Apr 11 13:50:16 PDT 2009


Lars Kyllingstad wrote:
> Andrei Alexandrescu wrote:
>> Hi everybody,
>>
>>
>> I just committed all of Phobos into svn on dsource.org. That is not an
>> official release and has known and unknown bugs, limitations, and
>> rhinodemons. I expect some ripples before we stabilize, but when we will
>> we'll stabilize at a higher potential.
> 
> Some corrections/suggestions to std.range, if you are ready for such yet:

Thanks!

>  From the documentation it seems that the function series() is meant to 
> be called recurrence(). (Personally I think recursiveSequence() is more 
> fitting.)

Fixed. (I'm trying to stay with one-word names when possible.)

> The function sequence() is missing from the documentation, only struct 
> Sequence is listed. Guess there should be a ///ditto in there.

Oops... fixed.

> I think isInfinite!() should be called isInfiniteRange!(). The current 
> name is, in my opinion, too general.

I'm undecided about this (and similar cases). isInfinite sits inside 
std.range, so std.range.isInfinite is clear and 
std.range.isInfiniteRange feels redundant. On the other hand, I don't 
want to use too common symbols because then the user will be forced to 
prefix them whenever they clash.

I fixed everything and checked in. Speaking of which, I'd be glad if 
interested people could take a look at std.file and compare it against 
the old:

http://dsource.org/projects/phobos/browser/trunk/phobos/std/file.d

Previously many phobos modules, e.g. std.file, looked like this:

version(Windows)
{
     ... big chunk ...
}
version(Posix)
{
     ... big chunk ...
}

The advantage of this approach is that it keeps platform-specific code 
together. The disadvantage is that it encourages code duplication. I 
found that about 25% of the functions inside std.file actually were not 
platform dependent; they essentially were duplicated verbatim.

So I suggest we change this to per-declaration granularity where it 
makes sense:

/**
Doc for read...
*/

version(Windows) void[] read(in char[] filename, void[] data) { ... }

version(Posix) void[] read(in char[] filename, void[] data) { ... }

The current std.file implements this alternative factoring and initial 
experience seems to suggest it works fine. Also, the code got smaller by 
18%. This must also because I got rid of all goto's :o).

By the way, here's a neat trick I think may be used in other situations 
as well: factoring some constant function arguments together.

version(Windows) void[] read(in char[] name)
{
     alias TypeTuple!(GENERIC_READ,
             FILE_SHARE_READ, (SECURITY_ATTRIBUTES*).init, OPEN_EXISTING,
             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
             HANDLE.init)
         defaults;
     auto h = useWfuncs
         ? CreateFileW(std.utf.toUTF16z(name), defaults)
         : CreateFileA(toMBSz(name), defaults);
     ...
}

The previous code duplicated all those arguments.


Andrei



More information about the Digitalmars-d mailing list