Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8061413

Add extensible arrays and dictionaries to the syntax

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P5
    • Resolution: Other
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: specification
    • Labels:

      Description


      Name: gm110360 Date: 02/04/2002


      FULL PRODUCT VERSION :
      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)


      FULL OPERATING SYSTEM VERSION :



      A DESCRIPTION OF THE PROBLEM :
      A number of modern languages (most recently, Python) support syntax-level creation and modification of certain basic extremely common data types, including strings, extensible arrays, and dictionaries. Java's facilities here are unnecessarily poor. Consider the following grotesque but sadly common example:

      Vector vec = new Vector();
      vec.addElement(new Double(2.3));
      vec.addElement(new Double(4.5));
      vec.addElement(new Double(3.1));
      vec.addElement(new Double(2.6));
      double d = ((Double)(vec.elementAt(2))).doubleValue();

      ...as opposed to an alternative syntax:
      double[] vec = new double[0];
      vec += 2.3; vec += 4.5; vec += 3.1; vec += 2.6;
      double d = vec[2];

      ...or if the += and + operators would be better suited to array concatenation, even a functional form would be preferred over the current monstrosity:

      double[] vec = new double[0];
      vec.push(2.3).push(4.5).push(3.1).push(2.6);
      double d = vec[2];

      Given that Java has no multidimensional arrays, this is a trivially easy thing to add to the semantics of the language. Just lazily define arrays as fixed-length until they are acted upon with variable-length operators, and then upgrade them to variable-length.

      While we're at it, Java's hashtable (and HashMap/HashSet) facility is similarly grotesque, not permitting numbers or string values as keys, and requiring a nasty syntax:

      Hashtable h = new Hashtable();
      h.put("key1","value1");
      h.put("key2","value2");
      h.put("key3","value3");

      ...instead of something like:

      Hashtable h =
         << "key1","value1" : "key2","value2", "key3","value3">>;

      These objects are so basic to Java that the enormously wordy syntax they rely on is only a hindrance.


      This bug can be reproduced always.
      (Review ID: 139148)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              abuckley Alex Buckley
              Reporter:
              abuckley Alex Buckley
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: