www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Should pure nothrow ---> pure nothrow ?

reply #ponce <aliloko gmail.com> writes:
 
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.
Nov 27 2009
next sibling parent reply Don <nospam nospam.com> writes:
#ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them). So deprecated is definitely an attribute. Is override really required? I've just tested on DMD2.037, and it still accepts functions without it. So at present it is behaving like an attribute. But if it became mandatory, I'm not so sure.
Nov 27 2009
next sibling parent reply "Denis Koroskin" <2korden gmail.com> writes:
On Fri, 27 Nov 2009 12:09:05 +0300, Don <nospam nospam.com> wrote:

 #ponce wrote:
 Definitely. And what about  deprecated and  override?


As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them). So deprecated is definitely an attribute. Is override really required? I've just tested on DMD2.037, and it still accepts functions without it. So at present it is behaving like an attribute. But if it became mandatory, I'm not so sure.

override is required when compiling with -w. By Walter's definition, property is not a valid attribute, because by removing it the program will fail to compile (due to missing parens in accessors). Either that or omissible empty parens will still be present, but I see no usefulness of property in that case.
Nov 27 2009
parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Denis Koroskin wrote:
 On Fri, 27 Nov 2009 12:09:05 +0300, Don <nospam nospam.com> wrote:
 
 #ponce wrote:
 Definitely. And what about  deprecated and  override?


As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them). So deprecated is definitely an attribute. Is override really required? I've just tested on DMD2.037, and it still accepts functions without it. So at present it is behaving like an attribute. But if it became mandatory, I'm not so sure.

override is required when compiling with -w. By Walter's definition, property is not a valid attribute, because by removing it the program will fail to compile (due to missing parens in accessors). Either that or omissible empty parens will still be present, but I see no usefulness of property in that case.

But it still doesn't affect the generated binary code, and I think that's the important part here. property void foo(int i) { ... } foo = 7; generates the exact same code as void foo(int i) { ... } foo(7); We need a definition of attributes/annotations that is a bit wider than "can be removed from program without anything happening". Denis' example clearly demonstrates this. Something in the vein of "annotations only provide additional information and constraints for the compiler, and do not affect the generated code" would be better. -Lars
Nov 27 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Denis Koroskin:

 I think "do not affect the generated code" is a bit restricting.
 [...] There are endless possibilities.

Lombok gives annotations to reduce boring lines of Java code: http://projectlombok.org/features/index.html Some of those annotations: Getter / Setter: Never write public int getFoo() {return foo;} again. ToString: No need to start a debugger to see your fields: Just let lombok generate a toString for you! (I think this can be automatic for D structs). EqualsAndHashCode: Equality made easy: Generates hashCode and equals implementations from the fields of your object. Synchronized: synchronized done right: Don't expose your locks. More info on the Synchronized:
 Synchronized is a safer variant of the synchronized method modifier. Like
synchronized, the annotation can be used on static and instance methods only.
It operates similarly to the synchronized keyword, but it locks on different
objects. The keyword locks on this, but the annotation locks on a field named
$lock, which is private. If the field does not exist, it is created for you. If
you annotate a static method, the annotation lo cks on a static field named
$LOCK instead. If you want, you can create these locks yourself. The $lock and
$LOCK fields will of course not be generated if you already created them
yourself. You can also choose to lock on another field, by specifying it as
parameter to the  Synchronized annotation. In this usage variant, the fields
will not be created automatically, and you must explicitly create them
yourself, or an error will be emitted. Locking on this or your own class object
can have unfortunate side-effects, as other code not under your control can
lock on these objects as well, which can cause race conditions and other nasty
threading-related bugs.<

Bye, bearophile
Nov 27 2009
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Fri, 27 Nov 2009 12:30:30 +0300, Lars T. Kyllingstad  
<public kyllingen.nospamnet> wrote:

 Denis Koroskin wrote:
 On Fri, 27 Nov 2009 12:09:05 +0300, Don <nospam nospam.com> wrote:

 #ponce wrote:
 Definitely. And what about  deprecated and  override?


As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them). So deprecated is definitely an attribute. Is override really required? I've just tested on DMD2.037, and it still accepts functions without it. So at present it is behaving like an attribute. But if it became mandatory, I'm not so sure.

By Walter's definition, property is not a valid attribute, because by removing it the program will fail to compile (due to missing parens in accessors). Either that or omissible empty parens will still be present, but I see no usefulness of property in that case.

