digitalmars.D.learn - Static function at module level
- Phil Lavoie (7/7) Aug 17 2014 Ok, so after years of D usage I just noticed that this is valid D
- Jonathan M Davis via Digitalmars-d-learn (7/12) Aug 17 2014 On Mon, 18 Aug 2014 01:32:40 +0000
- Phil Lavoie (3/21) Aug 18 2014 All right thanks!
- ketmar via Digitalmars-d-learn (6/8) Aug 17 2014 On Mon, 18 Aug 2014 01:32:40 +0000
- bearophile (6/8) Aug 17 2014 For various reasons, one of them is that accepting useless code
- H. S. Teoh via Digitalmars-d-learn (6/14) Aug 18 2014 [...]
- bearophile (5/6) Aug 18 2014 Probably there is. But I stopped filing similar bugs because they
- Phil Lavoie (12/18) Aug 18 2014 I looked around for it but didn't find it. I filed this one:
- Phil Lavoie (3/11) Aug 18 2014 Agreed. I was misled for a minute. I don't think it should
- ketmar via Digitalmars-d-learn (10/11) Aug 18 2014 On Mon, 18 Aug 2014 06:46:02 +0000
- Phil Lavoie (14/32) Aug 18 2014 I don't think he meant you personally. Well, I hope not. I was
- ketmar via Digitalmars-d-learn (8/12) Aug 18 2014 On Mon, 18 Aug 2014 17:55:01 +0000
Ok, so after years of D usage I just noticed that this is valid D (compiles anyways): static void myFunc() {} What is a static function at module level exactly? In C, that means private, in D, that means ___________? Thanks, Phil
Aug 17 2014
On Mon, 18 Aug 2014 01:32:40 +0000 Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Ok, so after years of D usage I just noticed that this is valid D (compiles anyways): static void myFunc() {} What is a static function at module level exactly? In C, that means private, in D, that means ___________?I'm pretty sure that it means nothing. It's just one of those cases where an attribute is ignored, because it doesn't apply rather than resulting in an error. - Jonathan M Davis
Aug 17 2014
On Monday, 18 August 2014 at 05:29:53 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:On Mon, 18 Aug 2014 01:32:40 +0000 Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:All right thanks!Ok, so after years of D usage I just noticed that this is valid D (compiles anyways): static void myFunc() {} What is a static function at module level exactly? In C, that means private, in D, that means ___________?I'm pretty sure that it means nothing. It's just one of those cases where an attribute is ignored, because it doesn't apply rather than resulting in an error. - Jonathan M Davis
Aug 18 2014
On Mon, 18 Aug 2014 01:32:40 +0000 Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:What is a static function at module level exactly? In C, that=20 means private, in D, that means ___________?nothing. static attribute for free function has no special meaning. but other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?
Aug 17 2014
ketmar:other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head. Bye, bearophile
Aug 17 2014
On Mon, Aug 18, 2014 at 06:46:02AM +0000, bearophile via Digitalmars-d-learn wrote:ketmar:[...] Is there a bug filed for this? T -- Век живи - век учись. А дураком помрёшь.other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head.
Aug 18 2014
H. S. Teoh:Is there a bug filed for this?Probably there is. But I stopped filing similar bugs because they seem to have a very low priority. Bye, bearophile
Aug 18 2014
On Monday, 18 August 2014 at 14:23:47 UTC, bearophile wrote:H. S. Teoh:I looked around for it but didn't find it. I filed this one: https://issues.dlang.org/show_bug.cgi?id=13322 As you'll see, every type of module level declaration accepts static. static int x; static void myFunc(){} static interface MyInterface{} static class MyClass{} static struct MyStruct{} static template myTemplate{} And maybe I am missing some.Is there a bug filed for this?Probably there is. But I stopped filing similar bugs because they seem to have a very low priority. Bye, bearophile
Aug 18 2014
On Monday, 18 August 2014 at 06:46:03 UTC, bearophile wrote:ketmar:Agreed. I was misled for a minute. I don't think it should compile.other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't?For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head. Bye, bearophile
Aug 18 2014
On Mon, 18 Aug 2014 06:46:02 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:accepting useless code confuses newbiesi think that i'm not really a newbie now ;-), but i'm still used to declare various private module functions and variables as 'static'. yes, sometimes this confuses me (as to "do i need to make this sta... ah, scrap that, it's D!"), but sometimes this is handy. why? i'm still have to use C sometimes, and i'm writing 'static' automatically. having compiler to accept it for anything high-level saves me one regexp search-and-replace. ;-)
Aug 18 2014
On Monday, 18 August 2014 at 17:42:37 UTC, ketmar via Digitalmars-d-learn wrote:On Mon, 18 Aug 2014 06:46:02 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:I don't think he meant you personally. Well, I hope not. I was confused by it too and I don't consider myself a D newbie. I get that it is convenient for you. I have done a lot of C myself. However, convenience loses to misleading in my book. Consider that in the future, for example, "static interface Toto{}" means something different than "interface Toto{}". I am not debating whether or not that would ever happen or what would even be the meaning of a static interface (even though I have an idea), the point is more like this: every compiler version will accept both versions of said interface, but some of those compiler will interpret it differently. Now that's a problem. Philzaccepting useless code confuses newbiesi think that i'm not really a newbie now ;-), but i'm still used to declare various private module functions and variables as 'static'. yes, sometimes this confuses me (as to "do i need to make this sta... ah, scrap that, it's D!"), but sometimes this is handy. why? i'm still have to use C sometimes, and i'm writing 'static' automatically. having compiler to accept it for anything high-level saves me one regexp search-and-replace. ;-)
Aug 18 2014
On Mon, 18 Aug 2014 17:55:01 +0000 Phil Lavoie via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:I don't think he meant you personally.ah, nothing personal, i just described my use case, maybe using some vague wording. i AM a newbie in D, there is nothing insulting in being newbie. ;-)the point is more like this: every compiler version will=20 accept both versions of said interface, but some of those=20 compiler will interpret it differently. Now that's a problem.hm. to be honest, i just don't want to fix almost all my code removing spurious 'static's here and there. ;-)
Aug 18 2014