Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-19 22:51, Andrej Mitrovic wrote:

On 3/19/12, Jacob Carlborg  wrote:

Yeah, but that will complicate the retrieval of the information.


What is so complicated about extracting fields? Just iterate via .tupleof:


It wasn't actually that much more complicated. But now there is one 
extra enum for each NonSerialized field.


--
/Jacob Carlborg


Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Matthias Walter
On 03/19/2012 08:21 PM, Andrej Mitrovic wrote:
> On 3/19/12, Matthias Walter  wrote:
>> Hi,
>>
>> I've written a small module (at the moment called utils.keywordargs)
>> which simulates keyword arguments (aka named parameters).
> 
> Cool. A small tip (in case you didn't already know):
> 
> You can use allSatisfy from std.typetuple when checking a single
> constraint on multiple parameters: static
> assert(allSatisfy!(isKeywordArgument, H, V));

Didn't know that - thanks a lot!





Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Matthias Walter
On 03/19/2012 07:53 PM, bearophile wrote:
> Matthias Walter:
> 
>> I've written a small module (at the moment called utils.keywordargs)
>> which simulates keyword arguments (aka named parameters). The
>> documentation can be found here,
> 
> Regardless the implementation quality of your code, I wait for the real thing 
> :-)

I understand "the real thing" as a language implementation of keyword
arguments instead of a library "workaround", right?



Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-19 22:00, Andrei Alexandrescu wrote:


I salute creative uses of the language over defining new features.

Andrei


The actual point of user defined attributes it to be able to create 
domain specific attributes so we don't have to add new features to the 
language. This is also to have a sane syntax for the attributes.


I think in several cases D could have chose to implement a more general 
feature but instead implemented a very specific feature or hack.


Example:

If D supported passing delegates to a function after the function call 
several language features could have been implemented in the library 
instead.


void synchronized (void delegate () dg)
{
try
{
lock();
dg();
}
finally
unlock();
}

synchronized {
// do something
}

In the same way foreach can be implemented in a library function:

void foreach (T) (T[] arr, void delegate (T) dg)
{
for (size_t i = 0; i < arr.length; i++)
dg(arr[i]);
}

auto arr = [3, 4, 5];

foreach (arr ; e // this is the parameter to the delegate) {
writeln(e);
}

--
/Jacob Carlborg


Re: Proposal: user defined attributes

2012-03-20 Thread F i L

Jacob Carlborg wrote:
If D supported passing delegates to a function after the 
function call several language features could have been 
implemented in the library instead.


void synchronized (void delegate () dg)
{
try
{
lock();
dg();
}
finally
unlock();
}

synchronized {
// do something
}

In the same way foreach can be implemented in a library 
function:


void foreach (T) (T[] arr, void delegate (T) dg)
{
for (size_t i = 0; i < arr.length; i++)
dg(arr[i]);
}

auto arr = [3, 4, 5];

foreach (arr ; e // this is the parameter to the delegate) {
writeln(e);
}


That's pretty slick. D would need delegate inlining + 
@forceInline before foreach could be expressed this way though.




Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread F i L

On Monday, 19 March 2012 at 21:18:02 UTC, alex wrote:

Hi everyone,

It may sounds a bit annoying because I already was asking 
everywhere in the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D 
project?


In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop. 
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - like 
a relatively nice but fast code completion, build support, 
small refactoring operations like they can be used in every 
modern IDE and few other things which will make application 
development with D a lot easier - especially for D newbies.
(Debugging is also available via gdb on Linux systems - so 
yeah, why not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt
- Especially things like the evaluation of constant expressions 
and CTFE made e.g. a pre-compile-time view of mixin expressions 
possible! - This would be more than nice, I guess!


So if you want to support D (and perhaps me, too ;)) - be a 
mentor for GSoC to let D roll a bit more!


Further project info @ http://mono-d.alexanderbothe.com
For contact, you can speak to me in the #d and #d.mono-d 
channel on freenode - I'm called 'alex|D-Guy' there


Bump.

This is a great project, and IMO, key to the popularity of D 
among a wider audience. Best of luck, Alex. Sounds like you've 
got some great ideas planned.


Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-20 10:49, F i L wrote:


That's pretty slick. D would need delegate inlining + @forceInline
before foreach could be expressed this way though.


Yes, but currently, as far as I know, the delegate passed to opApply is 
not inlined.


--
/Jacob Carlborg


Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread bearophile
Matthias Walter:

> I understand "the real thing" as a language implementation of keyword
> arguments instead of a library "workaround", right?

Right. Even if your code is good, named arguments are a feature that needs to 
be built-in, or it will not happen. Creative usage of the language has its 
limits.

Bye,
bearophile


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Christian Manning

On Monday, 19 March 2012 at 21:18:02 UTC, alex wrote:

Hi everyone,

It may sounds a bit annoying because I already was asking 
everywhere in the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D 
project?


In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop. 
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - like 
a relatively nice but fast code completion, build support, 
small refactoring operations like they can be used in every 
modern IDE and few other things which will make application 
development with D a lot easier - especially for D newbies.
(Debugging is also available via gdb on Linux systems - so 
yeah, why not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt


Surely debugging support on platforms other than linux is much 
more important than any of these things you have listed. These 
things may be nice, but absolutely unnecessary. Integrated 
debugging is a must.


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Manu
On 20 March 2012 14:34, Christian Manning  wrote:

> On Monday, 19 March 2012 at 21:18:02 UTC, alex wrote:
>
>> Hi everyone,
>>
>> It may sounds a bit annoying because I already was asking everywhere in
>> the IRC channels but still had no success -
>>
>> Is there anyone who wants to be my GSoC mentor for the Mono-D project?
>>
>> In the case you don't know what Mono-D is all about:
>> It's about creating a D language binding for MonoDevelop. (
>> http://monodevelop.com/**Screenshots )
>>
>> There are couple of things that are already implemented - like a
>> relatively nice but fast code completion, build support, small refactoring
>> operations like they can be used in every modern IDE and few other things
>> which will make application development with D a lot easier - especially
>> for D newbies.
>> (Debugging is also available via gdb on Linux systems - so yeah, why not?
>> :))
>>
>> The main road map for this summer of code is available under
>> https://github.com/aBothe/**Mono-D/blob/master/**MonoDevelop.DBinding/**
>> Remaining%20features.txt
>>
>
> Surely debugging support on platforms other than linux is much more
> important than any of these things you have listed. These things may be
> nice, but absolutely unnecessary. Integrated debugging is a must.
>

Debugging is great with VisualD in Windows. It's about the only thing
VisualD does really well yet, although the rest of the experience is
starting to come together. Needs a lot more polish in general.


Re: getHash inconsistency

2012-03-20 Thread H. S. Teoh
On Tue, Mar 20, 2012 at 05:07:12PM +1100, Daniel Murphy wrote:
> "H. S. Teoh"  wrote in message 
> news:mailman.910.1332214803.4860.digitalmar...@puremagic.com...
> > Is this a bug?
> >
> > char[] a = "abc".dup;
> > const(char)[] b = "abc";
> > string c = "abc";
> >
> > writeln(typeid(a).getHash(&a)); // 12914
> > writeln(typeid(b).getHash(&b)); // 8503969683799911018
> > writeln(typeid(c).getHash(&c)); // 12914
> >
> 
> Of course. 
[...]

Then the question is, what should be the fix?

Currently, char[] and string have getHash defined in
rt.typeinfo.ti_Ad.TypeInfo_Aa, which appears to be a custom hashing
algorithm, whereas const(char)[] uses TypeInfo_Array.getHash, which uses
rt.util.hash.hashOf. Which one should be used?


T

-- 
Life would be easier if I had the source code. -- YHL


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread alex
Surely debugging support on platforms other than linux is much 
more important than any of these things you have listed. These 
things may be nice, but absolutely unnecessary. Integrated 
debugging is a must.


Personally I don't want to waste time with scanning tons of API 
documentation just to find out what parameters my called phobos 
function has got.
In larger projects, with large amounts of classes and methods 
it'll be hard to find everything in a short time.

So I doubt that code completion is that unnecessary.

Debugging is important, for sure, but without having abstract 
access to the debugged code it'll be quite impossible to e.g. 
read out memory and to know what this memory represents.
Just imagine I was given a pointer address but don't know that 
it's a string[]?
And now imagine you want to debug mixed-in code? I guess you 
won't be able to do this without knowing what your mixin code 
finally looks like :)





Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Christian Manning

On Tuesday, 20 March 2012 at 13:24:40 UTC, Manu wrote:
On 20 March 2012 14:34, Christian Manning 
 wrote:



On Monday, 19 March 2012 at 21:18:02 UTC, alex wrote:


Hi everyone,

It may sounds a bit annoying because I already was asking 
everywhere in

the IRC channels but still had no success -

Is there anyone who wants to be my GSoC mentor for the Mono-D 
project?


In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop. (
http://monodevelop.com/**Screenshots 
)


There are couple of things that are already implemented - 
like a
relatively nice but fast code completion, build support, 
small refactoring
operations like they can be used in every modern IDE and few 
other things
which will make application development with D a lot easier - 
especially

for D newbies.
(Debugging is also available via gdb on Linux systems - so 
yeah, why not?

:))

The main road map for this summer of code is available under
https://github.com/aBothe/**Mono-D/blob/master/**MonoDevelop.DBinding/**
Remaining%20features.txt



Surely debugging support on platforms other than linux is much 
more
important than any of these things you have listed. These 
things may be
nice, but absolutely unnecessary. Integrated debugging is a 
must.




Debugging is great with VisualD in Windows. It's about the only 
thing
VisualD does really well yet, although the rest of the 
experience is

starting to come together. Needs a lot more polish in general.


I actually found myself using Mono-D for the nice completion and 
VisualD for debugging, which is a total pain and probably more 
effort than its worth :)


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Christian Manning

On Tuesday, 20 March 2012 at 13:58:51 UTC, alex wrote:
Surely debugging support on platforms other than linux is much 
more important than any of these things you have listed. These 
things may be nice, but absolutely unnecessary. Integrated 
debugging is a must.


Personally I don't want to waste time with scanning tons of API 
documentation just to find out what parameters my called phobos 
function has got.
In larger projects, with large amounts of classes and methods 
it'll be hard to find everything in a short time.

So I doubt that code completion is that unnecessary.

Debugging is important, for sure, but without having abstract 
access to the debugged code it'll be quite impossible to e.g. 
read out memory and to know what this memory represents.
Just imagine I was given a pointer address but don't know that 
it's a string[]?
And now imagine you want to debug mixed-in code? I guess you 
won't be able to do this without knowing what your mixin code 
finally looks like :)


Yeh I can see its utility but I would sooner have some debugging 
support for non-mixed-in code.


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Manu
On 20 March 2012 16:07, Christian Manning  wrote:

