v1.1.16 alpha - Properties

Community news and information about new or upcoming versions of AutoHotkey
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: v1.1.16 alpha - Properties

08 Aug 2014, 03:40

But how? Maybe I have a mental block.

Code: Select all

#NoEnv
Msgbox, 0, IsObject(Prop), % IsObject(Prop := Dummy.Property) ; shows 1
MsgBox, 0, Prop.Get(), % Prop.Get() ; shows ""
MsgBox, 0, Prop.Get, % Prop.Get ; shows ""
MsgBox, 0, Prop, % Prop ; shows ""
For Key In Prop
   MsgBox, 0, Key %A_Index%, %Key% ; no MsgBox
ExitApp
Class Dummy {
   Property {
      Get {
         Return "Hello!"
      }
      Set {
         Return "Hello!"
      }
   }
}
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: v1.1.16 alpha - Properties

08 Aug 2014, 03:52

Got it! You need to pass the "hidden" parameter.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: v1.1.16 alpha - Properties

01 Sep 2014, 05:27

Currently, static properties aren't really possible since the property has to be defined in a base -- or to put it another way, x.Property has different meaning depending on whether x is the exact class which defines Property, or a subclass or instance. Although this is consistent with meta-functions, it's inconsistent with methods and falls short of the goal, which was to provide a "more foolproof" alternative to meta-functions (for the most common cases).

Instead, I'm considering changing it so that properties are also invoked when the class which defines the property is accessed. The cost would be:
  • A small amount of flexibility. Invoking a property from a specific class on some other object (formerly Class.Prop.get(obj)) would involve retrieving the property using a more roundabout method, such as a for-loop or hypothetical ObjRawGet function. However, rather than designing a property to be used that way, one could put the needed code in a separate method. It's also true that flexibility isn't the real purpose here; meta-functions already provide that.
    .
  • A marginal performance hit. If retrieving an object from within another object takes 0.00014ms, it might take 0.00001ms longer due to a dynamic type check (is this object a Property?). However, I think the added user-friendliness is worth the price.
Anyone have thoughts on the matter?
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: v1.1.16 alpha - Properties

01 Sep 2014, 07:23

I'd appreciate the change.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: v1.1.16 alpha - Properties

02 Sep 2014, 08:39

Something like??:

Code: Select all

class Test
{
	;// can be accessed by both class object and instance
	static ClassProperty {
		get {
			;// code here
		}

		set {
			;// code here
		}
	}
	;// instance of class only
	InstanceProperty {
		get {
			;// code here
		}

		set {
			;// code here
		}
	}
}
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: v1.1.16 alpha - Properties

02 Sep 2014, 10:20

My simple custom property lib
Not interrelated too much. Extemporaneous, maybe enlighten on Property.
Also, easy to expand I think.

I still think the new syntax is an integrate, but don't know the background module, which seems unknown and mysterious.
Last edited by RobertL on 02 Sep 2014, 18:51, edited 1 time in total.
我为人人,人人为己?
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: v1.1.16 alpha - Properties

02 Sep 2014, 16:27

Coco wrote:Something like??:
No, the same as methods: just define one property, and it can serve both purposes.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: v1.1.16 alpha - Properties

09 Sep 2014, 16:59

v1.1.16.01 is now available.

Changes since v1.1.16.00-a01:
  • Changed Object to invoke Property even if defined directly. Found a way to negate the performance hit (and possibly even improve performance in some cases).
  • Fixed half-defined properties messing with __Set parameter order.
  • A long list of unrelated fixes.

Return to “Announcements”

Who is online

Users browsing this forum: No registered users and 4 guests