Re:SICP: JavaScript Edition available for pre-order
by kazinator on Friday January 21, 2022 @03:21PM
(#30029445)
> Why do you try to code JS without reading about the language?
Because it's painful drivel.
> Your code is potentially bad. `||` uses "falsey" values
We know that this dictionary will only contain things to which we will be adding 1, which we expect to be numerically done.
(I have already made the point that there shouldn't be multiple falsey values.)
I mean, there could be other problems in this direction: if a string is in there like "foo", then the + operation will make it "foo1".
It's unlikely we would ever want to code a "add 1 to dictionary element, treating non-existence as zero" which will work for absolutely any dictionary regardless of knowing/assuming anything about its content.
> This could happen in any language with a methodNotFound handler.
Only if you define that handler, and have it silently return.
Handlers for method not found are a very poor idea to include in an object system. Ruby and its ilk uses it for ugly, monkey patched solutions for this and that.
Because it's painful drivel.
> Your code is potentially bad. `||` uses "falsey" values
We know that this dictionary will only contain things to which we will be adding 1, which we expect to be numerically done.
(I have already made the point that there shouldn't be multiple falsey values.)
I mean, there could be other problems in this direction: if a string is in there like "foo", then the + operation will make it "foo1".
It's unlikely we would ever want to code a "add 1 to dictionary element, treating non-existence as zero" which will work for absolutely any dictionary regardless of knowing/assuming anything about its content.
> This could happen in any language with a methodNotFound handler.
Only if you define that handler, and have it silently return.
Handlers for method not found are a very poor idea to include in an object system. Ruby and its ilk uses it for ugly, monkey patched solutions for this and that.