Question

I believe D has the potential to add yet another cool feature to its suite of compilers, namely the power to disallow non-side-effect calls to pure functions.

For example

auto s = "a";
toStringz(a);

should error just like

a == "";

currently errors in DMD as

Error: == has no effect in expression (s == "")

Such as feature would prevent the programmer from accidentally calling non-muting algorithms when he expects it to have in-place (mutating) semantics. This without having to explicitly tag functions with attributes such as GCC's __attribute((warn_unused_result)) alongside __attribute((const)).

Is such a feature on the todo list for DMD?

Was it helpful?

Solution

There is no official TODO-list for DMD. Its development is mostly based on volunteers work and while some enhancement requests get "preapproved" tag in bugzilla, it does not tell anything about terms when this feature can be implemented or will it be implemented at all.

Given there are a lot of much more serious issues to address right now, I hardly can expect something that minor implemented in nearby years.

Also your question actually looks like proposal and is better suited to official DMD/Phobos bugzilla: http://d.puremagic.com/issues/

OTHER TIPS

The problem is D's heavy uses of templates. You don't always have control on either the template or it's arguments. For example:

class Foo{
    /*...*/
    pure int foo(){
        /*...*/
    }
    /*...*/
}

void bar(T)(T arg){
    /*...*/
    arg.foo();
    /*...*/
}

Now you can't call bar with a Foo arguments. This can be fixed(hacked) by either removing foo's pureness(which might break the code and/or harm performance) or changing bar to store foo()'s result in a variable(which is also bad, because it never uses that value and because foo's return type might be void or even worse - a struct with a destructor(which it's call will be postponed to the end of bar's execution). And ofcourse - that is only possible if you can change Foo or bar...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top