February 13, 2013
On 2013-02-13 09:34, Marco Leise wrote:
> Am Tue, 12 Feb 2013 13:38:53 +0100
> schrieb Jacob Carlborg <doob@me.com>:
>
>> I've compiled a list below of things used in Orbit (directly or
>> indirectly) that Phobos is lacking in. Please tell me if I'm wrong:
>
> I can only tell you what of that list I would have had a use
> for myself in the past:
>
>>     * Configuration
>
> Yes, native to the environment (e.g. use \AppData\Roaming on
> Windows or .config on Linux)

I didn't necessarily mean native configuration. I was referring to configuration internally for the application. But it could be useful to save to disk as well.

> All of that except "action" and "multiple command lines".
> Validation is probably too complex to include at the spot. I
> mean, sometimes you need to validate the combination of all
> options, so you can just as well write a separate function.

I would I do that when I only need so simple validation? Like that an argument is required. The arguments parser in Tango can handle validation.

>> CTFE:
>
> I think most of that exists in Phobos or can be constructed in
> one line of code:
>
>> * format - A simple formatting function
>
> http://dlang.org/phobos/std_metastrings.html#.Format
>
>> * indexOf
>
> http://dlang.org/phobos/std_typetuple.html#.staticIndexOf
>
>> * contains
>
> staticIndexOf!(something, Tuple) != -1
>
>> * fieldsOf - Returns all the fields of the given type
>
> http://dlang.org/phobos/std_traits.html#.FieldTypeTuple
>
>> * hasField - Returns true if the given type has the given field
>
> staticIndexOf!(field, fieldsOf!Type) != -1

That's good. But I would really prefer something like "hasField" instead of the above. It clearly shows that's going on.

>> * TypeOfField - Returns the type of a field
>> * nameOfFieldAt - Returns the name of the field at the given position
>> * set/getValueOfField - Sets/gets the value of a field
>
> :( No idea... at least without mixins.

There's no reason for mixins.

> So I figure, Object.factory("ClassName") is too limited. I
> used to just force my code work with that one.

Yes, it's too limited. Object.factory will only work for classes with a default constructor or a constructor which doesn't take any arguments.

If it's unclear, I already have all of this functionality implemented. It's just not in Phobos.

-- 
/Jacob Carlborg
February 13, 2013
On 2013-02-12 13:38, Jacob Carlborg wrote:
> In the thread "Expanding Phobos from a flat hierarchy" there started a
> discussion about package managers. Of course I mentioned the package
> manager I'm working on, Orbit. Unfortunately people weren't very happy
> with the third party dependencies. So I compiled a list of what's
> missing from Phobos, but I never got an answer to that post in the
> thread. I have now repeated the list below of what Orbit needs that
> don't exist in Phobos. I hope I have better luck here.
>
> Repeated message:
>
> I've compiled a list below of things used in Orbit (directly or
> indirectly) that Phobos is lacking in. Please tell me if I'm wrong:

If it's unclear, I already have all of this functionality implemented. It's just not in Phobos.

-- 
/Jacob Carlborg
February 13, 2013
On 2013-02-13 09:45, Jonathan M Davis wrote:

> format now works in CTFE. Format should go the way of the dodo. It's insanely
> inefficient.

Ok, cool.

-- 
/Jacob Carlborg
February 13, 2013
Am Tue, 12 Feb 2013 20:38:54 +0100
schrieb "qznc" <qznc@go.to>:

> 
> There will always be multiple solutions on different levels of power and applications have to choose, which suits them best.
> 
> My advice: If you find your self wanting that, try to rephrase first.
> 
> For example, instead of "there are %d cat(s)" output "number of cats: %d". It will be much easier to internationalize.

The gettext approach works quite well: There's no pluralize function. Instead you pass a singular and plural form and a number:

ngettext(string singular, string plural, int num).

Of course this works only for english strings, but that's what you use
in your source code:
writefln("Have %s %s", num, ngettext("message", "messages", num));

Other languages are handled transparently in the translation process: The translator can specify as many plural forms as necessary. A language specific formula then determines the correct plural form:

