Ruby does some conflation - methods use ()
, but arrays, hashes, and lambda expressions (closest thing that ruby has to functions) can all use []
. Together with ducktyping, this means you can pass around an object, and pass it values using []
not caring whether it's precomputed (an array), calculated each time (a lambda expression), or calculated as needed and cached (which can be done with a hash).
Another example that conflates the two is Haskell. As I remember it doesn't have an array syntax built into the languange - accessing array indices is a function call, and can be used just like any other function.
I prefer conflation actually - it allows for easier flexibility (which I like). Knowing whether you're optimizing for speed or memory (like David said) is good to know, but I'm willing to take that responsibility on myself, rather than leaving it to cues built into the language.