Proposed Enhancement: Deprecate std.conv.text With 0 Arguments

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 23 16:16:23 PDT 2016


On 6/23/16 6:46 PM, deadalnix wrote:
> On Wednesday, 22 June 2016 at 15:39:11 UTC, Meta wrote:
>> If it is called with 0 arguments it will return null.
>
> No it will  return empty string.

null is an empty string. And it does return null specifically.

>> This  behaviour has caused several bugs in my code because
>> combined with optional parens and UFCS, it is easy to accidentally
>> call text with 0 args but have it look like passing a variable to a
>> function. An example bug that I recently found in my code:
>>
>
> This is a problem with optional (), not text.

A valid point. But we aren't going to have this change.

> test takes n parameters and return a string representation of these
> parameters. returning an empty string when no parameters is provided is
> very much expected.

If it has to be valid, this is what I would expect, yes. But it doesn't 
have to be valid.

The only place I can see this being useful is generic code which itself 
takes a tuple.

> The alternative is to add special case. And here you get into the bad
> design land. When some bad design is introduced it causes problems. Now
> there is the option to introduce more and more bad design to work around
> the original bad design, or adopt a principled approach. I'd rather go
> for #2 . if I wanted #1, I'd be using C++ or PHP, which both fit that
> spot better than D.

It's not a special case to require a minimum number of parameters.

> When the solution to a problem is adding more special casing, you can be
> sure you are not moving in the right direction.

There is already a special case for zero arguments -- a whole static if 
branch, in fact.

-Steve


More information about the Digitalmars-d mailing list