Lots of low hanging fruit in Phobos

Timon Gehr timon.gehr at gmx.ch
Sat Mar 8 01:25:38 PST 2014


On 03/08/2014 03:15 AM, Adam D. Ruppe wrote:
>
> So the best we're looking to automate is input or perhaps forward
> ranges. And how hard are these really to write?
>
> yield query(string q) {
>     auto result = c_query(toStringz(q));
>     while(!HasRow(result))
>        yield GetNextRow(result);
> }
>
> OK, that is kinda nice, but, is the status quo so bad?
> (BTW the reason I
> went with some kind of C database api here is everything else I could
> think of are actually pretty short when using std.algorithm functions to
> help define them.)
>
> struct query {
>      private Result result;
>      this(string q) {
>           result = c_query(toStringz(q));
>           if(!empty) popFront();
>      }
>
>      Row front;
>      @property bool empty() { return HasRow(result); }
>      void popFront() in { assert(!empty); } body {
>           front = GetNextRow(result);
>      }
> }
>
>
> It is certainly a bit longer, but it isn't that bad, and is easily
> extended to other range capabilities.

This does not do the same thing. It computes the first row even if it is 
never requested. std.algorithm.filter suffers from the same problem. 
This is part of the reason why I think the separation of front and 
popFront is suboptimal design.


More information about the Digitalmars-d mailing list