| I completely agree that separate operators area MUST for dynamic languages. Lua allows operator overloading with metatables as do ruby and Python with classes http://lua-users.org/wiki/MetatableEvents https://docs.python.org/3/reference/datamodel.html#emulating... https://www.ruby-lang.org/en/documentation/faq/7/ > One number type in Lua: Not quite true. Lua had only 64-bit floats like JS until version 5.3 and the blazing fast LuaJIT still only has floats. Well, to be honest, it has hidden 32-bit integers for sake of bitwise operations just like JS (well, JS uses 31-bits with a tag bit which is probably a lot faster). > How about `{} + []`? I believe I can disable this part in JavaScript engine and no one would notice. That's very simple. {} at the beginning of a line is an empty block rather than an object (yay C). "Disabling" that would break the entire language. > UTF-16 UCS-2 actually. Back in those days, Unicode was barely a standard and that in name only. Java did/does use UCS-2 and JS for marketing reasons was demanded to look like Java. I don't want to go into this topic, but python, PHP, ruby, C/C++, Java, C#, and so on all have a long history not at all compatible with UTF-8. > You've said nothing about constructor oriented programming. Unique feature, I have not heard any other language adopted it yet. I'll give you that JS prototypal inheritance is rather complex due to them trying to pretend it's Java classes. Once again though, the deep parts of both Python and Ruby classes are probably more difficult to explain. Lua's metatables are very easy to understand on the surface, but because there's no standard inheritance baked in, every project has their own slightly different implementation with it's own footguns. Closures are almost always preferred over classes in modern JS. Likewise, composition is preferred over inheritance and the use of prototype chains while not necessarily code smell, does bear careful consideration. If someone insists on using deep inheritance techniques, they certainly shouldn't be using class syntax as it adds yet another set of abstractions on top. Object.create() and inheriting from `null` solves a ton of issues. > By the way, you can say "Yes, I know JavaScript has some problems". It is not a secret, everyone knows. I'd say if you take the top 20 languages on the tiobe index, it sits in the middle of the pack with regard to warts and weirdness. Maybe people are just attracted to weird languages. |
Sorry, I had to be clear, in Lua "one number type" means float, my bad. I meant Lua 5.3 integer still works like JavaScript Number. In the end we have to know about ToInteger, ToInt32, ToUint32, Number.MAX_SAFE_INTEGER [1]. It is not one number type but encoding of several number types, union.
Prior to 5.3 and in LuaJIT it has different limitations
they have extended original "one number type" without change of the interface. In any case both versions do not convert to BigNum like Ruby. Ruby unified Fixnum, Integer and BigNum as Integer in 2.4. Can't see benefits of Number/BigInt against Float/Integer. I'd rather have 3.6f literal.Yes, I know how WAT works. I meant ToPrimitive [2]
I've disabled this code in Firefox, have not done extensive testing but looks like no one depends on it. We infer types with TypeScript and flow but VM already knows it, it can report such cases without external tools. I think of it as extension of Firefox Developer edition — lint in the browser.Object.prototype.toString is not as useful as Ruby, Python
And there is no separate inspect/__repr__ > UCS-2 actuallyOh, DOM UTF-16 string broken by UCS-2 JavaScript function. I understand it is not easy to fix, Ruby fixed in 1.9, Python in 3.0, new languages (Rust, Elixir) come with UTF-8. Microsoft Windows has code pages, UCS-2, UTF-16.
Maybe Python way? b"binary", u"utf-8" (but together, not python fiasco), ruby has "# Encoding: utf-8", transformation tools can mark "b" or "u" all unspecified strings.
> Once again though, the deep parts of both Python and Ruby classes are probably more difficult to explain.
No, every Ruby object contains variables and has a link to a class which defines instance methods, we call it singleton_class
There is ancestors chain There is a bit of syntactic sugar There are few revelations with main (method defined in Object) Nothing like audible "click" I had when understood that "function" is a "constructor" that unlike any other language [[Prototype]] is hidden. I've red through ES5 to be sure there are no hidden traps left.Every JavaScript programmer has to go through this list either beforehand or by experience. I do not want to undermine TC39 effort — arrow functions, string interpolation in template literals, strict BigInt, Object.create — these are great advancement. I don't feel same way for "class", underlying weirdness is still there.
Make [[Prototype]] visible
now it is easy to reason about once redefined: I've shown it in another comment [3].Languages are weird, there are a lot of C++ developers, I've been there, no way to know all dark corners. Pythons ideology hurts. Java took EE way. C# was tied to Microsoft. C K&R is beautiful, hard to write safe, packs a lot in the code. PHP has its bag of problems. SQL is not composable, CTE helps. Go ideology. Ruby — performance. And JavaScript because browser, not bad when know and avoid skeletons in the shelf.
Lua metatables looked like a proxy/method_missing for me.
[1] https://www.ecma-international.org/ecma-262/5.1/#sec-9.5
[2] https://www.ecma-international.org/ecma-262/5.1/#sec-9.1
[3] https://news.ycombinator.com/item?id=24815922