digitalmars.D - Changes before 1.0
- Jordan Miner (64/64) Dec 02 2006 Hello, I have been reading this newsgroup on and off for over a year, bu...
- Miles (15/25) Dec 02 2006 Properties are also broken for cases like:
- Jordan Miner (9/34) Dec 02 2006 Yeah, this was just an idea I had, and I thought that it would be easy t...
- Unknown W. Brackets (8/13) Dec 02 2006 Personally, I think it wouldn't be hard for the compiler to do this for
- Oskar Linde (19/31) Dec 04 2006 What is sad is that with the current property syntax, D can *never*
- Leandro Lucarella (27/39) Dec 04 2006 I think you can add this to the thread "Python-like tabs instead of
- Frits van Bommel (4/14) Dec 04 2006 I think that cursor.position should be button.width...
- Leandro Lucarella (7/24) Dec 04 2006 Well, they have the same value at that point, so what's the difference?
- Frits van Bommel (12/24) Dec 04 2006 Sorry, I thought cursor.position was a property?
- Tom (10/34) Dec 02 2006 I've discovered D in a similar manner :) (only that I'm following it
- Thomas Kuehne (11/17) Dec 03 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Bruno Medeiros (6/23) Dec 06 2006 Or just:
- janderson (11/16) Dec 03 2006 It would be even more helpful if a .ToString() for enums was added. The...
- Bill Baxter (12/31) Dec 03 2006 I agree that I've wanted this kind of feature before too, but I don't
- janderson (11/24) Dec 03 2006 I don't agree on this point (that it would only be used in debug). As I...
- Bill Baxter (7/35) Dec 03 2006 Useful for bridging with scripting code. That's a good point. Python
- Kirk McDonald (8/9) Dec 04 2006 Currently nothing. Python has no obvious analogue, so enums are not
- janderson (33/68) Dec 04 2006 sorry I ment: slightly more bug prone but not much longer...
- janderson (7/94) Dec 05 2006 For clarity that should be more like:
Hello, I have been reading this newsgroup on and off for over a year, but this is my first post. I first found D because I got fed up with the VMs of Java language that compiled to native code, but was easier to use than C++, and I found D within minutes. When I first started using D, there were many parts I though could be improved, but I am OK with most of them now. I have been working on a GUI library for D for months now, but I don't want to release it until it is usable. While working on it, I have run into several things in D that I wish were changed. Here are a few I think could be added before 1.0. --1-- The following does not work, but it really should: void print(char[][] strs) { } print(["Matt", "Andrew"]); Gives: Error: cannot implicitly convert expression ("Andrew") of type char[6] to char[4] --2-- Sometimes using the property syntax causes a compiler error: with(obj.propName) { // gives an error without parentheses } auto foo = obj.propName; // gives an error without parentheses These are common uses of property syntax, and I think they should work. --3-- I noticed one day that this kind of a loop is fairly common: while(true) { doSomething(); if(!shouldContinue) break; doSomethingElse(); } It might be better to make an extended do-while loop that has code before and after the condition: do { doSomething(); } while(shouldContinue) { doSomethingElse(); } The latter is shorter and IMO cleaner. --4-- It would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2); It should print "Value2", but instead gives: Error: std.format formatArg so I tried printing it and I got the name of the enum member. enum TestEnum { Value1, Value2 } Console.WriteLine(TestEnum.Value2); This prints "Value2" with .NET. --5-- I know that it has been brought up before, but I would like to add my support to this being put into object.d: alias char[] string; ----- I also really want stack traces for exceptions/access violations and big Ddoc improvements, but those don't change the language and can wait until after 1.0. I would also really really like to have closures/static delegates, but that would probably take some time, what with escape analysis and all. BTW, I really like how Walter wants to implement them--with the current delegate syntax using escape analysis. D will be amazing then.
Dec 02 2006
Jordan Miner wrote:Sometimes using the property syntax causes a compiler error:Properties are also broken for cases like: button.width -= 5; cursor.position++; This is the essence of properties (it should be completely transparent for the user if it is accessing a variable or calling a method), yet D doesn't support it properly. This has the potential to break a lot of code when you convert variables into properties.do { doSomething(); } while(shouldContinue) { doSomethingElse(); }Interleaving. But it would be pretty useless if the two blocks had different scopes.enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);IMO, a nice way to bloat your executable code. I'd recommend placing this feature on a debugger, and the string repr of enums should be debug data. If you need string equivalence for enums, you should put them in a separate string array, and just index it with the enum. This allows better description of values and also makes l10n more straightforward.
Dec 02 2006
== Quote from Miles (_______ _______.____)'s articleJordan Miner wrote:Yes, it would be great if operators would work with them as well.Sometimes using the property syntax causes a compiler error:Properties are also broken for cases like: button.width -= 5; cursor.position++; This is the essence of properties (it should be completely transparent for the user if it is accessing a variable or calling a method), yet D doesn't support it properly. This has the potential to break a lot of code when you convert variables into properties.Yeah, this was just an idea I had, and I thought that it would be easy to implement. And it would definitely be best if both blocks had the same scope.do { doSomething(); } while(shouldContinue) { doSomethingElse(); }Interleaving. But it would be pretty useless if the two blocks had different scopes.Yes, the only time I wanted this was during debugging. Otherwise it can be difficult to find out which enum name a variable is. .NET's docs do not say enum values, and the source is not available. Even with D, it is more convinient to just put writefln("%s", variable) to find out. (I don't use debuggers.) Any other time I need the description of an enum, I would use a string array.enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);IMO, a nice way to bloat your executable code. I'd recommend placing this feature on a debugger, and the string repr of enums should be debug data. If you need string equivalence for enums, you should put them in a separate string array, and just index it with the enum. This allows better description of values and also makes l10n more straightforward.
Dec 02 2006
Personally, I think it wouldn't be hard for the compiler to do this for you, but only bloat your code with it if it's ever used. For example: enum Example; writefln("%s", Example.names[some_value]); Or whatever. Then again, maybe it's non-trivial to detect the usage. I wouldn't think so, though. -[Unknown]IMO, a nice way to bloat your executable code. I'd recommend placing this feature on a debugger, and the string repr of enums should be debug data. If you need string equivalence for enums, you should put them in a separate string array, and just index it with the enum. This allows better description of values and also makes l10n more straightforward.
Dec 02 2006
Miles wrote:Jordan Miner wrote:What is sad is that with the current property syntax, D can *never* achieve transparency. Even if ++a.x would be transformed into a.x(a.x()+1) there are cases that can never be transformed into an "accessor" property and make the accessing code remain the same. E.g: struct Type { int delegate() prop; } Type t; Used: t.prop() Try transforming that into an accessor property: struct Type { int delegate() prop() { return { return 0; }; } } Now, t.prop() will have a different meaning. The problem here is that the trailing parenthesis pair () is allowed but not necessary. t.prop() could mean both t.prop and t.prop()(). /OskarSometimes using the property syntax causes a compiler error:Properties are also broken for cases like: button.width -= 5; cursor.position++; This is the essence of properties (it should be completely transparent for the user if it is accessing a variable or calling a method), yet D doesn't support it properly. This has the potential to break a lot of code when you convert variables into properties.
Dec 04 2006
Miles escribió:Jordan Miner wrote:I think you can add this to the thread "Python-like tabs instead of curley brackets?" where Walter says: "Every programming language has some stupid mistake in it that sounded like a good idea at the time: [other languages problems] D: I'm sure you all have your own ideas for this!" I mean, properties are great, but to be really useful they have to support the same semantics as regular variables. Maybe somethig as simple as translating button.width -= 5; as cursor.position = button.width - 5; is enough. Postfix incrementation is maybe the only problematic one, but could be done with something like: { auto tmp = cursor.position; cursor.position = cursor.position + 1; return tmp; } (I think you'll get the idea ;) This last scheme could be generally used to implement the other operators: 1) make a copy of the property 2) operate over the copy 3) update the property. Or maybe the "stupid mistake" is deeper and it comes from the side of treating differently POD and objects... -- Leandro Lucarella Integratech S.A. 4571-5252Sometimes using the property syntax causes a compiler error:Properties are also broken for cases like: button.width -= 5; cursor.position++; This is the essence of properties (it should be completely transparent for the user if it is accessing a variable or calling a method), yet D doesn't support it properly. This has the potential to break a lot of code when you convert variables into properties.
Dec 04 2006
Some nitpicks :) Leandro Lucarella wrote:I mean, properties are great, but to be really useful they have to support the same semantics as regular variables. Maybe somethig as simple as translating button.width -= 5; as cursor.position = button.width - 5; is enough. Postfix incrementation is maybe the onlyI think that cursor.position should be button.width...problematic one, but could be done with something like: { auto tmp = cursor.position; cursor.position = cursor.position + 1;Surely you mean 'cursor.position = tmp + 1;'?return tmp; }
Dec 04 2006
Frits van Bommel escribió:Some nitpicks :) Leandro Lucarella wrote:Yup! =)I mean, properties are great, but to be really useful they have to support the same semantics as regular variables. Maybe somethig as simple as translating button.width -= 5; as cursor.position = button.width - 5; is enough. Postfix incrementation is maybe the onlyI think that cursor.position should be button.width...Well, they have the same value at that point, so what's the difference?problematic one, but could be done with something like: { auto tmp = cursor.position; cursor.position = cursor.position + 1;Surely you mean 'cursor.position = tmp + 1;'?-- Leandro Lucarella Integratech S.A. 4571-5252return tmp; }
Dec 04 2006
Leandro Lucarella wrote:Frits van Bommel escribió:<snip>Some nitpicks :) Leandro Lucarella wrote:Sorry, I thought cursor.position was a property? If so, the way you wrote it the getter would be called twice as opposed to once with the rewrite. If the getter returned something else the second time[1] then the returned value wouldn't even be one less than the new value[2]. Plus accessing a local variable is probably more efficient than calling a getter :). [1]: This is probably pretty bad style, but it _is_ legal. [2]: Unless of course the setter did something weird as well, but let's not get into that.Well, they have the same value at that point, so what's the difference?problematic one, but could be done with something like: { auto tmp = cursor.position; cursor.position = cursor.position + 1;Surely you mean 'cursor.position = tmp + 1;'?
Dec 04 2006
Jordan Miner wrote:Hello, I have been reading this newsgroup on and off for over a year, but this is my first post. I first found D because I got fed up with the VMs of Java language that compiled to native code, but was easier to use than C++, and I found D within minutes.I've discovered D in a similar manner :) (only that I'm following it since 2004). I'm still so glad I found it.--4-- It would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2); It should print "Value2", but instead gives: Error: std.format formatArg so I tried printing it and I got the name of the enum member. enum TestEnum { Value1, Value2 } Console.WriteLine(TestEnum.Value2); This prints "Value2" with .NET.I agree enums could be so much better.--5-- I know that it has been brought up before, but I would like to add my support to this being put into object.d: alias char[] string;Yep, I do ALWAYS write this alias in my D programs. Also: alias wchar[] wstring; alias dchar[] dstring; -- Tom;
Dec 02 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jordan Miner schrieb am 2006-12-02:--1-- The following does not work, but it really should: void print(char[][] strs) { } print(["Matt", "Andrew"]); Gives: Error: cannot implicitly convert expression ("Andrew") of type char[6] to char[4]current by-pass: print([cast(char[])"Matt", "Andrew"]); Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFcokqLK5blCcjpWoRApj5AJsEefCVGCPbDNEbQ7w2X4o2YfFxiQCeNSMj UrCf1EgP/ihgUeHVVOpc6go= =Vr9o -----END PGP SIGNATURE-----
Dec 03 2006
Thomas Kuehne wrote:-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jordan Miner schrieb am 2006-12-02:Or just: print(["Matt"[], "Andrew"]); -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D--1-- The following does not work, but it really should: void print(char[][] strs) { } print(["Matt", "Andrew"]); Gives: Error: cannot implicitly convert expression ("Andrew") of type char[6] to char[4]current by-pass: print([cast(char[])"Matt", "Andrew"]); Thomas
Dec 06 2006
It would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);It would be even more helpful if a .ToString() for enums was added. The compiler could detect when it was used and only add those particular enums to the binary. It would be most useful in scripting where you want to convert a string to an enum. Which leads on to having a way of converting a string to an enum directly. string myenum = "Value1"; TestEnum result = myenum; Ok getting its a bit complicated here and probably not worth the effort however I deal with this type of code at least once a week. Maybe that would be a 2.0 feature. -Joel
Dec 03 2006
janderson wrote:I agree that I've wanted this kind of feature before too, but I don't want it at the expense of bloating every single library that contains enums with lots of string equivalents that will never get used in real code. I.e. this kind of thing is really only useful for debug or prototype code. But I think you're right, the compiler has to have access to the enum names in order to compile any code that uses the enums, and if it does then it should be able to replace something like enumval.str with the literal string value. So it would act more like a macro expanded at compile time than an actual function. --bbIt would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);It would be even more helpful if a .ToString() for enums was added. The compiler could detect when it was used and only add those particular enums to the binary. It would be most useful in scripting where you want to convert a string to an enum. Which leads on to having a way of converting a string to an enum directly. string myenum = "Value1"; TestEnum result = myenum; Ok getting its a bit complicated here and probably not worth the effort however I deal with this type of code at least once a week. Maybe that would be a 2.0 feature.
Dec 03 2006
Bill Baxter wrote:janderson wrote:I don't agree on this point (that it would only be used in debug). As I said, in scripting (ie game ai ect...) and in plugin libraries (ie maya) its common place to use a string lookup for enums. The code isn't *much* longer or more bug pron to write unless you go the other way and want it to be efficient (ie string->enum is more complex then enum->string). Still both cases are pretty trivial to write in code. I guess the main thing going for it is that users would recognize the pattern much more quickly (ie readability) although it does reduce the chance of offset errors (had one of those just the other day). -JoelI agree that I've wanted this kind of feature before too, but I don't want it at the expense of bloating every single library that contains enums with lots of string equivalents that will never get used in real code. I.e. this kind of thing is really only useful for debug or prototype code. --bbIt would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);
Dec 03 2006
janderson wrote:Bill Baxter wrote:Mmmm -- bug pr0n. *much* longer ... more bug pr0n.... :-)janderson wrote:I don't agree on this point (that it would only be used in debug). As I said, in scripting (ie game ai ect...) and in plugin libraries (ie maya) its common place to use a string lookup for enums. The code isn't *much* longer or more bug pronI agree that I've wanted this kind of feature before too, but I don't want it at the expense of bloating every single library that contains enums with lots of string equivalents that will never get used in real code. I.e. this kind of thing is really only useful for debug or prototype code. --bbIt would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);to write unless you go the other way and want it to be efficient (ie string->enum is more complex then enum->string). Still both cases are pretty trivial to write in code. I guess the main thing going for it is that users would recognize the pattern much more quickly (ie readability) although it does reduce the chance of offset errors (had one of those just the other day). -JoelUseful for bridging with scripting code. That's a good point. Python has no enums either, so they sometimes get turned into strings when going into Python land. Hey Kirk if you're listening, what does PyD do with enums? --bb
Dec 03 2006
Bill Baxter wrote:Hey Kirk if you're listening, what does PyD do with enums?Currently nothing. Python has no obvious analogue, so enums are not currently a convertible type. Enums and structs are high on the list of things I need to support. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Dec 04 2006
Bill Baxter wrote:janderson wrote:sorry I ment: slightly more bug prone but not much longer... //enum -> string enum A { Value1, ... }; string A[] = { "Value1", ... }; //string to enum A AToString[char[]]; void register() { AToString["Value1"] = Value; //ect... } Really not that much code. Also a lot of times in C++ you register lots of things together... struct AInfo { string name; string discription; int cost; }; string A[] = { { "Value1", "Some value I picked", 10 }, ... };Bill Baxter wrote:Mmmm -- bug pr0n. *much* longer ... more bug pr0n.... :-)janderson wrote:I don't agree on this point (that it would only be used in debug). As I said, in scripting (ie game ai ect...) and in plugin libraries (ie maya) its common place to use a string lookup for enums. The code isn't *much* longer or more bug pronI agree that I've wanted this kind of feature before too, but I don't want it at the expense of bloating every single library that contains enums with lots of string equivalents that will never get used in real code. I.e. this kind of thing is really only useful for debug or prototype code. --bbIt would be helpful if the following code would work: enum TestEnum { Value1, Value2 } writefln("%s", TestEnum.Value2);to write unless you go the other way and want it to be efficient (ie string->enum is more complex then enum->string). Still both cases are pretty trivial to write in code. I guess the main thing going for it is that users would recognize the pattern much more quickly (ie readability) although it does reduce the chance of offset errors (had one of those just the other day). -JoelUseful for bridging with scripting code. That's a good point. Python has no enums either, so they sometimes get turned into strings when going into Python land. Hey Kirk if you're listening, what does PyD do with enums? --bb
Dec 04 2006
janderson wrote:Bill Baxter wrote: > janderson wrote: >> Bill Baxter wrote: >>> janderson wrote: >>>>> It would be helpful if the following code would work: >>>>> enum TestEnum { >>>>> Value1, Value2 >>>>> } >>>>> writefln("%s", TestEnum.Value2); >>> >>> I agree that I've wanted this kind of feature before too, but I don't >>> want it at the expense of bloating every single library that contains >>> enums with lots of string equivalents that will never get used in >>> real code. I.e. this kind of thing is really only useful for debug >>> or prototype code. >>> --bb >> >> I don't agree on this point (that it would only be used in debug). As >> I said, in scripting (ie game ai ect...) and in plugin libraries (ie >> maya) its common place to use a string lookup for enums. The code >> isn't *much* longer or more bug pron > > Mmmm -- bug pr0n. *much* longer ... more bug pr0n.... :-) sorry I ment: slightly more bug prone but not much longer... //enum -> string enum A { Value1, ... }; string A[] = { "Value1", ... }; //string to enum A AToString[char[]]; void register() { AToString["Value1"] = Value; //ect... } Really not that much code. Also a lot of times in C++ you register lots of things together... struct AInfo { string name; string discription; int cost; }; string A[] = { { "Value1", "Some value I picked", 10 }, ... };For clarity that should be more like: AInfo A[] = { { "Value1", "Some value I picked", 10 }, ... };> >> to write unless you go the other way and want it to be efficient (ie >> string->enum is more complex then enum->string). Still both cases are >> pretty trivial to write in code. >> >> I guess the main thing going for it is that users would recognize the >> pattern much more quickly (ie readability) although it does reduce the >> chance of offset errors (had one of those just the other day). >> >> -Joel > > Useful for bridging with scripting code. That's a good point. Python > has no enums either, so they sometimes get turned into strings when > going into Python land. > > Hey Kirk if you're listening, what does PyD do with enums? > > --bb
Dec 05 2006