digitalmars.D - initial values
- Ben Hinkle (21/21) Mar 16 2005 Let me bring up an old chestnut topic: default initial values.
- Jarrett Billingsley (4/6) Mar 16 2005 I can see it now.
- Ben Hinkle (4/9) Mar 16 2005 actually that is a bug in dmd since the spec says dynamic arrays are fil...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/9) Mar 16 2005 There is a similar bug with the autocreated value of missing AA keys...
- Jarrett Billingsley (4/6) Mar 16 2005 Oh.
- Craig Black (4/6) Mar 17 2005 I don't know if I like the idea of needlessly initializing large arrays ...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/10) Mar 17 2005 At least allocating them as "zero" would be both fast and usable... ?
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (22/36) Mar 17 2005 Note that this only talks about local variables. Class fields are always
- Ben Hinkle (19/54) Mar 17 2005 Wow - it also says unused variables are an error. Is the doc out of date...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/12) Mar 17 2005 As in "we haven't had a good fight in a while". Or as in it has changed?
- Ben Hinkle (14/25) Mar 17 2005 heh. you're right - I shouldn't have been surprised.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (15/21) Mar 17 2005 Well, there's been several "lacks of consistancy" over my time here.
- Sean Kelly (10/11) Mar 17 2005 I wrote a version of this ages ago. I haven't tested it since perhaps r...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (8/19) Mar 17 2005 I actually just updated this, that was why I mentioned it.
Let me bring up an old chestnut topic: default initial values. My beef with the current treatment of initial values is that some initial values (like integer and pointer types) are very convenient and some are very inconvenient (like char and floating point types). Walter has stated that if there existed an inconvenient integer or pointer value he would use that (I hope I remembered that correctly). But in practice the convenience of the initial values can be crucial. I almost never see code that explicitly initializes integers to 0 or pointers to null. For example the word count example at the bottom of the associative array example uses the statement dictionary[word]++; to both insert the word in the array if it wasn't present and increment its word count. I noticed that statement when thinking about the associative array indexing behavior but I'd like to use it now as an example of how people (including Walter himself) use initial values for their convenience. D is harder to use when some types have convenient intial values and some don't. Let's aim for consistency and just make all initial values convenient. Does anyone know of another language that has nan as the default floating point value? While I'm at it the char types initial values should IMO go back to 0, too. As an aside, if you allocate an array of double[] or char[] the array is initially filled with 0's. -Ben
Mar 16 2005
As an aside, if you allocate an array of double[] or char[] the array is initially filled with 0's.I can see it now. "DMD 0.119 release! Bugs fixed: double[] and char[] arrays are now initialized to nan and 0xffff, respectively." ;)
Mar 16 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:d1a507$22h8$1 digitaldaemon.com...actually that is a bug in dmd since the spec says dynamic arrays are filled with the default value when resized.As an aside, if you allocate an array of double[] or char[] the array is initially filled with 0's.I can see it now. "DMD 0.119 release! Bugs fixed: double[] and char[] arrays are now initialized to nan and 0xffff, respectively."
Mar 16 2005
Ben Hinkle wrote:There is a similar bug with the autocreated value of missing AA keys... I guess just uses calloc, and "forgets" to set the proper .init values? --anders"DMD 0.119 release! Bugs fixed: double[] and char[] arrays are now initialized to nan and 0xffff, respectively."actually that is a bug in dmd since the spec says dynamic arrays are filled with the default value when resized.
Mar 16 2005
"Ben Hinkle" <bhinkle mathworks.com> wrote in message news:d1a5mt$235t$1 digitaldaemon.com...actually that is a bug in dmd since the spec says dynamic arrays are filled with the default value when resized.Oh. ..
Mar 16 2005
actually that is a bug in dmd since the spec says dynamic arrays are filled with the default value when resized.I don't know if I like the idea of needlessly initializing large arrays to unusable values. Wouldn't this have a significant adverse effect on performance? Perhaps this could be a compiler option. -Craig
Mar 17 2005
Craig Black wrote:At least allocating them as "zero" would be both fast and usable... ? I think the arrays are right, and that the .init values need changing. --andersactually that is a bug in dmd since the spec says dynamic arrays are filled with the default value when resized.I don't know if I like the idea of needlessly initializing large arrays to unusable values. Wouldn't this have a significant adverse effect on performance? Perhaps this could be a compiler option.
Mar 17 2005
Ben Hinkle wrote:My beef with the current treatment of initial values is that some initial values (like integer and pointer types) are very convenient and some are very inconvenient (like char and floating point types). Walter has stated that if there existed an inconvenient integer or pointer value he would use that (I hope I remembered that correctly).http://www.digitalmars.com/d/function.html says:Local Variables It is an error to use a local variable without first assigning it a value. The implementation may not always be able to detect these cases. Other language compilers sometimes issue a warning for this, but since it is always a bug, it should be an error.Note that this only talks about local variables. Class fields are always initialized to the .init values (arrays *should* be, but it is buggy...) It sounds a bit strange that the default values of all such fields, that are being automatically initialized, should be as inconvenient as possible ? (for local vars, it would make sense since those are illegal anyway and might as well have such "sentinel" default values) Not to give Walter any ideas, but -1 is a pretty inconvenient value... Imagine if all integers and pointers started with that default! Ouch. It would make more sense to give all types convenient values instead ? (i.e. make them *all* zero, as in: 0 or 0.0 or false or null or '\0') That is: change characters and floats, instead of integers and pointers? (but this has probably *also* been beaten to death already, on this NG?)Does anyone know of another language that has nan as the default floating point value?No, but D floating point support aims to be... different. :-) (just take a look at x!<>=y, which I haven't seen elsewhere?)While I'm at it the char types initial values should IMO go back to 0, too.That would make D closer to what I am used to, too: Let's just hope this does not end up making the default value for integers and pointers unusable too... That would be sad... Like when the default string points to 0xDEADBEEF and is -1 long :-P --anders
Mar 17 2005
"Anders F Björklund" <afb algonet.se> wrote in message news:d1c7ch$157m$1 digitaldaemon.com...Ben Hinkle wrote:Wow - it also says unused variables are an error. Is the doc out of date? DMD doesn't complain if I use an implicitly-initialize variable or declare an unsed variable. Not even a warning. If the doc is right I urge Walter to fix the compiler to enforce the error so that we have time to update our code. Given a choice I prefer the current compiler behavior - allow people to use defaults and be sloppy with declarations (though perhaps warn). If there is a strong reason for it (eg, it enables better optimizations, etc) then erroring is fine.My beef with the current treatment of initial values is that some initial values (like integer and pointer types) are very convenient and some are very inconvenient (like char and floating point types). Walter has stated that if there existed an inconvenient integer or pointer value he would use that (I hope I remembered that correctly).http://www.digitalmars.com/d/function.html says:Local Variables It is an error to use a local variable without first assigning it a value. The implementation may not always be able to detect these cases. Other language compilers sometimes issue a warning for this, but since it is always a bug, it should be an error.Note that this only talks about local variables. Class fields are always initialized to the .init values (arrays *should* be, but it is buggy...) It sounds a bit strange that the default values of all such fields, that are being automatically initialized, should be as inconvenient as possible ? (for local vars, it would make sense since those are illegal anyway and might as well have such "sentinel" default values) Not to give Walter any ideas, but -1 is a pretty inconvenient value... Imagine if all integers and pointers started with that default! Ouch. It would make more sense to give all types convenient values instead ? (i.e. make them *all* zero, as in: 0 or 0.0 or false or null or '\0')agreed.That is: change characters and floats, instead of integers and pointers? (but this has probably *also* been beaten to death already, on this NG?)yeah - but it's been a while :-)But at least that is additional behavior that other languages don't have. One can safely ignore those extra features. Default values exist in other languages and it gets annoying that D's are different.Does anyone know of another language that has nan as the default floating point value?No, but D floating point support aims to be... different. :-) (just take a look at x!<>=y, which I haven't seen elsewhere?)That's what I have in mind, too.While I'm at it the char types initial values should IMO go back to 0, too.That would make D closer to what I am used to, too:Let's just hope this does not end up making the default value for integers and pointers unusable too... That would be sad...All I'm asking for is consistency - either all unusable or all usable. With a preference for making them usable.Like when the default string points to 0xDEADBEEF and is -1 long :-Phehe.
Mar 17 2005
Ben Hinkle wrote:Wow - it also says unused variables are an error. Is the doc out of date?You must be new here :-) (just kidding, but a lot of D docs are old...?)As in "we haven't had a good fight in a while". Or as in it has changed?That is: change characters and floats, instead of integers and pointers? (but this has probably *also* been beaten to death already, on this NG?)yeah - but it's been a while :-)All I'm asking for is consistency - either all unusable or all usable. With a preference for making them usable.Consistency seems to be a big deal lately :-) Not sure we're getting it. --anders
Mar 17 2005
In article <d1cb3k$19ic$1 digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...Ben Hinkle wrote:heh. you're right - I shouldn't have been surprised.Wow - it also says unused variables are an error. Is the doc out of date?You must be new here :-) (just kidding, but a lot of D docs are old...?)As in "it has been a while since it was last discussed and given the people reading the list have changed and Walter is winding down on 1.0 it would be worth revisiting to make sure the right thing happens". If all that happens is the doc is fixed and the compiler bugs are fixed with dynamic arrays then that would be better than nothing.As in "we haven't had a good fight in a while". Or as in it has changed?That is: change characters and floats, instead of integers and pointers? (but this has probably *also* been beaten to death already, on this NG?)yeah - but it's been a while :-)Please don't lump this in with length, if that is what you mean. :-P The two are unrelated - mostly w.r.t the scope of the issue. The $length and friends were about a consitent syntax for some pretty different concepts - some of which already existed in C and some not. That makes life much more complicated. Consistency within a single concept (default values) feels to me like a different argument than the length consistency argument.All I'm asking for is consistency - either all unusable or all usable. With a preference for making them usable.Consistency seems to be a big deal lately :-) Not sure we're getting it.
Mar 17 2005
Ben Hinkle wrote:Well, there's been several "lacks of consistancy" over my time here. The latest one was _arguments versus __FILE__, that is correct... Then there was "bit" versus "true" and "false" (which *still* sucks) http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/11757 And there was the lack of std.stdio.readf and std.string.unformat. Plus the lack of a "isnot", even though === was replaced with "is" ? http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/14705 How bitfields are now totally lame, but how bit arrays rules the world. ... Little things like that. Some of them petty, some of them disturbing... Obviously I like D a lot, or I wouldn't bother with these trivialities. But me too hopes the .init values can be changed into more convenient. And that the definition of void main can be settled, once and for all. --andersPlease don't lump this in with length, if that is what you mean. :-PAll I'm asking for is consistency - either all unusable or all usable. With a preference for making them usable.Consistency seems to be a big deal lately :-) Not sure we're getting it.
Mar 17 2005
In article <d1cijj$1i10$2 digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...And there was the lack of std.stdio.readf and std.string.unformat.I wrote a version of this ages ago. I haven't tested it since perhaps release 96, but it's available here: http://home.f4.ca/sean/d/stdio.zip I never submitted it to Walter because I was waiting for typeinfo to improve for pointers so I could tune it a bit first. It also needs some testing with wide characters, since putback may potentially have to put back up to 4 bytes at the end of the read process. Sean
Mar 17 2005
Sean Kelly wrote:I actually just updated this, that was why I mentioned it. See my other post, titled "readf and unformat (updated)" ? It's working great, but TypeInfo is broken - especially on GDC... The workaround you used only works on "_arguments", not on copies. I renamed your "sreadf" as std.string.unformat instead, and changed the definitions of getc/ungetc to use EOF... --andersAnd there was the lack of std.stdio.readf and std.string.unformat.I wrote a version of this ages ago. I haven't tested it since perhaps release 96, but it's available here: http://home.f4.ca/sean/d/stdio.zip I never submitted it to Walter because I was waiting for typeinfo to improve for pointers so I could tune it a bit first. It also needs some testing with wide characters, since putback may potentially have to put back up to 4 bytes at the end of the read process.
Mar 17 2005