TypeFunction example: ImplictConvTargets

claptrap clap at trap.com
Wed Oct 7 08:32:14 UTC 2020


On Wednesday, 7 October 2020 at 02:10:03 UTC, Daniel K wrote:
> On Wednesday, 7 October 2020 at 01:07:17 UTC, claptrap wrote:
>> On Tuesday, 6 October 2020 at 23:39:24 UTC, H. S. Teoh wrote:
>>> On Tue, Oct 06, 2020 at 11:16:47PM +0000, claptrap via 
>>> Digitalmars-d wrote: [...]
>>>>
>>> I would write it like this:
>>>
>>> 	int[] vals = [4,7,28,23,585,73,12];
>>>
>>> 	int[] getMultiplesOf(int i)
>>> 	{
>>> 	    return vals.filter!(v => (v % i) == 0).array;
>>> 	}
>>>
>>> One line vs. 4, even more concise. ;-)
>>
>> The point is to show language not library.
>>
>>
>>> Thing is, what someone finds intuitive or not, is a pretty 
>>> subjective matter, and depends on what programming style he's 
>>> familiar with and/or prefers.  What a C programmer finds 
>>> readable and obvious may be needlessly arcane to a Java 
>>> programmer, and what an APL programmer finds totally obvious 
>>> may be completely impenetrable to anyone else. :-P
>>
>> We're not looking for "is this intuitive to Java programmers", 
>> we're asking is this intuitive to D programmers, so if they 
>> already know D then *you have context* in which to judge 
>> whether it's intuitive or not. And "It's just like regular D 
>> code but with types" pretty much hits the nail on the head as 
>> fair as intuitive goes.
>
> If recursive templates are not intuitive to you, perhaps you 
> still have more D to learn, to become this mythical "D 
> programmer".

There's 2 or 3 times more stuff going on in the template version. 
Two function calls, more things passed around, array or alias seq 
slicing, appending, more ifs and elses, etc...

Is less intuitive because it's an algorithm that makes more sense 
as iteration, so you have to bend it all out of shape to make it 
recursive.

I like code as simple as possible, that isnt it.


> My 16 lines of template essentially compiled in D for at least 
> the past 10 years.
> It literally is "regular D code".

By regular D code, I mean non-teplate / meta code. I thought that 
was obvious.


> If recursion and declarative programming isn't intuitive to you 
> in general, then perhaps that's not D's problem at all.

Recursion is fine, there's algorithms that make more sense that 
way, this isnt one of them. Thats the point. You're forcing 
everything in meta land to be recursive.

If all you have is a hammer....

And if all you've had is a hammer for 10 years, you start to 
doubt the existing of screws.




More information about the Digitalmars-d mailing list