On Thursday, 14 January 2016 at 15:54:02 UTC, Daniel Kozak wrote:
V Thu, 14 Jan 2016 16:17:41 +0100
anonymous via Digitalmars-d <digitalmars-d@puremagic.com> napsáno:

On 14.01.2016 15:25, Byron Heads wrote:
> I got burned by this yesterday, this code should not compile
>

void foo() {
     import std.net.curl; /* not mentioning trace */
     trace("hello");
}
----
Using local imports is dangerous. It should be used only with selective imports


Some of these problems can be avoided when you write good code. Explicit import is allowed but not the best especially when you are just using one or two functions (locally or globally).


Same as those who write:

class Name {
    string name;
    this(string name) {
        name = name;
    }
}

Instead of;

class Name {
    string name;
    this(string name) {
        this.name = name;
    }
}

Imagine you have;

class Name {
    string realName;

    this(string name) {

        .... a lot of code here.......

        string realName = name ..... //This will punish you

        .... a lot of code here.......
        string finalName = realName .......

        .... a lot of code here.......

        realName = finalName; // code maintained for a long time
    }
}


Writing good code takes time much like mining diamond.

Reply via email to