Go and generic programming on reddit, also touches on D

Peter Alexander peter.alexander.au at gmail.com
Sun Sep 18 10:16:34 PDT 2011


On 18/09/11 5:08 PM, Timon Gehr wrote:
> On 09/18/2011 03:48 AM, Andrei Alexandrescu wrote:
>> Quite interesting.
>>
>> http://www.reddit.com/r/programming/comments/kikut/think_in_go_gos_alternative_to_the/
>>
>>
>>
>
> 2 hours ago, Andrei Alexandrescu wrote:
>  > The problem is, Vector was just an example of a multitude of
> containers. The huge problem with slices is dogfood-related - they are >
> "magic" because the language features proposed to programmers were not
> enough for expressing a simple abstraction. Reserving "special" features
> for the language is a terrible way to go about programming language design.
>
> Don't D arrays do a similar thing? They are not templates, yet work with
> generic element types.

Yes. As I understand, Andrei prefers things in libraries and Walter 
prefers things built in to the compiler (obviously an 
oversimplification, but I believe that's the general way they 'lean').

There's advantages to both. Being implementable in a library means that 
they can easily be swapped out or modified to work with other code, but 
being built-in ("magic", as Andrei puts it) means that the compiler has 
greater awareness of them and can do better optimizations, give better 
errors etc.

Of course, there are ways of extending the language to provide better 
errors and allow better optimizations (e.g. 'pure' in D), but as a 
purely practical matter, it's easier if they are just built-in.


> Afaics, improving the language to the point were dynamic array-like
> structures could be implemented in the library without resulting in a
> bloated executable would be quite involved.

I don't think you'd get much bloat in D by implementing dynamic arrays 
with templates. Remember, the built-in arrays *are* mostly implemented 
in D: https://github.com/D-Programming-Language/druntime/tree/master/src/rt


More information about the Digitalmars-d mailing list