title: what is the point of heterogenous arrays?
body: <p>I know that more-dynamic-than-Java languages, like Python and Ruby, often allow you to place objects of mixed types in arrays, like so:</p>
  
  <pre><code>["hello", 120, ["world"]]
  </code></pre>
  
  <p>What I don't understand is why you would ever use a feature like this. If I want to store heterogenous data in Java, I'll usually create an object for it.</p>
  
  <p>For example, say a <code>User</code> has <code>int ID</code> and <code>String name</code>. While I see that in Python/Ruby/PHP you could do something like this:</p>
  
  <pre><code>[["John Smith", 000], ["Smith John", 001], ...]
  </code></pre>
  
  <p>this seems a bit less safe/OO than creating a class <code>User</code> with attributes <code>ID</code> and <code>name</code> and then having your array:</p>
  
  <pre><code>[&lt;User: name="John Smith", id=000&gt;, &lt;User: name="Smith John", id=001&gt;, ...]
  </code></pre>
  
  <p>where those <code>&lt;User ...&gt;</code> things represent User objects.</p>
  
  <p>Is there reason to use the former over the latter in languages that support it? Or is there some bigger reason to use heterogenous arrays?</p>
  
  <p>N.B. I am not talking about arrays that include different objects that all implement the same interface or inherit from the same parent, e.g.:</p>
  
  <pre><code>class Square extends Shape
  class Triangle extends Shape
  [new Square(), new Triangle()]
  </code></pre>
  
  <p>because that is, to the programmer at least, still a homogenous array as you'll be doing the same thing with each shape (e.g., calling the <code>draw()</code> method), only the methods commonly defined between the two.</p>