Hacker News new | ask | show | jobs
by scotty79 1455 days ago
I would really like a language where you can swap simple data collections like dicts or arrays with others, better defined, employing better suited algorithms without changing everywhere in your code how you access them.

So if getting a field using simple structure is mycol[key] it should look exacty the same when mycol is no longer a flexible dict containing adhoc objects but complex strongly typed immutanble trie or btree indexed array because at some point of evolution of your code it became apparent that this is exactly what you need.

The only language that I know of that has consistent interface between simple and complex (also custom) collections is Scala.

1 comments

You can do this in any language that has operator overloading, right?

C# or C++ for example.

Or in fact, you can just define an interface with Get/Set methods. Any language with interfaces supports that and you can swap them out as you please.

Doesn't seem like the language is really the restricting factor for implementing this if you really wanted it.

> You can do this in any language that has operator overloading, right?

The thing is that language and standard library designers don't do that.

And if you are not hellbent on creating your own collection library and using it everywhere, even when interfacing with system functions that don't understand it you pretty much have no way of swapping out your data structures without carefully replacing all lines that access them.

Scala standard collection library designers are the only ones I know of that actually went through the trouble of making this for us.