[improve-it] Parsing NG archive and sorting by post-count

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Mar 15 15:46:40 PDT 2011


On 3/15/11, bearophile <bearophileHUGS at lycos.com> wrote:
> Andrej Mitrovic:
>
>> I've also implemented an `allSatisfy` function which works on runtime
>> arguments. There's a similar function in std.typetuple, but its only
>> useful for compile-time arguments. There's probably a similar method
>> someplace in std.algorithm, but I was too lazy to check. I thought it
>> would be nice to have.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=4405

Cool, I was afraid I was reinventing the wheel.

> I suggest you to add unit tests and Contracts to your CommonAA() and
> allSatisfy() :-)

allSatisfy definitely doesn't work for a bunch of cases, like passing
a delegate instead of a literal. And CommonAA doesn't take into
account things like removing elements, etc. It's definitely a half-ass
implementation. :p

>
> Have you tried to replace this:
>
>         if (key in payload)
>         {
>             payload[key] ~= val;
>         }
>         else
>         {
>             payload[key] = [val];
>         }
>
> With just:
>
>         payload[key] ~= val;
>

Good catch. Since the value type is an array I could simply append to
it. Although one didn't exist yet, so I figure I had to assign
something to an empty spot in an AA. Oh well..

>
> I suggest to replace this:
> sortedKeys.sort;
>
> With:
> sortedKeys.sort();
>

Yes, I prefer it that way too. Since DMD doesn't complain about it (is
sort even a property?), I missed it.

Thanks for the input.


More information about the Digitalmars-d-learn mailing list