Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: multi-line Strings Date: Mon, 17 Dec 2012 22:18:25 -0700 Organization: bilaterally symmetric Lines: 42 Message-ID: References: <7f36342c-2331-4484-874b-4a0f8953f160@googlegroups.com> <1rfmfoqs8bzc6.4pavkn8829dk$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="17839"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+N8OlJw3ToD4XvIV7kB36g" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:dTmyJHomz9VAwAGIjm1u9Y2OvEk= sha1:bgW/0zMuJuplvVoL6pawI60jwhA= Xref: csiph.com comp.lang.java.programmer:20430 Eric Sosman writes: > On 12/17/2012 8:11 PM, Peter Duniho wrote: >> On Mon, 17 Dec 2012 20:45:58 -0400, Arved Sandstrom wrote: >> >>>> I wonder, in general, where the line should be drawn? Java coding >>>> guidelines recommend that 1 and -1 can be used as literals, but other >>>> integer constants should defined as a "constant" by the programmer. >>> [ SNIP ] >>> >>> If I am multiplying by 2, or 10, or 1000, or using 100 or 400 when doing >>> some forms of date conversions, almost all the time the context will >>> make it clear what that constant is. If I were to religiously follow the >>> coding guidelines, in no small number of cases I'd have to define >>> constants that were called TWO or THOUSAND...which is sort of stupid. >> >> Naming constants to be the same as the name of the value they represent, >> yes...that's stupid. >> >> But nothing about your example suggests that's actually how the constances >> should be named in the scenarios you describe. >> >> If you are multiplying by a constant, there's a reason. Often, for example, >> you are converting units (hours per day, days per week, etc., following >> your "date conversions" theme). The conversion itself is the correct name >> (e.g. "hoursPerDay", "daysPerWeek", etc.) in those examples. Similar logic >> can be applied to other values. > > public static final int MILLIMETERS_PER_METER = 1000; > public static final int MILLIGRAMS_PER_GRAM = 1000; > public static final int MILLIAMPERES_PER_AMPERE = 1000; > public static final int MILLISECONDS_PER_SECOND = 1000; > > Great aids to understanding, I'm sure. (And stop calling me Millie!) public static final int MILLISECONDS_IN_24_HOURS = 1000 * 60 * 60 * 24; One should not, of course, write MILLISECONDS_PER_DAY due to the possibility of DST. -- Jim Janney