I have no grudge against operator overloading when done consciously — complex numbers, matrix multiplication. I've tried to implement JavaScript arithmetic in Ruby, failed so far.
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
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]
[] * {}
//NaN
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
class Foo {}
`${new Foo}`
//"[object Object]"
class Foo end
Foo.new
#=> #<Foo:0x0000560b7a10df20>
>>> class Foo:
... pass
>>> Foo()
<__main__.Foo object at 0x7fb53aecf1f0>
Oh, 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 are few revelations with main (method defined in Object)
def baz
end
Object.instance_method(:baz)
=> #<UnboundMethod: Object#baz() (irb):19>
Nothing like audible "click" I had when understood that "function" is a "constructor"
constructor Foo {}
// you can call me as function too
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
Object = Object.prototype
Function = Function.prototype
now it is easy to reason about
typeof Object
//"object"
Foo = class {}.prototype // redefine with sweetjs macro
Bar = class extends Foo.constructor {}.prototype
new Foo.constructor // redefine with sweetjs macro
Object.constructor.create(Bar) // redefine as Reflect.create
once redefined:
Foo = class {}
Bar = class extends Foo {}
new Foo
Reflect.create(Bar)
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.
> Object.prototype.toString is not as useful as Ruby, Python
I don't know that returning that info would be good or secure in JS
> Oh, 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.
The best and most compatible answer is moving JS to UTF-32. JS engines already save space by encoding strings internally as latin1 instead of UCS when possible (even around 90% of text from Chinese sites is still latin1). IMO they should have made backtick strings UTF-32, but that doesn't exactly transpile well.
> No, every Ruby object contains variables and has a link to a class which defines instance methods, we call it singleton_class
I'll let you decide which implementation is easier to work through, but I have a definite opinion that Ruby's system is more complex (and Python layers their OOP on top of what is basically a hidden prototypal system).
> I've red through ES5 to be sure there are no hidden traps left.
You'll love newer ES versions then. The upcoming private fields are an even bigger mess.
JS needs a "use stricter" mode which really slices away the bad parts. Even better, just add a `version="es20xx"` requirement to use newer features and have browsers ignore what they don't know, so you could even compile and link to multiple compilation levels of the same script and have the browser choose.
In truth, JS would be in the best place of any top-20 language if Eich had just been allowed to make a scheme variant as he had planned.
Of course prototype based language is simpler than class based. Ruby system is more complex. It provides more tools — Class, Module, class and instance methods, variables (as depicted on the picture). You've asked eigenclass (singleton_class these days), that's Class:a -> A, very simple concept.
And yet Ruby inheritance is much easier, it is all around and it just works. No one does this in JavaScript, too complex. There were many attempts of building OOP people could understand on top of JavaScript in 200x. No one does this for Ruby.
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