3 ms·
So, the stereotype (mostly negative ;P) of "fully idiomatic Java" involves using factories (themselves managed by factory factories via dependency injection thr
by saurik 5y ago
So, the stereotype (mostly negative ;P) of "fully idiomatic Java" involves using factories (themselves managed by factory factories via dependency injection through factory factory factories... see "the hammer factory" post mirrored at https://danstroot.com/2018/10/03/hammer-factories/ https://danstroot.com/2018/10/03/hammer-factories/ or, to a lesser extent, Execution in the Kingdom of Nouns at http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom... for more information) to obtain objects, and most APIs simply don't need temporary arrays or large composites, so it tends to be pretty easy to take the high-performance parts of your code and modify them to never allocate anything at all (instead reusing existing objects from free lists, as the goal is to remove as much of--if not all of--the garbage collection pressure as possible, not to avoid the heap), in no small part because there is a pretty 1:1 mapping between the source code and the byte code... essentially, it is the same argument people use for why they love C (even more than C++, which I maintain has almost the same property): there are never any "hidden" allocations.
- throwaway894345 5y agoI guess I wasn't thinking about the stereotype of idiomatic Java, but rather I'm assuming that--barring escape analysis--every `new` corresponds to an allocation and idiomatic Java (again, not the stereotype) has lots of `new`s. So I'm asking if escape analysis is eliding most of those allocations, or if I'm misunderstanding something and there is some other mechanism for reducing those allocs?
- saurik 5y agoMy mental model of truly idiomatic Java already doesn't use new often, and it is then easy to take code which was written in idiomatic Java to remove remaining uses of new; like, idiomatic Java--even the classic stuff--tends to pass around primitives and uses imperative code to manipulate data structures... most algorithms don't really allocate anything other than strings (which are easy to accidentally allocate as those allocations are hidden by the library as opposed to the language, but also tend to be well-scoped in the codebase to parsing logic that should be using more powerful abstractions anyway... and knowing Java developers probably got replaced by XML early in the development cycle, the parser for which you might choose to view as a massive string factory factory ;P). As for the stereotype, it is really important... I added some extended references to my comment, as if you aren't using factory factory factories are you really using Java at all?! ;P. (FWIW, in Execution in the Kingdom of Nouns, two of the examples use new... but almost entirely in ways that feel completely unrealistic to me as someone who did a lot of programming in Java; then the remaining couple allocations I could see being "forced into" would trivially be replaced by a shared instance ;P.)
- loopz 5y agoIf you're into factory factories, you should really dig deep into delegation factory factories. There are many. They are a joy to work with as you get to export both interface blueprints and heap allocations to external third counter-parties. Just remember to sign full contract certs before doing anything by wire.