tag:blogger.com,1999:blog-34454975.post5289476165248542403..comments2023-06-28T16:58:41.189+02:00Comments on Web Reflection: A Pascal record via JavaScriptAndrea Giammarchihttp://www.blogger.com/profile/16277820774810688474noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-34454975.post-35594340567315720722011-06-01T10:26:55.827+02:002011-06-01T10:26:55.827+02:00Calling it a record doesn't make it less class...Calling it a record doesn't make it less class-like, but it *being* a record makes it less class-like.<br /><br />A record = a structure = essentially a block of variables. A structure TYPE is similar to a class in some ways, but quite different in others.<br /><br />The main difference is that if you make a TYPE RECORD =... in Pascal, then you can declare multiple actual records using that type, but each has only data. An actual class (using ObjectPascal) will have data, but methods too. (And the methods will not be duplicated). Of course you could use dynamically allocated records and use procedures instead of class methods to process them - and this isn't a lot different than what happens under the hood in C++, etc. (Look up Virtual Method Table).Shirubahttps://www.blogger.com/profile/10503809755592576431noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-23109226148472697662010-08-20T16:02:47.440+02:002010-08-20T16:02:47.440+02:00many changes/improvements in my next experiment, h...many changes/improvements in <a href="http://webreflection.blogspot.com/2010/08/objectdefineproperty-but-strict.html" rel="nofollow">my next experiment</a>, have a look ;)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-30291175841127904402010-08-19T12:23:07.869+02:002010-08-19T12:23:07.869+02:00function Person(name, age) {
this.name = name;...function Person(name, age) {<br /> this.name = name;<br /> if (age) this.age = age;<br />}<br /><br />// we can define a type hint<br />// or we can define both hint<br />// and value plus enumerable<br /><br />Person.prototype = JSRecord({<br /> name: "string",<br /> age: {<br /> type: "number",<br /> value: 0<br /> },<br /> toString: {<br /> enumerable: false,<br /> type: Function,<br /> value: function () {<br /> return this.name + " is " + this.age + " years old";<br /> }<br /> }<br />});<br /><br />written in semi-java-like syntax:<br /><br />public class Person {<br /> public function Person(name, age){<br /> this.name = name;<br /> if (age) this.age = age;<br /> }<br /><br /> public string name {get, set}; //C#-like<br /> public number age = 0;<br /> private function toString() { //enumerable = false => private<br /> return this.name + " is " + this.age + " years old";<br /> }<br />}<br /><br />Let me quote wikipedia (much simpler than the official explanation in the UML standard: "a class is a construct that is used as a blueprint (or template) to create objects of that class".<br /><br />The fact that you call it Record does not make it less class-like :)<br /><br />(In order to have a class-like structure, you don't have to have class-based inheritance.)Aadaamhttps://www.blogger.com/profile/05843560041038857258noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-16767407031236428222010-08-19T10:40:31.651+02:002010-08-19T10:40:31.651+02:00Aadaam I am not inventing classes, I am implementi...Aadaam I am not inventing classes, I am implementing type hint usable through prototype following a good old Pascal notation as model ;)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-44321060093389221262010-08-19T10:34:45.953+02:002010-08-19T10:34:45.953+02:00thanks, one missing thing is the arguments and the...thanks, one missing thing is the arguments and the returns property for methods, once I change the code to validate those too, if specified, the final thing to do will be a sort of production/development switch in order to ensure performances when necesary. Stay tunedAndrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-25661998461453811982010-08-19T09:37:23.512+02:002010-08-19T09:37:23.512+02:00i think it is an interesting abstracion for the va...i think it is an interesting abstracion for the validation problem: it defines a whitelist and ensure the values are compliant. can be used every time you want to be shure that data passed inside your routine are clean, can be used as an alternative to assertions to go toward design by contract...Anonymoushttps://www.blogger.com/profile/00307516763260873196noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-40641583006679167842010-08-18T19:48:22.128+02:002010-08-18T19:48:22.128+02:00You're just inventing classes, I hope you'...You're just inventing classes, I hope you're aware of it...<br /><br />Classes exists because we like to think in categories, we, late descendants of Aristoteles' antic culture.<br /><br />(Not that Kama Sutra, being written before Aristoteles was born, and far away, wouldn't use a taxonony)<br /><br />Nowadays I'm thinking that the notion of 'class' is hardwired into the western culture, and we, javascripters, probably shouldn't try to avoid that much as we like (yes, it does make us hip and different, but what if we just dance around a lack of feature instead of having something...)<br /><br />BTW, if old books, try to read Structured Programming from Dahl-Dijsktra-Hoare. Classes aren't the successors or the opposite of Structured programming: they were part of its concepts from the very beginning.Aadaamhttps://www.blogger.com/profile/05843560041038857258noreply@blogger.com