4 ms·
Related: I'm still frustrated by Java randomly (in a minor release, none the less!) switching to copy-on-substring. If I, a random nobody, had something that h
by TheLoneWolfling 12y ago
Related: I'm still frustrated by Java randomly (in a minor release, none the less!) switching to copy-on-substring. If I, a random nobody, had something that had its running time increased by a factor of ~50 (simple recursive-descent-ish parser for coercing tabulated data from one format to another - just call substring to trim off the first token repeatedly), how many dev hours were required overall to fix the results of the change? And there's no simple alternative either or way to preserve the old behavior - the simplest one, rolling your own String class or wrapper, ends up being relatively slow and annoying.
And "all" of this would be solved by having a proper way of doing array slicing - for things like substring's previous worst case (something like a single character being referenced in a substring holding up a gigabyte+-sized string) Java's garbage collector could recognize that the array was only referenced through slices of part of the array, copy that section into another array (updating references to it), and free the large one.
Also, Java's lack of a way to specify that a class is immutable (and that all children classes thereof must also be) is frustrating. Because optimizations like this can and should apply to more than just strings!
- chvid 12y agoAgreed. I am not sure how big a change this is but it seems to me that after Oracle took over Java they have been getting into the bad habit of putting fairly big changes in an "update" only ticking up the minor version after the silly underscore (eg. update 20 is version 1.8.0_20-b26). For example the changes in applet security policies killed thousands of perfectly legit applications that had been running for years - all in an automated rolled out update.
- TheLoneWolfling 12y agoI've largely started avoiding Java applets altogether. Why? Because it's become really really annoying to try to get them to run at all.
- pjmlp 12y agoThose changes are only specific to Oracle's implementation, there are lots of others to choose from. Most of those changes don't have any relation whatsoever with the Java Language Specification or Java Virtual Machine Specification.
- thescrewdriver 12y agoIn theory yes. In practice 99.99% of mainstream Java developers will run their code on Oracle's JVM.
- pjmlp 12y agoI doubt only 00,01% accounts for: - Real time deployment scenarios - J2EE containers, which tend to work best with the respective vendor JVM - factory control JVMs - car infotaiment JVMs - smart card JVMs - Compilation to native code - Android - Embedded deployments like MicroEJ - Commercial UNIX systems - Mainframes - ...
- deleted 12y ago[deleted]
- TheLoneWolfling 12y agoI find it... odd, that, considering the overspecification of Java, maximum big-Os are not specified for things like this. You do have a point, although it does not refute mine. However, Oracle's implementation is the most widespread - the chances are high that at some point most non-specialized Java code will be run on Oracle's implementation.
- needusername 12y agoI believe this was done as part of the unification of JavaSE and JavaME VMs. AFAIK saving three instance variables per String instance is a big deal on JavaME. ByteBuffer and CharBuffer are a way of doing array slicing. CharBuffer even implements Appendable and CharSequence so it's half way polymorphic with String. I sometimes whish there would be multiple String classes tailored for specific purposes like there are Collection classes. Especially a String class for ASCII strings that uses only eight bytes per character.
- anon4 12y agoMy biggest gripe with String is that it's not an immutable Iterable<Char>. They could have at least implemented the interface.
- needusername 12y agoYou must be pretty happy with String then, if that's your biggest gripe :-) Do you really mean Iterable<Character> and not Iterable<Integer>. Because a Unicode code point can spawn two chars.
- TheLoneWolfling 12y agoPersonally, I wish there was a GraphemeCluster class, with a way to coerce a String into an Iterable<GraphemeCluster>, Collection<GraphemeCluster>, etc. Because most of the time people don't want to iterate over code points - they want to iterate over user-perceived characters instead. It makes more sense that by default "école".reverse() (that's the two-code-point version of "é") would be "elocé" rather than "eloće". But I've said a lot on the subject of strings already: https://news.ycombinator.com/item?id=8198811 https://news.ycombinator.com/item?id=8198811 https://news.ycombinator.com/item?id=8066158 https://news.ycombinator.com/item?id=8066158 https://news.ycombinator.com/item?id=7606084 https://news.ycombinator.com/item?id=7606084 https://news.ycombinator.com/item?id=7574665 https://news.ycombinator.com/item?id=7574665 https://news.ycombinator.com/item?id=7075858 https://news.ycombinator.com/item?id=7075858