News for hackers. Stuff that matters.
Re:JSX - a faster, safer, easier alternative to JavaScript by politician on Wednesday May 30, 2012 @08:53PM (#4045731)
"JSX offers a solid class system much like the Java programming language, freeing the developers from working with the too-primitive prototype-based inheritance system provided by JavaScript."

Pass.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @09:09PM (#4045780)
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?
Re:JSX - a faster, safer, easier alternative to JavaScript by fleitz on Wednesday May 30, 2012 @09:21PM (#4045806)
That 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.

Re:JSX - a faster, safer, easier alternative to JavaScript by j_baker on Wednesday May 30, 2012 @09:28PM (#4045833)
I'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?
Re:JSX - a faster, safer, easier alternative to JavaScript by fleitz on Wednesday May 30, 2012 @09:35PM (#4045852)
It 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.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @09:41PM (#4045873)
Prototypes 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()
Re:JSX - a faster, safer, easier alternative to JavaScript by olalonde on Wednesday May 30, 2012 @09:27PM (#4045830)
When talking about programming languages, "primitive" usually means low level. For example, primitive data types (http://en.wikipedia.org/wiki/Primitive_data_type).
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @09:35PM (#4045851)
So given that, how do you come to the conclusion that prototypes are more primitive than classes?
Re:JSX - a faster, safer, easier alternative to JavaScript by olalonde on Wednesday May 30, 2012 @09:37PM (#4045861)
Just 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.
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @09:45PM (#4045883)
The Gameboy color hardware can be simulated on a desktop computer in a browser, in javascript. Does that make desktop computers more primitive than Gameboys?
Re:JSX - a faster, safer, easier alternative to JavaScript by viraptor on Wednesday May 30, 2012 @09:53PM (#4045901)
It'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

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @10:01PM (#4045924)
@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?
Re:JSX - a faster, safer, easier alternative to JavaScript by viraptor on Wednesday May 30, 2012 @10:19PM (#4045973)
I'd still stand by the opinion that the browser in GBA is the same level of complexity as GBA in browser. They're interpreters of some code essentially (one of GBA roms, the other of html/js). There is of course a different human complexity of "how hard would it be to implement"... but if we're adding JS engine to the mix, the browser may be actually harder.

With classes / prototypes (sorry for wibbly wobbly explanation, my CS is not good enough to use the proper terms, which probably exist out there), you can pretend there's a "behaves like" relationship. To simulate a prototype using a class you have to build the freely accessible dictionary and initialisation/cloning semantics level inside of the class.

To simulate classes using a prototype... that depends on your definition of a class. Dynamic dispatch is already there, encapsulation too, subtypes just need a field specifying the name and cloning the right prototype, inheritance is on by default. Self-referencing is usually in there too.

So in my opinion classes can be substituted by prototypes in a large number of cases. Classes however need another layer on top to act like prototypes. So prototypes look like more primitive than classes and classes look like a special-cased version of prototypes. Then again, it's late here, so maybe I missed something obvious...

Re:JSX - a faster, safer, easier alternative to JavaScript by chii on Thursday May 31, 2012 @04:26AM (#4046989)
I htink the word you are looking for isn't actually "primative", but expressiveness.

A prototypical inheritance model can express a larger range of constructs than a class based inheritance model can, and this is normally called expressiveness. Its actually difficult to say which one is more "primative" (by your definition of primative), because they are actually both on a similar layer.

Re:JSX - a faster, safer, easier alternative to JavaScript by aethr on Wednesday May 30, 2012 @10:58PM (#4046102)
Anything I can do with a string, I could also do with an array. However, it would take extra work to make an array behave like a string, in the form of helper functions, etc.

If I really wanted to prove a point, I could make a string behave like an array. But that would take even more work because an array is a very flexible tool used for a variety of low level purposes.

Therefor, according to your argument, a string is a more primitive data type because it takes more work to make a string act like an array than it does to make an array act like a string. This goes in direct contradiction to the actual definition of a programming primitive.

Back to the original poster's quote, "JSX offers a solid class system much like the Java programming language, freeing the developers from working with the too-primitive prototype-based inheritance system provided by JavaScript."

He is quite clearly addressing a specific case here, which is programmers who want to use Java-like classes when developing in Javascript. A lot of extra work is required if you want to make a Javascript prototype behave like a Java class, with inheritance, etc. So in this context, it is obvious that Javascript prototypes are "too primitive" for the task at hand.

Similar to the way that strings are, in fact, arrays with lots of extra functions for frequently repeated, string-related tasks, JSX classes are JS prototypes with a lot of the oft-repeated boilerplate code done for you. I'm not sure how to make it more clear how the chain of "primitiveness" flows in this case.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @11:52PM (#4046263)
You're kind of stretching the metaphor a bit far here. In the javascript language interpreters, prototypes are implemented with classes. In JSX classes are implemented with prototypes. In C, strings are implemented as arrays. In shell scripting, arrays are implemented with strings. All we get out of this is that whether a programming construct is low level or high level is relative to how it was implemented, and is not an intrinsic quality of the construct itself. This doesn't make any sense to me.
Re:JSX - a faster, safer, easier alternative to JavaScript by aethr on Thursday May 31, 2012 @12:35AM (#4046396)
Something being "a primitive" is entirely based on implementation details. Not implementation details of how the language interpreters/compilers are constructed, but how you as a programmer implement things in the language in question.

A associative array might be considered a language primitive in PHP, but not in C. It is contextually dependent on the language being discussed.

Without speaking about a specific language, you cannot define something as a primitive or not in the strictly programming sense. Once you start talking about comparing two types of constructs in an abstract sense, the word primitive can only be interpreted using the English common usage, and then you are talking about an entirely different concept.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Thursday May 31, 2012 @12:44AM (#4046420)
Re-reading this... It's clear what is "a primitive" in javascript. but what does "Too-Primitive" mean? The sense of the word "primitive" as in language primitive is a set, not a quantity. Something is either a primitive or it is not. there's no such thing as "too primitive"
Re:JSX - a faster, safer, easier alternative to JavaScript by aethr on Thursday May 31, 2012 @03:27AM (#4046832)
You're right, when talking about a primitive type in the programming sense, something either is primitive or it isn't.

I took this phrase to mean that the prototype construct is "one step down on the composite type hierarchy" from what is needed to emulate as a Java-style class.

Rather, its a good building block but the necessary boilerplate code makes it "too basic" for that purpose. Therefor this developer has created a type further up the composite type hierarchy (or further away from the primitives) to accomplish his goal.

I don't think he's trying to suggest any deficiency in the expressiveness or capability of the prototype construct (he's obviously quite familiar with it to create this language). This is simply a tool for people who aren't familiar with (or don't make use of) that aspect of Javascript to be productive by utilising a more brief, or possibly more familiar (ie Java) syntax.

Re:JSX - a faster, safer, easier alternative to JavaScript by olalonde on Wednesday May 30, 2012 @10:33PM (#4046016)
It seems you are confusing a number of things. I suggest you read this Wikipedia article, it should answer most of your questions: http://en.wikipedia.org/wiki/High-level_programming_language
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @10:39PM (#4046039)
@olalonde that's a bit of a cop out, of course I've read that article. That is why I'm baffled by the assertion that prototypes are more primitive than classes. It doesn't add up with the definitions of what amounts to being high level and low level. If you have something more specific to say I suggest you say it, but it's pretty lame to just wave your hands at a wikipedia article and tell me to figure out something that you've obviously got wrong, from my point of view.
Re:JSX - a faster, safer, easier alternative to JavaScript by olalonde on Wednesday May 30, 2012 @10:49PM (#4046070)
Prototypes are a primitive data type of Javascript (a basic building block). Classes are not offered natively and have to be constructed with lower level building blocks such as prototypes. This is why classes are said to be higher level than prototypes in Javascript. Does that help?
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Thursday May 31, 2012 @12:34AM (#4046390)
Do you think that is the sense of the word "Primitive" intended by the author of JSX? In that sense of the word, what does "More" primitive or "Too primitive" mean? I would have thought something was either a primitive or it wasn't- not a sliding scale.
Re:JSX - a faster, safer, easier alternative to JavaScript by aethr on Wednesday May 30, 2012 @11:07PM (#4046123)
I find it hilarious that olalonde appears to be turning your condescending use of socratic irony back on you by treating you as the "ignorant student" that you pretend to be, and then not only do you not pick up on it, you actually get offended! Brilliant.
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @11:46PM (#4046248)
There was no question that he was asking me to answer. He just told me that I was confused and pointed me at an article. He didn't say what he thought I was confused about. There was no obvious conclusion he was attempting to lead me to. There was no new evidence he was presenting. It's probably an mistake to read offense into text. There is no way for you to know whether I was offended or not. In this case I was not offended, I was pointing out that his reply was devoid of content, and lacking in effort. Likewise if you want to read condescension into my text, that's up to you, but has nothing to do with anything I wrote.
Re:JSX - a faster, safer, easier alternative to JavaScript by aethr on Thursday May 31, 2012 @12:27AM (#4046370)
Your arguments all tend to make sense when using the English common usage of the word primitive, because I believe that JS prototypes are possibly more advanced than Java classes.

However, speaking solely about the language Javascript, I think it's also fairly clear that in Javascript a prototype is a language primitive that you would use to build a Java-like class construct. Therefore in this context, according to the programming term primitive, prototypes are clearly "more primitive".

It doesn't matter what the Javascript interpreters are doing behind the scenes, because all we care about is Javascript as a language, and what building blocks are available there.

Your use of the word primitive does not seem to logically match the definition of the word provided in the Wikipedia article (admittedly not the best reference for programming concepts), which is why I believe the link was entirely warranted.

And just as a side note, it is entirely possible to be condescending without consciously intending to be.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Thursday May 31, 2012 @01:37AM (#4046572)
As a side note, when a human communicates something there is an intent and an interpretation. If the two don't match up, do you defer to the intent, or the interpretation as the correct meaning?
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @10:28PM (#4045999)
@viraptor (i can't reply directly to messages sometimes for some reason. is it a karma thing?) , So, what you are saying is that if you want to simulate A in B, but B needs an abstraction layer to simulate A, while A can simulate B more directly and naturally, that makes A more primative? So then does that mean that C is more Primitive than Assembler?
Re:JSX - a faster, safer, easier alternative to JavaScript by politician on Wednesday May 30, 2012 @10:57PM (#4046098)
Could you use the reply button when replying instead of using the @name notation? It's kind of hard to follow your responses.
Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @11:44PM (#4046240)
I would have if I could have, but I didn't know the rules of when reply buttons appear.
Re:JSX - a faster, safer, easier alternative to JavaScript by biot on Thursday May 31, 2012 @12:34AM (#4046391)
Click on "link" for the message to reply if you don't want to wait.
Re:JSX - a faster, safer, easier alternative to JavaScript by sophacles on Wednesday May 30, 2012 @11:05PM (#4046120)
Replying to replies to your messages has a cooling-down period built in on this forum. Give it 5 or so minutes, and the reply link appears.
Re:JSX - a faster, safer, easier alternative to JavaScript by ams6110 on Wednesday May 30, 2012 @09:20PM (#4045805)
Re:JSX - a faster, safer, easier alternative to JavaScript by sophacles on Wednesday May 30, 2012 @10:45PM (#4046061)
Here is an example of doing prototypes with classes in python: http://kashif.razzaqui.com/30414548

I presume similar is available in just about any language with decent reflection and/or generics.

Re:JSX - a faster, safer, easier alternative to JavaScript by ZenPsycho on Wednesday May 30, 2012 @09:25PM (#4045823)
@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.

Re:JSX - a faster, safer, easier alternative to JavaScript by j_baker on Wednesday May 30, 2012 @09:23PM (#4045817)
It 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?

Re:JSX - a faster, safer, easier alternative to JavaScript by olalonde on Wednesday May 30, 2012 @09:29PM (#4045835)
That's not what expressiveness means. Classes can be simulated in assembly but assembly isn't very expressive.
Re:JSX - a faster, safer, easier alternative to JavaScript by politician on Wednesday May 30, 2012 @09:59PM (#4045913)