> On Tuesday, 20 March 2012 at 13:24:40 UTC, Manu wrote:
>
>> On 20 March 2012 14:34, Christian Manning  wrote:
>>
>>  On Monday, 19 March 2012 at 21:18:02 UTC, alex wrote:
>>>
>>>  Hi everyone,

 It may sounds a bit annoying because I already was asking everywhere in
 the IRC channels but still had no success -

 Is there anyone who wants to be my GSoC mentor for the Mono-D project?

 In the case you don't know what Mono-D is all about:
 It's about creating a D language binding for MonoDevelop. (
 http://monodevelop.com/Screenshots<
 http://monodevelop.com/**Screenshots
 >)


 There are couple of things that are already implemented - like a
 relatively nice but fast code completion, build support, small
 refactoring
 operations like they can be used in every modern IDE and few other
 things
 which will make application development with D a lot easier - especially
 for D newbies.
 (Debugging is also available via gdb on Linux systems - so yeah, why
 not?
 :))

 The main road map for this summer of code is available under
 https://github.com/aBothe/Mono-D/blob/master/
 MonoDevelop.DBinding/**
 Remaining%20features.txt>>> blob/master/MonoDevelop.**DBinding/Remaining%20features.**txt
 >


>>> Surely debugging support on platforms other than linux is much more
>>> important than any of these things you have listed. These things may be
>>> nice, but absolutely unnecessary. Integrated debugging is a must.
>>>
>>>
>> Debugging is great with VisualD in Windows. It's about the only thing
>> VisualD does really well yet, although the rest of the experience is
>> starting to come together. Needs a lot more polish in general.
>>
>
> I actually found myself using Mono-D for the nice completion and VisualD
> for debugging, which is a total pain and probably more effort than its
> worth :)
>

Yes, I can see your motivation though :)
VisualD is starting to show signs of code understanding and
auto-completion. Goto definition has started to work in limited cases...
It's coming along.


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread alex
I actually found myself using Mono-D for the nice completion 
and VisualD for debugging, which is a total pain and probably 
more effort than its worth :)


Beta as hell ;D

But nevertheless it'd be nice if there was a mentor for this
project :)


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread F i L

Manu wrote:

Yes, I can see your motivation though :)
VisualD is starting to show signs of code understanding and
auto-completion. Goto definition has started to work in limited 
cases...

It's coming along.


Unfortunately It's not cross platform. This is why I like Mono-D 
so much, it's a very similar experience to writing C# in Visual 
Studios only I get the same experience on a Linux machine (+ some 
debugging).




Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 12:50 AM, Kapps wrote:

On Monday, 19 March 2012 at 21:00:32 UTC, Andrei Alexandrescu wrote:

On 3/19/12 3:55 PM, F i L wrote:

I think this could get tricky for the compiler to confidently use given
that the mixed in enums can collide with existing members (although not
likely). Also, if objects are not identified as being unique marked (in
the compilers eyes), what specific attribute post-fixes will it be
searching for on enums members?


Not a big issue, the name could always contain a uuid which makes
collision practically impossibile.

Andrei


And with parameters? Or how about run-time reflection, which is
something that should be added eventually for attributes as well (that
is, typeid(Blah).getCustomAttributes())? We can't manually add things
into the TypeInfo.


Perhaps we should add a field of type Variant[string].


This is an already ridiculously hackish approach, and
it *does not* work for anything besides trivial applications. It is
completly unreasonable to expect everything to be done in a library; the
compiler exists for a reason and at some point you have to draw the
line.


I'm afraid I disagree. A targeted language feature definitely makes a 
library approach inferior, by definition. But adding features is 
cheating, like printing money is for a government: very tempting, with 
apparently good short-term benefits, but with devastating cumulative 
effects.


Also, as I mentioned, the availability of the easy escape hatch of 
adding a language feature thwarts creativity. Nobody will care to think 
about and come with idioms that use the language to do great things, if 
they know a language feature could be always added that makes things 
"nicer".


I'm not saying this particular feature should or should not be in the 
language, but I wish our community exercised considerably more restraint 
when it comes about adding new language features.



Why even bother having an auto keyword? Instead of 'auto a = b +
c' you could simply use 'Auto!(b + c) a = b + c'. It is a more extreme
example for now, but won't be too much different once more complicated
things arise; after all, auto!2 a = 2 is not much different from auto a
= 2. Just like it's not too much different for parameterless attributes
(even if it is uglier and much more hackish), but once you get into
parameters and runtime stuff it becomes just as ugly as the above example.


I don't think your example with auto is relevant.


Andrei


Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 1:22 AM, dennis luehring wrote:

and how to add attribute parameters like DoSerialize(type=packed) for
example - very very common in C# attributes and java annotations

http://en.wikipedia.org/wiki/Java_annotation


One more argument to the template?

Andrei



Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 7:14 AM, bearophile wrote:

Matthias Walter:


I understand "the real thing" as a language implementation of
keyword arguments instead of a library "workaround", right?


Right. Even if your code is good, named arguments are a feature that
needs to be built-in, or it will not happen. Creative usage of the
language has its limits.


I think we're very far away from them.

Andrei


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 9:22 AM, alex wrote:

I actually found myself using Mono-D for the nice completion and
VisualD for debugging, which is a total pain and probably more effort
than its worth :)


Beta as hell ;D

But nevertheless it'd be nice if there was a mentor for this
project :)


I think this is a valuable project, but without a mentor we can't take 
if off the ground. Who is interested?


Thanks,

Andrei


Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


This is an already ridiculously hackish approach, and
it *does not* work for anything besides trivial applications. It is
completly unreasonable to expect everything to be done in a library; the
compiler exists for a reason and at some point you have to draw the
line.


I'm afraid I disagree. A targeted language feature definitely makes a
library approach inferior, by definition. But adding features is
cheating, like printing money is for a government: very tempting, with
apparently good short-term benefits, but with devastating cumulative
effects.

Also, as I mentioned, the availability of the easy escape hatch of
adding a language feature thwarts creativity. Nobody will care to think
about and come with idioms that use the language to do great things, if
they know a language feature could be always added that makes things
"nicer".

I'm not saying this particular feature should or should not be in the
language, but I wish our community exercised considerably more restraint
when it comes about adding new language features.


See my reply to one of your other posts:

http://forum.dlang.org/thread/bccwycoexxykfgxve...@forum.dlang.org?page=9#post-jk9gk8:242t7k:241:40digitalmars.com

--
/Jacob Carlborg


Re: Proposal: user defined attributes

2012-03-20 Thread F i L

Andrei Alexandrescu wrote:
like printing money is for a government: very tempting, with 
apparently good short-term benefits, but with devastating 
cumulative effects.


RON PAUL 2012!!!

sorry, I couldn't help myself.


Also, as I mentioned, the availability of the easy escape hatch 
of adding a language feature thwarts creativity. Nobody will 
care to think about and come with idioms that use the language 
to do great things, if they know a language feature could be 
always added that makes things "nicer".


You can be creative with a sledge hammer, or you can be creative 
with a jack hammer. D is already a bulldozer, but that doesn't 
mean it shouldn't become a wreaking ball.


;-)




Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread bearophile

Andrei Alexandrescu:


I think we're very far away from them.


What do you mean? Do you mean that Matthias Walter's
implementation is very far from being a good enough 
implementation of named

arguments? :-)

(I have not said that named arguments are necessary. I have said 
that I think it's not probable that a library implementation of 
them will be good enough.)


Hugs,
bearophile


Re: Proposal: user defined attributes

2012-03-20 Thread Steven Schveighoffer
On Tue, 20 Mar 2012 11:17:02 -0400, Andrei Alexandrescu  
 wrote:



Perhaps we should add a field of type Variant[string].


1. Variant is not (and shouldn't be IMO) part of druntime.
2. This is *static* data that should be available at compile time.  D's  
runtime wasting cycles filling in static data (including lots of heap  
allocations) seems like a big enough detriment that compiler help is  
warranted.



This is an already ridiculously hackish approach, and
it *does not* work for anything besides trivial applications. It is
completly unreasonable to expect everything to be done in a library; the
compiler exists for a reason and at some point you have to draw the
line.


I'm afraid I disagree. A targeted language feature definitely makes a  
library approach inferior, by definition. But adding features is  
cheating, like printing money is for a government: very tempting, with  
apparently good short-term benefits, but with devastating cumulative  
effects.


Not exactly.  We could all be writing code in assembly if "adding  
features" was always caustic.


What is nice about adding this feature is it provides a custom solution to  
hooking the compiler's TypeInfo generation.  We are setting up the  
compiler to give us hooks so we *don't* have to extend the compiler every  
time we want new reflection features.


One of the oft-requested features of D is reflection capability.  The  
answer is generally that we have compile-time reflection, which can  
theoretically be used to build runtime reflection.  However, the rebuttal  
I always come back with is "yeah, but why should I build at runtime that  
which is obvious at compile time?"


Note that one library that did attempt runtime reflection capability  
(flectioned) does all this at runtime, and does some really funky shit,  
like opening /proc/self/map on Linux, or requiring you to pass an OPTLINK  
map file.  I don't look at these as "innovations" as much as I do as  
workarounds.


Also, as I mentioned, the availability of the easy escape hatch of  
adding a language feature thwarts creativity. Nobody will care to think  
about and come with idioms that use the language to do great things, if  
they know a language feature could be always added that makes things  
"nicer".


I have to disagree for this instance, the barrier to creating reflection  
data from compile-time info is very large.  If anything, this *expands*  
the ability to create, since you now have a new way to pass information  
from compiler to runtime.


-Steve


Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.


I'm not saying this particular feature should or should not be in the
language, but I wish our community exercised considerably more restraint
when it comes about adding new language features.


See my reply to one of your other posts:

http://forum.dlang.org/thread/bccwycoexxykfgxve...@forum.dlang.org?page=9#post-jk9gk8:242t7k:241:40digitalmars.com


I understand the intention there, but my point stands: let's first 
explore doing it in the language, and advocate a new feature only when 
that fails. We've been too trigger-happy about proposing features even 
for the most trivial inconveniences.



Andrei




Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 11:09 AM, Steven Schveighoffer wrote:

On Tue, 20 Mar 2012 11:17:02 -0400, Andrei Alexandrescu
 wrote:


Perhaps we should add a field of type Variant[string].


1. Variant is not (and shouldn't be IMO) part of druntime.
2. This is *static* data that should be available at compile time. D's
runtime wasting cycles filling in static data (including lots of heap
allocations) seems like a big enough detriment that compiler help is
warranted.


Forgot to mention - I snipped these points because I agree with them.

Andrei



Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 11:09 AM, Steven Schveighoffer wrote:

On Tue, 20 Mar 2012 11:17:02 -0400, Andrei Alexandrescu
 wrote:

I'm afraid I disagree. A targeted language feature definitely makes a
library approach inferior, by definition. But adding features is
cheating, like printing money is for a government: very tempting, with
apparently good short-term benefits, but with devastating cumulative
effects.


Not exactly. We could all be writing code in assembly if "adding
features" was always caustic.


This is trivializing my point. Please.


What is nice about adding this feature is it provides a custom solution
to hooking the compiler's TypeInfo generation. We are setting up the
compiler to give us hooks so we *don't* have to extend the compiler
every time we want new reflection features.


There is something nice about every new feature.


One of the oft-requested features of D is reflection capability. The
answer is generally that we have compile-time reflection, which can
theoretically be used to build runtime reflection. However, the rebuttal
I always come back with is "yeah, but why should I build at runtime that
which is obvious at compile time?"


I thought there were discussions that didn't add runtime overhead.


Note that one library that did attempt runtime reflection capability
(flectioned) does all this at runtime, and does some really funky shit,
like opening /proc/self/map on Linux, or requiring you to pass an
OPTLINK map file. I don't look at these as "innovations" as much as I do
as workarounds.


Maybe there's a better approach than flectioned. Consider the language 
is frozen solid. How would you solve problems with it?



Also, as I mentioned, the availability of the easy escape hatch of
adding a language feature thwarts creativity. Nobody will care to
think about and come with idioms that use the language to do great
things, if they know a language feature could be always added that
makes things "nicer".


I have to disagree for this instance, the barrier to creating reflection
data from compile-time info is very large. If anything, this *expands*
the ability to create, since you now have a new way to pass information
from compiler to runtime.


I hope I'll be convinced.


Andrei


Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Alex Rønne Petersen

On 20-03-2012 17:01, bearophile wrote:

Andrei Alexandrescu:


I think we're very far away from them.


What do you mean? Do you mean that Matthias Walter's
implementation is very far from being a good enough implementation of named
arguments? :-)

(I have not said that named arguments are necessary. I have said that I
think it's not probable that a library implementation of them will be
good enough.)

Hugs,
bearophile


I have to agree that a library implementation cannot provide what the 
language would be able to here. Just the requirement that functions with 
named arguments must be templatized makes the strategy more or less 
unusable for class hierarchies.


--
- Alex


Re: Proposal: user defined attributes

2012-03-20 Thread Adam D. Ruppe
On Tuesday, 20 March 2012 at 15:17:04 UTC, Andrei Alexandrescu 
wrote:
Also, as I mentioned, the availability of the easy escape hatch 
of adding a language feature thwarts creativity.


I agree entirely. Usually, when I see threads like this,
my response is "challenge accepted".

But, on this problem, my answer is, unfortunately,
"challenge failed".

I want to annotate declarations for my web.d, where
you can write a class and have D do a bunch of work
for you in creating all kinds of stuff.

Let me do up a quick example:

===
struct MyType {
   int num;
   string name;
   string desc;
   Element makeHtmlElement() {
  auto e = Element.make("div", desc).addClass("my-type");
  return e;
   }
}

class MySite : ApiProvider {
MyType getSomething(int someNumber, string name, Text 
description) {

 return MyType(someNumber, name, description);
}

void savePhoneNumber(string name, string phoneNumber) {
_checkLoggedIn();
ensureGoodPost();
_doSave();
}

void _doSave() { yada yada yada }
}
===


Now, when you go to mysite.com/get-something, it will
generate a form like this:

  
  Some Number: 
 Name: 
  Description: 
   
   

  [Get Something]
   



It pulls this info from the D code - it uses an alias
template param to the method, then parses .stringof
to get the names and default params. (It then mixes
in the default to get a D type, which doesn't work
on custom types since they aren't in the right scope,
but hey, it works in a lot of cases.)



When possible, it uses the type of the parameter
to specialize the form. This comes from ParameterTypeTuple.

Here, it recognizes struct Text{} as being a textarea.
tbh, I'd prefer to use @note(Textarea(rows)), but this
works, and alias this to string makes it pretty natural
to work with too.



Moreover, I wrote method="GET". It pulls this from the
method name. Since it starts with get, it doesn't require
http post for it.



So far, so good. Let's look at the next method, savePhoneNumber.
This !startsWith("get"), so it generates a POST form, with
the same kind of thing:

Name: _
Phone Number: _
 [Save Phone Number]


Hey, it works. But, I'd like to do even better. Could
we do validation?

Well, yeah, I think we could.

struct PhoneNumber {
 enum _validationRegex = "[0-9]+";
}

Boom.

What about an example text, though? You could use
that same enum method, but you would need a different
type for each example.

If you have two "string name" and in one case, you want
it to be "e.g. Bob Smith" and in the other, you want
"e.g. Downtown Office", you'd have to make separate
structs for them, despite it just being strings in
every other way.


That's one big case where the compile time annotation
comes through:

void savePhoneNumber
@note(ExampleText("e.g. Downtown Office")
string name,
PhoneNumber phoneNumber)
{ }


To do that with a mixin, you might:

mixin(ExampleText!(savePhoneNumber, "name", "downtown"));
void savePhoneNumber(string name, ...) {...}

and have that yield:

enum _attribute_DsavePhoneNumberMangle_param_name_FILE_LINE_type 
= ExampleText("downtown");




ok, this is a bit of a pain in the ass, but I think it'd
work... (the file_line_type stuff is so you can have multiple
things of the same type. Moderately fragile! But, it'd work.)


The pain gets bad down the line though. Renaming things means
repetition. Separate declarations might get lost as you
shuffle the order around. But, not too awful...


Until you get into more functions. Enter 
arsd.web.prepareReflection

and makeJavascriptApi:

foreach(member; __traits(allMembers, yourclass))
// build a runtime map and corresponding bindings for other 
languages




Should our enum be included here? Should this include code
to detect the annotations and translate them to the
native target language? How much code is this going to take?

What if I use a third party lib? Will it have to be hacked to
ignore these extra names too?


Well, we can work around this too. web.d has a convention
where static if(name[0] == '_') { don't process }. (This
is actually a workaround for a lack of __traits(getProtection)
though. We already have D keywords that do this: public
and/or export. But, there's currently no way to check for these,
so I settled for a naming convention.

This is what _doSave() demonstrates in the example.

I'm hoping to do a dmd pull request to add getProtection at
some point though.)

We could all agree on a naming convention, in theory. In
practice, I don't know. If I could check export || public,
I might drop the underscore.



Another problem is how do we get this data? We have
an alias of the method... but not it's parent. Well,
there's __traits(getParent). I think we could actually
do that.

But the idea of a parent reminds me of another problem.
This is a class, the method is virtu

Re: Proposal: user defined attributes

2012-03-20 Thread sclytrack

On 03/20/2012 05:31 PM, Adam D. Ruppe wrote:


Even /ignoring/ them takes a lot code, and that's
what, to me, pushes it over into compiler territory.


vote++


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Adam Wilson

On Mon, 19 Mar 2012 14:18:01 -0700, alex  wrote:


Hi everyone,

It may sounds a bit annoying because I already was asking everywhere in  
the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D project?

In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop.  
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - like a  
relatively nice but fast code completion, build support, small  
refactoring operations like they can be used in every modern IDE and few  
other things which will make application development with D a lot easier  
- especially for D newbies.
(Debugging is also available via gdb on Linux systems - so yeah, why  
not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt
- Especially things like the evaluation of constant expressions and CTFE  
made e.g. a pre-compile-time view of mixin expressions possible! - This  
would be more than nice, I guess!


So if you want to support D (and perhaps me, too ;)) - be a mentor for  
GSoC to let D roll a bit more!


Further project info @ http://mono-d.alexanderbothe.com
For contact, you can speak to me in the #d and #d.mono-d channel on  
freenode - I'm called 'alex|D-Guy' there


I might be up for this. Can anybody fill me in on what is involved in  
being a mentor? I've never done it before, but I have some project  
management experience and I am really interested in seeing improved IDE  
integrations for D.


--
Adam Wilson
Project Coordinator
The Horizon Project
http://www.thehorizonproject.org/


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 12:25 PM, Adam Wilson wrote:

I might be up for this. Can anybody fill me in on what is involved in
being a mentor? I've never done it before, but I have some project
management experience and I am really interested in seeing improved IDE
integrations for D.


Great! For details on the application process, refer to 
http://dlang.org/gsoc2012.html.


For details on what mentors are expected to do, see 
http://www.google-melange.com/gsoc/document/show/gsoc_program/google/gsoc2012/faqs 
and the excellent mentor manual at 
http://en.flossmanuals.net/GSoCMentoring/.



Thanks,

Andrei


String mixin syntax sugar

2012-03-20 Thread Mantis

Hello,

since people discussed a lot about user-defined attributes recently, 
I've been thinking about a way to implement it with a string mixins. The 
problem with them is their syntax - it's far from what we want to use in 
everyday job. I understand, they should be easily distinguished at use 
site, but perhaps this may be accomplished in other ways as well. My 
idea is to translate this kind of statements:


# identifier statement

into this:

mixin( identifier( q{ statement } ) );

where an identifier is a, possibly templated, function that accepts one 
string argument and returns a string. Here are some possible use cases:


#serialize int a; // marked to be serializable
#serialize!not int b; // -.- non-serializable

#readonly float c; // generate trivial private setter and public getter

#handles!Events.Foo void handler(); // event handler

#attribute!"Foo" void foo(); // function with additional compile-time info

Most of these examples require some D parser, but, since it is planned 
to add parser-generation into Phobos, this shouldn't be a problem.
What do you think, does it have some value for the language, and, if 
yes, is it possible to implement?


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread alex

On Tuesday, 20 March 2012 at 17:25:06 UTC, Adam Wilson wrote:
On Mon, 19 Mar 2012 14:18:01 -0700, alex 
 wrote:



Hi everyone,

It may sounds a bit annoying because I already was asking 
everywhere in the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D 
project?


In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop. 
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - like 
a relatively nice but fast code completion, build support, 
small refactoring operations like they can be used in every 
modern IDE and few other things which will make application 
development with D a lot easier - especially for D newbies.
(Debugging is also available via gdb on Linux systems - so 
yeah, why not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt
- Especially things like the evaluation of constant 
expressions and CTFE made e.g. a pre-compile-time view of 
mixin expressions possible! - This would be more than nice, I 
guess!


So if you want to support D (and perhaps me, too ;)) - be a 
mentor for GSoC to let D roll a bit more!


Further project info @ http://mono-d.alexanderbothe.com
For contact, you can speak to me in the #d and #d.mono-d 
channel on freenode - I'm called 'alex|D-Guy' there


I might be up for this. Can anybody fill me in on what is 
involved in being a mentor? I've never done it before, but I 
have some project management experience and I am really 
interested in seeing improved IDE integrations for D.


Thanks for the offer!

'Unfortunately' there already is one who wants to be a mentor -
but anyway: Thanks for being willed to do this!


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread alex

On Tuesday, 20 March 2012 at 18:27:40 UTC, alex wrote:

On Tuesday, 20 March 2012 at 17:25:06 UTC, Adam Wilson wrote:
On Mon, 19 Mar 2012 14:18:01 -0700, alex 
 wrote:



Hi everyone,

It may sounds a bit annoying because I already was asking 
everywhere in the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D 
project?


In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop. 
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - 
like a relatively nice but fast code completion, build 
support, small refactoring operations like they can be used 
in every modern IDE and few other things which will make 
application development with D a lot easier - especially for 
D newbies.
(Debugging is also available via gdb on Linux systems - so 
yeah, why not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt
- Especially things like the evaluation of constant 
expressions and CTFE made e.g. a pre-compile-time view of 
mixin expressions possible! - This would be more than nice, I 
guess!


So if you want to support D (and perhaps me, too ;)) - be a 
mentor for GSoC to let D roll a bit more!


Further project info @ http://mono-d.alexanderbothe.com
For contact, you can speak to me in the #d and #d.mono-d 
channel on freenode - I'm called 'alex|D-Guy' there


I might be up for this. Can anybody fill me in on what is 
involved in being a mentor? I've never done it before, but I 
have some project management experience and I am really 
interested in seeing improved IDE integrations for D.


Thanks for the offer!

'Unfortunately' there already is one who wants to be a mentor -
but anyway: Thanks for being willed to do this!


Oops, small mistake happened - didn't know that he was called 
"LightBender"




Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Adam Wilson

On Tue, 20 Mar 2012 11:40:49 -0700, alex  wrote:


On Tuesday, 20 March 2012 at 18:27:40 UTC, alex wrote:

On Tuesday, 20 March 2012 at 17:25:06 UTC, Adam Wilson wrote:
On Mon, 19 Mar 2012 14:18:01 -0700, alex   
wrote:



Hi everyone,

It may sounds a bit annoying because I already was asking everywhere  
in the IRC channels but still had no success -


Is there anyone who wants to be my GSoC mentor for the Mono-D project?

In the case you don't know what Mono-D is all about:
It's about creating a D language binding for MonoDevelop.  
(http://monodevelop.com/Screenshots )


There are couple of things that are already implemented - like a  
relatively nice but fast code completion, build support, small  
refactoring operations like they can be used in every modern IDE and  
few other things which will make application development with D a lot  
easier - especially for D newbies.
(Debugging is also available via gdb on Linux systems - so yeah, why  
not? :))


The main road map for this summer of code is available under
https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Remaining%20features.txt
- Especially things like the evaluation of constant expressions and  
CTFE made e.g. a pre-compile-time view of mixin expressions possible!  
- This would be more than nice, I guess!


So if you want to support D (and perhaps me, too ;)) - be a mentor  
for GSoC to let D roll a bit more!


Further project info @ http://mono-d.alexanderbothe.com
For contact, you can speak to me in the #d and #d.mono-d channel on  
freenode - I'm called 'alex|D-Guy' there


I might be up for this. Can anybody fill me in on what is involved in  
being a mentor? I've never done it before, but I have some project  
management experience and I am really interested in seeing improved  
IDE integrations for D.


Thanks for the offer!

'Unfortunately' there already is one who wants to be a mentor -
but anyway: Thanks for being willed to do this!


Oops, small mistake happened - didn't know that he was called  
"LightBender"




 I really should put that in my sig...

--
Adam Wilson
Project Coordinator
The Horizon Project
http://www.thehorizonproject.org/


Official deprecation dates, -property

2012-03-20 Thread bearophile
This post is about two partially related topics. It's also related to recent 
things said by Walter about deprecation and code breakage.

I have plenty of D1 code that now and then I port to D2 and I have some old D2 
code too that I port to the modern D2 compiler. I have seen that adding the 
"override" annotations and adding the missing "()" (because I now compile with 
-wi -property) requires me a short time, and it's kind of mindless work, I 
don't have to think much about it. On the other hand I need some time to port 
the usage of the old regex module to the new one, and sometimes it requires a 
bit of thinking.

So I think requiring the "override" annotation (unless -d is used to compile) 
and deprecating the lack of "()" (unless -d is used to compile) doesn't cause 
significant problems.

In my opinion (based on hundreds of thousands of lines of D1/D2 code written) 
often small language changes are less painful than Phobos API changes. I have 
seen similar things in other languages (fixing code to work on Python3 is for 
me is often less painful than fixing code to adapt it to different libs of to 
modified API of the the same libs).

So I suggest Walter to write down somewhere on the site the date when those two 
things will become deprecated (the lack of override and ()). We now officially 
know when DMD1 will stop having bug fixes, so it's right to know when override 
and () will be enforced, it's a much small thing.

- - - - - - - - - -

A related thing:

If I compile this code (with -wi -property) I get "Error: not a property f.bar":

struct Foo {
void bar() {}
}
void main() {
Foo f;
f.bar;
}


But this code gives me no errors (compiled with -wi -property):

struct Foo {
@property void bar() {}
}
void main() {
Foo f;
f.bar();
}

Here  I have used () on a property. Currently -property enforces the usage of 
() on non-properties. But my logic tells me that it should also do the opposite 
and show an error if you use () with a @property method. What do you think?

Bye,
bearophile


"Forward reference" eror message improvement?

2012-03-20 Thread Mehrdad

auto fact(int n) { return n > 1 ? fact(n - 1) : 0; }

// Error: forward reference to fact


I think the error message could be improved... maybe something like "forward 
reference to inferred return type" like we get with templates? 



Three Unlikely Successful Features of D

2012-03-20 Thread Andrei Alexandrescu
I plan to give a talk at Lang.NEXT 
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the 
subject above. There are a few features of D that turned out to be 
successful, in spite of them being seemingly unimportant or diverging 
from related consecrated approaches.


What are your faves? I have a few in mind, but wouldn't want to 
influence answers.



Thanks,

Andrei


Re: Proposal: user defined attributes

2012-03-20 Thread Piotr Szturmaj

Andrei Alexandrescu wrote:

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.


Please, do not transform D into a dynamic language.


Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 2:04 PM, Piotr Szturmaj wrote:

Andrei Alexandrescu wrote:

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.


Please, do not transform D into a dynamic language.


Where's the "dynamic languages rok" crowd when you need it :o).

Andrei


Re: Three Unlikely Successful Features of D

2012-03-20 Thread maarten van damme
I really like the $ opperator on slices. It's something small and looks
rather unneeded. When I was dealing with java I never even wished it was
there but when I came to d and did some array manipulation I was really
glad we had that $ sign. I regularly use it and I don't seem to be the only
one feeling that way.

Maarten


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Alex Rønne Petersen

On 20-03-2012 20:02, Andrei Alexandrescu wrote:

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Thanks,

Andrei


In no particular order: Lazy values, guaranteed initialization, scope 
guards, perhaps array slices, alias this / single inheritance, unittest 
blocks.


--
- Alex


Re: String mixin syntax sugar

2012-03-20 Thread Dmitry Olshansky

On 20.03.2012 22:25, Mantis wrote:

Hello,

since people discussed a lot about user-defined attributes recently,
I've been thinking about a way to implement it with a string mixins. The
problem with them is their syntax - it's far from what we want to use in
everyday job.


Use template mixins? At least in struct/class area that catches the most 
attention it should work perfectly.


 I understand, they should be easily distinguished at use

site, but perhaps this may be accomplished in other ways as well. My
idea is to translate this kind of statements:

# identifier statement

into this:

mixin( identifier( q{ statement } ) );

where an identifier is a, possibly templated, function that accepts one
string argument and returns a string. Here are some possible use cases:

#serialize int a; // marked to be serializable
#serialize!not int b; // -.- non-serializable

#readonly float c; // generate trivial private setter and public getter


Why not just leave it alone, and (if need comes) turn it into property 
on demand.




#handles!Events.Foo void handler(); // event handler

#attribute!"Foo" void foo(); // function with additional compile-time info


It's just voodoo - no guaranties that #attribute can do that given the 
above rewrite.




Most of these examples require some D parser, but, since it is planned
to add parser-generation into Phobos, this shouldn't be a problem.
What do you think, does it have some value for the language, and, if
yes, is it possible to implement?


Looks like throwing nukes to pin down a pesky cockroach.
The sugar is more or less nice, but encourages ineffective compile-time 
wise idiom.


--
Dmitry Olshansky


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Dmitry Olshansky

On 20.03.2012 23:02, Andrei Alexandrescu wrote:

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.




To throw in a few:
Scope guards, opDispatch, alias and _string_ template parameters.


--
Dmitry Olshansky


Re: Three Unlikely Successful Features of D

2012-03-20 Thread H. S. Teoh
On Tue, Mar 20, 2012 at 02:02:15PM -0500, Andrei Alexandrescu wrote:
> I plan to give a talk at Lang.NEXT
> (http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
> subject above. There are a few features of D that turned out to be
> successful, in spite of them being seemingly unimportant or
> diverging from related consecrated approaches.
> 
> What are your faves? I have a few in mind, but wouldn't want to
> influence answers.
[...]

By far: CTFE.

Unittest blocks, extended concept of purity, template syntax (as opposed
to C++'s ugly mess), all types have a default value (.init - makes it so
painless to write generic code!), scope guards.


T

-- 
I am a consultant. My job is to make your job redundant. -- Mr Tom


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 20/03/2012 16:17, Andrei Alexandrescu a écrit :

On 3/20/12 12:50 AM, Kapps wrote:

On Monday, 19 March 2012 at 21:00:32 UTC, Andrei Alexandrescu wrote:

On 3/19/12 3:55 PM, F i L wrote:

I think this could get tricky for the compiler to confidently use given
that the mixed in enums can collide with existing members (although not
likely). Also, if objects are not identified as being unique marked (in
the compilers eyes), what specific attribute post-fixes will it be
searching for on enums members?


Not a big issue, the name could always contain a uuid which makes
collision practically impossibile.

Andrei


And with parameters? Or how about run-time reflection, which is
something that should be added eventually for attributes as well (that
is, typeid(Blah).getCustomAttributes())? We can't manually add things
into the TypeInfo.


Perhaps we should add a field of type Variant[string].


This is an already ridiculously hackish approach, and
it *does not* work for anything besides trivial applications. It is
completly unreasonable to expect everything to be done in a library; the
compiler exists for a reason and at some point you have to draw the
line.


I'm afraid I disagree. A targeted language feature definitely makes a
library approach inferior, by definition. But adding features is
cheating, like printing money is for a government: very tempting, with
apparently good short-term benefits, but with devastating cumulative
effects.

Also, as I mentioned, the availability of the easy escape hatch of
adding a language feature thwarts creativity. Nobody will care to think
about and come with idioms that use the language to do great things, if
they know a language feature could be always added that makes things
"nicer".

I'm not saying this particular feature should or should not be in the
language, but I wish our community exercised considerably more restraint
when it comes about adding new language features.



That feature has been added to java with great benefit. I think the 
underlying need here is AOP. Adding annotation to java had great 
benefice in introducing AOP capabilities to the language.


See :
http://projectlombok.org/

Considering that D has great compile time capabilities, this is 
somewhere we want to go.


Additionnaly, this is something that remove other capabilities, and 
replace them by lib support. For example, with @synchronized, I could 
specify the phobos that I want that method or class to be synchronized, 
and the lib is able to add the needed code to ensure that functionality 
at compile time.


I have to say that the whole idea of attaching property to instance 
doesn't make any sense to me - Walter make a good point on that I think, 
so I will not repeat his arguments.


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 20/03/2012 20:17, Andrei Alexandrescu a écrit :

On 3/20/12 2:04 PM, Piotr Szturmaj wrote:

Andrei Alexandrescu wrote:

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.


Please, do not transform D into a dynamic language.


Where's the "dynamic languages rok" crowd when you need it :o).

Andrei


They are busy debugging what they coded sooo quickly and efficiently.


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 20/03/2012 17:13, Andrei Alexandrescu a écrit :

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.



I was probably one of the most controversial part of the thread :D


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 20/03/2012 17:16, Andrei Alexandrescu a écrit :

Maybe there's a better approach than flectioned. Consider the language
is frozen solid. How would you solve problems with it?



Easy, I already did that many times. I'd preprocess the source code with 
some homebrew tool before compiling.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Don

On 20.03.2012 20:02, Andrei Alexandrescu wrote:

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Thanks,

Andrei


There's one huge one.

Strings as built-in types, including concatenation and slicing. This 
meant that they could be constant-folded. Together with 'static if', 
this was the basis of metaprogramming in D. Pretty much all the rest was 
a natural consequence of that foundation.
It was *completely* unexpected. When, as a D newbie, I posted some of my 
initial exploration of the language, Walter wrote "I had no idea this 
was even possible."


Probably not what you have in mind, though -- it *was* expected to be a 
success, just not to anything like this extent.


* pragma(msg) is something that's been used 100X as often as anticipated.

* Builtin properties of types, eg int.max. Doesn't sound like much of an 
improvement over a header file of constants, but it's had a huge impact. 
It really encourages you to write correct code, (I especially notice it 
for floating point, but I bet if you grep for "int.max" in D code, 
you'll get far more hits than for "MAXINT" in C code).




Re: Three Unlikely Successful Features of D

2012-03-20 Thread Jesse Phillips

On Tuesday, 20 March 2012 at 19:50:25 UTC, Dmitry Olshansky wrote:


To throw in a few:
Scope guards, opDispatch, alias and _string_ template 
parameters.


I like this list. And add, the template shorthand to!(int)() -> 
to!int() and q{} strings (though I need to remember them more 
often.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Don

On 20.03.2012 21:33, Don wrote:

On 20.03.2012 20:02, Andrei Alexandrescu wrote:

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Thanks,

Andrei


There's one huge one.

Strings as built-in types, including concatenation and slicing. This
meant that they could be constant-folded. Together with 'static if',
this was the basis of metaprogramming in D. Pretty much all the rest was
a natural consequence of that foundation.
It was *completely* unexpected. When, as a D newbie, I posted some of my
initial exploration of the language, Walter wrote "I had no idea this
was even possible."

Probably not what you have in mind, though -- it *was* expected to be a
success, just not to anything like this extent.

* pragma(msg) is something that's been used 100X as often as anticipated.


Note that because it was so successful, it was incorporated into static 
assert.




* Builtin properties of types, eg int.max. Doesn't sound like much of an
improvement over a header file of constants, but it's had a huge impact.
It really encourages you to write correct code, (I especially notice it
for floating point, but I bet if you grep for "int.max" in D code,
you'll get far more hits than for "MAXINT" in C code).


And is(typeof()), even though the syntax is really horrible. Brilliant 
concept.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread H. S. Teoh
On Tue, Mar 20, 2012 at 01:31:08PM -0700, H. S. Teoh wrote:
> On Tue, Mar 20, 2012 at 02:02:15PM -0500, Andrei Alexandrescu wrote:
> > I plan to give a talk at Lang.NEXT
> > (http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
> > subject above. There are a few features of D that turned out to be
> > successful, in spite of them being seemingly unimportant or
> > diverging from related consecrated approaches.
> > 
> > What are your faves? I have a few in mind, but wouldn't want to
> > influence answers.
> [...]
> 
> By far: CTFE.
> 
> Unittest blocks, extended concept of purity, template syntax (as opposed
> to C++'s ugly mess), all types have a default value (.init - makes it so
> painless to write generic code!), scope guards.
[...]

Oh, and I forgot static if. It's a major feature in making compile-time
stuff work like a charm.


T

-- 
Life is too short to run proprietary software. -- Bdale Garbee


Re: Three Unlikely Successful Features of D

2012-03-20 Thread dsimcha

1.  Scope guards.  The need to execute some code at the end of a
scope is pervasive and has led to about a zillion workarounds
from gotos in C to RAII in C++ to try/finally in Java and C# to
with statements in Python.  D is the only language I know of that
lets the programmer specify such a simple and common intention
directly.

2.  CTFE.  There's a certain elegance to having most of the
language available at compile time and it seems like there's no
shortage of creative uses for this.

3.  Static if.  This is the most important feature for converting
template metaprogramming from an esoteric form of sorcery to a
practical, readable tool for the masses.  Most of the compile time
introspection D provides would be almost unusable without it.


Re: String mixin syntax sugar

2012-03-20 Thread Jacob Carlborg

On 2012-03-20 19:25, Mantis wrote:

Hello,

since people discussed a lot about user-defined attributes recently,
I've been thinking about a way to implement it with a string mixins. The
problem with them is their syntax - it's far from what we want to use in
everyday job. I understand, they should be easily distinguished at use
site, but perhaps this may be accomplished in other ways as well. My
idea is to translate this kind of statements:

# identifier statement

into this:

mixin( identifier( q{ statement } ) );



I don't like it. I want real user defined attributes.


--
/Jacob Carlborg


Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-20 17:13, Andrei Alexandrescu wrote:

On 3/20/12 10:52 AM, Jacob Carlborg wrote:

On 2012-03-20 16:17, Andrei Alexandrescu wrote:

On 3/20/12 12:50 AM, Kapps wrote:



Perhaps we should add a field of type Variant[string].


No, not Variant[string] again.


Why? I thought it was agreed that that's a good idea for exceptions.


Maybe you agreed on that. I still don't like it.

--
/Jacob Carlborg


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 16/03/2012 17:09, Andrei Alexandrescu a écrit :

On 3/16/12 8:35 AM, Adam D. Ruppe wrote:

enum Serializable { yes, no }

@note(Serializable.yes) int a;

[...]

foreach(i, exp; __traits(getNotes, a)) {
static assert(is(typeof(exp) == Serializable);
static assert(exp == Serializable.yes);
}


So we have:

class A {
@note(Serializable.yes) int a;
...
}

vs. a hypothetical in-language solution:

class A {
int a;
mixin(note("a", Serializable.yes));
...
}

I wonder to what extent the in-language solution can be made to work.


Andrei


It is more tricky if the property isn't a simple attribute to read. 
Again, consider what is done with this simple example : 
http://projectlombok.org/


We have the opportunity here to introduce in D the concept of aspect 
oriented programming. This is HUGE. If you are afraid of the addition of 
a functionnality to the language, don"t worry, you are not just adding a 
functionnality, but a whole new paradigm.


And, BTW, this would allow us to drop some functionalities that now can 
be provided by phobos (synchronized for example is an obvious one). Same 
goes for override, deprecated, and the fun thing is that we can 
implement our own to extends the language even more as lib.


Even the propagation of pure, @safe, nothrow and const that has been 
discussed recently can be done with that feature.


If you are worried about introducing language features (I am) you should 
definitively introduce that one, because lot of features has already 
been included just because that one is lacking.


Adding compile time information to a type is the visible part of the 
iceberg. Really.


Re: Proposal: user defined attributes

2012-03-20 Thread Jacob Carlborg

On 2012-03-20 20:17, Andrei Alexandrescu wrote:

On 3/20/12 2:04 PM, Piotr Szturmaj wrote:

Please, do not transform D into a dynamic language.


Where's the "dynamic languages rok" crowd when you need it :o).

Andrei


They left you behind after all those "d rox" comments :)

--
/Jacob Carlborg


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 16/03/2012 19:23, Andrej Mitrovic a écrit :

On 3/16/12, Adam D. Ruppe  wrote:

The current language solution isn't really *bad* with enough
library help, but it isn't particularly *good* either and I
don't think it can be. I've tried a few things, and I still
see the lack of user annotations as D's biggest miss right now.


Yeah, but I would say if we had even better compile-time introspection
we could have the freedom to implement any number of annotation
implementations in library code. When you put something into the
language you have to depend on C++ hackers to implement and then
inevitably fix the upcoming bugs in the front-end (ICEs are an
annoying blocker), and there's always that issue where the devs are
against adding new features to an existing language feature. (say
annotations were implemented, soon enough someone is going to complain
it doesn't have enough functionality and that it needs to be
extended).

Personally I'd love it if we had more __traits and compile-time
introspection abilities.


And not just introspection, but modification would be king.


Re: Proposal: user defined attributes

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 4:36 PM, deadalnix wrote:

We have the opportunity here to introduce in D the concept of aspect
oriented programming. This is HUGE. If you are afraid of the addition of
a functionnality to the language, don"t worry, you are not just adding a
functionnality, but a whole new paradigm.


I dabbled into AOP quite a bit, but I'm not all that jazzed about it. 
It's been around for quite a while but it has little to show for it. At 
the present it's rather unstructured and lacks a strong corpus of useful 
idioms. I'd say - interesting, but I wouldn't bet the farm on it.


Andrei



Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 16/03/2012 18:36, Adam D. Ruppe a écrit :

On Friday, 16 March 2012 at 16:57:26 UTC, Steven Schveighoffer wrote:

I thought @ was supposed to be a user-defined annotation.
Otherwise, why did we introduce @syntax?


idk, to "reduce" the number of keywords or somethiny.

This is why I call it a mistake or missed opportunity
right now though: @property, @safe, @disable, @system,
and @trusted have already made a claim on the @syntax.

Now, we have to work around that, which is why I'm
thinking @note(expression) rather than @.


I'd rather see something like this:


I could live with that too, but I think it'd be harder
to make happen due to potential clashes with the current
thing @ is used for.


This isn't a problem because they'd be scoped to the module anyway. D 
have no top level names, except for the one provided by the compiler, 
and that is great !


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Walter Bright

On 3/20/2012 12:02 PM, Andrei Alexandrescu wrote:

What are your faves? I have a few in mind, but wouldn't want to influence 
answers.


Although array slices have been in D nearly since the beginning, I had little 
idea they would become so darn useful and foundational. They originated from an 
idea by Jan Knepper.


The unexpected utility of them explains why they haven't appeared in other 
languages (yet).


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Sean Kelly
On Mar 20, 2012, at 12:02 PM, Andrei Alexandrescu wrote:

> I plan to give a talk at Lang.NEXT 
> (http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the subject 
> above. There are a few features of D that turned out to be successful, in 
> spite of them being seemingly unimportant or diverging from related 
> consecrated approaches.
> 
> What are your faves? I have a few in mind, but wouldn't want to influence 
> answers.

strings as a built-in type, plus slicing.  There's a lot of great stuff in D, 
but that one's a game changer.

Re: Three Unlikely Successful Features of D

2012-03-20 Thread Andrei Alexandrescu

On 3/20/12 4:43 PM, Walter Bright wrote:

On 3/20/2012 12:02 PM, Andrei Alexandrescu wrote:

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Although array slices have been in D nearly since the beginning, I had
little idea they would become so darn useful and foundational. They
originated from an idea by Jan Knepper.

The unexpected utility of them explains why they haven't appeared in
other languages (yet).


Go has slices. (Unlike D slices, they include capacity.)

Andrei


Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 20/03/2012 22:36, Andrei Alexandrescu a écrit :

On 3/20/12 4:36 PM, deadalnix wrote:

We have the opportunity here to introduce in D the concept of aspect
oriented programming. This is HUGE. If you are afraid of the addition of
a functionnality to the language, don"t worry, you are not just adding a
functionnality, but a whole new paradigm.


I dabbled into AOP quite a bit, but I'm not all that jazzed about it.
It's been around for quite a while but it has little to show for it. At
the present it's rather unstructured and lacks a strong corpus of useful
idioms. I'd say - interesting, but I wouldn't bet the farm on it.

Andrei



Honestly, AOP is quite hard to use right now because of the lack of 
language support. This is a chicken and egg issue.


This is more and more used in Java, for good reasons. I think we will 
sooner or later talk about modern Java like we talk about modern C++ today.


You are well placed to know how template have been implemented in C++ 
simply for generic, and what comes out of it. And how awesome that is.


Many feature of the current D could have been implemented using AOP. I 
think that pretty much made the point. AOP is useful, and as a proof 
emulating it by compiler magic, when we cannot do without (synchronized, 
override, deprecated, as examples).


If AOP wasn't useful, theses feature wouldn't have been included in D at 
all. I'm suggesting templates, your answering « everything is a object, 
so let's do generic, I don't see the point of templates ».


Re: Three Unlikely Successful Features of D

2012-03-20 Thread F i L

Andrei Alexandrescu wrote:

What are your faves?


opDispatch was expectantly successful for me. I haven't seen it
often used in examples or others peoples code, but it allows for
some really awesome stuff.

For instance, who says D doesn't have multiple inheritance?

struct A { void a() { writeln("a"); } }
struct B { void b() { writeln("b"); } }
struct C {
   private A _a;
   private B _b;
   void opDispatch(string s)() {
 static if (__traits(hasMember, A, s))
mixin("_a."~s~"();");
   else if (__traits(hasMember, B, s))
mixin("_b."~s~"();");
   else static assert("Method not found.");
   }
}

void main() {
   auto c = C();
   c.a();
   c.b();
}

and similarly, "alias x this" is useful for pseudo hierarchy. The
only down-side to doing this is that Mono-D doesn't currently
parse the syntax.



Re: Proposal: user defined attributes

2012-03-20 Thread deadalnix

Le 18/03/2012 05:49, Walter Bright a écrit :

On 3/17/2012 9:12 PM, F i L wrote:

Walter Bright wrote:

I also do not get why per-instance attributes even exist, as I agree
that's
what fields are for.


Attributes are per-type (type properties, methods, etc), not
per-instance, and
only accessible (in C#) through type reflection (to my knowledge).
According to
http://msdn.microsoft.com/en-us/library/z919e8tw(v=vs.80).aspx
attribute objects
aren't constructed until reflected upon.


My impression is it is just obfuscation around a simple lazy
initialization pattern.

While I can see the abstraction usefulness of compile time attribute
metadata, I am having a hard time seeing what the gain is with runtime
attributes over more traditional techniques.


The attribute itself doesn't do anything at runtime. But the attribute 
should be able to modify what is qualified before it is compiled.


With that model it is much simpler, it open the door to AOP, and it 
allow us to implement as lib many feature that would have required 
compiler support before.


AS mentioned deprecated, synchronized and override (including the recent 
propagation of @safe, pure, nothrow that have made so much noise) could 
have been implemented with no compiler changes with a good 
@property/@annotation support. This tells us quite a lot about its 
usefulness and how much powerful it is.


Probably as powerful as templates are, and close to nuclear power 
combined with template.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread deadalnix

Le 20/03/2012 20:02, Andrei Alexandrescu a écrit :

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Thanks,

Andrei


To me it is pragma(msg, blabla) and slices.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Piotr Szturmaj

deadalnix wrote:

Le 20/03/2012 20:02, Andrei Alexandrescu a écrit :

I plan to give a talk at Lang.NEXT
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
subject above. There are a few features of D that turned out to be
successful, in spite of them being seemingly unimportant or diverging
from related consecrated approaches.

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Thanks,

Andrei


To me it is pragma(msg, blabla) and slices.


Yes, pragma(msg, ...) is very handy when debugging templates and generic 
code.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Andrej Mitrovic
On 3/20/12, Andrei Alexandrescu  wrote:
> What are your faves? I have a few in mind, but wouldn't want to
> influence answers.

Here's one: C compatibility.

Maybe it wasn't "unlikely" to be successful but most new languages
don't seem to care about C compatibility all that much. It's been a
boon for D though.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread David
I really love CTFE, even though it's sometimes pretty slow, maybe 
because I am axaggerating it …


One more thing are these slices, they really impressed me when working 
with pointers, float* v; v[x..y] = foo; ! awesome, no more memcpy


And of yourse opDispatch, I haven't used it a lot yet, just in gl3n for 
vector swizzling, I've seen glms swizzling ... I thought I can never do 
this in D, I made it in nearly no time and 10 lines of code!


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Andrej Mitrovic
On 3/20/12, Andrej Mitrovic  wrote:
> Here's one: C compatibility.

Now a real one: auto type inference. Could you possibly imagine what
the type name should be on the left-hand side?

? x = retro(stride(chain([1, 2], [3, 4]), 2));

Who knows. auto is great for these higher-level types.


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread James Miller
On 21 March 2012 03:22, alex  wrote:
>> I actually found myself using Mono-D for the nice completion and VisualD
>> for debugging, which is a total pain and probably more effort than its worth
>> :)
>
>
> Beta as hell ;D
>
> But nevertheless it'd be nice if there was a mentor for this
> project :)

A bit of a side note, but is there any way that some of this work
could be made more standalone, even if somebody else has to take up
the work to finish it and make it truly standalone. I personally can't
stand fully integrated environments, but I do like things like code
completion and the like, so it would be nice to be able to use these
features in, for example, vim. I don't know how feasible this is, but
it's worth mentioning.

--
James Miller


Re: Three Unlikely Successful Features of D

2012-03-20 Thread James Miller
On 21 March 2012 11:49, Andrej Mitrovic  wrote:
> Now a real one: auto type inference. Could you possibly imagine what
> the type name should be on the left-hand side?
>
> ? x = retro(stride(chain([1, 2], [3, 4]), 2));
>
> Who knows. auto is great for these higher-level types.

Also when dealing with complex parameterized types, so when I have a
function that gives me the type

foo!(bar!(int, 5), baz!string) I don't have to know that, I can just
use `auto` instead.

--
James Miller


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Nick Sabalausky
- Type inference
- alias
- foreach
- Everything about arrays/slices
- Built-in associative arrays that support nearly any type as a key
- Reference semantics for classes
- All the niceities of ctors compared with C++'s ctors
- Backtick strings
- Scope guards (And even finally: I head somewhere C++ doesn't even have 
finally: Is that true?!?)
- GC
- Name any of D's metaprogramming features

Many of those can seem like simple things, but I'd *hate* to have to get by 
without them. Heck, most of them I now take for granted.

Alias in particular is a much bigger deal than it seems since it's seemingly 
trivial but can be *incredibly* helpful with templates *and* with importing.

Actually, looking at this list, I'm now starting to get a little worried 
about an upcoming C++ project... No doubt I'll be trying to reinvent a lot 
of D in it. Probably in ugly hackish ways.




Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread Adam D. Ruppe

On Tuesday, 20 March 2012 at 22:52:13 UTC, James Miller wrote:

features in, for example, vim.


I use this script called supertab.vim that maps tab
to vim's control+p and control+n completition.

I find it works really well, and for virtually
everything too, not just code.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Jonathan M Davis
On Tuesday, March 20, 2012 14:02:15 Andrei Alexandrescu wrote:
> I plan to give a talk at Lang.NEXT
> (http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with the
> subject above. There are a few features of D that turned out to be
> successful, in spite of them being seemingly unimportant or diverging
> from related consecrated approaches.
> 
> What are your faves? I have a few in mind, but wouldn't want to
> influence answers.

I'd probably list

1. auto
2. static if
3. template constraints

But slices is also a good one. Thread-local by default is also one that could 
be listed, but I'm not sure that that's really "unlikely." Its benefits are 
quite obvious with little explanation. The only question is how well it works 
when trying to actually share data and communicate between threads, which is 
an area where we still need work (e.g. finishing implementing shared).

- Jonathan M Davis


Re: Three Unlikely Successful Features of D

2012-03-20 Thread H. S. Teoh
On Tue, Mar 20, 2012 at 06:58:31PM -0400, Nick Sabalausky wrote:
> - Type inference

Yeah I forgot about this one. Being able to write:

auto veryLongNamedObject = new VeryLongNamedClass(veryLongArguments);

is a big boon over C++ or Java's stuttering verbosity:

VeryLongNamedClass veryLongNamedObject = new 
VeryLongNamedClass(veryLongArguments);

Plus, it's immensely useful when dealing with Range templates... can you
imagine the horrifically long typenames you'd have to type you have to
explicitly specify the type of a long chain of functional expressions
involving 15+ std.algorithm and std.range templates?


> - alias

This, together with static ifs and templates, make for awesome tricks
involving templates that would've been an utter bear to pull off in C++.

template innerKeyType(T) {
static if (is(T U : U[K], K))
alias innerKeyType!K innerKeyType;
else
alias T innerKeyType;
}
innerKeyType!(int[string[char[byte]]]) innerKey;


[...]
> - Built-in associative arrays that support nearly any type as a key

This is actually quite buggy right now... but that's merely an
implementation issue. :-)  My new AA implementation, for example,
already correctly supports AA's with AA keys, which can be arbitrarily
nested. So you could have something like int[string[char[byte]]], and it
does lookups correctly based on the contents of the AA's you pass in as
key.


> - All the niceities of ctors compared with C++'s ctors

C++ ctors are a royal pain in the neck. I remember in the early days of
C++ when you can still call the base class ctor in the body of the
derived class ctor... nowadays you have to contort ctor code into a
horrible ugly mess just to get your ctor to do things right. Plus, the
C++ standard requires fields to be initialized in declaration order,
which is needlessly restrictive and basically makes ctors even more of a
pain.

I ended up using just stub ctors for a lot of my code, and doing the
actual initialization after the object is constructed. Which is very bad
OO style, I agree, but the pain of working with C++ ctors just pushes me
in the wrong direction, y'know?


> - Scope guards (And even finally: I head somewhere C++ doesn't even have 
> finally: Is that true?!?)

Yes, it's true. I don't know about C++11, but certainly the previous
standard has no finally clause, leading to horribly unmaintainable and
ugly code like:

Resource r = acquireResource();
try {
doSomethingDangerous();
} catch(...) {
r.release();
}
r.release();

(Yes, yes, I know, RAII and all that... which leads to inventing
ridiculous classes which make no sense in terms of OO, just to wrap
resource handles.)


> - GC

For all the warts the current GC has, the fact that D has a GC at all
makes things like array slicing possible, and *fast*, which leads to all
the other niceties of slicing.


> - Name any of D's metaprogramming features
[...]
> Alias in particular is a much bigger deal than it seems since it's
> seemingly trivial but can be *incredibly* helpful with templates *and*
> with importing.

Definitely. Using alias and static if in a recursive template is one of
the hallmarks of the awesomeness of D templates.


> Actually, looking at this list, I'm now starting to get a little worried 
> about an upcoming C++ project... No doubt I'll be trying to reinvent a lot 
> of D in it. Probably in ugly hackish ways.
[...]

#include "dmd.h"

;-)


T

-- 
Don't modify spaghetti code unless you can eat the consequences.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Walter Bright

On 3/20/2012 3:58 PM, Nick Sabalausky wrote:

Alias in particular is a much bigger deal than it seems since it's seemingly
trivial but can be *incredibly* helpful with templates *and* with importing.


I'd have to agree with this. I find it amazing that other languages entirely 
miss the boat on this.


C++ has a very crippled version of it in "template template parameters".


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Brad Roberts
On Tue, 20 Mar 2012, Don wrote:

> On 20.03.2012 21:33, Don wrote:
> > * pragma(msg) is something that's been used 100X as often as anticipated.
> 
> Note that because it was so successful, it was incorporated into static
> assert.

I wrote the original msg part of assert and static assert.  It wasn't 
because of pragma(msg), it was because I wanted a message with my asserts. 
:)

Later,
Brad


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Walter Bright

On 3/20/2012 2:51 PM, Andrei Alexandrescu wrote:

On 3/20/12 4:43 PM, Walter Bright wrote:

On 3/20/2012 12:02 PM, Andrei Alexandrescu wrote:

What are your faves? I have a few in mind, but wouldn't want to
influence answers.


Although array slices have been in D nearly since the beginning, I had
little idea they would become so darn useful and foundational. They
originated from an idea by Jan Knepper.

The unexpected utility of them explains why they haven't appeared in
other languages (yet).


Go has slices. (Unlike D slices, they include capacity.)


Can you, in Go:

1. slice a static string?
2. slice any arbitrary data?



Re: String mixin syntax sugar

2012-03-20 Thread Tove

On Tuesday, 20 March 2012 at 21:28:25 UTC, Jacob Carlborg wrote:

On 2012-03-20 19:25, Mantis wrote:

Hello,

since people discussed a lot about user-defined attributes 
recently,
I've been thinking about a way to implement it with a string 
mixins. The
problem with them is their syntax - it's far from what we want 
to use in
everyday job. I understand, they should be easily 
distinguished at use
site, but perhaps this may be accomplished in other ways as 
well. My

idea is to translate this kind of statements:

# identifier statement

into this:

mixin( identifier( q{ statement } ) );



I don't like it. I want real user defined attributes.


I think the idea has merit, string mixins together with CTFE 
parsing is the holy grail... because of the current syntax it's 
not really feasible to use on a per-member basis... but it is 
possible to use on a struct/class basis...


mixin(attr(q{struct Foo
{
  @NonSerialized int x;
  @NonSerialized int y;
  int z;
}}));

Please disregard my broken parser(it's just a proof of concept)
However, consider what we could do with the latest CTFE parser 
advances,

coupled with a tighter compiler/library callback interface.


import std.stdio;
import std.array;
import std.string;
import std.algorithm;

string attr(string complex_decl)
{
  string org_struct;
  string ser_struct;

  auto lines = splitLines(complex_decl);

  {
auto decl = split(stripLeft(lines[0]));

if(decl[0]=="struct")
{
  org_struct = decl[0] ~ " " ~ decl[1];
  ser_struct = decl[0] ~ " " ~ decl[1] ~ "_Serializable";
}
else
  return complex_decl;
  }

  foreach(line; lines[1..$])
  {
auto attr = findSplitAfter(stripLeft(line), "@NonSerialized 
");


if(attr[0]=="@NonSerialized ")
  org_struct ~= attr[1];
else
{
  org_struct ~= attr[1];
  ser_struct ~= attr[1];
}
  }

  return ser_struct ~ "\n" ~ org_struct;
}

mixin(attr(q{struct Foo
{
  @NonSerialized int x;
  @NonSerialized int y;
  int z;
}}));

void main()
{
  auto m = [ __traits(allMembers, Foo) ];
  writeln("Normal members of Foo:", m);

  auto n = [ __traits(allMembers, Foo_Serializable) ];
  writeln("Serializable members of Foo:", n);
}



Re: Proposal: user defined attributes

2012-03-20 Thread James Miller
Sorry for not quoting, but I'm not sure who to quote...

I think people are over-thinking this issue. Adam's initial proposal
was simply to be able to add compile-time checkable data to data
structures and functions. I think this works well at this level. As he
demonstrated, string mixins and ctfe only get you so far in this
instance.

The idea that in order to replicate this functionality, you need to
actually parse the D code to get what you want, is horrific. Relying
on naming conventions for functionality is horrendous, especially when
a simple @note(data1,data2=val) can solve all of the issues. And if
they're only compile time, then it can all be discarded when you get
to code-gen, and if you deliberately limit the scope of them, then you
aren't fostering the "new language features will solve all my
problems".

Looking at other languages is a good start for ideas, but ultimately
we need a D-flavoured solution, and using simple `__trait`-inspectable
annotations is a good way of doing it. As Teoh said, think of it as a
hook into Typeinfo, allowing the programmer to alter it at compile
time.

I don't care about Aspect-Oriented programming, or anything like that,
I just want to be able write:

@note(GET,POST)
auto myClassFunction(arg1, arg2, arg3) { ... }

without having to use templates that break inheritance, or doing
checks in the function for the request type, that could be handled in
a library. There's already a mechanism for seeing what attributes that
function has, so why can't I have some code that does this:

template hasAnnotation(alias data, string an) {
enum hasAnnotation = __traits(hasAnnotation, data, an);
}

(Or something, my template-fu leave something to be desired, not the
point though). It already looks like idiomatic D code.

Its not some big change that massively overhauls the way code is
written, the same way annotations in Java haven't meant that people
suddenly write Java completely differently. They do what they look
like they do, they add some extra information to the "thing" in
question that allow for some more advanced decision making.

Going back to the Web-based example, if I use an opDispatch system to
forward requests to the appropriate controller, I can use compile-time
reflection to generate checking code for the handlers, based , this
means that a simple annotation makes reading the function code much
simpler, since boiler-plate checking code has been removed, I can
implement a white-list based policy for request-type access, rather
than a blacklist that using isPost or isGet methods to check
in-handler. This is more secure, since if I forget to add /any/
annotations, then it wont receive /any/ requests. Lo and behold, I can
now have secure inter-controller communication without needing 1. a
naming convention, 2. an access control list or 3. boilerplate code.

I could go on a similar rant about serialization, but I think my point is made.

deadalnix is talking about being able to re-write language features in
terms of this system, but that's taking it too far, like a lot of
people, he wants D to be all thing to all people. The original idea
was to just to be able to add simple attributes to functions. Other
people sought to extend this unnecessarily, but everything else is
just templates, mixins and CTFE, nothing else.

The real discussion that need to be going on is: How far do notes
extend? (can you have arbitrary expressions annotated?) What data can
be packed into annotations? (Can i put any data into annotations, or
only internal types?) Syntax details, obviously using the @-syntax,
but specific naming, so @note, or @annotation? for example.
Scoping/Collision, I don't think this will be an issue, but if two
libraries are looking for the same annotation name, then there could
be some issues.

I think there is merit in having a Java/C# @, but I
don't think it is needed for D, everything that those annotations
cover can be done using CTFE and mixins, with the minor addition
above.

--
James Miller


Re: Mono-D@GSoC - Mentor needed

2012-03-20 Thread James Miller
On 21 March 2012 12:08, Adam D. Ruppe  wrote:
> On Tuesday, 20 March 2012 at 22:52:13 UTC, James Miller wrote:
>>
>> features in, for example, vim.
>
>
> I use this script called supertab.vim that maps tab
> to vim's control+p and control+n completition.
>
> I find it works really well, and for virtually
> everything too, not just code.

I've seen that, but its not very smart. I'm ok with that, but I've
been spoiled by clang_complete, which makes C++ development bearable,
but uses clang to give only valid options for the context. I'd love
something like that for D.

--
James Miller


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Geoffrey Biggs
On Mar 21, 2012, at 6:43 AM, Walter Bright wrote:

> On 3/20/2012 12:02 PM, Andrei Alexandrescu wrote:
>> What are your faves? I have a few in mind, but wouldn't want to influence 
>> answers.
> 
> Although array slices have been in D nearly since the beginning, I had little 
> idea they would become so darn useful and foundational. They originated from 
> an idea by Jan Knepper.
> 
> The unexpected utility of them explains why they haven't appeared in other 
> languages (yet).

Python has had slices since at least 2000. I can't imagine using Python without 
them, and I always miss them when using languages such as C++. D providing 
slices in a compiled, system programming language is a massive advantage over 
other such languages.

Geoff

Re: Proposal: user defined attributes

2012-03-20 Thread Adam D. Ruppe

On Wednesday, 21 March 2012 at 00:03:28 UTC, James Miller wrote:

template hasAnnotation(alias data, string an) {
enum hasAnnotation = __traits(hasAnnotation, data, an);
}


I'm actually thinking of identifying them by type. Types
are well established in the language - scoping, namespaces,
fields, and so on are all solved.

Querying them is solved too - we can look over a TypeTuple
and use is(typeof()) to get what we want.

(using types as names instead of strings is the idea that
came to me on my ride that prompted this thread - it is the
missing piece in what I wanted here. Strings can conflict,
but types already handle this.)


So you'd just very simply do:

struct MyAttribute { bool activated; }

// @note is just like doing internalTuple ~= MyAttribute(true)
// and MyAttribute is of course just a plain old struct
initializer
@note(MyAttribute(true)) int a;

To check it:

foreach(note; __traits(getNotes, member_a))
 static if(is(typeof(note) == MyAttribute) {
 // do what you want here, ignore types you don't know
 }


Of course, this is in a plain template. No implicit
stuff, no modifying the ast. This data only comes up
when you ask for it, and you ask for it in a plain
old mixin template or something like that - existing
language features.


How far do notes extend?


I'd only put it on declarations (variables,
classes, structs, enums, members, and function
parameters.)


What data can be packed into annotations?


Being able to use custom types is an
important part of my idea here.


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Adam D. Ruppe

What you might want to do is look back at
early ng posts about features and see which
ones were met with "meh", but universally
considered to rok now.

Asking for stuff now will be hard to be
unbiased on the surprise issue.


If my memory serves, a few things that were
"meh" when announced but that rok now are:

1) enum. I remember an argument over if we
should call it invariant, manifest, or the
relatively unpopular enum keyword, but I
don't recall people at the time expecting
it to be as useful as it is now.

The argument was between

manifest MY_VALUE = 1;
and
enum MY_VALUE = 1;

without thoughts along the line of:

template octal(...) {
alias octalImpl(t) octal;
}

or most the other stuff we use ctfe with now.


(Speaking of octal, I remember that being dismisses
as a "hack" by some members too. Now, it looks like
that pattern is catching on for user defined literals,
and it rox.)


My memory might be bad, but looking at some old posts
could confirm if the "unlikely success" label is warranted.




2) Leaving the parenthesis off of simple template
instantiations is something I was against early on,
and now I love it.

IIRC, you wanted to use a different symbol entirely,
and leaving the parens off was a compromise between
the radical Unicode character proposal and Walter's
conservative parenthesis.



This is a really small change. At the time, it seemed
like it would be stupid and useless.



But, would templates be as popular now if we didn't
make this change?

auto a = to!(int)("10");

vs

auto a = to!int("10");



to!int feels like one word, unlike to!(int)().
Who needs atoi when we can say to!int?


Decls too: Appender!int, etc. The popularity of
this in phobos and outside speaks to a success
I didn't expect.



3) My mind is coming up blank on a third newsgroup argument
over an awesome feature we use now. But, something I
am often amazed about is how cool structs are.

When you say "struct", I used to think of "whoo a collection
of vars, big deal".

But, now, with D2, when you say "struct", I think "fully
customizable powerhouse".

(even coming from C++, where much of this can be done, D's
structs are still a little mindblowing in comparison.)


Re: Changing the name of the language?

2012-03-20 Thread Chris Dahl
A while back I put this search page together.  I killed the old
domain, but have set the site up on a new domain.  In short, it is a
custom Google search of D related web sites.  The list of sites is
old, so if I need to add some, just let me know.  I would prefer to
base urls that are strictly D related to keep the results 'pure'.

http://crdahl.com/d/

--Chris

On Fri, Mar 16, 2012 at 4:48 PM, Manu  wrote:
> On 16 March 2012 23:29, Nick Sabalausky  wrote:
>>
>> "Manu"  wrote in message
>> news:mailman.778.1331920080.4860.digitalmar...@puremagic.com...
>> > On 16 March 2012 03:23, ixid  wrote:
>> >
>> >> D is a very poor name for a language. I appreciate it's late in the day
>> >> for this and that it has probably been discussed before (not that I
>> >> could
>> >> find such a discussion with Google which relates to my point). Although
>> >> the
>> >> results for D are fine when googling for things like "D tutorial", more
>> >> obscure terms are hard to find because "d" is so commonly used as a
>> >> variable name. Searchability is important though I understand that this
>> >> might be seen as a trivial point, it is a major human factor. The
>> >> language
>> >> would be far better off with a 3 to 5 letter identifier. It will
>> >> succeed
>> >> or
>> >> fail for other reasons but an easily searchable name would help. Dlang
>> >> as
>> >> the search term isn't good enough because it's not actually the
>> >> language's
>> >> name, people don't use it that much when referring to D, nor do they
>> >> usually use D2.
>> >>
>> >
>> > Do you have trouble googling for C? I find that D related results are
>> > currently only around 4-5 down the google results list, and it'll only
>> > get
>> > higher as it get's more popular.
>> > C searches are fine... I am often surprised just how much influence
>> > programmers seem to have on search results placement.
>> >
>>
>> Google search results are different for everybody. They tailor the search
>> results they give you based on your past search (and clickthrough)
>> history.
>> If you're doing a lot of programmer searches, they're going to start
>> giving
>> you more programmer results.
>
>
> Perfect! So no problem then! Use D for a couple of months, and your search
> results will sort themselves out :)


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Adam D. Ruppe

On Wednesday, 21 March 2012 at 00:53:19 UTC, Adam D. Ruppe wrote:

template octal(...) {
alias octalImpl(t) octal;
}


LOL, I was bloviating about "enum" and ended up
using "alias" here.

alias rox too (which is a bit amazing, considering how
simple it is), but I should have said:

enum octal = octalImpl(t);



Re: Three Unlikely Successful Features of D

2012-03-20 Thread bearophile
There are a few features of D that turned out to be successful, 
in spite of them being seemingly unimportant or diverging from 
related consecrated approaches.


What are your faves?


After thinking some time about this, I can't find one of them :-)
I see many useful/successful features in D, but none of them
seemed unimportant at first to me.

Maybe I am just strange, but very little of syntax and semantics
of a language is unimportant. In languages even unused features
(C trigraphs?) sometimes bite your bum, so they become important,
with negative value.

Bye,
bearophile


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Nick Sabalausky
"Walter Bright"  wrote in message 
news:jkb2v6$kq4$2...@digitalmars.com...
> On 3/20/2012 3:58 PM, Nick Sabalausky wrote:
>> Alias in particular is a much bigger deal than it seems since it's 
>> seemingly
>> trivial but can be *incredibly* helpful with templates *and* with 
>> importing.
>
> I'd have to agree with this. I find it amazing that other languages 
> entirely miss the boat on this.
>
> C++ has a very crippled version of it in "template template parameters".

I particulary love how D's alias is used to disambiguate symbol conflicts. 
Brilliant approach. I know I wouldn't have thought of it.




Re: String mixin syntax sugar

2012-03-20 Thread d coder
> Use template mixins? At least in struct/class area that catches the most
> attention it should work perfectly.


I believe template mixins are equally ugly. Don't you have to explicitly
specify that you are invoking a mixin? Or am I missing something here.

Regards
- Puneet


Re: Three Unlikely Successful Features of D

2012-03-20 Thread Rene Zwanenburg
On Tuesday, 20 March 2012 at 19:02:16 UTC, Andrei Alexandrescu 
wrote:
I plan to give a talk at Lang.NEXT 
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) with 
the subject above. There are a few features of D that turned 
out to be successful, in spite of them being seemingly 
unimportant or diverging from related consecrated approaches.


What are your faves? I have a few in mind, but wouldn't want to 
influence answers.



Thanks,

Andrei


I've seen most of D's cool features mentioned, but I believe 
nobody mentioned mixins yet. Mixins are messy to maintain, but 
together with CTFE they can be used to create some really neat 
code if used properly.


One of the first things I wrote while learning D is a vector 
class. In GLSL vectors can be 'swizzled', for example:

vec3(1, 2, 3).zyx == vec3(3, 2, 1);
Swizzles are often useful in graphics or physics code. I don't 
know of any non-shading language that allows me to use swizzle 
syntax. As the following code shows, it's quite easy to do in D:



module main;

import std.stdio;
import std.process;
import std.conv;


int main(string[] argv) {
  alias Vec!4 Vec4;
  Vec4 v = Vec4(1, 2, 3, 4);

  writeln(v.bgra); // Prints Vec!(4)([3, 2, 1, 4])
  writeln(v.rg); // Prints Vec!(2)([1, 2])

  return 0;
}

private immutable (char[][]) elementNames = [['x', 'y', 'z', 
'w'], ['r', 'g', 'b', 'a'], ['s', 't', 'p', 'q']];


struct Vec(size_t size) {
  alias size Size;

  mixin(generateConstructor(Size));

  mixin(generateProperties(Size));

  auto opDispatch(string s)() {
mixin(generateSwizzle(s));
  }

  float v[Size];
}

private string generateConstructor(size_t size) {
  string constructorParams;
  string constructorBody;

  foreach(i; 0..size) {
string paramName = "v" ~ to!string(i);
constructorParams ~= "float " ~ paramName ~ "=0,";
constructorBody ~= "v[" ~ to!string(i) ~ "] = " ~ paramName ~ 
";";

  }

  return "this(" ~ constructorParams[0..$-1] ~ "){" ~ 
constructorBody ~ "}";

}

private string generateProperties(size_t size) {
  string props;

  foreach(names; elementNames) {
foreach(i, name; names[0..size]) {
  props ~= "@property float " ~ name ~ "() const { return v[" 
~ to!string(i) ~ "]; }";
  props ~= "@property void " ~ name ~ "(float f) { v[" ~ 
to!string(i) ~ "] = f; }";

}
  }

  return props;
}

private string generateSwizzle(string elements) {
  string swizzleImpl = "return Vec!" ~ to!string(elements.length) 
~ "(";


  foreach(e; elements) {
swizzleImpl ~= e ~ ",";
  }

  return swizzleImpl[0..$-1] ~ ");";
}



Re: Three Unlikely Successful Features of D

2012-03-20 Thread Rene Zwanenburg

And there goes the formatting, here's a pastebin version:
http://pastebin.com/dHdiG0ce

On Wednesday, 21 March 2012 at 01:41:27 UTC, Rene Zwanenburg 
wrote:
On Tuesday, 20 March 2012 at 19:02:16 UTC, Andrei Alexandrescu 
wrote:
I plan to give a talk at Lang.NEXT 
(http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012) 
with the subject above. There are a few features of D that 
turned out to be successful, in spite of them being seemingly 
unimportant or diverging from related consecrated approaches.


What are your faves? I have a few in mind, but wouldn't want 
to influence answers.



Thanks,

Andrei


I've seen most of D's cool features mentioned, but I believe 
nobody mentioned mixins yet. Mixins are messy to maintain, but 
together with CTFE they can be used to create some really neat 
code if used properly.


One of the first things I wrote while learning D is a vector 
class. In GLSL vectors can be 'swizzled', for example:

vec3(1, 2, 3).zyx == vec3(3, 2, 1);
Swizzles are often useful in graphics or physics code. I don't 
know of any non-shading language that allows me to use swizzle 
syntax. As the following code shows, it's quite easy to do in D:



module main;

import std.stdio;
import std.process;
import std.conv;


int main(string[] argv) {
  alias Vec!4 Vec4;
  Vec4 v = Vec4(1, 2, 3, 4);

  writeln(v.bgra); // Prints Vec!(4)([3, 2, 1, 4])
  writeln(v.rg); // Prints Vec!(2)([1, 2])

  return 0;
}

private immutable (char[][]) elementNames = [['x', 'y', 'z', 
'w'], ['r', 'g', 'b', 'a'], ['s', 't', 'p', 'q']];


struct Vec(size_t size) {
  alias size Size;

  mixin(generateConstructor(Size));

  mixin(generateProperties(Size));

  auto opDispatch(string s)() {
mixin(generateSwizzle(s));
  }

  float v[Size];
}

private string generateConstructor(size_t size) {
  string constructorParams;
  string constructorBody;

  foreach(i; 0..size) {
string paramName = "v" ~ to!string(i);
constructorParams ~= "float " ~ paramName ~ "=0,";
constructorBody ~= "v[" ~ to!string(i) ~ "] = " ~ paramName 
~ ";";

  }

  return "this(" ~ constructorParams[0..$-1] ~ "){" ~ 
constructorBody ~ "}";

}

private string generateProperties(size_t size) {
  string props;

  foreach(names; elementNames) {
foreach(i, name; names[0..size]) {
  props ~= "@property float " ~ name ~ "() const { return 
v[" ~ to!string(i) ~ "]; }";
  props ~= "@property void " ~ name ~ "(float f) { v[" ~ 
to!string(i) ~ "] = f; }";

}
  }

  return props;
}

private string generateSwizzle(string elements) {
  string swizzleImpl = "return Vec!" ~ 
to!string(elements.length) ~ "(";


  foreach(e; elements) {
swizzleImpl ~= e ~ ",";
  }

  return swizzleImpl[0..$-1] ~ ");";
}





Re: Three Unlikely Successful Features of D

2012-03-20 Thread Nick Sabalausky
"H. S. Teoh"  wrote in message 
news:mailman.933.1332286692.4860.digitalmar...@puremagic.com...
> On Tue, Mar 20, 2012 at 06:58:31PM -0400, Nick Sabalausky wrote:
>> - Type inference
>
> Yeah I forgot about this one. Being able to write:
>
> auto veryLongNamedObject = new VeryLongNamedClass(veryLongArguments);
>
> is a big boon over C++ or Java's stuttering verbosity:
>
> VeryLongNamedClass veryLongNamedObject = new 
> VeryLongNamedClass(veryLongArguments);
>
> Plus, it's immensely useful when dealing with Range templates... can you
> imagine the horrifically long typenames you'd have to type you have to
> explicitly specify the type of a long chain of functional expressions
> involving 15+ std.algorithm and std.range templates?
>
>
>> - alias
>
> This, together with static ifs and templates, make for awesome tricks
> involving templates that would've been an utter bear to pull off in C++.
>
> template innerKeyType(T) {
> static if (is(T U : U[K], K))
> alias innerKeyType!K innerKeyType;
> else
> alias T innerKeyType;
> }
> innerKeyType!(int[string[char[byte]]]) innerKey;
>
>

Yea, C++'s STL *needs* type inference and alias. At least the new spec has 
"auto". Don't know about other stuff though.


> [...]
>> - Built-in associative arrays that support nearly any type as a key
>
> This is actually quite buggy right now... but that's merely an
> implementation issue. :-)

Heck, I just love that I can use a string, or an int, or make my own struct 
work as a key, etc. Actually, over just the last 24 hours I've been making a 
lot of use of AAs with int keys. (AA's make it *so* much easier to avoid 
poor time complexity in a lot of things.)

Many langauges (like Haxe, for example) will have hashtables, and may even 
have them templated (or otherwise generic) on *value*, but the keys will be 
string-only. Which is still very useful, but it also misses out on many 
other use-cases.

> My new AA implementation, for example,
> already correctly supports AA's with AA keys, which can be arbitrarily
> nested. So you could have something like int[string[char[byte]]], and it
> does lookups correctly based on the contents of the AA's you pass in as
> key.
>

Crazy stuff :)

Actually I've been meaning to ask what the main benefits of your new AA 
implementation are. I know there's the benefit of just simply having it be 
implemented in the library. And you mention using AA's as AA keys here. Are 
there any other, umm, "key" points?

>
>> - All the niceities of ctors compared with C++'s ctors
>
> C++ ctors are a royal pain in the neck. I remember in the early days of
> C++ when you can still call the base class ctor in the body of the
> derived class ctor... nowadays you have to contort ctor code into a
> horrible ugly mess just to get your ctor to do things right. Plus, the
> C++ standard requires fields to be initialized in declaration order,
> which is needlessly restrictive and basically makes ctors even more of a
> pain.
>
> I ended up using just stub ctors for a lot of my code, and doing the
> actual initialization after the object is constructed. Which is very bad
> OO style, I agree, but the pain of working with C++ ctors just pushes me
> in the wrong direction, y'know?
>

Yea, that's what I've been planning on doing with the C++ stuff I have 
coming up. Don't even want to bother with C++'s ctor limitations. Just make 
an init() member and be done with it. Actually, that seems to be turning 
into more and more of a common C++ idiom though, from what (little) I've 
seen.

>
>> - Scope guards (And even finally: I head somewhere C++ doesn't even have
>> finally: Is that true?!?)
>
> Yes, it's true. I don't know about C++11, but certainly the previous
> standard has no finally clause, leading to horribly unmaintainable and
> ugly code like:
>
> Resource r = acquireResource();
> try {
> doSomethingDangerous();
> } catch(...) {
> r.release();
> }
> r.release();
>

Haxe also lacks finally! Which I always found rediculous. So yea, I'm 
intimately familiar with that idiom. I've used it myself far more than I 
would like.

And even *that* still doesn't work if you don't catch *every* exception (and 
then rethrow the ones you don't care about? Ick!). I've seen C++ programmers 
swear off exceptions because of this, and I can't blame them at all. 
Exception systems *need* a finally.

> (Yes, yes, I know, RAII and all that... which leads to inventing
> ridiculous classes which make no sense in terms of OO, just to wrap
> resource handles.)
>

Yea, if I wanted to write Java-style code, I'd just use Java (and at least 
not have to deal with header files).

>
>> - GC
>
> For all the warts the current GC has, the fact that D has a GC at all
> makes things like array slicing possible, and *fast*, which leads to all
> the other niceties of slicing.
>

I used to do indie game dev in C/C++ and I feel downright spoiled now with 
tossing in a "new" whenever appropriate and not have to worry about cleanup 
(and even that wouldn't be *too* b

Re: Three Unlikely Successful Features of D

2012-03-20 Thread Nick Sabalausky
"Nick Sabalausky"  wrote in message 
news:jkbcoh$15k3$1...@digitalmars.com...
>
> And even *that* still doesn't work if you don't catch *every* exception 
> (and then rethrow the ones you don't care about? Ick!).
>

And AIUI, even *that* doesn't work in C++ because, IIRC, the class hierarchy 
doesn't have *any* common root. So what, are you going to have a catch block 
for *every* class type in your program? Heck, even *that* might be feasable 
in D thanks to the compile-time reflection and quality metaprogramming, but 
with C++, you're SOL.




Re: Three Unlikely Successful Features of D

2012-03-20 Thread Nick Sabalausky
"Adam D. Ruppe"  wrote in message 
news:txwnbkafemkurcqje...@forum.dlang.org...
>
> 2) Leaving the parenthesis off of simple template
> instantiations is something I was against early on,
> and now I love it.
>
> IIRC, you wanted to use a different symbol entirely,
> and leaving the parens off was a compromise between
> the radical Unicode character proposal and Walter's
> conservative parenthesis.
>
> This is a really small change. At the time, it seemed
> like it would be stupid and useless.
>

Yea, that's a good one. I seem to remember initally thinking that it felt 
sloppy, but I was otherwise relatively indifferent about it. But now I 
absolutely love it...sooo much.

> But, would templates be as popular now if we didn't
> make this change?
>
> auto a = to!(int)("10");
>
> vs
>
> auto a = to!int("10");
>

Exactly.

Ooh, nested functions and closures are another good one (or two). I get so 
much use of of those.

Speaking of, here's a good one (IMO): The syntax for delegate types (as 
opposed to C's crude function pointer syntax). A small change, but really 
helps open up the world of first-class functions, even just by itself.




Re: Three Unlikely Successful Features of D

2012-03-20 Thread Andrej Mitrovic
On 3/21/12, H. S. Teoh  wrote:
> This is actually quite buggy right now... but that's merely an
> implementation issue. :-)  My new AA implementation..

You know it would be sweet if we got map types as well instead of
using void[0][Key] hacks. :)


  1   2   >