Women in Technology

Hear us Roar



Article:
  Design Tips for Building Tag Clouds
Subject:   Correction
Date:   2006-06-13 23:22:31
From:   dkrukovsky
Jim,


Good article. It would be even better if you would know that both Java and C++ do support what you call associative arrays: http://en.wikipedia.org/wiki/Associative_array#Java


Denis Krukovsky
http://talkinghub.com/

Full Threads Newest First

Showing messages 1 through 5 of 5.

  • Correction
    2006-06-15 04:17:53  KristoferHoch [View]

    Dkrukovsky,
    I believe the type of Associative array that Jim is speaking of, is a be more free than the Java generic.

    Take the example you provided for instance. That Map can only take a String and Another String.
    [snippet]
    Map<String, String> phoneBook = new HashMap<String, String>();
    phoneBook.put("J. Random Hacker", "555-1337");
    [/snippet]

    It cannot nest in more Maps because the phone book only accepts String objects. In Perl, you can do some crazy things like ...

    [snippet]

    %phonebook =
    (
    'name' =>
    {'J. Random Hacker',

    );




    • Correction
      2006-06-15 04:40:46  KristoferHoch [View]

      This was an unfinished post, sorry about that :-(
  • Correction
    2006-06-15 04:39:25  KristoferHoch [View]

    Denis,
    I believe the type of Associative array that Jim is speaking of, is a be more free than the Java generic.

    Take the example you provided for instance. The phonebook is a
    Map Object that can only accept two arguments. Both arguments MUST be of the
    String type.

    Map<String, String> phoneBook = new HashMap<String, String>();
    phoneBook.put("Sally Smart", "555-9999");
    phoneBook.put("John Doe", "555-1212");
    phoneBook.put("J. Random Hacker", "555-1337");


    In Perl, you can do all sorts of crazy things, for instance ...


    use strict;
    my %phonebook =
    (
    'Sally Smart' =>
    {
    name =>
    {
    'last' => 'Smart',
    'first' => 'Sally',
    'middle initial' => '',
    'salutation' => [ qw(Ms. Lady) ],
    'titles' => [ qw(PhD. Esquire M.D.) ],
    }
    'number' => '555-9999',
    },
    );


    In this instance, I have associated Sally's full name to another associative array (really an anonymous associative array) which contains her full name and some more information.

    If you wanted to do the same thing in Java you would, as Jim said, you will end up writing considerably more code.
    • Jim Bumgardner photo Hashes
      2006-06-15 08:15:43  Jim Bumgardner | O'Reilly AuthorO'Reilly Blogger [View]

      Yes, "considerably more code" was the point.

      Certainly associative arrays are supported by C++ and Java, via libraries, but they are not built-in data types, as they are in Perl, PHP, Python and Ruby.

      The code to construct and manipulate them is more ungainly in the lower-level languages.
    • Correction
      2006-06-30 02:00:51  stephan.schmidt [View]

      Yes you can't do that in Java, but on the other hand, most Java developers use object oriented development and have seldom the need to use structs anymore.

      Syntactic sugar is nice to have for maps (see Groovy for an example of map sugar in the JVM) but usually in my applications maps are rather filled dynamically than statically.