Imperative templates

Robert Clipsham robert at octarineparrot.com
Sun Jul 17 04:13:38 PDT 2011


On 17/07/2011 01:36, Timon Gehr wrote:
> On Saturday 16 July 2011 16:58:25 Robert Clipsham wrote:
>> So in several presentations given about D that I've seen there's a list
>> of supported paradigms given which looks something like this:
>>    // List
>> (That list from
>> http://assets.en.oreilly.com/1/event/45/The%20D%20Programming%20Language%20P
>> resentation.pdf ). But if this is the case, why do we not get this choice
>> for template programming?
>>
>> Currently templates have to be written in a functional manner, which is
>> incredibly difficult if you're used to imperative programming, and I've
>> found the code that it leads to is really difficult to maintain, even if
>> it's well commented (this may not be the case for folk that are well
>> versed in functional programming).
>> // Code
>> Which is a lot more code, and a lot harder to understand at a quick
>> glance. It gets even worse if you want to do something more
>> complicated[1][2].
>>
>> I don't think my example is the best example for a possible syntax, but
>> that could be worked on. What does anyone else think?
>>
>> [1] https://github.com/mrmonday/dmd/blob/js/dsrc/bind/util.d#L134
>> [2]
>> https://github.com/mrmonday/serenity/blob/master/serenity/persister/Sqlite.d
>> #L126
>
> You can actually compute most things in an imperative way using this idiom:
>
> enum x = {/*imperative code to compute value of x*/}();
>
> When TypeTuples are involved, you can get away with mostly imperative code and
> careful workarounds for bugs and limitations of the compiler:

Have these been reported?

> // Code here

This is cool, if hacky! What's it like performance wise compared to the 
fully functional version?

> But usually, well written functional code is both more concise and better
> maintainable than imperative code.

Well that's debatable ;)

> Cheers,
> -Timon

-- 
Robert
http://octarineparrot.com/


More information about the Digitalmars-d mailing list