digitalmars.D - static this
- Max Samuha (14/14) Oct 06 2006 Two questions to the community:
- Chris Miller (4/18) Oct 06 2006 I also asked about this before and it's not a bug, "static" and "this" a...
- Derek Parnell (7/12) Oct 06 2006 But each module can have it own constructor method and they can't all be
- Max Samuha (7/29) Oct 06 2006 Then the compiler should definitely disallow 'this' in a static block
- Chris Miller (3/14) Oct 06 2006 There would only be one module-level 'this', the rest would be 'static
- Hasan Aljudy (7/26) Oct 06 2006 As Chris already said, static is not really an attribute, it's just
- Max Samuha (5/31) Oct 06 2006 Ok, that's clear. Anyway, the compiler should issue an error if 'this'
- Max Samuha (20/56) Oct 06 2006 And, IMO, this one shouldn't compile without complaint, either:
- Ary Manzana (7/66) Oct 06 2006 In some recent post I told it should be great if the compiler could tell...
- Chris Nicholson-Sauls (9/76) Oct 06 2006 Would cause a problem with the continuous attribute syntax...
- Max Samuha (12/88) Oct 07 2006 Error, warning, anything to let me know about my static constructor
- Hasan Aljudy (3/13) Oct 07 2006 My wild guess would be that the "static" significantly changes the
- Ivan Senji (3/86) Oct 07 2006 Who knows what the explanation might be. But it helps to look at static
Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } } 2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?
Oct 06 2006
On Fri, 06 Oct 2006 06:01:09 -0400, Max Samuha <maxter i.com.ua> wrote:Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }I also asked about this before and it's not a bug, "static" and "this" are supposed to be together, like static assert.2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess you're right; my suggestion was to rename main() to this() :)
Oct 06 2006
On Fri, 06 Oct 2006 06:40:46 -0400, Chris Miller wrote:But each module can have it own constructor method and they can't all be 'main'. -- Derek Parnell Melbourne, Australia "Down with mediocrity!"2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess you're right; my suggestion was to rename main() to this() :)
Oct 06 2006
On Fri, 06 Oct 2006 06:40:46 -0400, "Chris Miller" <chris dprogramming.com> wrote:On Fri, 06 Oct 2006 06:01:09 -0400, Max Samuha <maxter i.com.ua> wrote:Then the compiler should definitely disallow 'this' in a static block giving a good compile time error message?Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }I also asked about this before and it's not a bug, "static" and "this" are supposed to be together, like static assert.There may be 'this' in different modules. How the entry point would be determined then? Or please give me a link to the thread where your suggestion was discussed.2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess you're right; my suggestion was to rename main() to this() :)
Oct 06 2006
On Fri, 06 Oct 2006 07:30:18 -0400, Max Samuha <maxter i.com.ua> wrote:Then the compiler should definitely disallow 'this' in a static block giving a good compile time error message?There would only be one module-level 'this', the rest would be 'static this'.There may be 'this' in different modules. How the entry point would be determined then? Or please give me a link to the thread where your suggestion was discussed.2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess you're right; my suggestion was to rename main() to this() :)
Oct 06 2006
Max Samuha wrote:Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 06 2006
On Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 06 2006
On Fri, 06 Oct 2006 17:24:35 +0300, Max Samuha <maxter i.com.ua> wrote:On Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:And, IMO, this one shouldn't compile without complaint, either: class Test { static { static this() { writefln("In static ctor"); } } static static void foo() { } } void main() { } How do you think?Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 06 2006
Max Samuha wrote:On Fri, 06 Oct 2006 17:24:35 +0300, Max Samuha <maxter i.com.ua> wrote:In some recent post I told it should be great if the compiler could tell if a modifier is redundant. I've seen the parser code and it seems pretty easy to implement. Try with any modifier (abstract abstract, public private, even abstract final) and you'll get no error (of course, you won't be able to instantiate that class, the compiler thinks it's abstract).On Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:And, IMO, this one shouldn't compile without complaint, either: class Test { static { static this() { writefln("In static ctor"); } } static static void foo() { } } void main() { } How do you think?Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 06 2006
Max Samuha wrote:On Fri, 06 Oct 2006 17:24:35 +0300, Max Samuha <maxter i.com.ua> wrote:Would cause a problem with the continuous attribute syntax... I'd say make it a non-blocking warning, rather than an error. -- Chris Nicholson-SaulsOn Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:And, IMO, this one shouldn't compile without complaint, either: class Test { static { static this() { writefln("In static ctor"); } } static static void foo() { } } void main() { } How do you think?Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 06 2006
On Fri, 06 Oct 2006 16:05:07 -0500, Chris Nicholson-Sauls <ibisbasenji gmail.com> wrote:Max Samuha wrote:Error, warning, anything to let me know about my static constructor being compiled as instance one. Btw, i still can't see the reason why D doesn't treat 'static' as an attribute of 'this' like other static methods? Could anybody explain? class Test { static: this(){}; // make it static ctor, not instance. it's confusing! void foo(); }On Fri, 06 Oct 2006 17:24:35 +0300, Max Samuha <maxter i.com.ua> wrote:Would cause a problem with the continuous attribute syntax... I'd say make it a non-blocking warning, rather than an error. -- Chris Nicholson-SaulsOn Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:And, IMO, this one shouldn't compile without complaint, either: class Test { static { static this() { writefln("In static ctor"); } } static static void foo() { } } void main() { } How do you think?Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 07 2006
Max Samuha wrote:Btw, i still can't see the reason why D doesn't treat 'static' as an attribute of 'this' like other static methods? Could anybody explain? class Test { static: this(){}; // make it static ctor, not instance. it's confusing! void foo(); }My wild guess would be that the "static" significantly changes the functionality of "this()" so it's much more than just an attribute.
Oct 07 2006
Max Samuha wrote:On Fri, 06 Oct 2006 16:05:07 -0500, Chris Nicholson-Sauls <ibisbasenji gmail.com> wrote:Who knows what the explanation might be. But it helps to look at static this as staticthis.Max Samuha wrote:Error, warning, anything to let me know about my static constructor being compiled as instance one. Btw, i still can't see the reason why D doesn't treat 'static' as an attribute of 'this' like other static methods? Could anybody explain?On Fri, 06 Oct 2006 17:24:35 +0300, Max Samuha <maxter i.com.ua> wrote:Would cause a problem with the continuous attribute syntax... I'd say make it a non-blocking warning, rather than an error. -- Chris Nicholson-SaulsOn Fri, 06 Oct 2006 06:53:08 -0600, Hasan Aljudy <hasan.aljudy gmail.com> wrote:And, IMO, this one shouldn't compile without complaint, either: class Test { static { static this() { writefln("In static ctor"); } } static static void foo() { } } void main() { } How do you think?Max Samuha wrote:Ok, that's clear. Anyway, the compiler should issue an error if 'this' is used in static block. If not, it will be be confusing for newcomers who will be unlucky enough to use it the way I did.Two questions to the community: 1. The following is obviously a bug? class Test { static { this(){}; // defined not as static constructor but as instance constructor ... more static members here } }As Chris already said, static is not really an attribute, it's just "static this".2. Why module constructor must be attributed with static? All module level methods are already static so the attribute seems to be redundant. Make it optional?I guess the reason is to be consistent. "static this" refers to a static constructor, i.e. a constructor that will be called at the beginning of the program's start. Module constructors are static constructors, so "static this" is used.
Oct 07 2006