4 ms·
>A somewhat contrived example It's not a contrived example. When Java changed this exact behaviour it caused a lot of pain for people. Code that previously ran
by anon1385 11y ago
>A somewhat contrived example
It's not a contrived example. When Java changed this exact behaviour it caused a lot of pain for people. Code that previously ran in a reasonable amount of time suddenly became impractically slow:
https://news.ycombinator.com/item?id=9862556 https://news.ycombinator.com/item?id=9862556
>may require a quick look at the API docs
The behaviour isn't specified by the spec. That is why they were able to change it from one release to the next.
>premature optimization and all that.
The "premature optimization" meme you are parroting contains the implication that at some point optimisation will be necessary. When that happens you have to think about memory management, even in a GC language. The string example given by danieldk is just one of many ways in which that can happen.
- rakoo 11y ago> The "premature optimization" meme you are parroting contains the implication that at some point optimisation will be necessary. When that happens you have to think about memory management, even in a GC language. The string example given by danieldk is just one of many ways in which that can happen. That's exactly the point: caring about the actual memory used by interesting may not be as important as other parts of the application, or may not be important at all for now. You should only care about that when it does prevent pose a problem (performance, impossibility to evolve features, ...) (all while making the initial code flexible enough to be potentially changed in the future)
- danieldk 11y agoYou should only care about that when it does prevent pose a problem Then you are setting up yourself for a lot of trouble. Another part of memory management is thinking about ownership (to which the substring discussion is very much related) and it pains me to see how many bugs are caused by code like: Foo getFoo() { return myFoo; } Where Foo is some mutable class and the invariants of the wrapping class suddenly don't hold anymore because some outside code is mutating the Foo instance through the pointer/reference. Throw in some amount of concurrency and you get something that is not only hard to debug but also difficult to reproduce. tl;dr: in a GCed language you need to think about memory management and ownership as well. (Note: I am not arguing against garbage collection.)
- wtetzner 11y ago> Where Foo is some mutable class Ah, there's your problem :)