digitalmars.D - Auto-Boxing
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (22/30) Oct 15 2004 A question, I'm not sure if it's been asked:
- Stewart Gordon (7/14) Oct 15 2004 Before we can possibly have this, we'd need standard wrapper classes for...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (9/13) Oct 15 2004 I'm not sure. The issue just arose when discussing boolean and strings?
- Stewart Gordon (17/22) Oct 15 2004 AIUI the main reason for wrapper classes in Java was so that they can be...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/9) Oct 15 2004 Integer o = new Integer(i);
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/8) Oct 15 2004 I think you meant "D" instead of Java here ? If you did, I agree :-)
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (3/5) Oct 15 2004 Ehrm, Objective-C is just "C and Smalltalk". I meant C# and Python :-)
- Matthew (5/9) Oct 15 2004 IMO, Walter's single greatest point of genius vision was in the definiti...
- Derek (5/19) Oct 15 2004 Ummm... slices are not new. Euphoria has had them since 1993.
- Matthew (9/25) Oct 16 2004 news:ckp37m$2clu$2@digitaldaemon.com...
- Derek (7/35) Oct 16 2004 Sorry. I misunderstand you then. Your phrase "Walter's single greatest
- Matthew (2/34) Oct 16 2004 No worries. :)
- Stewart Gordon (6/20) Oct 18 2004 Oops ... should've caught that silly little typo before I pressed Send.
- Andy Friesen (7/11) Oct 15 2004 What would you use it for?
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (9/14) Oct 15 2004 Yeah, it does seem that way. So far the most opinions
A question, I'm not sure if it's been asked: Is Auto-Boxing a Good Thing or a Bad Thing ? And if it's good, should be available in D ? * With boxing, you can write stuff like: int i; Integer o = i; And have the compiler create an object. * Without boxing, you instead just get a type error: "cannot implicitly convert expression i of type int to Integer" And have to spell the object creation out for it: Integer o = new Integer(i); Makes it more readily apparent that a new object is being created, but takes a couple of extra keystrokes ? Would it be good to have the first code map into the second ? (so that when you assign a primitive to an object, it "boxes") Note that D already supports auto-*un*boxing, with opCast(): i = cast(int) o; Trying to do same cast thing in the other direction, cast(Integer), stuffs the address i in the reference and it goes South from there. What do you think? --anders PS. The class code was:class Integer { public: this(int i) { value = i; } int opCast() { return value; } private: int value; }
Oct 15 2004
Anders F Björklund wrote:A question, I'm not sure if it's been asked: Is Auto-Boxing a Good Thing or a Bad Thing ? And if it's good, should be available in D ?Before we can possibly have this, we'd need standard wrapper classes for the various types. But what do we need standard wrapper classes for? <snip>Note that D already supports auto-*un*boxing, with opCast(): i = cast(int) o;<snip> That isn't *auto*-unboxing. It's using the cast operator to manually unbox. Stewart.
Oct 15 2004
Stewart Gordon wrote:Before we can possibly have this, we'd need standard wrapper classes for the various types. But what do we need standard wrapper classes for?I'm not sure. The issue just arose when discussing boolean and strings? In Java, they're just used to pass around Objects to the Collection API and other such things. But I guess you could just as well just use the primitive types and instead apply templating ? Probably faster, too...That isn't *auto*-unboxing. It's using the cast operator to manually unbox.Right. Got my terminology a little confused there. Unboxing, not auto. So I guess using a primitive type constructor is manually boxing then? It's not that I miss all those Java objects for Strings and Arrays much. --anders
Oct 15 2004
Anders F Björklund wrote: <snip>In Java, they're just used to pass around Objects to the Collection API and other such things. But I guess you could just as well just use the primitive types and instead apply templating ? Probably faster, too...AIUI the main reason for wrapper classes in Java was so that they can be put into containers, in a language that lacks templates. Now Java 1.5 has templates, but only classes are allowed as parameter types. I'm guessing that this is down to some implementation constraint in how the Java VM works. The wrapper classes remain both to support legacy code and for use in the new templates. If these wrapper classes weren't needed for templates, then there probably wouldn't have been any point in inventing auto-(un)boxing this late in Java's life. OTOH, Java allows primitive types to be template parameters, and so chances are we don't really need wrapper classes. <snip>Right. Got my terminology a little confused there. Unboxing, not auto. So I guess using a primitive type constructor is manually boxing then?<snip> Primitive type constructor? You mean wrapper class constructor? Stewart.
Oct 15 2004
Stewart Gordon wrote:Primitive type constructor? You mean wrapper class constructor?Yeah, "wrapper class constructor that takes a primitive type argument".class Integer { public: this(int i) { value = i; }Integer o = new Integer(i); --anders
Oct 15 2004
Stewart Gordon wrote:OTOH, Java allows primitive types to be template parameters, and so chances are we don't really need wrapper classes.I think you meant "D" instead of Java here ? If you did, I agree :-) Wrapper classes are evil. Especially when used for things like String. If everything should be an object, there are plenty of other languages. (Smalltalk, Objective-C, Java, Ruby). No wrapper classes => No boxing. --anders
Oct 15 2004
Correction:If everything should be an object, there are plenty of other languages. (Smalltalk, Objective-C, Java, Ruby). No wrapper classes => No boxing.--anders
Oct 15 2004
"Anders F Björklund" <afb algonet.se> wrote in message news:ckp37m$2clu$2 digitaldaemon.com...Stewart Gordon wrote:IMO, Walter's single greatest point of genius vision was in the definition of slices. As with so many other things from D, I'm busy at the moment implementing slices for C++. Without garbage collection it is, as you can imagine, somewhat more difficult than it is in D. :-)OTOH, Java allows primitive types to be template parameters, and so chances are we don't really need wrapper classes.I think you meant "D" instead of Java here ? If you did, I agree :-) Wrapper classes are evil. Especially when used for things like String.
Oct 15 2004
On Sat, 16 Oct 2004 07:12:18 +1000, Matthew wrote:"Anders F Björklund" <afb algonet.se> wrote in message news:ckp37m$2clu$2 digitaldaemon.com...Ummm... slices are not new. Euphoria has had them since 1993. -- Derek Melbourne, AustraliaStewart Gordon wrote:IMO, Walter's single greatest point of genius vision was in the definition of slices. As with so many other things from D, I'm busy at the moment implementing slices for C++. Without garbage collection it is, as you can imagine, somewhat more difficult than it is in D. :-)OTOH, Java allows primitive types to be template parameters, and so chances are we don't really need wrapper classes.I think you meant "D" instead of Java here ? If you did, I agree :-) Wrapper classes are evil. Especially when used for things like String.
Oct 15 2004
"Derek" <derek psyc.ward> wrote in message news:1de5brneaifqv.1h59yjmxgfd11$.dlg 40tude.net...On Sat, 16 Oct 2004 07:12:18 +1000, Matthew wrote:news:ckp37m$2clu$2 digitaldaemon.com..."Anders F Björklund" <afb algonet.se> wrote in messageso chances are we don't really need wrapper classes.Stewart Gordon wrote:OTOH, Java allows primitive types to be template parameters, and:-)I think you meant "D" instead of Java here ? If you did, I agreeString.Wrapper classes are evil. Especially when used for things likedefinition of slices.IMO, Walter's single greatest point of genius vision was in theimplementing slices for C++. Without garbage collection itAs with so many other things from D, I'm busy at the momentThanks, but I didn't say they were. :-)is, as you can imagine, somewhat more difficult than it is in D. :-)Ummm... slices are not new. Euphoria has had them since 1993.
Oct 16 2004
On Sat, 16 Oct 2004 20:08:30 +1000, Matthew wrote:"Derek" <derek psyc.ward> wrote in message news:1de5brneaifqv.1h59yjmxgfd11$.dlg 40tude.net...Sorry. I misunderstand you then. Your phrase "Walter's single greatest point of genius vision was in the definition of slices" sounds to me as if it was saying that Walter was the person the defined what slices were. -- Derek Melbourne, AustraliaOn Sat, 16 Oct 2004 07:12:18 +1000, Matthew wrote:news:ckp37m$2clu$2 digitaldaemon.com..."Anders F Björklund" <afb algonet.se> wrote in messageso chances are we don't really need wrapper classes.Stewart Gordon wrote:OTOH, Java allows primitive types to be template parameters, and:-)I think you meant "D" instead of Java here ? If you did, I agreeString.Wrapper classes are evil. Especially when used for things likedefinition of slices.IMO, Walter's single greatest point of genius vision was in theimplementing slices for C++. Without garbage collection itAs with so many other things from D, I'm busy at the momentThanks, but I didn't say they were. :-)is, as you can imagine, somewhat more difficult than it is in D. :-)Ummm... slices are not new. Euphoria has had them since 1993.
Oct 16 2004
"Derek" <derek psyc.ward> wrote in message news:1n43gmo4ws1da$.14h8ff6hyyiyp$.dlg 40tude.net...On Sat, 16 Oct 2004 20:08:30 +1000, Matthew wrote:No worries. :)"Derek" <derek psyc.ward> wrote in message news:1de5brneaifqv.1h59yjmxgfd11$.dlg 40tude.net...Sorry. I misunderstand you then. Your phrase "Walter's single greatest point of genius vision was in the definition of slices" sounds to me as if it was saying that Walter was the person the defined what slices were.On Sat, 16 Oct 2004 07:12:18 +1000, Matthew wrote:news:ckp37m$2clu$2 digitaldaemon.com..."Anders F Björklund" <afb algonet.se> wrote in messageso chances are we don't really need wrapper classes.Stewart Gordon wrote:OTOH, Java allows primitive types to be template parameters, and:-)I think you meant "D" instead of Java here ? If you did, I agreeString.Wrapper classes are evil. Especially when used for things likedefinition of slices.IMO, Walter's single greatest point of genius vision was in theimplementing slices for C++. Without garbage collection itAs with so many other things from D, I'm busy at the momentThanks, but I didn't say they were. :-)is, as you can imagine, somewhat more difficult than it is in D. :-)Ummm... slices are not new. Euphoria has had them since 1993.
Oct 16 2004
Derek wrote:On Sat, 16 Oct 2004 07:12:18 +1000, Matthew wrote:Oops ... should've caught that silly little typo before I pressed Send. <snip>"Anders F Björklund" <afb algonet.se> wrote in message news:ckp37m$2clu$2 digitaldaemon.com...Stewart Gordon wrote:OTOH, Java allows primitive types to be template parameters, and so chances are we don't really need wrapper classes.I think you meant "D" instead of Java here ? If you did, I agree :-) Wrapper classes are evil. Especially when used for things like String.Ummm... slices are not new. Euphoria has had them since 1993.Fortran 90 has slices - I'm not sure about F77. Just about every BASIC ever invented has string slices at least. Stewart.
Oct 18 2004
Anders F Björklund wrote:A question, I'm not sure if it's been asked: Is Auto-Boxing a Good Thing or a Bad Thing ? And if it's good, should be available in D ?What would you use it for? The only time I have ever wanted to do this is when stuffing primitive automatic boxing is a cludge over a horrible, crippling weakness and not a feature. :) -- andy
Oct 15 2004
Andy Friesen wrote:Is Auto-Boxing a Good Thing or a Bad Thing ?The only time I have ever wanted to do this is when stuffing primitive automatic boxing is a cludge over a horrible, crippling weakness and not a feature. :)Yeah, it does seem that way. So far the most opinions have been that auto-boxing creates a lot of wasteful objects, especially if you *mix* classes and primitives. And that auto-unboxing creates some troubles will null, and with checks for identity and also with assignments... So it does seem that it's more or less just a kludge ? And of course, it's a nice little marketing buzzword. --anders
Oct 15 2004