Jump to content

Talk:Boxing (computer programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pcap (talk | contribs) at 12:52, 27 August 2009 (Def, scope, mess: clarify). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


WikiProject iconComputing: Software / CompSci Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Software (assessed as Mid-importance).
Taskforce icon
This article is supported by WikiProject Computer science (assessed as Mid-importance).
Things you can help WikiProject Computer science with:

int i = 9;
int j = 13;
int k = i + j;

This is done all in a primitive type. Shouldn't the first line, for example, be "Integer i = 9"? -- Taku 01:24, September 1, 2005 (UTC)

This article doesn't say much about what an object type is. It's trying to explain autoboxing, but not doing a very good job. I'd rather read the Sun article. Can anyone do a better job? --Uncle Ed 21:42, 7 November 2006 (UTC)[reply]


Isn't it all about 'object types' living garbage collectably on the heap, and primitive types, structs living on the stack? (at least in c# and java). Boxing is creating a new object on heap out of a stack object so it can be manipulated with a reference - it is unsafe to get a reference to an object living on stack, because it could die too early and program could crash. exe 03:32, 13 May 2007 (UTC)[reply]


I think that the part about unboxing mostly speaks about what code constructs different versions of the java compiler/language accepts, and not about the language neutral concept of boxing/unboxing. I think that part should be removed, or at least some of it. (Sorry, no wikipedia account. LarsR) 10:10, 8 Aug 2007 (CET)


Made it a little more generic, and precised that since .Net, not all value types are primitive types.Medinoc (talk) 11:10, 8 October 2008 (UTC)[reply]

Haskell unboxing

Unboxing redirects here, but this is about how objects work in Java. It doesn't seem to be a suitable place to put something about unboxed types in Haskell, although there is similarity in the underlying concepts. In Haskell everything by default is 'boxed', and a boxed thing could be either the thing itself or some unevaluated expression that could evaluate to something of the correct type (because Haskell is lazy). Furby100 (talk) 21:15, 12 January 2008 (UTC)[reply]

Drepnir (talk) 23:08, 26 November 2008 (UTC) Found something wrong:[reply]

Another example:

int i = 4;
int j = 5;
Integer k = new Integer(i + j); // always OK
Integer l = i + j; // would have been an error, but okay now - equivalent to previous line


C# does not support automatic unboxing. A boxed object must be explicitly unboxed with a typecasting operator:

int i = 42;
object o = i; //box
int j = (int)o; //unbox
Console.Writeline(j); //outputs 42


It is assumed that the following will compile on Java, but it won't. C# does support automatic unboxing of primitives, but not objects, just like Java.

int i = 42;
Object o = i; //box
int j = o; //unbox
System.out.println(j); //outputs "42"

Will not compile because it can't unbox objects of type Object.

Def, scope, mess

This article is about boxing, unboxing and autoboxing. The definition of "object type" given here is dubiously narrow. See object type. I think this article should be moved to Boxing, unboxing and autoboxing. Compare with Covariance and contravariance (computer science)... Pcap ping 09:26, 26 August 2009 (UTC)[reply]

Shouldn't the solution be to rewrite the article so to include more general discussion? Boxing is simply an example. The concept is more general. -- Taku (talk) 19:57, 26 August 2009 (UTC)[reply]
Object type should normally redirect to Object (computer science) where the notion should be defined in context. Except that article is a mess too because it tries to do Object-oriented programming advocacy instead of focusing on the technical matters. The other reason I made that ridiculous dab is the uncited definition given in this article and the (IMO, unjustifiably general) name this article had.
Boxing/unboxing/autoboxing are issues in the implementation of object oriented programming languages. These aren't issues of how objects are implemented, but of how primitive types relate to objects; in some languages like Ruby (or Scala IIRC), all primitive types are objects.
So, I think the best solution is to rename this article to Boxing, unboxing and autoboxing and add a WP:SUMMARY of this at primitive types and at object (computer science). Pcap ping 07:01, 27 August 2009 (UTC)[reply]
After a little more thought, these are not just implementation issues, but design too. Whether you force the programmer to write boilerplate code for boxing/unboxing or decide to go for autoboxing is a language design issue as well. Still, this doesn't change the fact that this article is about the relation between primitive types and object types in OOP languages. Pcap ping 07:11, 27 August 2009 (UTC)[reply]

I agree that currently the content of the article is inconsistent with the title. So, the simplest solution, I guess, is to rename it. But I'm afraid the name Boxing, unboxing and autoboxing may narrow the scope of the article too much. The article starts with saying that an object type is a datatype, and so it should be about a general concept, mentioning boxing of a primitive data type as one example, not as a primary subject. The lack of a precise definition is not a good reason for not to have an article. For example, an interpreted language doesn't give a precise definition, but tries to cover context and give a lot of examples. In short, "Object type" may be too vague to be a good title. But "boxing, ..." doesn't seem a good one, either. It suggests a very concrete approach to primitive data types that are not objects. Maybe someone can propose a better title. -- Taku (talk) 11:57, 27 August 2009 (UTC)[reply]

The first sentence in this article has little to do with the rest of it. Pcap ping 12:51, 27 August 2009 (UTC)[reply]