digitalmars.D.learn - Where to place function attributes?
- Jeremy DeHaan (19/19) Aug 19 2012 This probably isn't specifically a D only question as I've seen
- Jonathan M Davis (15/18) Aug 19 2012 No. Any function attribute can go on either side, and which side they go...
- Simen Kjaeraas (10/12) Aug 19 2012 I would also say that putting function attributes on a separate line
- Era Scarecrow (6/9) Aug 19 2012 I've gotten in a habit of putting it to the right.
This probably isn't specifically a D only question as I've seen this in C++ too, but does it make any kind of difference where an attribute is placed when writing a function? example class C { immutable void foo() { //code } } vs class D { void foo() immutable { //code } }
Aug 19 2012
On Sunday, August 19, 2012 09:57:14 Jeremy DeHaan wrote:This probably isn't specifically a D only question as I've seen this in C++ too, but does it make any kind of difference where an attribute is placed when writing a function?No. Any function attribute can go on either side, and which side they go on is generally personal preference. const is a funny one though (as is immutable), since putting it on the left is the same as putting it on the right (as with all of the other attributes), but this can throw you off, because you might think that it's part of the return type when it isn't. e.g. const C func() {...} is the same as C func() const {...} If you want the return type to be const, you need to use parens: const(C) func() {...} So, it's generally considered good practice to put const and immutable on the right-hand side. - Jonathan M Davis
Aug 19 2012
On Sun, 19 Aug 2012 10:15:42 +0200, Jonathan M Davis <jmdavisProg gmx.com> wrote:it's generally considered good practice to put const and immutable on the right-hand side.I would also say that putting function attributes on a separate line above the function is fairly common: const property pure int foo() { return 3; } -- Simen
Aug 19 2012
On Sunday, 19 August 2012 at 07:57:15 UTC, Jeremy DeHaan wrote:This probably isn't specifically a D only question as I've seen this in C++ too, but does it make any kind of difference where an attribute is placed when writing a function?I've gotten in a habit of putting it to the right. struct X { string something() safe const pure nothrow { ... } }
Aug 19 2012