Re: static class vs. static struct

2015-11-19 Thread vyarthrot via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:02:54 UTC, ref2401 wrote: What's the difference between static class and static struct? What should i use? In simple words, Singleton is a pattern and not a keyword. The Singleton pattern has several advantages over static classes. A singleton allows a class f

Re: static class vs. static struct

2015-07-15 Thread creiglee via Digitalmars-d-learn
In simple words, Singleton is a pattern and not a keyword. The Singleton pattern has several advantages over static classes. A singleton allows a class for which there is just one, persistent instance across the lifetime of an application. That means, it created a single instance and that insta

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:33 PM, Piotrek wrote: > On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: >> On 01/27/2015 08:33 AM, Piotrek wrote: >> >> >> Non-static means nested. >> > >> > Hmm,this can be misleading. Nesting in structs doesn't >> introduce context >> > pointer. Oh, I misread w

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:44 PM, Piotrek wrote: > Let me here thank for your book I am glad that it is useful. > which I've been reading for some time. Me too! I browsed the index section to remember the other uses of 'static'. :) Ali

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:18:02 UTC, Ali Çehreli wrote: On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b;

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs t

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs that are nested inside functions do have the context pointer. Al

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b; > etc. > > 2. static declaration > > static struct A{int a}; //s

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: static class vs. static struct

2015-01-27 Thread Artur Skawina via Digitalmars-d-learn
On 01/27/15 10:40, Daniel Kozak via Digitalmars-d-learn wrote: > On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: >> On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: >>> For several times I've met struct(or static struct) usage in Phobos for >>> singleton pattern impleme

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:55:19 UTC, anonymous wrote: On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Ma

Re: static class vs. static struct

2015-01-27 Thread ketmar via Digitalmars-d-learn
On Tue, 27 Jan 2015 09:40:08 +, Daniel Kozak wrote: > import std.stdio; > import std.conv; > > struct S { > @disable this(); > } > > final class C { > } > > void main() { > writeln(C.sizeof); > writeln(S.sizeof); > } blind guess: vmt with "toString()" from Object? ;-) signa

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: static class vs. static struct

2015-01-27 Thread ref2401 via Digitalmars-d-learn
For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struct for or singleton pattern implementation? Why don't use sta

Re: static class vs. static struct

2015-01-26 Thread anonymous via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Maybe you are talking about nested structs? Non-static means

Re: static class vs. static struct

2015-01-26 Thread Piotrek via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Maybe you are talking about nested structs? Piotrek

Re: static class vs. static struct

2015-01-26 Thread bearophile via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:02:54 UTC, ref2401 wrote: What's the difference between static class and static struct? What should i use? Non-static structs/classes have an extra pointer. Static ones don't have it, so their differences are the usual ones: a class is used by reference and th

Re: static class instances not allowed?

2013-06-11 Thread bearophile
C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs, like CS1525: http://msdn.microsoft.com/en-gb/library/3hdyz4dw%28v=vs.80%29.aspx In such pages you can explain w

Re: static class instances not allowed?

2013-06-11 Thread Eric
On Tuesday, 11 June 2013 at 16:09:39 UTC, Steven Schveighoffer wrote: On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can

Re: static class instances not allowed?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can be solved with a static ctor. Essentially, any static initializers mu

Re: static class instances not allowed?

2013-06-11 Thread Eric
Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs, like CS1

Re: static class instances not allowed?

2013-06-11 Thread bearophile
Eric: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error void main() {} (dmd7) desk3:~/tp/d_test2/dlib>dmd T.d T.d(4): Error: variable T.Bar.f is mutable. Only const or immutable clas

Re: static class

2013-02-22 Thread Jonathan M Davis
On Friday, February 22, 2013 22:12:44 Michael wrote: > In D a module can be statically imported and then I can use full > names. > > But question: is it possible to force a static import? No. - Jonathan M Davis

Re: static class

2013-02-22 Thread Michael
In D a module can be statically imported and then I can use full names. But question: is it possible to force a static import?

Re: static class

2013-02-22 Thread Jonathan M Davis
On Friday, February 22, 2013 20:39:01 Michael wrote: > On Friday, 22 February 2013 at 04:06:09 UTC, Jonathan M Davis > > wrote: > >I'm not talking about static. I'm talking about the fact that > >putting both final and abstract on a class isn't a problem. > > > > - Jonathan M Davis > > Initial qu

Re: static class

2013-02-22 Thread Michael
On Friday, 22 February 2013 at 04:06:09 UTC, Jonathan M Davis wrote: I'm not talking about static. I'm talking about the fact that putting both final and abstract on a class isn't a problem. - Jonathan M Davis Initial question for me was how to get something like: They only contain static me

Re: static class

2013-02-22 Thread Michael
It's natural and would be good if something will be stated in documentation about static at top-level. "static" is well known feature. Yes it can act differently in diff languages. They're losing their time if they expect D to act as another language. With this point of view to user, only

Re: static class

2013-02-22 Thread Andrej Mitrovic
On 2/22/13, Ary Borenszweig wrote: > Don't you see that as a problem? People loosing their time answering > this questions over and over again instead of the compiler giving you > the answer. They're losing their time if they expect D to act as another language. Anyway an annoying compiler compl

Re: static class

