On 1/5/15 4:10 PM, Walter Bright wrote:
On 12/30/2014 4:14 AM, Steven Schveighoffer wrote:
But I agree. The problem is, most times, you WANT to ensure your code
is @safe
pure nothrow (and now @nogc), even for template functions. That's a
lot of
baggage to put on each signature. I just helped someone recently who
wanted to
put @nogc on all the std.datetime code, and every signature had these 4
attributes except a few. I tried to have him put a big @safe: pure:
nothrow:
@nogc: at the top, but the occasional exceptions made this impossible.

The way to do it is one of:

1. reorganize the code so the non-attributed ones come first

2. write the attributes as:

    @safe pure nothrow @nogc {
       ... functions ...
    }

    ... non attributed functions ...

    @safe pure nothrow @nogc {
       ... more functions ...
    }

To give you an example of why that sucks, imagine that your accessor for member_x is nothrow, but your setter is not. This means you either "make an exception", or you just split up obvious file-mates into separate corners. Source control gets confused if one of those attributes changes. Nobody is happy.

Grouping by attributes is probably one of the worst ways to have readable/maintainable code.

One of the most important reasons why unittests are so successful is that you can just plop the code that tests a function right next to it. So easy to find the code, so easy to maintain when you change the target of the test. Making some way to bundle attributes, or be able to negate currently one-way attributes would go a long way IMO.

-Steve

Reply via email to