Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1

bachmeier no at spam.net
Tue Mar 16 16:55:47 UTC 2021


On Tuesday, 16 March 2021 at 16:08:46 UTC, H. S. Teoh wrote:
> On Tue, Mar 16, 2021 at 03:18:49PM +0000, bachmeier via 
> Digitalmars-d wrote:
>> On Monday, 15 March 2021 at 17:18:19 UTC, H. S. Teoh wrote:
>> 
>> > Although there are definitely cases for which it's actually 
>> > useful, the problems it brings along make it of questionable 
>> > value as a general language feature.  I'd also be in favor 
>> > of getting rid of it, at least from classes, if not 
>> > completely. (The latter is probably impossible; quite a lot 
>> > of my own code relies on it, and I imagine I'm not the only 
>> > one using it among the users of D.)
>> 
>> A feature that can't be used wrong isn't much of a feature. 
>> alias this is easy to use correctly and provides immense 
>> value. The removal of useful features is not a good solution 
>> to bad program design.
>
> I used to have your stance.  But these days, I'm starting to 
> realize more and more that implicit conversions are almost 
> always a bad idea. They are convenient and fast in the 
> beginning when you're trying to get the job done, but in the 
> long term, they hurt readability and maintainability.  I've 
> come to realize that when the code relies too much on this kind 
> of implicit conversion, esp. via alias this, it's often a sign 
> of poor code structure. It's a code smell.  It works, but 
> smells bad, and eventually you realize that it *is* bad.

If you're calling into a C library for matrix operations, but you 
have three or more strategies for allocating the underlying 
memory, alias this is reasonable. Otherwise you're writing 
*extremely* verbose code or you need to engage in extraordinary 
code duplication or you're writing a bunch of ugly generic code 
that sits on top of the C library. alias this is a clean, trivial 
solution in this case.



More information about the Digitalmars-d mailing list