Class Property Instance Variable

Propose new features and changes
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Class Property Instance Variable

16 Feb 2017, 20:13

Helgef wrote: then you make a function, where you have one instance of the class as a static variable, then delete the class.
This is similar to one of the links by Coco that I shared to the OP which he didn't like for some reason:

https://autohotkey.com/boards/viewtopic.php?t=7072

RFM
Posts: 28
Joined: 21 May 2016, 12:50

Re: Class Property Instance Variable

16 Feb 2017, 20:19

nnnik wrote:If you want to use a OOP library from another person you need to understand OOP.
That is not true. I can give you an AHK class with instruction on how to use it in your procedural language, such as AHK, which is a procedural language with OOP enhancement. You do not need to have any clue about OOP to use a third party OOP product, you just follow the instructions.

nnnik wrote:If you understand OOP why would you try to access any member directly?
I suppose you have never been curious to try things out just to see what would happen? If so, I believe you to be in the minority. Especially if you are one who likes to tweak things and make them faster. And, you find that a direct assignment to the class variable is faster.

nnnik wrote:I think it's not completely impossible to create a piece of code within AutoHotkey that can emulate the kind of behavior that you are searching for.
A few have, and their code is posted, and some are even referenced in the above comments. But, none work and all take a lot of work, and you have to do it for each and every variable you wish to protect.

nnnik wrote:However rewriting code for that would be a hassle to do every time you want to create a class.
Not just a class, but for every variable in that class.

nnnik wrote:That's one of the arguments I never understood.
Suppose a programmer, Larry, in a particular company got curious and wanted to see what would happen if he did a direct assignment of user input to a third party class his Boss bought for their use in the Application he was working on. In other words, he bypassed the property and did a direct assignment. As he was testing this out, a coworker came by and said, "Let's go to lunch." So Larry quickly saved his work and went to lunch. When he got back, the Boss had an urgent thing for Larry to work on and Larry's direct assignment test was soon forgotten.

As the users of the Application written by Larry and his coworkers were pretty good at entering the correct values, the direct assignment didn't cause any errors. However, as time passed, things changed and the Boss hired the third party to update the class to handle the changes. Some of the numbers that used to work no longer worked and other numbers now changed more than one variable, that is, when a property was used to pass in the number, depending on what that number was, it could cause more than one class variable to be changed. Well, low and behold. When the number was entered by the user of the Application, it was no longer producing the correct results. The Boss got on the case of the third party class developers he bought the class from, but the class developers could find no error with their code and insisted that one of the Boss' programmers were not using the class properly. Of course, now you have egos and pride involved. Oh, in the mean time, Larry found a job closer to home that he liked better and therefore no longer worked there.

The Boss sat down with his programmers and told them what the third party class developer said. So, the Boss' programmers went through the code and eventually found the direct assignment Larry had made in the code. The Boss now humbly apologized to the third party class developers and of course, was angry at Larry, who no longer worked there, for all the headache and time and money wasted because he used a direct assignment instead of a property. Larry wasted not only the Boss' time and money, but delayed other programming work his programmers needed to do. And not only that, he wasted the third party class developer's time and money having to prove the class worked properly, if used properly, and of course, delayed the work the third party class developers needed to do.

The above is just one of numerous examples of why a third party class developer would not want any possible means of direct assignments within their class. Think about the damage a disgruntled programmer could do, going through the Application code and deliberately changing property assignments to direct assignments. Even making it date sensitive, that is, it only used the property assignment until a year had passed since he quit, then from then on, it did a direct assignment. And, lets say he was smart enough to only use the direct assignment on a very random basis averaging one out of 100 times. So, the Application would only produce invalid results on occasion, very hard to track down.

Well, I hope this gives you a little more understanding.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Class Property Instance Variable

16 Feb 2017, 20:23

Sure that's a good example, but has that actually happened to you? I highly doubt AHK code is being used in that context, so your example is purely hypothetical, and not at all likely to happen in the real world.

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Class Property Instance Variable

16 Feb 2017, 20:52

RFM wrote:
nnnik wrote:If you want to use a OOP library from another person you need to understand OOP.
That is not true. I can give you an AHK class with instruction on how to use it in your procedural language, such as AHK, which is a procedural language with OOP enhancement. You do not need to have any clue about OOP to use a third party OOP product, you just follow the instructions.
If you follow instructions you don't actually need background info at all in general. But we are talking about serious programming here don't be delusional.
I suppose you have never been curious to try things out just to see what would happen?
No I always write my entire code by myself so I always know what it does. And if I didn't I just read through the source code, because that's faster than compiling.
And, you find that a direct assignment to the class variable is faster.
Well unless it is an optimized language and calling the setter method is the same as setting the class variable.

