From: mgreenberg <pub...@gm...> - 2008-03-31 20:33:19
|
According to various javadoc and code usage, various methods require the use of interned strings. I grepped the 2.2.1 release code base and see various lines like if (name == "__class__") But don't see anywhere obvious that "__class__" gets interned (but presumably it does -- is that implicit in classes in a single jar or something?). But, would it make sense to define constants in PyObject like static final String __class__ = "__class__" /* .intern() ? */; for all the well-know python attribute names. The warning about interning strings in the javadoc would still be required, but this would prevent a certain class of errors in user code, by recommending the use of PyObject.__class__, PyObject.__name__, ... for these attributes. Marvin |
From: David H. <dav...@gm...> - 2008-03-31 21:06:59
|
On Mon, Mar 31, 2008 at 3:33 PM, mgreenberg <pub...@gm...> wrote: > According to various javadoc and code usage, various methods require the > use of interned strings. I grepped the 2.2.1 release > code base and see various lines like > > if (name == "__class__") > > But don't see anywhere obvious that "__class__" gets interned (but > presumably it does -- is that implicit in classes in a single jar or > something?). String literals in Java source code get interned. >From http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5: "# Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1). # Literal strings within different classes in the same package represent references to the same String object. # Literal strings within different classes in different packages likewise represent references to the same String object. # Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals. # Strings computed by concatenation at run time are newly created and therefore distinct. " - David |
From: marvin g. <pub...@gm...> - 2008-04-01 01:03:56
|
David Huebel wrote: > String literals in Java source code get interned. > ok. personally I still prefer defining some constants since it avoids typographical errors that would not be checked by the compiler. |
From: David H. <dav...@gm...> - 2008-04-01 02:59:59
|
On Mon, Mar 31, 2008 at 8:03 PM, marvin greenberg <pub...@gm...> wrote: > David Huebel wrote: > > String literals in Java source code get interned. > > > ok. personally I still prefer defining some constants since it avoids > typographical errors that would not be checked by the compiler. > It's tempting to say something snide like, "Why are you interested in Python, then?" ;-) but I tend to agree with you. Supposedly (I'm not a developer) a lot of internals have been cleaned up for 2.5; you should have a look at the latest code and then maybe bring the issue up on jython-dev. -David |