But it still doesn't affect the generated binary code, and I think that's the important part here. property void foo(int i) { ... } foo = 7; generates the exact same code as void foo(int i) { ... } foo(7); We need a definition of attributes/annotations that is a bit wider than "can be removed from program without anything happening". Denis' example clearly demonstrates this. Something in the vein of "annotations only provide additional information and constraints for the compiler, and do not affect the generated code" would be better. -Lars

I think "do not affect the generated code" is a bit restricting. I see attributes as hints to compiler (especially since there is no way to use user-defined attributes). Compiler may understand and make use of some of them. For example, I'd like to be able to annotate a function as thread-safe, and hope that a smart compiler will optimize my code based on that information (it doesn't mean it have to). Other example is that I'd like for some functions to leave all bounds checks (even in -release) without making it safe. Or profile this concrete method. Or exclude this concrete method from profiling. There are endless possibilities. Some of this attributes might be vendor-specific, they should probably start with a double-underscore (e.g. __naked). That's the way I see attributes.
Nov 27 2009
prev sibling next sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them).

If this is the rule, shouldn't the protection attributes be moved into the annotation namespace as well? ( private, protected, package, public) Since everything is public by default in D, a program will keep working even if you remove them. NOTE: I don't necessarily think they should, but I do think there should be a definite rule for which attributes are annotations and which aren't. Otherwise it just seems random. -Lars
Nov 27 2009
parent reply Don <nospam nospam.com> writes:
Lars T. Kyllingstad wrote:
 Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them).

If this is the rule, shouldn't the protection attributes be moved into the annotation namespace as well? ( private, protected, package, public) Since everything is public by default in D, a program will keep working even if you remove them. NOTE: I don't necessarily think they should, but I do think there should be a definite rule for which attributes are annotations and which aren't. Otherwise it just seems random. -Lars

Obviously my rule isn't correct. It's hard to come up with a rule that includes property, without including everything else.
Nov 27 2009
parent "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Don wrote:
 Lars T. Kyllingstad wrote:
 Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them).

If this is the rule, shouldn't the protection attributes be moved into the annotation namespace as well? ( private, protected, package, public) Since everything is public by default in D, a program will keep working even if you remove them. NOTE: I don't necessarily think they should, but I do think there should be a definite rule for which attributes are annotations and which aren't. Otherwise it just seems random. -Lars

Obviously my rule isn't correct. It's hard to come up with a rule that includes property, without including everything else.

That's what I suspected. How about saying that annotations only provide compile-time constraints on the body, i.e. the internals, of the function being annotated? Then, the following would be annotations: safe, unsafe, system, pure, nothrow while the following would have to be ordinary keywords: property, private, public, deprecated -Lars
Nov 27 2009
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Fri, 27 Nov 2009 13:56:10 +0300, Lars T. Kyllingstad  
<public kyllingen.nospamnet> wrote:

 Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them).

If this is the rule, shouldn't the protection attributes be moved into the annotation namespace as well? ( private, protected, package, public) Since everything is public by default in D, a program will keep working even if you remove them. NOTE: I don't necessarily think they should, but I do think there should be a definite rule for which attributes are annotations and which aren't. Otherwise it just seems random. -Lars

