Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: startup code Date: Wed, 29 Aug 2012 17:14:05 -0400 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: <9b4cce4e-99b1-414f-a033-1acf9200e90a@googlegroups.com> <2r4q38p3790lc86fpttn4arc58m5m1tjen@4ax.com> <3926176c-0940-4080-95a1-fb67bbbec50e@googlegroups.com> <2667fee7-d27c-4d64-8fcc-501c188a2d33@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 29 Aug 2012 21:14:07 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ffb8f7085759b339c1002252b48331a4"; logging-data="1397"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IPCrNlLgiz/VMwncx+3kE" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: Cancel-Lock: sha1:CjUOgbAxwD/kCew3mS1VsLKc760= Xref: csiph.com comp.lang.java.programmer:18417 On 8/29/2012 4:06 PM, Robert Klemme wrote: > On 29.08.2012 21:41, Eric Sosman wrote: >> "What she said," with a stylistic suggestion: If the code to >> create the bitmap grows to more than a very few lines, consider >> putting them in a private static method of their own and calling >> that method from the static initializer: >> >> class Thing { >> ... >> static { >> createTheBitmap(); >> } >> >> /** Called only during class initialization. */ >> private static void createTheBitmap() { >> // create the bitmap >> } >> ... >> } >> >> Doesn't change the code's meaning in any significant way, but >> may make it easier to debug/adapt/refactor later on. > > If you go through the effort why then call it from an initializer? Why > not just via the field declaration that holds the bitmap? > > class Thing { > private static final BitMap bm = loadTheBitmap(); > > private static BitMap loadTheBitmap() { > ... > return ...; > } > } > > Assuming that the state will be held in this class. If the result of "create the bitmap" is a single value that is stored in a single field, sure -- but that's an assumption. For more general class initialization I think it would be misleading to hide the setup of several fields behind what looks like an initializer for just one of them. -- Eric Sosman esosman@ieee-dot-org.invalid