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


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

Re: constructing a constant HashMap

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: constructing a constant HashMap
Date Sun, 6 Nov 2011 14:37:07 -0800 (PST)
Organization http://groups.google.com
Lines 50
Message-ID <12098997.1015.1320619027312.JavaMail.geo-discussion-forums@prms22> (permalink)
References <ktbk975fhdiok67oitle60ihoqhlrt1ml1@4ax.com> <49CdnacDvODl-wfTnZ2dnUVZ_hmdnZ2d@earthlink.com> <j7dq4g$8tv$1@speranza.aioe.org> <4e9b910a$0$288$14726298@news.sunsite.dk> <j7il4v$ccd$3@speranza.aioe.org> <4eb6f91f$0$290$14726298@news.sunsite.dk>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 173.164.137.214
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1320619027 22007 127.0.0.1 (6 Nov 2011 22:37:07 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Sun, 6 Nov 2011 22:37:07 +0000 (UTC)
In-Reply-To <4eb6f91f$0$290$14726298@news.sunsite.dk>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9688

Show key headers only | View raw


Arne Vajhøj wrote:
> B1ll Gat3s wrote:
>> Arne Vajhøj wrote:
>>> B1ll Gat3s wrote:
>>>> This works in ANY setting where an expression of type Map<String,String>
>>>> is appropriate:
>>>>
>>>> new HashMap<String,String> () {
>>>> {
>>>> put("aaa", "bbb");
>>>> ...
>>>> }}
>>>
>>> But it is way more difficult to read
>>
>> No it isn't.
>
> Yes - it is.
> 
> Read what Tom wrote:
> 
> #and it is a very useful but also highly surprising construct (i love
> #dropping one in front of my pair when pair programming, and watching
> #their brains trying to work out what's going on - it takes a while to
> #realise it's not a special syntax, just a combination of two other
> #bits of syntax).

Yeah, but once you're used to it it's quite readable.  So you're both right.

The question of "readability" shouldn't be treated like an absolute - it is or it ain't.  Readability is relative to experience and cognitive style.  To someone not trained in computer programmers, none of it is readable.  To a junior programmer, anonymous classes are rather "unreadable".  Should you eschew them for that reason?  To a slightly less junior programmer the anonymous-class/initializer combination cited here is strange, but should you really code to his level?  Or maybe should that programmer up their skill a little and stop being so namby-pamby about legitimate, useful syntax?

There's also a relative readability between that idiom and alternatives to load a Map.  There's gotta be an initializer somewhere, folks!

Personally, I don't like the overly-clever anonymous/initializer idiom.  I prefer a stodgy old separate initializer block and a non-subclasses HashMap.  I think it's more readable that way than the tricky subclass way presented here.

-- 
Lew

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


Thread

constructing a constant HashMap Roedy Green <see_website@mindprod.com.invalid> - 2011-10-15 18:14 -0700
  Re: constructing a constant HashMap Arne Vajhøj <arne@vajhoej.dk> - 2011-10-15 21:36 -0400
    Re: constructing a constant HashMap Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-10-16 16:51 +0200
  Re: constructing a constant HashMap markspace <-@.> - 2011-10-15 18:59 -0700
    Re: constructing a constant HashMap Roedy Green <see_website@mindprod.com.invalid> - 2011-10-15 19:25 -0700
  Re: constructing a constant HashMap Roedy Green <see_website@mindprod.com.invalid> - 2011-10-15 19:19 -0700
  Re: constructing a constant HashMap Patricia Shanahan <pats@acm.org> - 2011-10-16 06:07 +0100
    Re: constructing a constant HashMap B1ll Gat3s <wm.g4t3s@m1cr0s0f7.c0m> - 2011-10-16 01:29 -0400
      Re: constructing a constant HashMap Tom Anderson <twic@urchin.earth.li> - 2011-10-17 00:57 +0100
        Re: constructing a constant HashMap Patricia Shanahan <pats@acm.org> - 2011-10-17 01:02 +0100
      Re: constructing a constant HashMap Arne Vajhøj <arne@vajhoej.dk> - 2011-10-16 22:20 -0400
        Re: constructing a constant HashMap B1ll Gat3s <wm.g4t3s@m1cr0s0f7.c0m> - 2011-10-17 21:35 -0400
          Re: constructing a constant HashMap Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-18 09:28 -0700
            Re: constructing a constant HashMap David Lamb <dalamb@cs.queensu.ca> - 2011-10-20 12:55 -0400
          Re: constructing a constant HashMap Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 16:16 -0500
            Re: constructing a constant HashMap Lew <lewbloch@gmail.com> - 2011-11-06 14:37 -0800
              Re: constructing a constant HashMap Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 18:00 -0500
                Re: constructing a constant HashMap Ian Pilcher <arequipeno@gmail.com> - 2011-11-06 18:34 -0600
                Re: constructing a constant HashMap Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 19:47 -0500
            Re: constructing a constant HashMap B1ll Gat3s <wm.g4t3s@m1cr0s0f7.c0m> - 2011-11-07 12:23 -0500
    Re: constructing a constant HashMap Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-10-16 11:11 -0300
  Re: constructing a constant HashMap Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-16 10:39 -0700

csiph-web