digitalmars.D - Revert attributes to their defaults with default keywords
- Daniel Kozak (16/16) Jan 09 2015 I often have code like this:
- ketmar via Digitalmars-d (18/39) Jan 09 2015 i've dreamt about similar feature for a long time! i was thinking about
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d (7/24) Jan 09 2015 not now, but I plan add this
- Steven Schveighoffer (13/29) Jan 09 2015 Nice, but I don't like the fact that it bluntly returns all attributes
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d (9/51) Jan 09 2015 V Fri, 09 Jan 2015 07:21:02 -0500
- Steven Schveighoffer (6/56) Jan 09 2015 I'd rather combine the parameterization with attribute sets (i.e.
- aldanor (7/80) Jan 09 2015 It could work both ways at the same time.
- Meta (18/23) Jan 09 2015 @disable is also currently a keyword.
- ketmar via Digitalmars-d (12/42) Jan 09 2015 i chose to go with `@impure`, `@canthrow` and `@gc`. the fact is that
- ketmar via Digitalmars-d (5/34) Jan 09 2015 i think it's acceptable even in this form. please, please make a PR
I often have code like this: class A { final: nothrow: ... some methods ... } Problem comes when I need add methods which for eg.: throws or need to be virtual. I can put them before final: but this is not perfect, because I prefer when methods are place in specific order (method abc call method asd so asd is bellow abc and so on). So today I download dmd source and make some small modification (only few lines) and this is the result: http://dpaste.dzfl.pl/472afc938397
Jan 09 2015
On Fri, 09 Jan 2015 11:57:50 +0000 Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> wrote:I often have code like this: =20 class A { final: nothrow: ... some methods ... } =20 Problem comes when I need add methods which for eg.: throws or=20 need to be virtual. =20 I can put them before final: but this is not perfect, because I=20 prefer when methods are place in specific order (method abc call=20 method asd so asd is bellow abc and so on). =20 So today I download dmd source and make some small modification=20 (only few lines) and this is the result: =20 http://dpaste.dzfl.pl/472afc938397i've dreamt about similar feature for a long time! i was thinking about "negative attributes" though ( canthrow, virtual, etc), but your solution seems to be better as it's not poluting language with new attrs. can it be used like this: final: nothrow: ... default void foo () { ... } ... so only `foo` becomes default, but all other methods after `foo` are `final nothrow`? and can it be used like this: default void foo () nothrow { ... } so `default` resets all attrs and then i can specify another set of attrs inline?
Jan 09 2015
V Fri, 9 Jan 2015 14:11:00 +0200 ketmar via Digitalmars-d <digitalmars-d puremagic.com> napsáno:can it be used like this: final: nothrow: ... default void foo () { ... } ... so only `foo` becomes default, but all other methods after `foo` are `final nothrow`?not now, but I plan add this for now you can use: default { void foo () { ... }}and can it be used like this: default void foo () nothrow { ... } so `default` resets all attrs and then i can specify another set of attrs inline?same as the first one but this works: default { void foo () nothrow { ... }}
Jan 09 2015
On 1/9/15 6:57 AM, Daniel Kozak wrote:I often have code like this: class A { final: nothrow: ... some methods ... } Problem comes when I need add methods which for eg.: throws or need to be virtual. I can put them before final: but this is not perfect, because I prefer when methods are place in specific order (method abc call method asd so asd is bellow abc and so on). So today I download dmd source and make some small modification (only few lines) and this is the result: http://dpaste.dzfl.pl/472afc938397Nice, but I don't like the fact that it bluntly returns all attributes to default. For example, if you need to remove the final attribute, but not nothrow, I'm assuming it looks something like: default nothrow void foo() which doesn't read very well. If we are going to do this, I'd rather see something like has been suggested before -- parameterizing attributes: final(false) -> remove final This allows compile-time booleans to modify attributes in ways that are extremely difficult in templates today. -Steve
Jan 09 2015
V Fri, 09 Jan 2015 07:21:02 -0500 Steven Schveighoffer via Digitalmars-d <digitalmars-d puremagic.com> napsáno:On 1/9/15 6:57 AM, Daniel Kozak wrote:I think both ways shoud be available when I need remove just one attr than attr!false is nice but when I need remove for eg: 3 or more it will look like: void someFunc final(false) pure(false) nothrow(false) in this case I think that: default void foo() nothrow looks OK now :)I often have code like this: class A { final: nothrow: ... some methods ... } Problem comes when I need add methods which for eg.: throws or need to be virtual. I can put them before final: but this is not perfect, because I prefer when methods are place in specific order (method abc call method asd so asd is bellow abc and so on). So today I download dmd source and make some small modification (only few lines) and this is the result: http://dpaste.dzfl.pl/472afc938397Nice, but I don't like the fact that it bluntly returns all attributes to default. For example, if you need to remove the final attribute, but not nothrow, I'm assuming it looks something like: default nothrow void foo() which doesn't read very well. If we are going to do this, I'd rather see something like has been suggested before -- parameterizing attributes: final(false) -> remove final This allows compile-time booleans to modify attributes in ways that are extremely difficult in templates today. -Steve
Jan 09 2015
On 1/9/15 7:47 AM, Daniel Kozák via Digitalmars-d wrote:V Fri, 09 Jan 2015 07:21:02 -0500 Steven Schveighoffer via Digitalmars-d <digitalmars-d puremagic.com> napsáno:I'd rather combine the parameterization with attribute sets (i.e. aliasing sets of attributes to one symbol). The 'default' idea is ok, but I think it's too clever -- the word "default" doesn't immediately say "attributes", so it's going to confuse people. -SteveOn 1/9/15 6:57 AM, Daniel Kozak wrote:I think both ways shoud be available when I need remove just one attr than attr!false is nice but when I need remove for eg: 3 or more it will look like: void someFunc final(false) pure(false) nothrow(false) in this case I think that: default void foo() nothrow looks OK now :)I often have code like this: class A { final: nothrow: ... some methods ... } Problem comes when I need add methods which for eg.: throws or need to be virtual. I can put them before final: but this is not perfect, because I prefer when methods are place in specific order (method abc call method asd so asd is bellow abc and so on). So today I download dmd source and make some small modification (only few lines) and this is the result: http://dpaste.dzfl.pl/472afc938397Nice, but I don't like the fact that it bluntly returns all attributes to default. For example, if you need to remove the final attribute, but not nothrow, I'm assuming it looks something like: default nothrow void foo() which doesn't read very well. If we are going to do this, I'd rather see something like has been suggested before -- parameterizing attributes: final(false) -> remove final This allows compile-time booleans to modify attributes in ways that are extremely difficult in templates today.
Jan 09 2015
On Friday, 9 January 2015 at 13:01:14 UTC, Steven Schveighoffer wrote:On 1/9/15 7:47 AM, Daniel Kozák via Digitalmars-d wrote:It could work both ways at the same time. Maybe even something like "default(pred) final(pred) nothrow" --> if pred is compile-time-true, reset all attributes and then add final/nothrow; if it's compile-time-false, disable final and enable nothrow.V Fri, 09 Jan 2015 07:21:02 -0500 Steven Schveighoffer via Digitalmars-d <digitalmars-d puremagic.com> napsáno:I'd rather combine the parameterization with attribute sets (i.e. aliasing sets of attributes to one symbol). The 'default' idea is ok, but I think it's too clever -- the word "default" doesn't immediately say "attributes", so it's going to confuse people. -SteveOn 1/9/15 6:57 AM, Daniel Kozak wrote:I think both ways shoud be available when I need remove just one attr than attr!false is nice but when I need remove for eg: 3 or more it will look like: void someFunc final(false) pure(false) nothrow(false) in this case I think that: default void foo() nothrow looks OK now :)I often have code like this: class A { final: nothrow: ... some methods ... } Problem comes when I need add methods which for eg.: throws or need to be virtual. I can put them before final: but this is not perfect, because I prefer when methods are place in specific order (method abc call method asd so asd is bellow abc and so on). So today I download dmd source and make some small modification (only few lines) and this is the result: http://dpaste.dzfl.pl/472afc938397Nice, but I don't like the fact that it bluntly returns all attributes to default. For example, if you need to remove the final attribute, but not nothrow, I'm assuming it looks something like: default nothrow void foo() which doesn't read very well. If we are going to do this, I'd rather see something like has been suggested before -- parameterizing attributes: final(false) -> remove final This allows compile-time booleans to modify attributes in ways that are extremely difficult in templates today.
Jan 09 2015
On Friday, 9 January 2015 at 14:26:26 UTC, aldanor wrote:It could work both ways at the same time. Maybe even something like "default(pred) final(pred) nothrow" --> if pred is compile-time-true, reset all attributes and then add final/nothrow; if it's compile-time-false, disable final and enable nothrow.disable is also currently a keyword. pure nothrow safe nogc immutable Test { //doSomething is nothrow safe nogc immutable disable(pure) void doSomething() {} //getAnInt is pure nogc immutable disable(nothrow, safe) int getAnInt() {} //typeof(n) == int disable(immutable) int n; } This is also useful for templated functions, methods, etc. It allows one to tell the compiler that the function in question should never have a particular attribute inferred for it. //doSomethingElse will never be inferred as pure, //but may be inferred as nothrow, safe, or nogc disable(pure) void doSomethingElse()() {}
Jan 09 2015
On Sat, 10 Jan 2015 02:47:00 +0000 Meta via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Friday, 9 January 2015 at 14:26:26 UTC, aldanor wrote:i chose to go with ` impure`, ` canthrow` and ` gc`. the fact is that adding new "inverted" attributes requres adding new STC flags into the compiler. this is very intrusive change. yed UDAs can be checked just before we set `FUNCFLAG*Inprocess`. this was ALOT easier than hunting down all the places where i need to take care on new STC flags. yes, this is ugly hack with ugly new set of attributes, but it's way easier to support for me. and as i have no hope of taking something like this into mainline (at least not sooner than another year pass), maintenance costs becomes very important. complex PR will rot soon and rotten PR will never make it into mainline.It could work both ways at the same time. Maybe even something like "default(pred) final(pred) nothrow"=20 --> if pred is compile-time-true, reset all attributes and then=20 add final/nothrow; if it's compile-time-false, disable final=20 and enable nothrow.=20 disable is also currently a keyword. =20 pure nothrow safe nogc immutable Test { //doSomething is nothrow safe nogc immutable disable(pure) void doSomething() {} =20 //getAnInt is pure nogc immutable disable(nothrow, safe) int getAnInt() {} =20 //typeof(n) =3D=3D int disable(immutable) int n; } =20 This is also useful for templated functions, methods, etc. It=20 allows one to tell the compiler that the function in question=20 should never have a particular attribute inferred for it. =20 //doSomethingElse will never be inferred as pure, //but may be inferred as nothrow, safe, or nogc disable(pure) void doSomethingElse()() {}
Jan 09 2015
On Fri, 9 Jan 2015 13:16:48 +0100 Daniel Koz=C3=A1k via Digitalmars-d <digitalmars-d puremagic.com> wrote:V Fri, 9 Jan 2015 14:11:00 +0200 ketmar via Digitalmars-d <digitalmars-d puremagic.com> naps=C3=A1no: =20i think it's acceptable even in this form. please, please make a PR from it, so even if it will not be accepted to mainline, i still can steal it for my private builds! ;-)can it be used like this: =20 final: nothrow: ... default void foo () { ... } ... =20 so only `foo` becomes default, but all other methods after `foo` are `final nothrow`?=20 not now, but I plan add this for now you can use: default { void foo () { ... }} =20=20 and can it be used like this: =20 default void foo () nothrow { ... } =20 so `default` resets all attrs and then i can specify another set of attrs inline?=20 same as the first one but this works: =20 default { void foo () nothrow { ... }}
Jan 09 2015