Re: Static function at module level

2014-08-18 Thread bearophile via Digitalmars-d-learn

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


Re: Static function at module level

2014-08-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 18, 2014 at 06:46:02AM +, bearophile via Digitalmars-d-learn 
wrote:
 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.
[...]

Is there a bug filed for this?


T

-- 
Век живи - век учись. А дураком помрёшь.


Re: Static function at module level

2014-08-18 Thread bearophile via Digitalmars-d-learn

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


Re: Static function at module level

2014-08-18 Thread Phil Lavoie via Digitalmars-d-learn

On Monday, 18 August 2014 at 06:46:03 UTC, bearophile wrote:

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


Agreed. I was misled for a minute. I don't think it should 
compile.




Re: Static function at module level

2014-08-18 Thread Phil Lavoie via Digitalmars-d-learn
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 +
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


All right thanks!


Re: Static function at module level

2014-08-18 Thread Phil Lavoie via Digitalmars-d-learn

On Monday, 18 August 2014 at 14:23:47 UTC, bearophile wrote:

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


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.


Re: Static function at module level

2014-08-18 Thread ketmar via Digitalmars-d-learn
On Mon, 18 Aug 2014 06:46:02 +
bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 accepting useless code confuses newbies
i 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. ;-)


signature.asc
Description: PGP signature


Re: Static function at module level

2014-08-18 Thread Phil Lavoie via Digitalmars-d-learn
On Monday, 18 August 2014 at 17:42:37 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Mon, 18 Aug 2014 06:46:02 +
bearophile via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


accepting useless code confuses newbies
i 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. ;-)


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.


Philz


Re: Static function at module level

2014-08-18 Thread ketmar via Digitalmars-d-learn
On Mon, 18 Aug 2014 17:55:01 +
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 
 accept both versions of said interface, but some of those 
 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. ;-)


signature.asc
Description: PGP signature


Static function at module level

2014-08-17 Thread Phil Lavoie via Digitalmars-d-learn
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


Re: Static function at module level

2014-08-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 18 Aug 2014 01:32:40 +
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


Re: Static function at module level

2014-08-17 Thread ketmar via Digitalmars-d-learn
On Mon, 18 Aug 2014 01:32:40 +
Phil Lavoie via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 What is a static function at module level exactly? In C, that 
 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?


signature.asc
Description: PGP signature