-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this
is unintuitive
#115
Comments
Thanks for bringing this up. Indeed, the use of In the end, I don't care so much for whether The topic touches two aspects, related to static vs. dynamic binding:
Compared with statically typed languages, additional complications arise from the fact that dynamic name lookup ("duck typing") is the default. In the current design, there are three ways to access members from within a class:
You can think of it as follows:
In all cases, lookup goes up the inheritance chain until a (visible) member is found. One possible solution may be to introduce a new syntax for the last case, maybe something along the lines of It should be noted that in TScript, In terms of functionality, I'd like to cover the following:
Now, different languages came up with different solutions. C++ has the concept of TScript is somewhere in between. It is dynamically typed (like Python and Javascript), but it enforces static object layout though classes (because I want to teach basics of object oriented design, therefore objects are not dictionaries, extensible at runtime). TScript is already capable of duck typing, and therefore it does not have a need for a second mechanism for dynamic binding. That's why One advantage of virtual functions is that they make the interface between classes more explicit. While a protected member is an interface for the subclass to interact with the superclass, a virtual method is an interface through which the superclass can call its subclass. Right now, the latter is not solved at the level of the interface definition, but instead inside of the method body, where a call like I see the following ways of moving forward:
Finally, I hesitate to alter the meaning of |
Thank you very much for your detailed reply. Due to my lack of experience with dynamic OOP languages, I had failed to consider the ramifications of dynamic name lookup. Looks like Ruby behaves the same way. I apologize for wasting your time :) I like your suggestions overall. The one thing I would oppose is the syntax |
Unlike other object-oriented languages that allow the elision of
this
when accessing class members (cf. Java), the resulting expressions exhibit differing behavior in TScript. I found two specific instances of this.this
can only access public membersThis seems to be a known "feature". I understand that it might make the
.
operator easier to handle for the interpreter (althoughsuper.y
on a protected member works just fine for some reason???), but from a beginner's perspective this communicates some questionable ideas about encapsulation and obfuscates how the heck non-static members even work in the first place. (I have found that to be a big hurdle in my own learning process when first starting out in C#, and reminding myself that I could always prepend an explicitthis.
has made it a lot easier to grasp.)Furthermore, the lack of a way to disambiguate between constructor parameters and non-public members means that different sets of names have to be chosen for each, whether through Hungarian notation or a more irregular naming scheme. Not a big issue, but it has always bugged me from an aesthetic perspective.
Eliding
this
breaks overridingSame thing happens for methods. This effectively makes anything non-overridable unless you make sure to write out the
this.
everywhere, and as stated above this isn't always possible.I believe that making the notations
x
andthis.x
interchangeable in all places would make the language more conceptually sound and in tune with object-oriented design principles. Would be glad to see this fixed or to be enlightened on why it shouldn't or can't be fixed.The text was updated successfully, but these errors were encountered: