The Sweet With

Tomasz Tomasz
Tue Mar 3 05:12:22 PST 2009


Ideas for features based on the with.

The with can make calling functions with enum arguments sexier. So instead of:
auto d = dirEntries(".", SpanMode.breadth);

you could say:
auto d = dirEntries(".", breadth);

by declaring the function as:
dirEntries(string path, with SpanMode mode);    // "with" does the trick

At first glance, such feature seems lesser. But I noticed that for fear of redundancy programmers resort to cluttering the global scope with constants, or even worse - using bool to offer only two options. So when the API needs an equivalent of GUI's dropdown list, the with encourages the right way - enums.


The with can also tidy up numerous imports:

import extremely.long.package.name.module1;
import extremely.long.package.name.module2;
import extremely.long.package.name.module3;
import renamed = extremely.long.package.name.module4;
import extremely.long.package.name.module5 : selective;
...

could be compressed to:

import with (extremely.long.package.name)
{
    module1;
    module2;
    module3;
    renamed = module4;
    module5 : selective;
    ...
}

or even:

import with (extremely.long.package.name)
    module1, module2, module3, renamed = module4, module5 : selective, ... ;


What do you say?

Tomek



More information about the Digitalmars-d mailing list