January 12, 2013
> A static static array?

Very static array? =)
January 12, 2013
Andrey:

>> A static static array?
>
> Very static array? =)

Elsewhere I have suggested a "static static", because I think sometimes D static is not static enough:

http://d.puremagic.com/issues/show_bug.cgi?id=9088

So with that you have Very static static arrays too :o)

Bye,
bearophile
January 12, 2013
> Elsewhere I have suggested a "static static", because I think sometimes D static is not static enough:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=9088
>
> So with that you have Very static static arrays too :o)

I think such words as "single" and "only" are more appropriate in your case.

single static function();

Or, if the developers will finally allow to take advantages of the unicode: static², static³... :-)
January 12, 2013
Andrey:

> I think such words as "single" and "only" are more appropriate in your case.
>
> single static function();

Right, but we generally try to minimize the number of keywords.

"static static" is a special case of a more general feature, @templated(), that is similar to the "utilizes" keyword discussed here, in Figure 21:

"Minimizing Dependencies within Generic Classes for Faster and Smaller Programs" by Dan Tsafrir, Robert W. Wisniewski, David F. Bacon and Bjarne Stroustrup:

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.155.1773


The "static static" is the same as an empty @templated():


int foo(T)() if (is(T == char) || is(T == dchar) || is(T == wchar)) {
    @templated() dchar[] table = ['a', 'b', 'c'];
    @templated() immutable val = someHeavyCTFE(10);
    // uses table and val here
    return 0;
}


Adapted from that Figure 21:

struct C(X, Y, Z) {
    void f1() @templated(X, Z) {
        // only allowed to use X or Z, not Y
    }
    void f2() {
        // for backward compatibility, this is
        // equivalent to: void f2() @templated(X,Y,Z)
    }
    class Inner @templated(Y) {
        // only allowed to use Y, not X nor Z
    }
}


@templated() (or @utilizes()) is much more flexible than "static static". And I generally I'd like @templated() to be implemented instead of "static static".


> Or, if the developers will finally allow to take advantages of the unicode: static², static³... :-)

Please, no :-)

Bye,
bearophile
January 12, 2013
I think this might be a problem because every template instance creates separate independent class, as far as I know.

Well, maybe you can use function pointer and create static constructor. More job need to be done, but the resulting class doesn't lose much and even become more flexible, configurable;

final class StaticMyClass {

	static void _myfun() {
		writeln("Hello!");
	}
}

class MyClass(T) {
	uint x, y;

	static void function() myfun;

	static this() {
		MyClass.myfun = &StaticMyClass._myfun;
	}

        //still you have additional memory consumed by static constructor function;

	this() {
		this.myfun();
	}
}

void main() {
    auto obj = new MyClass!int();
}
January 12, 2013
> The "static static" is the same as an empty @templated():
>
>
> int foo(T)() if (is(T == char) || is(T == dchar) || is(T == wchar)) {
>     @templated() dchar[] table = ['a', 'b', 'c'];
>     @templated() immutable val = someHeavyCTFE(10);
>     // uses table and val here
>     return 0;
> }

Sorry "static static" is the same as "@templated() static".

Bye,
bearophile
January 13, 2013
Could be even simpler. But I do not know about additional overhead. How do you feel on this?

abstract class _MyClass {

    static string str = "Hello!";

    static void myfun() {
	writeln(str);
    }

}

class MyClass(T) : _MyClass {

	this() {
            this.myfun();
	}
}

P.S.: sorry if I don't understand your vision about this problem correctly. I've never been doing template programming much.
January 13, 2013
On Saturday, 12 January 2013 at 21:12:06 UTC, bearophile wrote:
> Maxim Fomin:
>
>> I see, but these names are interchangeable. Dlang.org uses "static" (as opposed to dynamic) and tdpl tends to use fixed-size name.
>
> If you call a1 static array, then what name do you give to a2? A static static array?
>
> void main() {
>     int[5] a1;
>     static int[5] a2;
>     __gshared int[5] a3;
> }
>
> Bye,
> bearophile

Static static array (yes, it is rather dumb). I see no point in selecting more appropriate name among these too if both are correct, both are heavily used in discussions (judging by google search on dlang.org and subdomains - even if I query fixed array, I still receive pages with static name), both are understandable (the only little confusion happens with arrays with static attribute) and there is no language standard which uses some set of terminology.

A case when popular naming is incorrect, is, for example, calling this(this) a struct copy constructor (it happens sometimes) - when it is certainly incorrect, because it is a postblit, and copy constructor is another thing. Even such strictly speaking incorrect naming is understandable and widely used.
1 2
Next ›   Last »