Keyword Prototype instead of Class

Discuss the future of the AutoHotkey language
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Keyword Prototype instead of Class

29 May 2014, 02:40

I brought this up a while ago, but not since the new site. Also, I don't feel strongly about this - but I would like to see what others think.

Whereas the concept of class-like syntax is great, I believe the keyword "class" is misleading. A class-object in AHK is not a class, in the typical sense of the word when comparing to most other languages. I feel this could lead to confusion to developers who are used to classes in other languages, as well as noobies who are tying to understand classes by comparing to other languages. I feel Prototype-based programming is correct for AHK, but using the keyword "class" just adds an un-intuitive twist to the already steep learning curve of Prototype-based programming.

Also, I realize the documentation clearly states:
An object is a prototype or base if another object derives from it ... For convenience and familiarity, the "class" keyword can be used to construct a base object.
... but why mix the two concepts?

Also, since Prototype is longer, simply Proto could be an option. Or maybe even just Base.
lexikos
Posts: 6608
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Keyword Prototype instead of Class

29 May 2014, 20:12

How is it a problem? Mostly scripters don't need to know that objects are prototype-based. "Class" is a much more familiar/common concept.

Edit: More importantly, how does it deviate from the familiar class concept, aside from being mutable and dynamic?
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Keyword Prototype instead of Class

30 May 2014, 01:46

My concern isn't so much about functionality, but about understanding what the code is doing.
"Class" is a much more familiar/common concept.
Exactly - to the point that if I didn't read the documentation, I might be surprised to find out AHK is prototype-based.
More importantly, how does it deviate from the familiar class concept, aside from being mutable and dynamic?
First off, depending on the language (ruby comes to mind), classes can be mutable and dynamic. To your point, if we are only talking functionality, perhaps there isn't much deviation. However, when questions about creating custom objects come up, I find it can be hard to explain code if the user doesn't realize/understand what prototyping is. After this is explained, you can then explain how the code is using this concept. (again, I realize they should have read the documentation)

I guess ultimately I'd ask if you agree that Class-based & Prototype-based OOP are two distinctly different approaches. If you agree they are, then I'd ask why mix the concepts?

... and please don't misunderstand - I'm not criticizing the class-like syntax itself. I think it was a great add, and I was quite impressed how quickly you implemented it. I just think the keyword "class" is misleading.
elmo
Posts: 92
Joined: 09 Oct 2013, 09:08

Re: Keyword Prototype instead of Class

30 May 2014, 15:27

You guys are technical heavy weights; likely the heaviest round these parts. Me, not so much. I'm just a business puke who uses AHKScript to produce results quickly. As a business person however I am keenly interested in the "trajectory" of products. It feels like folks will turn around in a few years and find that there are LOTS of AHKScripted solutions in places no one anticipated. Taking liberties I might compare it - albeit on a smaller scale - to the rise of JavaScript. Continuing in that vein I would note that Javascript is upfront regarding the use of prototypes to provide "class functionality".

Straight from the developer.mozilla.org website :
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse (known as inheritance in class-based languages) is accomplished through a process of decorating existing objects which serve as prototypes. This model is also known as class-less, prototype-oriented, or instance-based programming.
JavaScript is an object oriented dynamic language; it has types and operators, core objects, and methods. Its syntax comes from the Java and C languages, so many structures from those languages apply to JavaScript as well. One of the key differences is that JavaScript does not have classes; instead, the class functionality is accomplished by object prototypes. The other main difference is that functions are objects, giving functions the capacity to hold executable code and be passed around like any other object.
As someone who is struggling with understanding Classes in AHKScript I can tell you that no amount of clarity and accuracy will be too great. So I'm not really smart enough to say whether they should be called Classes or Prototypes or Functions but - IMHO - it could be advantageous to pick the most accurate one.

Thank you again lexikos for moving this most excellent project forward and Jethrow for your amazing contributions to the community.
lexikos
Posts: 6608
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Keyword Prototype instead of Class

30 May 2014, 20:46

jethrow wrote:I guess ultimately I'd ask if you agree that Class-based & Prototype-based OOP are two distinctly different approaches.
No.
elmo wrote:Straight from the developer.mozilla.org website :
That's not a very straightforward explanation. It seems to imply that prototype-based programming does not use inheritance; AutoHotkey does, so Mozilla's definition is not applicable. Wikipedia states that behaviour reuse (inheritance) is performed by cloning an existing object. AutoHotkey can certainly do that, but that's not the recommended way of doing things - it uses inheritance in much the same way as other class-based languages.

It seems that "decorating existing objects" forms a fundamental part of Mozilla's definition of what prototype-based programming is, but that's a technique which is also applicable to class-based programming. (I wasn't familiar with the term "decorator pattern" until just now.)

I think some people have an erroneously narrow view of what a "class" is.
class
klɑːs
noun
1.
a set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality.
As an example of how differently a 'class' can be implemented, consider Squirrel.
Class
Classes are associative containers implemented as pairs of key/value. Classes are created through a 'class expression' or a 'class statement'. class members can be inherited from another class object at creation time. After creation members can be added until a instance of the class is created.

Class instance
Class instances are created by calling a class object. Instances, as tables, are implemented as pair of key/value. Instances members cannot be dyncamically added or removed however the value of the members can be changed.

Source: Squirrel 3.0 Reference Manual
jethrow wrote:However, when questions about creating custom objects come up, I find it can be hard to explain code if the user doesn't realize/understand what prototyping is.
What is prototyping?

Perhaps what you're calling prototyping is just another form of inheritance from a class, or really not specific to either. When you say 'creating custom objects', the meta-functions come to mind. They really have nothing to do with either prototype- or class-based programming in general. Similar functionality can be found in Lua's meta-tables or C#'s DynamicObject.
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: Keyword Prototype instead of Class

31 May 2014, 00:46

I moved to AutoHotkey from JavaScript(codecademy course) and was really confused when I read that OOP is prototype-based but have classes. I think Class in AutoHotkey is misleading if it does not means the same as in Class-based OOP.
DRAKON-AutoHotkey: Visual programming for AutoHotkey.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 9 guests