[INCORRECT] action with class object instance

Discuss the future of the AutoHotkey language
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[INCORRECT] action with class object instance

28 Jun 2016, 13:02

In my opinion there two main problems with class definitions
1. No protected variables - so programmer can`t encapsulate important values. (May be in the future)
2. User can erase class method using instance variable

Code: Select all

#SingleInstance Force

class Test {
	__new(data) {
		this.data:= data
	}
	v1() {
		return this.data
	}
	v2() {
		try {
			return this.v1()
		} catch e {
			return e.message
}	}	}

var:=new Test(100)
msgBOX(var.v1())
var.v1():=""			; <<<< erase v1() method finally
try {
	msgBOX(var.v1())	; call to nonexistent function 
} catch e {
	msgBOX(e.message)
}
msgBOX(var.v2())		; call to nonexistent function
Missing protected variables and possibilities for erasing methods are incorrect due to changed generally class definition at the running stage.

And one more example showing changing variable scope in runtime stage:

Code: Select all

#SingleInstance Force

class Timed {
	__new() {
		this.cn:= 0
	}
	timed(tm:=0) {
		; 1.
		if tm, setTimer LABEL, %tm%
		else   setTimer LABEL, Off
		
		; 2.
		LABEL:
			tooltip((++this.cn)) ; timer: No object to invoke
			; when timer call this code variable scope changed (this not visible)
		return
	}
}
t:= new Timed()
t.timed(1000) ; method void message 1 and after 1000 ms throw exception No object to invoke 
; in normal flow (1. 2.) this is visible
; in timer flow (only 2.) this not visible
Q::ExitApp ; persistent
Normal call work perfect - class variables visible.
When timer call the same code - class variables not visible (this not visible).
AHKv2.0 alpha forever.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [INCORRECT] action with class object instance

29 Jun 2016, 08:25

_3D_ wrote:In my opinion there two main problems with class definitions
1. No protected variables - so programmer can`t encapsulate important values. (May be in the future)
I never understood why one would need that.
_3D_ wrote:2. User can erase class method using instance variable
That is probably the biggest advantage of AutoHotkeys Classes.
Recommends AHK Studio
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [INCORRECT] action with class object instance

30 Jun 2016, 00:37

nnnik wrote:
_3D_ wrote:In my opinion there two main problems with class definitions
1. No protected variables - so programmer can`t encapsulate important values. (May be in the future)
I never understood why one would need that.
Protecting data secure of data EXISTING - I don`t know is that important but persist in ANY OOP language.
nnnik wrote:
_3D_ wrote:2. User can erase class method using instance variable
That is probably the biggest advantage of AutoHotkeys Classes.
Losing functionality in most cases treated like exception and/or run time error - so advantage is far more word.

As I said this actions changed GENERALLY meaning of class definition - so why you need class at all if someone can change internal functionality and dependencies?
In most cases class ENCAPSULATE AND PROTECT data (class variables) and treatment of data (class methods) in ONE CONSISTENT object that we call CLASS INSTANCE VARIABLE OBJECT or just OBJECT.
AHKv2.0 alpha forever.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [INCORRECT] action with class object instance

30 Jun 2016, 03:17

I barely understood any of the sentences you wrote here. That is not any form of english I am aware of.
Also since you mentioned OOP. AutoHotkey is not an OOP language - although you can write OOP code.
Recommends AHK Studio
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [INCORRECT] action with class object instance

30 Jun 2016, 03:25

He seems to talk about something like PROTECTED / PRIVATE / PUBLIC methods and properties.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [INCORRECT] action with class object instance

30 Jun 2016, 03:40

Yeah I got that much but
Losing functionality in most cases treated like exception and/or run time error - so advantage is far more word.
WTH does that even mean????
Recommends AHK Studio
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [INCORRECT] action with class object instance

30 Jun 2016, 06:10

nnnik wrote:Yeah I got that much but
Losing functionality in most cases treated like exception and/or run time error - so advantage is far more word.
WTH does that even mean????
nnnik this forum is not ENGLISH learning forum - so just keep an eye at the first example of first post and write to me in ANY language where is the advantage. This post is not to teach me how to speak correct English but to evolving AHK.
AHKv2.0 alpha forever.
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: [INCORRECT] action with class object instance

30 Jun 2016, 06:16

_3D_ wrote:Missing protected variables and possibilities for erasing methods are incorrect due to changed generally class definition at the running stage.
_3D_ wrote: As I said this actions changed GENERALLY meaning of class definition - so why you need class at all if someone can change internal functionality and dependencies?
In most cases class ENCAPSULATE AND PROTECT data (class variables) and treatment of data (class methods) in ONE CONSISTENT object that we call CLASS INSTANCE VARIABLE OBJECT or just OBJECT.
that's because AHK objects are not "classes" in the normal usage of the word. AHK is a Prototype-based OOP language, not a Class-based language.

https://en.wikipedia.org/wiki/Prototype ... rogramming
https://en.wikipedia.org/wiki/Class-based_programming

as i remember, the keyword "class" was chosen out of convenience and familiarity, but it is the wrong word to describe AHK objects. if you are trying to use AHK "classes" as if they were java/c++ classes, then you're doing it wrong

_3D_ wrote:
nnnik wrote:
_3D_ wrote:2. User can erase class method using instance variable
That is probably the biggest advantage of AutoHotkeys Classes.
Losing functionality in most cases treated like exception and/or run time error - so advantage is far more word.
its an 'advantage' of prototype-based programming:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model wrote: Adding and removing properties

In class-based languages, you typically create a class at compile time and then you instantiate instances of the class either at compile time or at run time. You cannot change the number or the type of properties of a class after you define the class. In JavaScript, however, at run time you can add or remove properties of any object.
Last edited by guest3456 on 30 Jun 2016, 06:49, edited 6 times in total.

_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [INCORRECT] action with class object instance

30 Jun 2016, 06:46

Thanks guest3456 now I understand the code (don`t understand the meaning but will read more).
AHKv2.0 alpha forever.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [INCORRECT] action with class object instance

30 Jun 2016, 11:38

_3D_ wrote:
nnnik wrote:Yeah I got that much but
Losing functionality in most cases treated like exception and/or run time error - so advantage is far more word.
WTH does that even mean????
nnnik this forum is not ENGLISH learning forum - so just keep an eye at the first example of first post and write to me in ANY language where is the advantage. This post is not to teach me how to speak correct English but to evolving AHK.
In this forum we discuss AutoHotkey v2. If you can't even defend an argument, let alone speak the language used to discuss, then there is no way your arguments will ever be considered.
Recommends AHK Studio

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: Marium0505 and 23 guests