3 ms·
> Awesome: prototypes Meh. I still have to write that rant, but javascript's "prototypes" are a boondoggle, they've got nothing to do with Self's prototypes[0]
by masklinn 15y ago
> Awesome: prototypes
Meh. I still have to write that rant, but javascript's "prototypes" are a boondoggle, they've got nothing to do with Self's prototypes[0] and don't provide anything more than classes do in nice dynamic languages (you can, in fact, do more fucking around with Python's types than with Javascript's prototypes). For all intents and purposes, Javascript's so-called prototypes are shitty single-inheritance classes without the sugar.
> dynamic function scope (not sure if there's a proper name for this)
Not sure what you mean by "dynamic function scope", since you don't seem to like `this` (which is indeed complete garbage, but is sorta dynamically scoped) I'm guessing you mean lexical closures? The part where a nested function has read/write access to bindings created in its outer functions/scopes?
> for now there is a lot we can do with it.
There's also a lot we could do with Fortran and Cobol. That's no bloody excuse.
[0] in Self, prototypes are just the thing you clone to get a basic object, they're just a template. They're not a unit of code reuse or inheritance: that's the job of mixins[1]
[1] which, again, are very different from what you get in JavaScript or Ruby (though Ruby is closer): in Self, a mixin is an object you link to your own via a "parent slot", a special type of slot used for message resolution. When a message is sent to an object, the runtime first checks all of the object's non-parent slots and if there's no match it follows the parent slots recursively to try and find a slot matching the message.
- yuchi 15y agoWhile you're generally right, you must not forget about Harmony Proxies and all that meta-programming fuzz. While the final result of a prototypal class hierarchy is in fact very similar to pseudo-classic inheritance, remember that it's just the result of an internal, manual, modifiable process.
- masklinn 15y ago> While you're generally right, you must not forget about Harmony Proxies and all that meta-programming fuzz. All of which (and more) is available in class-based dynamically typed languages
- wwweston 15y ago> don't provide anything more than classes do in nice dynamic languages How would you do in-place method mutation in something like Python or Ruby?
- chc 15y agoNot quite sure what you mean, but I think it's something like this: a = "hello" puts a.size #=> 5 class <<a def size 1 end end puts a.size #=> 1 Am I on the right track?
- judofyr 15y agoIn Ruby: foo = "Hello" def foo.to_s; "Hello world!" end Because "def" introduces a new local variable scope, you'll have to use #define_singleton_method if you want to close over variables: foo = "Hello" old = foo.method(:to_s) foo.define_singleton_method(:to_s) { old.call + " world!" }
- masklinn 15y agoCould you explain what you mean by "in-place method mutation"? With an example in javascript maybe? Is it just about adding or replacing a method on a type (or an instance), or do you mean something more complex?
- fruchtose 15y ago> For all intents and purposes, Javascript's so-called prototypes are shitty single-inheritance classes without the sugar. You're right. I would much rather have Java's or C++'s inheritance models in JavaScript. JS's object model is mutable, which is a plus for me, but it is far only language with mutable object methods or properties. I'll have to move prototypes from the "awesome" pile into the "meh" pile. > lexical closures Beyond closures, which I am glad to see in JS, I am referring to the call and apply functions which allow the user to set the scope of the functions during the function call. Again, I am hardly an expert, so the term for this escapes me. Your reply has been very helpful in that regard. > There's also a lot we could do with Fortran and Cobol. That's no bloody excuse. Very true, but I'd really like to know why you would put JS in the same class as Fortran and Cobol.
- masklinn 15y ago> I am referring to the call and apply functions which allow the user to set the scope of the functions during the function call. Ah yes, so it is indeed about `this` and its dynamic scoping. I can't say I'm much fond of it, I'd rather have correctly bound methods (à la python) and actual, optional dynamic scoping when needed (à la Common Lisp) > Very true, but I'd really like to know why you would put JS in the same class as Fortran and Cobol. I don't, I'm just saying being able to do "a lot" with a language does not mean the language is good in and of itself, and Fortran and Cobol are good examples of that: few under 50 will try and defend them (as opposed to PHP, an unmitigated disaster of a language which still finds defenders), and there are fucktons of code written in these languages and still running.