Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 17 Dec 2012 21:40:53 -0600 Date: Mon, 17 Dec 2012 19:41:06 -0800 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: multi-line Strings References: <7f36342c-2331-4484-874b-4a0f8953f160@googlegroups.com> <50cfda1c$0$287$14726298@news.sunsite.dk> In-Reply-To: <50cfda1c$0$287$14726298@news.sunsite.dk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 36 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.205.210 X-Trace: sv3-XfxUn+yeXyPpv6Cha7DCNwTeVEl7Y/gknA2u2kyDEDJi6E9052x3b1NL2JioEwnVf5GwyHwqyrbYOV0!JzobwcmOC150tu9FnWESdim0L/FzoLo1M4J0RQyJyqe/azEojkxwAov4q0XzLex3grXTdAyumfPW!EPD3Am+7dZlgNeV69PJ1j81x7II5arpvjjM60hAF64cUo7k= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2643 X-Received-Bytes: 2784 Xref: csiph.com comp.lang.java.programmer:20424 On 12/17/2012 6:51 PM, Arne Vajhøj wrote: ... > TWO fails to achieve any of those. It is far from given that all > constants of 2 must be changes. TWO does not tell any more than 2. > > if(daysPaymentOverdue() > 2) { > setAlarmLevel(2); > } > > should not be converted to: > > if(daysPaymentOverdue() > TWO) { > setAlarmLevel(TWO); > } > > but to: > > if(daysPaymentOverdue() > NO_DAYS_TO_SET_ALARM) { > setAlarmLevel(ALARM_NO_PAYMENT); > } I think a good test for deciding to name a constant is whether the constant would have a better name than the number itself. It has nothing to do with how big a number is, but with what it means. For example, 2 in the Euclidean distance formula just means 2, and has no better name. Similarly, 100 in the formula for calculating a percentage is just 100. On the other hand, each 2 in the example above does not just mean 2. It is a number of days, or an alarm level, and can be given a more meaningful name. If the example had used 1 instead of 2, I would still agree with naming it. Patricia