Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: alias for Integer Date: Fri, 18 Nov 2011 10:17:16 -0800 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: <21374513.220.1321627842805.JavaMail.geo-discussion-forums@yqmj32> <12712433.869.1321630449979.JavaMail.geo-discussion-forums@prmf13> <19404286.1644.1321633587044.JavaMail.geo-discussion-forums@yqhd1> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 18 Nov 2011 18:17:19 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="24296"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VBwd91R2KGmuK73UPVdaYZPvbpNHWlb8=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <19404286.1644.1321633587044.JavaMail.geo-discussion-forums@yqhd1> Cancel-Lock: sha1:jEbEvjczj0JWTueZkvP9gluK0ow= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10052 On 11/18/2011 8:26 AM, jrobinss wrote: > See this as the same as when you call a method that takes ten ints as > entry params: the main risk of error is to get confused in the order > of parameters, This is actually a bit of an anti-pattern too. It's hard for anyone to remember the order of more than about 4 parameters, according to Effective Java. > and nothing will warn you except some strange bug a > year later. A way to avoid it is to type strongly parameters, so that > the caller may call new Rect(new Rect.Length(x), new Rect.Width(y)) > instead of new Rect(x, y) which is kind of verbose overkill in this > particular example of course, but it's just an illustration. > This is also verbose, but one recommended pattern here is to use the builder pattern Rect r = new RectBuilder().length( 10 ).width( 12 ).make(); It gains value as you have more and more parameters to remember, and also obviates the problem with remembering their order, because the builder will accept them in any order. I personally would not use it for Rect here as it only has two parameters. For a method or ctor that has 10+ parameters, I would consider it. Other standard patterns: 1. Use an IDE. I good idea will show the names of the parameters when you type them in, so you don't have to remember their order. This is a good form of reflection that costs you nothing at runtime, and doesn't add any lines of code either. 2. Take a cue from the IDE, get a lexical parser for Java, and build your own custom source code formatter. Break up long lists of parameters automatically and comment them to include their names. This again is a big win that has no runtime costs, but will keep your current and future code base formatted according to a standard. This is a huge win, imo. Try to think outside of the "code" box. There's more to developing software than things that run inside your code. Study the Unix operating system and try to learn from its "tool building" examples.