Hacker News new | ask | show | jobs
by ralfn 5145 days ago
>>Nobody with the actual skillset to design and implement a programming language would consider, for example, merging vectors and dictionaries into some kind of mutated frankenarray.

>Actually, JavaScript and Lua have merged vectors and Dictionaries.

I'm not sure about Lua, but in the case of Javascript, it's not entirely true. Arrays are objects, yes, but objects are not arrays.

So, unless you are extending the build-in array type, objects do not behave as arrays. They are not recognized as arrays, and more importantly, no modern javascript engine actually implements arrays as hashes.

For example {}.length has no value. It does not have a length of zero, it does not have a length at all. Visa versa, when looking at an object-map as a 'map', you'll get the array entries, as well as the length property, and the push and pop methods.

It's orthogonal. Imagine a javascript engine having no special implementation for an Array. We could implement it on top of the object-map. So, an array does not behave as a map, its implemented in a map. There's a clear distinction.

But the parallels with PHP are interesting. Both languages were not designed with the intent of large applications, but with the intent of adding a small piece of isolated logic to what is mostly a template. Both languages have had a lot of flack for their early design choices as well. People are still upset how Javascript handles casting (which is similar to how PHP handles it), and they are still upset how Javascript handles scoping (which is again similar to how PHP handles it).

Where the languages start differing, is that Javascript is much more reflective, which allows one to fix many language flaws in library or framework code, to suit different use-cases like the development of large scale projects. (just consider the hundreds of class-based systems implemented in Javascript)

But even for Javascript, the same logic applies. Considering the role and purpose it has now, the language design would have been different, if it was not for backwards compatibility.

And there as well, people are trying to figure out ways to make it radically better. Dart comes to mind. Compiling other languages into javascript. (coffeescript, gwt, etc.)

And even arguments in favor of Node.js are all based on the assumption that we are stuck with Javascript in the browser.

And just as with PHP, the original authors themselves, make no secret that their language design wasn't optimized or optimal for how we are using it now.