equivariant functions

Sean Kelly sean at invisibleduck.org
Wed Oct 15 21:16:31 PDT 2008


Andrei Alexandrescu wrote:
> Benji Smith wrote:
>>
>> For me, one of the main perks of the other proposal was less "const" 
>> litter all over the code, and yet with stronger const safety.
> 
> You'll be glad then to learn that "in" means const at least in D2:
> 
> void foo(in char[] s); // same as foo(const(char)[] s)

This has been an absolute godsend for writing D1->D2 portable code.  So 
much so that I'm not sure I'd have even attempted it without this feature.

>> Driving a car with a manual transmission requires a more detailed 
>> mental model than driving an automatic. Maybe the manual transmission 
>> offers other advantages, but ease-of-use is not one of them.
> 
> Hmmmm. I'd compare the wild west when everything is mutable at any time 
> much more with an unwieldy manual-transmission car that leaks oil and 
> blows a gasket every so often. That's congruent with my earlier point: 
> you think const is more trouble for you. IMHO it's exactly, but I mean 
> exactly, the opposite.

I think being const-free results in more succinct code, and I'd argue 
it's more easily readable as well, because of the syntactic dissonance 
that the const labels introduce.  But your wild west analogy is an apt 
one, because it makes data protection largely a matter of convention, 
while at least the switches and knobs of the manual transmission car 
provide a means to ensure safety at the design level.  I think one could 
argue the benefits of each.

>> I actually plan on giving D2 a spin as soon as a compatible version of 
>> Tango is available.
> [snip]
>> But the const system just smells bad to me. I've tried to enumerate my 
>> reasons, and maybe switching to D2 will change my mind. But right now, 
>> I'm calling it as I see it. You asked for feedback, and you got it!!
> 
> Now I'm not sure how to sugarcoat or spin positively or put nicely what 
> I'm going to say. Let me try (actually it took me a couple of minutes to 
> figure out a formula).
> 
> At least to me, "feedback" implies a closed-loop system. Stuff happens, 
> has consequences, the consequences are observed, and information is 
> "fed" "back" to the system. In our case, I'd say that using const is an 
> absolute prerequisite for feedback to be taken seriously, particularly 
> when it's as informal as "just smells bad to me". Otherwise I think 
> "candid opinion" is the best way I can put it. Sorry.

I've been a fairly vocal opponent of the const system in the past, 
largely because I'm not terribly happy with the complexity it can 
introduce in user code.  However, I think it's important to note that I 
said /can/ rather than /will/.  A great deal still comes down to 
programmer skill, and the rest, hopefully, will be addressed by 
discussions such as this.


Sean



More information about the Digitalmars-d mailing list