June 04, 2014
Meta:

> and there's always std.variant.Variant when you don't want to bother with them.

How many good usages of D Variant do you know?

Bye,
bearophile
June 04, 2014
On Wednesday, 4 June 2014 at 17:55:15 UTC, bearophile wrote:
> How many good usages of D Variant do you know?
>
> Bye,
> bearophile

It depends on what you mean by a good usage. I rarely ever use Variant, but you *can* use it if you need weak and/or dynamic typing.
June 04, 2014
On 6/4/14, 2:50 PM, Meta wrote:
> On Wednesday, 4 June 2014 at 17:31:56 UTC, Ary Borenszweig wrote:
>> You still have to worry about types, though.
>
> Yes, but you can often get away without explicitly writing types in D,
> and there's always std.variant.Variant when you don't want to bother
> with them.

Even in function signatures?
June 04, 2014
On Wednesday, 4 June 2014 at 17:57:40 UTC, Ary Borenszweig wrote:
> Even in function signatures?

alias var = std.variant.Variant;

auto DoStuff(var x, var y)
{
    //Do stuff with x and y
}
June 04, 2014
Am 04.06.2014 19:57, schrieb Meta:
> On Wednesday, 4 June 2014 at 17:55:15 UTC, bearophile wrote:
>> How many good usages of D Variant do you know?
>>
>> Bye,
>> bearophile
>
> It depends on what you mean by a good usage. I rarely ever use
> Variant, but you *can* use it if you need weak and/or dynamic
> typing.
>

but D+Variant is still far away from an untyped language - because
everything needs to be based on Variant - every signature... so
it isn't an ~"correct"~ solution in this context
June 04, 2014
On Wednesday, 4 June 2014 at 18:01:04 UTC, dennis luehring wrote:
> Am 04.06.2014 19:57, schrieb Meta:
>> On Wednesday, 4 June 2014 at 17:55:15 UTC, bearophile wrote:
>>> How many good usages of D Variant do you know?
>>>
>>> Bye,
>>> bearophile
>>
>> It depends on what you mean by a good usage. I rarely ever use
>> Variant, but you *can* use it if you need weak and/or dynamic
>> typing.
>>
>
> but D+Variant is still far away from an untyped language - because
> everything needs to be based on Variant - every signature... so
> it isn't an ~"correct"~ solution in this context

You're right, but you can get fairly close. You will never be able to completely forget about types in D.
June 04, 2014
On 6/4/14, 2:59 PM, Meta wrote:
> On Wednesday, 4 June 2014 at 17:57:40 UTC, Ary Borenszweig wrote:
>> Even in function signatures?
>
> alias var = std.variant.Variant;
>
> auto DoStuff(var x, var y)
> {
>      //Do stuff with x and y
> }

Cool! It also looks nice too.
June 04, 2014
On Wednesday, 4 June 2014 at 18:03:48 UTC, Ary Borenszweig wrote:
> Cool! It also looks nice too.

you should check out my jsvar too

https://github.com/adamdruppe/arsd/blob/master/jsvar.d

weak typing and dynamic like javascript:

import arsd.jsvar;

void main() {
        var a = 10;
        var b = "20";
        b += a;
        b -= 4;
        import std.stdio;
        writeln(b);

        b = [1,2,3];
        b[0] *= "5";
        writeln(b);

        b = var.emptyObject;
        b.foo = (var a) {
                foreach(i; 0 .. a.get!int)
                        writeln("Hello");
        };

        b.foo()(5); // would be nice if @property worked!
}

26
[5, 2, 3]
Hello
Hello
Hello
Hello
Hello


Of course, sometimes the type still matters, like the a.get!int in there, but oh well.
June 04, 2014
Adam D. Ruppe:

> Of course, sometimes the type still matters,

Haskell programmers have a very different attitude toward types. They do a kind of type-driven programming, even in small programs. They lay down the data types (like the algebraic data types that describe the data structures of the problem), and then let the compiler, the type errors (and even a recent feature of the compiler named type holes) to write down the solutions and be guided toward correct code. This is kind of the opposite of trying to remove types using dynamic typing, and it's also far from the kind of strong static typing you see in Ada language.

Bye,
bearophile
June 04, 2014
On Wednesday, 4 June 2014 at 17:31:56 UTC, Ary Borenszweig wrote:
> On 6/4/14, 1:27 PM, Meta wrote:
>> On Wednesday, 4 June 2014 at 06:19:05 UTC, Andrei Alexandrescu wrote:
>>> http://www.reddit.com/r/programming/comments/27911b/conversation_with_andrei_alexandrescu_all_things/
>>>
>>>
>>> Andrei
>>
>> When that person made the statement about expressing his mental model in
>> a simpler way that is still somewhat fast, and then optimizing/adding
>> annotations/etc. after he gets it working, I kept expecting you to
>> mention RDMD and D's ability to be used for scripting, and
>> purity/nothrow/@safe/@nogc inference. This is an advantage D has over
>> Rust and C++. With Rust especially, there is no way to avoid dealing
>> with its pointer semantics, as they permeate the language. With D, you
>> can write in a C or even Python-like way (while not having to worry
>> about ownership, memory, etc. as the GC handles it for you), but you can
>> then optimize and add annotations to your code to get a lot more
>> performance and safety once your initial implementation is working.
>
> You still have to worry about types, though.

But using function templates and the like you can still get fairly 'Python-like' code in D.  I find dealing with types to be one of the areas that requires the 'least' amount of mental effort in software development. I don't understand why people see 'untyped' languages as simpler for the most part.