Earlier quoted context omitted.
Strong sequential consistency is a big one. Most architectures that have tried to diverge from this for performance reasons run into trouble with the way people like to write C code (but will not have trouble with languages actually built for concurrency). Arguably the scalar focus of CPUs is also to make them more suited for C-like languages. Now, attempts to do radically different things (like Itanium) failed for v…
> Now, attempts to do radically different things (like Itanium) failed for various reasons, in Itanium's case at least partially because it was hard to write compilers good enough to exploit its VLIW design. It's up in the air whether a different high-level language would have made those compilers feasible. My day job involves supporting systems on Itanium: the Intel C compiler on Itanium is actually pretty good... n…
ARM chips have an instruction with JavaScript in the name
291–300 of 312 posts
Re: ARM chips have an instruction with JavaScript in the name
#292It seems like every 2 months I feel the burn of JS not having more standard primitive types and choices for numbers. I get this urge to learn Rust or Swift or Go which lasts about 15 minutes... until I realize how tied up I am with JS. But I do think one day (might take a while) JS will no longer be the obvious choice for front-end browser development.
bools (Boolean)
floats (Number)
ints (x|0 for i31 and BigInt)
arrays (Array, and 11-ish variants of TypedArray)
linked lists (Array)
sets (Set and WeakSet)
maps (Map and WeakMap)
structs (Object)
genSym (Symbol)
functions (Function)
strings (String)
What are they missing that you are dying to have?Re: ARM chips have an instruction with JavaScript in the name
#293Earlier quoted context omitted.
Consider Node JS is a top server side language, and arm for data centers is coming ( to the extent it's not already here), this makes sense. Technically someone can just make a better VM engine for JavaScript to execute inside of, but whatever I guess they decided this would be easier.
I'd say JS on the mobile ARM devices is 10.000x more common, and thus important, than the NodeJS on ARM servers.
Re: ARM chips have an instruction with JavaScript in the name
#294Earlier quoted context omitted.
JavaScript has good parts, I write it a lot. But it is ignorant to close eyes on its warts 1 + '2' 1 - '2' Number.MAX_SAFE_INTEGER + 2 and entire WAT series, stems from "don't raise" ethos. JavaScript exposes constructor instead of prototype that messed up a lot, in Ruby terms Object.alias_method :__proto__, :class Object = Object.instance_method(:initialize) Class = Class.instance_method(:initialize) Class.__proto__…
Operator overloading can lead to ambiguities in dynamic languages. Ruby, python, and any number of other languages have it much worse because they can be overloaded any way you want while JS overloads are (currently at least) set in stone by the language. If you could only choose one number type, would it be floats or ints? Crockford would say decimal, but the rest of use using commodity hardware would choose floats…
1 + "2"
#3
1 - "2"
#-1
1 . "2" | 1 .. "2"
#"12"
1 . "-2" | 1 .. "-2"
#"1-2"
Python and Ruby throw exception, use explicit type conversion and string interpolation 1 + '2'
Traceback (most recent call last):
TypeError (String can't be coerced into Integer)
1 + '2'.to_i
#3
"1#{'2'}"
#"12"
Hardly any language is perfect, I have not encounter much of operator overload in ruby (nokogiri?) but I believe C++ got it bad.One number type in Lua:
> 0 | 0xffffffff
4294967295
> 0 | 0xffffffffffffffff
-1
> 0 | 0x7fffffffffffffff
9223372036854775807
limited but better than JavaScript: 0 | 0xffffffff
//-1
BigInt is an improvement 0n | 0xffffffffn
//4294967295n
0xffffffffffffffffn
18446744073709551615n
it is strict 1n - "2"
1 + 1n
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
works nice with string interpolation: `${1n}`
"1"
Numbers is a sane example. One can argue it was for good. How about `{} + []`? I believe I can disable this part in JavaScript engine and no one would notice. And misleading `object[key]` where it calls toString, sure I have not tried that in a decade but it is stupid. UTF-16: ""[1] # there were emoji
//"�"
You've said nothing about constructor oriented programming. Unique feature, I have not heard any other language adopted it yet. The post you've replied contents sketch for Ruby. Actually I've got it wrong — every JavaScript function is a closure (Ruby method is not closure) and Prototype method was a class method (not instance method), fixed but ugly: def function(&block)
Class.prototype.new.tap do |c|
c.define_method(:initialize, block)
end.instance_method(:initialize)
end
def function_(object, name, &block)
object.class_eval do
define_method(name, &block)
end
end
Person = function { |name|
@name = name
}
function_(Person.prototype, :name_) {
@name
}
john = new.call Person, 'john'
puts john.__proto__ == Person.prototype
puts john.name_
def function__(object, name, &block)
object.singleton_class.class_eval do
define_method(name, &block)
end
end
function__(john, :name__) {
@name
}
puts john.name__
By the way, you can say "Yes, I know JavaScript has some problems". It is not a secret, everyone knows.Re: ARM chips have an instruction with JavaScript in the name
#295Earlier quoted context omitted.
Operator overloading can lead to ambiguities in dynamic languages. Ruby, python, and any number of other languages have it much worse because they can be overloaded any way you want while JS overloads are (currently at least) set in stone by the language. If you could only choose one number type, would it be floats or ints? Crockford would say decimal, but the rest of use using commodity hardware would choose floats…
Perl and Lua have separate arithmetic and concatenation operators 1 + "2" #3 1 - "2" #-1 1 . "2" | 1 .. "2" #"12" 1 . "-2" | 1 .. "-2" #"1-2" Python and Ruby throw exception, use explicit type conversion and string interpolation 1 + '2' Traceback (most recent call last): TypeError (String can't be coerced into Integer) 1 + '2'.to_i #3 "1#{'2'}" #"12" Hardly any language is perfect, I have not encounter much of operat…
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.
Re: ARM chips have an instruction with JavaScript in the name
#296Earlier quoted context omitted.
> Through the 80s it was the other way around. You counted as having a language with a spec, even if there was no implementation, but an implementation without a spec was a "toy" Not to my recollection. I don’t recall anyone at uni discussing a C standard until 1989, and even by 2000 few compilers were fully compliant with that C89 spec. There were so many incompatible dialects of FORTRAN 77 that most code had to be…
C was specified by K&R in 1978. Pascal had a specification for the core language, and BASIC was largely seen as a toy.
No it wasn’t. K&R was far removed from many C implementations of the time, wasn’t ever written as a formal spec, and had gaping holes of undefined behavior.
An educational textbook isn’t a formal language specification.
Re: ARM chips have an instruction with JavaScript in the name
#297Earlier quoted context omitted.
Perl and Lua have separate arithmetic and concatenation operators 1 + "2" #3 1 - "2" #-1 1 . "2" | 1 .. "2" #"12" 1 . "-2" | 1 .. "-2" #"1-2" Python and Ruby throw exception, use explicit type conversion and string interpolation 1 + '2' Traceback (most recent call last): TypeError (String can't be coerced into Integer) 1 + '2'.to_i #3 "1#{'2'}" #"12" Hardly any language is perfect, I have not encounter much of operat…
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 bl…
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
> print(string.format("%18.0f",9007199254740991 + 1))
9007199254740992
> print(string.format("%18.0f",9007199254740991 + 2))
9007199254740992
they have extended original "one number type" without change of the interface. In any case both versions do not convert to BigNum like Ruby. 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
=> 115792089237316195423570985008687907853269984665640564039457584007913129639935
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
#=> #
>>> class Foo:
... pass
>>> Foo()
And there is no separate inspect/__repr__ Date.today
#=> #
Date.today.to_s
#=> "2020-10-20"
> 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
foo = Object.new
foo.class == Object
#=> true
foo.singleton_class == Object
#=> false
def foo.bar
end
foo.singleton_class.instance_method(:bar)
#=> #>#bar() (irb):7>
There is ancestors chain Object.ancestors
#=> [Object, Kernel, BasicObject]
There is a bit of syntactic sugar Foo = Class.new
There are few revelations with main (method defined in Object) def baz
end
Object.instance_method(:baz)
=> #
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.
[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
Re: ARM chips have an instruction with JavaScript in the name
#298Earlier quoted context omitted.
>> Why do you think modern CPUs still expose mostly C-abstract-machine-like interface instead of their actual out-of-order, pipelined, heterogeneous-memory-hierarch-ied internal workings? Because exposing that would be a huge burden on the compiler writers. Intel tried to move in that direction with Itanium. It's bad enough with every new CPU having a few new instructions and different times, the compiler guys would…
> Until a new standard down at that level comes into widespread use hardware will be designed to run C code efficiently. Exactly this hinders any substantial progress in computer architecture for at least 40 years now. Any hardware today needs to simulate a PDP-7 more or less… As otherwise the hardware is doomed to be considered "slow" should it not match the C abstract machine (which is mostly a PDP-7) close enough.…
Hacker news post: https://news.ycombinator.com/item?id=16967675
Re: ARM chips have an instruction with JavaScript in the name
#299Earlier quoted context omitted.
I occasionally write JavaScript since 2007, experiment a lot last 5 years, red through ES5 specification several times. I've worked as C++, PHP, Python, Ruby developer. Experimented with a few languages. "JS" instead of "TypeScript" brings confusion. TS solves some issues and I've mentioned it, still typeof null //"object" Template literals interpolation helps but if string (not literal string) slips by it is a mess…
C++ has WAY more spec footguns than JS (and that's without counting all the C undefined behaviors which alone outweight all the warts of JS combined). PHP also beats out JS for warts (and outright bad implementation like left-to-right association of ternaries). Ruby has more than it's fair share of weirdness too (try explaining eigenclass interactions to a new ruby dev). Even python has weirdness like loops having an…
Eigenclass (singleton_class) explained in another thread. I have not encountered Pythons for/else [1] yet.
Right, typeof null exposed by Microsoft IE 2 (?). Web is many times bigger now yet even such a small mistake is not fixed.
I have issue + of being concatenator, I prefer string interpolation, separate operators. Implicit type conversion often does not make sense spoils a lot
[] * 2
//0
foo = {}
bar = {}
foo[bar] = 1 // just throw please
Object.keys(foo)
//["[object Object]"]
> they could also silently fail as well.But they don't. If only these rules were defined as library. I am sure it would be ditched long ago. Actually this may be argument in favor of operator overloading in JavaScript, the way to fix it.
> Foo being an instance of function is MUCH more honest
class Foo
end
Foo.send(:initialize)
TypeError (already initialized class)
# wrong one
Foo.instance_method(:initialize).call
NoMethodError (undefined method `call' for #)
# does not allow unbound
Foo.new
new constructs an object and calls initialize. Same in JavaScript function Foo () {
console.log(this)
}
new Foo
// Foo {}
Foo()
// Window
It kind of make sense — new creates an object of constructor.prototype and calls constructor. I can't see how it is MUCH more honest than if new creates an object of prototype and calls prototype.constructor. By that logic Object.create is not honest Object.create(Object.prototype) // expects [[Prototype]] not constructor
Object.create(null)
And even if it was foo = {}
bar = Object.create(foo)
bar.__proto__ === foo
//true
bar.__proto__.__proto__ === Object.prototype
//true
bar.__proto__.__proto__.__proto__ === null
//true
class Foo {}
class Bar extends Foo {}
bar = new Bar
bar.__proto__ === Bar.prototype
bar.__proto__.__proto__ === Foo.prototype
bar.__proto__.__proto__.__proto__ === Object.prototype
bar.__proto__.__proto__.__proto__.__proto__ === null
I don't need constructor except in new, otherwise I use it only to access prototype. Absence of languages adopting this approach confirms its usability issues.> This is even more true because you are looking at the primitive rather than the function object which contains the primitive.
Could you please expand this part? "Primitive" has specific meaning in JavaScript.
Re: ARM chips have an instruction with JavaScript in the name
#300Earlier quoted context omitted.
C was specified by K&R in 1978. Pascal had a specification for the core language, and BASIC was largely seen as a toy.
> C was specified by K&R in 1978. No it wasn’t. K&R was far removed from many C implementations of the time, wasn’t ever written as a formal spec, and had gaping holes of undefined behavior. An educational textbook isn’t a formal language specification.
The specification was the language, the fact that there was an implementation was a bonus. I never once in my comments above said "formal" so perhaps we are meaning two very different things by "specification." No version of Cs specification since K&R has done away with undefined, nor implementation defined behavior.