A straight line needs to be drawn, or we end up with something like this: public final override extern (Windows) naked deprecated pure int foo() invariant { // ... }
Nov 27 2009
prev sibling parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour.

This is not correct. For example in C# you have the Flags attribute for enums: enum Foo { One = 1, Two = 2, Three = 4, } You can't do: var x = Foo.One | Foo.Two; but if you do: [Flags] enum Foo { ... } you can do it now. Also see this: http://msdn.microsoft.com/en-us/library/system.flagsattribute(VS.71).aspx Removing the Flags attribute changes program behaviour. An attribute, indeed, tells someone (the compiler, the programmer, an external tool) that a symbol has some attribute. It could change the program if the compiler is the one using that attribute. So in theory every attribute in D could be an attribute.
Nov 27 2009
parent reply Don <nospam nospam.com> writes:
Ary Borenszweig wrote:
 Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour.

This is not correct. For example in C# you have the Flags attribute for enums: enum Foo { One = 1, Two = 2, Three = 4, } You can't do: var x = Foo.One | Foo.Two; but if you do: [Flags] enum Foo { ... } you can do it now. Also see this: http://msdn.microsoft.com/en-us/library/system.flagsattribute(VS.71).aspx Removing the Flags attribute changes program behaviour. An attribute, indeed, tells someone (the compiler, the programmer, an external tool) that a symbol has some attribute. It could change the program if the compiler is the one using that attribute. So in theory every attribute in D could be an attribute.

Interesting. I think if we go to that extreme, the annotations would just end up being keywords, but slightly uglier. It seems clear that if safe is an annotation, then pure and nothrow are, too. I also think that the huge body of C++, Java, C# (and even D!) code sets a precedent that public, protected, extern, and private should not be annotations -- I'd suggest that if it is a keyword in C or C++, it should not be an annotation. (Although that would make align a keyword, not an annotation, though it'd otherwise be a candidate). Beyond that, I'm not really sure. I'd tentatively go for deprecated, and property seems to have been decided, but for override -- no idea.
Nov 27 2009
parent reply Lutger <lutger.blijdestijn gmail.com> writes:
Don wrote:

 Ary Borenszweig wrote:
 Don wrote:
 #ponce wrote:
 Definitely. And what about  deprecated and  override?

As override is now required, i don't think it should be an attribute.

As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour.

This is not correct. For example in C# you have the Flags attribute for enums: enum Foo { One = 1, Two = 2, Three = 4, } You can't do: var x = Foo.One | Foo.Two; but if you do: [Flags] enum Foo { ... } you can do it now. Also see this: http://msdn.microsoft.com/en-us/library/system.flagsattribute(VS.71).aspx Removing the Flags attribute changes program behaviour. An attribute, indeed, tells someone (the compiler, the programmer, an external tool) that a symbol has some attribute. It could change the program if the compiler is the one using that attribute. So in theory every attribute in D could be an attribute.

Interesting. I think if we go to that extreme, the annotations would just end up being keywords, but slightly uglier. It seems clear that if safe is an annotation, then pure and nothrow are, too. I also think that the huge body of C++, Java, C# (and even D!) code sets a precedent that public, protected, extern, and private should not be annotations -- I'd suggest that if it is a keyword in C or C++, it should not be an annotation. (Although that would make align a keyword, not an annotation, though it'd otherwise be a candidate). Beyond that, I'm not really sure. I'd tentatively go for deprecated, and property seems to have been decided, but for override -- no idea.

In practice attributes in .NET are used for even more than that. A lot of API's seems to use them to provide features which could have been in code. Take nunit for example, it defines about 35 attributes to provide information about unittests. In a previous version this was done by naming convention and inheritance: http://www.nunit.org/index.php?p=attributes&r=2.5.2 I tend to think attributes in .NET are a regular means of abstraction, much like classes or generics. In part, they make up for lack of other metaprogramming features in some .NET languages.
Nov 28 2009
parent grauzone <none example.net> writes:
Lutger wrote:
 I tend to think attributes in .NET are a regular means of abstraction, much 
 like classes or generics. In part, they make up for lack of other 
 metaprogramming features in some .NET languages.

I agree; I think they are best for associating arbitrary information with arbitrary types or type members. I'm still hoping D will get user defined annotations some day in the future. I claim that they will be very useful for metaprogramming (at compile- and runtime). You wouldn't have to go roundabout ways to associate additional information to e.g. struct members. Especially I'm hoping that Walter doesn't mistake annotations for just a separate keywords namespace.
Nov 28 2009
prev sibling parent Leandro Lucarella <llucax gmail.com> writes:
Denis Koroskin, el 27 de noviembre a las 12:17 me escribiste:
 On Fri, 27 Nov 2009 12:09:05 +0300, Don <nospam nospam.com> wrote:
 
#ponce wrote:
Definitely. And what about  deprecated and  override?


As I understand it, one of the characteristics of attributes is that you should be able to remove them from the entire program, without affecting the behaviour. All they are doing is adding additional compile-time constraints. (const and immutable aren't attributes, because you're allowed to overload functions based on them). So deprecated is definitely an attribute. Is override really required? I've just tested on DMD2.037, and it still accepts functions without it. So at present it is behaving like an attribute. But if it became mandatory, I'm not so sure.

override is required when compiling with -w. By Walter's definition, property is not a valid attribute, because by removing it the program will fail to compile (due to missing parens in accessors). Either that or omissible empty parens will still be present, but I see no usefulness of property in that case.

deprecated will affect if a program compiles too. safe / trusted / system too. I think we need a better definition of what an annotation is :) -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- Si le decía "Vamos al cine, rica" Me decía "Veamos una de Kusturica" Si le decía "Vamos a oler las flores" Me hablaba de Virginia Wolf y sus amores Me hizo mucho mal la cumbiera intelectual
Nov 27 2009