A few have, and their code is posted, and some are even referenced in the above comments.
None of the codes mentioned above really work like I want them to. I'm going to try to create a good one tomorrow.

Not just a class, but for every variable in that class.
No that's where your dead wrong. You can either define every variable or define every part of the Interface that you want to expose or simply expose methods and hide values.
Out of those mentioned I really like the defining exposed Interface idea because it would be similar to a type system.

For your Larry story I'll give you an A+ in creative writing. I don't think Larrys or the companies fate has anything to say in how we design AutoHotkey because AutoHotkey is not targeted at companies at all.

Helgef wrote:Edit
nnnik wrote:Helgefs solution doesn't work with OOP.
What does that mean? (I do not mean the abbreviation)
There are 2 parts to that:
1. Your programming style is not OOP.
2. The code you created works by overwriting the base value and therefore breaks inheritance.

Also the code you have right now is much better however is still annoying to write.
Recommends AHK Studio
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Class Property Instance Variable

16 Feb 2017, 23:03

Private and protected is just to allow dumb programmers to use your code ( and IDE but those can be configured )
Just a wild guess, but roughly 75% of AHK users probably don't even use functions or classes.
I tend to use _ in front of attributes or methods that should be for internal uses within a class.
I know I would feel bad calling instance._something
I don't know if there is a somewhat official naming system/convention within AHK community ?!
RFM
Posts: 28
Joined: 21 May 2016, 12:50

Re: Class Property Instance Variable

16 Feb 2017, 23:37

Thanks all for your input, but I've spent too much time on this already:

1) I'm not interested in any code one has to write to trick/make AHK classes work as though it had private and/or protected variable capabilities. I'll do what I do now, use another language that implements classes the way I need them for those projects I need such an implementation for.

2) We are now beating a dead horse, as the phrase goes, one can always play the devil's advocate for anything they wish to disagree with, whether they really disagree or not. Some people do such because they haven't anything better to do, some because they enjoy wasting other people's time, and some because they enjoy provoking and inciting others.

3) This is in the Wish List, which the wish is: that AHK would implement classes with private, protected, and public attributes for variables, properties, and methods, particularly in the manner previously stated. No work a rounds, as I can just use a language where no work a rounds are needed. This is a wish, not a debate. Most mature languages used for professional programs implement classes they way I wish. Doing so in AHK would make AHK a serious competitor with other languages in the arena where such implementation is sought.

I'll be making no more responses on this thread, as someone will always play the devil's advocate. My previous comments are sufficient enough to expresses all that needs to be expressed as far as what I wish is concerned. Again, thanks for your input, and happy programming to all.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Class Property Instance Variable

17 Feb 2017, 04:02

guest3456 wrote: This is similar to one of the links by Coco that I shared to the OP which he didn't like for some reason:

https://autohotkey.com/boards/viewtopic.php?t=7072
Thanks, I'll have a look.
nnnik wrote: There are 2 parts to that:
1. Your programming style is not OOP.
2. The code you created works by overwriting the base value and therefore breaks inheritance.
Thanks for your answer.
nnnik wrote: Also the code you have right now is much better however is still annoying to write.
It has problems for sure. The most annoying thing to write would be the protected class I think, since you can't use statics and the classname itself, the interface is basically just copy-paste, and change the name of the method, and the function doesn't need to much work either I think. Well, it's writtern mostly for the fun of trying to solve a problem. I look forward to see what you have in mind. :geek:
RFM wrote: I'll do what I do now, use another language that implements classes the way I need them for those projects I need such an implementation for.
:thumbup:
RFM wrote: 3) This is in the Wish List,
I share your wish as an optional feature. I think what we currently have is very convenient, and quick to work with, and that fits better with what AHK is mostly used for (that's a vague statment).

If you think someone is wasing your time here, you are mistaken, you waste your own time.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Class Property Instance Variable

19 Feb 2017, 13:32

if users are going to mis-use the class and go against the documentation, then having a protected keyword won't stop them.

they'll just remove the keyword. so you still don't get any confidence that your class is encapsulated

qafeh
Posts: 2
Joined: 01 Nov 2022, 20:42

Re: Class Property Instance Variable

01 Nov 2022, 20:48

there're lots of idiots who have never done high level coding to have commented on this post thinking they're smart
had to make an account to post this comment
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Class Property Instance Variable

01 Nov 2022, 21:02

qafeh wrote: there're lots of idiots who have never done high level coding to have commented on this post thinking they're smart
had to make an account to post this comment
Thanks for going out of your way to share such wisdom with us. Can’t wait to see what other gems you have in store.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 48 guests