An array is essentially a function that takes a numeric parameter and returns a value. A Map can also be viewed as a function that takes an object (usually a String) argument and returns an object. They are essentially parametrized objects. Why can't we unify the syntax? A template (Generics) takes a parameter and behaves like a function also. Can we then move toward a syntax similar to the following?
We can standardize this feature for all classes by using a special method:
class TableRow() { String get(String name) { /* Return field name as a String */ } String get(Int i ) { /* Return field i as a String */ } }
TableRow row = getNextTableRow(); String city = row(5); // city == "Alexandria" String country = row("Country"); // country == "Egypt"
This is especially useful if we can extend the syntax to set values and not only retrieve them. The syntax might then look like this:
class TableRow() { String get(Int i) { /* Return field i as a String */ } void set(String value, Int key) { /* The first parameter is the new value */ } } TableRow row = getNextTableRow(); String city = row(5); // city == "Alexandria" row(5) = "Ankara"; // row(5) is mutable of course String town = row(5); // town == "Ankara"