Super-dee-duper D features (possible resolution?)

kris foo at bar.com
Mon Feb 12 11:16:19 PST 2007


Walter Bright wrote:
> kris wrote:
> 
>> Walter Bright wrote:
>>
>>> 3) Less code == more productivity, less bugs. I don't mean 
>>> gratuitously less code, I mean less code in the sense that one can 
>>> write directly what one means, rather than a lot of tedious bother. 
>>> For example, if I want to visit each element in an array:
>>>
>>>     foreach(v; e)
>>>     {...}
>>>
>>> is more direct than:
>>>
>>>     for (size_t i = 0; i < sizeof(e)/sizeof(e[0]); i++)
>>>     { T v = e[i];
>>>      ... }
>>>
>>
>> Yep, that's great! One of the reasons I like D so much, along with 
>> array slicing.
> 
> 
> The C++ version is even *worse* than the C one (for wordiness bother):
> 
>     for (std::vector<T>::const_iterator i = e.begin(); i != e.end(); i++)
>     {  T v = *i;
>     ... }
> 
> I mean I know the reasons for every bit of the syntax there, and in 
> isolation they make sense, but put it all together and it seems to go 
> backwards.

Not so hard to argue that example is actually C--  :)


> 
> 
>>> 5) Lisp gets things right, according to what I've read from heavy 
>>> Lisp users, by being a language that can be modified on the fly to 
>>> suit the task at hand, in other words, by having a customizable 
>>> language one can achieve dramatic productivity gains.
>>
>>
>> Yet, Lisp will always remain a niche language. You have to wonder why.
> 
> 
> I'm pretty sure it's the syntax.

Interestingly, I used to have lunch with one of the original designers. 
My understanding was that's not how it was viewed from the 'inside'.


> 
> 
>>> 7) A lot of companies have outlawed C++ templates, and for good 
>>> reason. I believe that is not because templates are inherently bad. I 
>>> think that C++ templates are a deeply flawed because they were 
>>> ***never designed for the purpose to which they were put***.
>>
>>
>> Agreed. But the issue is not about how badly they're flawed. Instead, 
>> it's the non-standard "language" problem. The MyDSL problem :)
> 
> 
> I disagree with that. When you write a program using classes and 
> functions, you *are* creating your own language. Classes are your custom 
> types, and functions are your custom operators.

So, the heart of the matter; the one that causes C++ Templates to be 
outlawed; is perhaps it's /potential/ for abuse? More on this later ...

> 
> 
>>> 8) I've never been able to create usable C++ templates. Notice that 
>>> the DMD front end (in C++) doesn't use a single template. I know how 
>>> they work (in intimate detail) but I still can't use them.
>>
>>
>> Same here.
> 
> 
> But I have been able to create usable D templates <g>.

Me too.


> 
> 
>> I also look at some D templates for ages, and still can't figure out 
>> just how they work. Don Clugston is known around here as the Template 
>> Ninja -- the very name itself shouts out "Here Dwell Demons!" :-D
> 
> 
> The very fact that Don's called the Template Ninja is a problem - after 
> all, there is no "function ninja", no "typedef ninja", no "+ ninja". 
> It's a sign that templates are still not easy enough to use.

Glad that you recognize the latent concern.

> 
> It's like Paul Mensonidas being recognized as the "World's Leading 
> Expert on the C Preprocessor." Obviously, something is seriously wrong 
> with the preprocessor if there's an ecological niche for a world's 
> leading expert on it. (By the way, Paul is a very nice fellow and has 
> been kind enough to help me iron out several subtle bugs in the DMC++ 
> preprocessor. As long as we're saddled with that preprocessor spec, I'm 
> glad there is a Paul to help!)
> 

Right :)


> 
>>> 12) Take a look at what Kirk McDonald is doing with Pyd. He needs all 
>>> this stuff to make it slicker than oil on ground steel. He's on the 
>>> bleeding edge of stuff D needs to *make* pedestrian.
>>
>>
>> Certainly :)
>>
>> What Kirk has been doing (much awesometude there) is one of those 
>> things that fit into the "narrow focus" or "speciality" field that 
>> /can/ benefit in some manner. But it's a black-box. When it works, 
>> nobody will fuss with the insides unless they /really/ have to. That's 
>> not how most commerical software is done today, regardless of all the 
>> efforts to make it more like circuit-design.
> 
> 
> Even if D fails to make metaprogramming easy for average joe coders to 
> use, if it still can be used by experts to create useful black box code 
> like Pyd, then it is worthwhile. After all, even though trig functions 
> are very hard to write, they are easily used by joe coders as black box 
> components without any problems.


I think this is where you've perhaps been missing my point? Let me try 
an example -- hrm -- you're into cars, right?

Ok ... I have a sleek and powerful car; rebuilt from the ground up. 
Dyno's at around 650ft/lbs & 625bhp at the wheels, with full boost at 
~half the rpm range.  This is something that can get you into serious 
trouble rather quickly, if you fail to treat it with utmost respect. 
Because of this, I have a little switch in the glovebox: it changes the 
fuel-map, the timing map, and drops max-boost from 30psi to 7psi. I call 
it the "valet switch" -- it's used for that purpose and for inclement 
weather.

Going back to the original point about pedestrian-code, costs and so on: 
these shops who outlaw C++ templates have to, in effect, "police" their 
own codebase. That's no easy task. So here's a suggestion that you may 
be able to do something with ...

If you were to enable a "valet switch" in the compiler, it wouldn't be 
so hard to present that as an outright /benefit/ for dev-shops <g>. In 
other words, the dev-shop would have a means to enforce whatever policy 
they choose, while the compiler acts as the arbitrator. "Mainstream code 
has to compile with the valet switch" sort of thing.

Of course, the trick would be to find a reasonable tripping point where 
the abuse-potential starts to require some serious respect; like the 
vehicle noted above. However, it could be done; perhaps with a 'level'? 
I understand you're not crazy about switches and so on, but please 
consider it ... it could potentially be responsible for alleviating 
adoption fears. That's a pretty darned powerful switch.

I hope this clarifies that I'm not pushing for less goodies; I'm pushing 
for responsible usage of them. Enabling that would surely garner D some 
respect from those people ultimately responsible for "letting" it 
through the door.

- Kris



More information about the Digitalmars-d mailing list