Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10052

Re: alias for Integer

From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: alias for Integer
Date 2011-11-18 10:17 -0800
Organization A noiseless patient Spider
Message-ID <ja67ff$nn8$1@dont-email.me> (permalink)
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>

Show all headers | View raw


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.



Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-18 06:50 -0800
  Re: alias for Integer markspace <-@.> - 2011-11-18 07:11 -0800
  Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 07:32 -0800
  Re: alias for Integer Lew <lewbloch@gmail.com> - 2011-11-18 07:34 -0800
    Re: alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-18 08:26 -0800
      Re: alias for Integer Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-18 18:00 +0000
      Re: alias for Integer markspace <-@.> - 2011-11-18 10:17 -0800
      Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 20:30 -0800
    Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 20:23 -0800
  Re: alias for Integer Jim Janney <jjanney@shell.xmission.com> - 2011-11-18 13:14 -0700
  Re: alias for Integer Patricia Shanahan <pats@acm.org> - 2011-11-18 12:43 -0800
  Re: alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-21 01:50 -0800
  Re: alias for Integer Robert Klemme <shortcutter@googlemail.com> - 2011-11-21 20:58 +0100
  Re: alias for Integer David Lamb <dalamb@cs.queensu.ca> - 2011-11-21 15:38 -0500

csiph-web