http://translate.sourceforge.net/wiki/l10n/pluralforms
February 13, 2013
13-Feb-2013 12:34, Marco Leise пишет:
> Am Tue, 12 Feb 2013 13:38:53 +0100
> schrieb Jacob Carlborg <doob@me.com>:
>
>> I've compiled a list below of things used in Orbit (directly or
>> indirectly) that Phobos is lacking in. Please tell me if I'm wrong:
>
> I can only tell you what of that list I would have had a use
> for myself in the past:
>
>>     * Configuration
>
> Yes, native to the environment (e.g. use \AppData\Roaming on
> Windows or .config on Linux)
>
>> * ConfigMap -  Does not exist. An associative array with opDispatch
>> added to it. Allows to do things like:
>>
>> auto config = ConfigMap();
>> config.foo = "asd";
>> config.bar.foo.baz = "foobar";
>>
>> assert(config.foo == "asd");
>
> I loaded an .INI template at CT (with default values and type
> inference) and created nested structs from that. Was fun to do
> in D. No matter what the implementation is, this is useful.
>
>> * std.process - I have not used it myself but I've heard it's not optimal
>
> The biggest shortcoming is that you cannot do IPC with it, as
> it doesn't give you two-way pipes to the child process. Again,
> that's useful and IIRC was in the std.process replacement.
>
>> * std.getopt - Doesn't support the following:
>>     * Required arguments
>>     * Restricting the values of a given argument
>>     * No way to automatically create a help/usage list out of the arguments
>>     * Handling positional arguments
>>     * No support for commands/action. That is "git commit", "commit"
>> would be the command/action
>>     * Handle multiple command lines
>>     * Validation of the arguments
>
> All of that except "action" and "multiple command lines".
> Validation is probably too complex to include at the spot. I
> mean, sometimes you need to validate the combination of all
> options, so you can just as well write a separate function.
>
>> CTFE:
>
> I think most of that exists in Phobos or can be constructed in
> one line of code:
>
>> * format - A simple formatting function
>
> http://dlang.org/phobos/std_metastrings.html#.Format

This should never see the light of day. Use plain format from std.string it works with CTFE and many, many times faster.

In fact the whole metastrings should be obliterated.



-- 
Dmitry Olshansky
February 13, 2013
On Wed, 13 Feb 2013 03:34:36 -0500, Marco Leise <Marco.Leise@gmx.de> wrote:

> Am Tue, 12 Feb 2013 13:38:53 +0100
> schrieb Jacob Carlborg <doob@me.com>:
>

>> * newInstance - Returns a new instance based on the class name or
>> ClassInfo. Can handle any class regardless of constructors
>
> So I figure, Object.factory("ClassName") is too limited. I
> used to just force my code work with that one.
>

Hm... I think all we need is a public interface to _d_newclass in druntime:

extern (C) Object _d_newclass(const ClassInfo ci)

In fact, it is pretty much public, since it's extern(C).

-Steve
February 13, 2013
On 2/12/2013 11:34 PM, Jacob Carlborg wrote:
> On 2013-02-12 22:35, Walter Bright wrote:
>
>> The trivial ones should not be added to Phobos, for example, 'any' being
>> defined as '!empty'. Such things add cognitive load but no value.
>
> This is just an extension to the already existing std.algorithm.any function. I
> think it adds value, that's why I have it. It clearly shows the intent. It's the
> same reason why I think it's good to have explicit interfaces and abstract
> classes in opposite of how it works in C++.
>


The any in std.algorithm is defined:

--------------
bool any(alias pred, Range)(Range range);

Returns true if and only if a value v satisfying the predicate pred can be found in the forward range range. Performs Ο(r.length) evaluations of pred.
--------------

I see that as very different from !empty.
February 13, 2013
On 2013-02-13 20:39, Steven Schveighoffer wrote:

> Hm... I think all we need is a public interface to _d_newclass in druntime:
>
> extern (C) Object _d_newclass(const ClassInfo ci)
>
> In fact, it is pretty much public, since it's extern(C).

That's what I'm using.

-- 
/Jacob Carlborg
February 14, 2013
On 2013-02-13 21:19, Walter Bright wrote:

> The any in std.algorithm is defined:
>
> --------------
> bool any(alias pred, Range)(Range range);
>
> Returns true if and only if a value v satisfying the predicate pred can
> be found in the forward range range. Performs Ο(r.length) evaluations of
> pred.
> --------------
>
> I see that as very different from !empty.

But if you use a predicate that always returns true that would be basically the same. At least for arrays.

int[] a = [];
assert(a.any!(e => true) == false);

int[] b = [3, 4, 5];
assert(b.any!(e => true) == true);

-- 
/Jacob Carlborg
February 14, 2013
Walter Bright:

> The trivial ones should not be added to Phobos,

The situation is not that simple. Just a general (not specific) note on this topic: Haskell has a standard module named "Prelude" that is usually loaded automatically at the start. It contains several commonly useful functions, types and constants:

http://www.haskell.org/onlinereport/standard-prelude.html

You can think of lot of the stuff you see in the Prelude as "trivial", like concatMap, that is just one line of very simple code (plus a first optional line that gives its type):


concatMap :: (a -> [b]) -> [a] -> [b]
concatMap f = concat . map f


Yet I think most Haskell programmers think it's a good idea to keep that stuff there. concatMap becomes a "chunk" so it reduces the thinking load of the programmer. And in some libraries there are "alternative" versions of concatMap that work on different types, like "packed" vectorized sequences, that are faster, but with the the same usage for the programmer.

Bye,
bearophile