2013-02-21 Thread Jonathan M Davis
On Friday, February 22, 2013 00:59:45 Ary Borenszweig wrote: > On 2/21/13 8:34 PM, Jonathan M Davis wrote: > > On Friday, February 22, 2013 00:06:26 bearophile wrote: > >> Jonathan M Davis: > >>> D doesn't > >>> bother to check, so you get the natural consequence of mixing > >>> them. I'm quite > >

Re: static class

2013-02-21 Thread Ary Borenszweig
On 2/21/13 8:34 PM, Jonathan M Davis wrote: On Friday, February 22, 2013 00:06:26 bearophile wrote: Jonathan M Davis: D doesn't bother to check, so you get the natural consequence of mixing them. I'm quite sure that the fact that it works that way is an accident. It was never intentially made t

Re: static class

2013-02-21 Thread Jonathan M Davis
On Friday, February 22, 2013 00:06:26 bearophile wrote: > Jonathan M Davis: > > D doesn't > > bother to check, so you get the natural consequence of mixing > > them. I'm quite > > sure that the fact that it works that way is an accident. It > > was never > > intentially made to be allowed or disall

Re: static class

2013-02-21 Thread bearophile
Jonathan M Davis: D doesn't bother to check, so you get the natural consequence of mixing them. I'm quite sure that the fact that it works that way is an accident. It was never intentially made to be allowed or disallowed. It's just allowed, because there's nothing intrinsic about either of t

Re: static class

2013-02-21 Thread Jonathan M Davis
On Thursday, February 21, 2013 19:52:39 Michael wrote: > > I'm sure you knew that and it's just a wording thing :) > > > > Fun fact: in Java, it's an error to combine 'final' and > > 'abstract'. > > Yes. > As I understand, in D the "abstract" keyword is some alternative > to @disable in that case

Re: static class

2013-02-21 Thread Michael
I'm sure you knew that and it's just a wording thing :) Fun fact: in Java, it's an error to combine 'final' and 'abstract'. Yes. As I understand, in D the "abstract" keyword is some alternative to @disable in that case.

Re: static class

2013-02-20 Thread Ben Davis
On 18/02/2013 21:25, Michael wrote: Yes, it's comes from C#. So, there is no static for classes at module level. Good to have a msg for it at compile-time. import std.stdio; public final abstract class Test { static this() { writeln("in static ctor"); } static : void foo() { writ

Re: static class

2013-02-18 Thread Michael
Yes, it's comes from C#. So, there is no static for classes at module level. Good to have a msg for it at compile-time. import std.stdio; public final abstract class Test { static this() { writeln("in static ctor"); } static : void foo() { writeln("in static method"); } } void

Re: static class

2013-02-18 Thread dennis luehring
Am 17.02.2013 23:25, schrieb Jonathan M Davis: On Sunday, February 17, 2013 23:00:19 Michael wrote: > That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it means for a class to

Re: static class

2013-02-18 Thread Ary Borenszweig
On 2/17/13 7:25 PM, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. Probably because of this: http://msdn.mi

Re: static class

2013-02-18 Thread Maxim Fomin
On Sunday, 17 February 2013 at 22:26:16 UTC, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: > That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 18:26:37 -0500, Ben Davis wrote: On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to tha

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:26:37 Ben Davis wrote: > On 17/02/2013 22:25, Jonathan M Davis wrote: > > However, non-static nested classes are associated with an instance of the > > outer class, and therefore only one can exist per class instance. > > That's not true, is it? You can make as many

Re: static class

2013-02-17 Thread Ben Davis
On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. In fairness, it is the natural guess you

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 14:47:12 H. S. Teoh wrote: > On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > > On 2/17/13, Steven Schveighoffer wrote: > > > A class that can't be instantiated has a private constructor. > > > > An alternative to that is: > > > > final abstract cla

Re: static class

2013-02-17 Thread H. S. Teoh
On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > On 2/17/13, Steven Schveighoffer wrote: > > A class that can't be instantiated has a private constructor. > > An alternative to that is: > > final abstract class C > { > static: > } > > You can't derive from it and you can't

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:00:19 Michael wrote: > > That's not the meaning of static in that context. > > As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it means for a class to be static at all. The only place that stati

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 17:00:19 -0500, Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. Static in that position is a no-op. The compiler (infuriatingly sometimes) accepts attributes that have no meaning silently. So i

Re: static class

2013-02-17 Thread Michael
That's not the meaning of static in that context. As I understand a static class can't be instantiated. The above is useful in nested classes. I just read it. Holy s.. cow. Instead you can use: class Test { static: void foo() { } } So in mine case if I want purely static class I nee

Re: static class

2013-02-17 Thread Andrej Mitrovic
On 2/17/13, Michael wrote: > Why members of static class are not implicitly static? > > static class Test > { > void foo() {} > } > That's not the meaning of static in that context. The above is useful in nested classes. Instead you can use: class Test { static: void foo() { } }

Re: Static class question

2013-02-14 Thread anonymous
On Thursday, 14 February 2013 at 12:49:01 UTC, Lubos Pintes wrote: Hi, I saw one ListBox class implementation. As we all know, ListBox class collects and displays strings. Author decided that he encapsulate the Object as item, and uses its toString() method when string is needed for display. Fo

Re: Static class members/methods and scope

2011-04-21 Thread Steven Schveighoffer
On Thu, 21 Apr 2011 04:54:49 -0400, Mike Parker wrote: I'm certain this used to work: class Foo { public static { void bar() {} } } But I've found that now, anything inside the public static block is not actually static. I get an error attempting to call Foo.bar(). I