5 ms·
That's a weird thing to think. If you can simulate classes with prototypes, but you can't simulate prototypes with classes, what is the natural conclusion you c
by ZenPsycho 14y ago
That's a weird thing to think. If you can simulate classes with prototypes, but you can't simulate prototypes with classes, what is the natural conclusion you can come to about which is more expressive or primitive?
- ams6110 14y agohttp://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html
- fleitz 14y agoThat prototypes are overly complex. You can't simulate most imperative programs with functional ones because writing in a functional language eliminates a vast majority of bugs due to incomplete reasoning about memory barriers and other really hard to duplicate issues like race conditions. CHESS is an amazing piece of software precisely because it CAN simulate race conditions and reproduce them, however, if these things didn't exist no one would ever bother trying to reproduce them. I'm quite fine not being able simulate these issues.
- j_baker 14y agoI'm not saying you're wrong, but isn't this a bit like saying that files are overly complex because they can be used to simulate sockets?
- fleitz 14y agoIt is, but on the other hand if you write code to work with sockets then you get a performance boost on spinning disks because your IO is sequential. And many other benefits like trivial cache prediction, buffering, etc. I do think that prototypes have useful properties, but I'm not sure that a prototype isn't a form of an open class. I tend to think that the biggest problem with prototypes in js is the interface.
- ZenPsycho 14y agoPrototypes in JS are problematic due to false cognates- it tried to look like Java (due to marketing department fuckery), and use the same keywords as java, but it doesn't act at all like Java which leads to some nasty surprises. This has been fixed in ES5- the correct way to inherit from a prototype is no longer via constructor functions and their prototype property, but via Object.create()
- j_baker 14y agoIt would seem as though prototypes are the more expressive option if you can use them to simulate classes. In fact, one could argue that this is essentially what Python does. ...but the OP seemed to indicate that prototypes were "primitive", and it sounds like you agree with him. Are you trying to say something that I'm missing?
- olalonde 14y agoThat's not what expressiveness means. Classes can be simulated in assembly but assembly isn't very expressive.
- politician 14y agohttp://en.wikipedia.org/wiki/Expressive_power http://en.wikipedia.org/wiki/Expressive_power
- ZenPsycho 14y ago@j_baker I do not agree that prototypes are primitive and I decided to express this in the form of socratic irony. @fleitz Whether prototypes are overly complex is neither here nor there. the question is whether they are primitive. More primitive than classes- something which is historically and demonstrably untrue, in my opinion.
- olalonde 14y agoWhen talking about programming languages, "primitive" usually means low level. For example, primitive data types (http://en.wikipedia.org/wiki/Primitive_data_type http://en.wikipedia.org/wiki/Primitive_data_type).
- ZenPsycho 14y agoSo given that, how do you come to the conclusion that prototypes are more primitive than classes?
- olalonde 14y agoJust as you said yourself: classes can be simulated with prototypes and are therefore higher level than prototypes. In other words, prototypes are lower level (more primitive) than classes.
- ZenPsycho 14y agoThe Gameboy color hardware can be simulated on a desktop computer in a browser, in javascript. Does that make desktop computers more primitive than Gameboys?
- viraptor 14y agoIt's a difference of power and size, not level of complexity. In theory you could simulate a desktop computer with a browser and javascript on a gameboy color given enough processing power and memory. (without increasing instruction set complexity / requiring more abstraction levels than on a desktop / sneakily inserting more complexity in some other way) Actually it's a rule of hacks, isn't it? If it can exist... https://www.youtube.com/watch?v=QsZrD622qf0 https://www.youtube.com/watch?v=QsZrD622qf0
- ZenPsycho 14y ago@viraptor and so we can see that we must take into account more than just whether one can be simulated on another, we must take into account /expressiveness/, or level of complexity as well! In theory, you could simulate prototypes with classes too. You have to be able to, or else it wouldn't be possible to write an interpreter for a language which supports prototypes. The question of "can" and "can't" then, in the context of my original question has to do with the level of difficulty in doing one or the other. Now that we've got this far, what is more difficult- simulating classes with prototypes, or simulating prototypes with classes? Which requires more code, and more complexity? And from that, what do we conclude about primitiveness?
- sophacles 14y agoHere is an example of doing prototypes with classes in python: http://kashif.razzaqui.com/30414548 http://kashif.razzaqui.com/30414548 I presume similar is available in just about any language with decent reflection and/or generics.