1

For example, when working with arrays there are methods like indexOf() that works like this:

if (array.indexOf("something")!=-1) { // do something or nothing }

Why hasn't someone made a contains method?

if (array.contains("something")) { // do something or nothing }

Or add functions people find useful like:

var fileHeader:int = byteArray.indexOf([0xFF, 0x00]);

Or with strings or regular expressions:

if (String(myString).contains("fox")) { // do something or nothing }

In the E4X XML classes I see so many cases where things don't work or you have to know certain things. For example, there is no remove call in XML objects. Instead of xml.remove() you have to do this:

 delete xml.parent()[xml.name()][xml.childIndex()];

There are plenty of places where improvements could be made with core language classes but it seems they stagnate. Some things haven't changed in over 30 years.

Why is that and can we add better calls instead of using the rotting corpse of yesterdays API's?

I wish that these features were added.

Winston Ewert
  • 25,052

2 Answers2

11

It is mostly a (standard) library issue (in programming language parlance), not a core language issue.

Several programming languages have extra libraries improving them (or even replacing their standard libraries) like you wish (e.g. Boost for C++, Batteries or Core for Ocaml, JQuery for JavaScript).

A programming language designer has to balance two conflicting goals (or approaches):

  • providing a very complete standard library, but that is a huge amount of work (a prototypical example is Java)

  • providing a small standard library (only the minimum required to e.g. the compiler) to lower the effort and focus on the core language features, but then the programming language would in practice succeed only if the community develops many external libraries (both C, and to a lesser extent, Ocaml, come to mind)

I disagree with the "stubborn" adjective in your question: most programming languages have a very limited language developer community (and being able to design or develop a programming language is a quite rare and demanding skill); it is hard to get paid to design a programming language. So programming language designers have to make choices on the areas they will focus their effort on.

If you wish more standard library features in your favorite programming language, contribute to it (by your own labor - and that takes a lot of time, or by funding the programming language developers).

3

You should be more clear about what you consider as an "upgrade" to a function. Do you mean to actually improve it's already existing implementation or add a new and better implementation ?

For improving implementation, it would be a bad idea. Think what would happen to an application you wrote on SDK version X and then deploy on a machine that runs an SDK with a higher version ? what would happen is that your functions may return different results on some edge cases and would provide unpredictable behavior, which will force you to either add support for that SDK version (no fun!) or tell your client to avoid that SDK (also no fun).

Many languages just add better implementations and function and just tell you to avoid the old ones to make your life easier. but they keep them around as legacy so your applications wouldn't break.

As for your example, instead of .contains, the Array.prototype.includes method exists and can replace .indexOf as you described it could.

But what if I still needed to use the function to actually find an index (I happen to like doing this as I'm getting my job done), instead of just figuring out it the array item exists ? I couldn't have done so with .contains, so for me, it's an inferior feature.

So languages only upgrade when there is a real necessity for it, otherwise it would have a huge, bloated, legacy of crappy unwanted features (javascript, php, etc..) So it would be best just to use libraries or API's that would provide you these "upgrades".

svarog
  • 489