[Issue 14125] std.file has gotten out of hand

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 4 16:22:35 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14125

--- Comment #11 from Dicebot <public at dicebot.lv> ---
(In reply to Andrei Alexandrescu from comment #5)
> S readText(S = string)(in char[] name) @safe if (isSomeString!S)
> {
>     import std.utf : validate;
>     static auto trustedCast(void[] buf) @trusted { return cast(S)buf; }
>     auto result = trustedCast(read(name));
>     validate(result);
>     return result;
> }
> 
> How exactly does that scaffolding help a four liner? It takes longer to read
> all that crap than to actually figure the function is correct!

I don't care how long it takes to read that crap. What is important is that if
anyone later will add some @system line to that function by an accident,
compiler will immediately complain about it.

Correct comes first and pretty comes later. If you want that code to be more
pretty, please forward this issue to DMD developers and show them how hardly
usable @safe is sometimes in practice because compiler is simply not clever
enough to reason that something is @safe (for example, declaring _all_ casts
@system is clearly an overkill)

We may move some of @trusted to actual core.stdc signatures, that is true. But
once you start marking whole functions (even 4 lines long) as @trusted, you
immediately destroy all trust in @trusted (pun intended) and becomes a
non-feature.

I completely refuse to accept your suggested coding style on this matter.

--


More information about the Digitalmars-d-bugs mailing list