AutoHotkey Community

It is currently May 26th, 2012, 4:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 259 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18  Next
Author Message
 Post subject:
PostPosted: March 23rd, 2009, 7:43 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
bmcclure wrote:
That's awesome! My only wish is that the website was posted before I started using the library

Yeah, I wish the website was posted before I started using the library too :D.

bmcclure wrote:
If the 15+ pages of this thread were scaring away beginners, one page, http://www.autohotkey.net/~animeaime/Cl ... Basics.htm should be almost all they need to get started

Exactly. That is the page I've been spending the most effort on.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 8:40 pm 
Currently:
Quote:
Class library (OOP) - Wish list / Bug reports
OOP (Object Oriented Programming) V2 - Help thread
Sync'ed Thread Subjects (easier to identify)
Quote:
Class Library (OOP) - Wish List & Bug Reports
Class Library (OOP) - Help Thread

OR

AHK Class Library (OOP) - Wish List & Bug Reports
AHK Class Library (OOP) - Help Thread
You might think to move your 'Help'-thread to "Ask for Help" (which might take even more attention to it!)

Make your mind. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 8:49 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
BoBo³ wrote:
Sync'ed Thread Subjects (easier to identify)

Good point, thanks.

BoBo³ wrote:
You might think to move your 'Help'-thread to "Ask for Help" (which might take even more attention to it!)

I thought better to have it Scripts and Functions because it is a help thread about a script. However, I can see the benefit to having it in ask for help.

How would I go about moving it?

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 9:24 pm 
2 options.
1) PM a moderator (recommended)
2) (ab)use the username WrongSectionAlert to get the attention of a Mod, and advise/request to move the thread on your behalf.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 9:25 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Ok. Who's a moderator?

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 10:43 pm 
Quote:
Our users have posted a total of 245725 articles
We have 12097 registered users

The newest registered user is mccoystl

In total there are 72 users online :: 7 Registered, 0 Hidden and 65 Guests [ Administrator ] [ Moderator ]

Registered Users: AutoWolfCub, Drugwash, ecksphore, jaco0646, jayp, JimKarvo, soccer18soccer18
That greenish ones ! :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2009, 10:45 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
K, thanks.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 6:57 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Just wanted to give an update (conerning the Dictionary class). Upon reading this thread, Scripting.Dictionary Object as Associative Array, I'm going to replace dictionaries internals with the functionality from this thread. I'm going to wrap it into a class object (so it can be used as a data value). Also, this means that any code using the Dictionary Class will work as it does now - only the insides change. Isn't encapsulation great! :D

If this is what I think it is, we can have our cake and eat it too. I was wondering how I was going to add associative arrays effectively (due to hashing and what not). I'm going to check this out (after I finish some mods to the Browser Class.

Also, hopefully everyone here is watching both this thread and the Class library (OOP) - Help Thread. I am no longer going to post updates to this thread - they will go on the Help thread. This thread is now dedicated to requests and bug reports. For example, if you're not watching the help thread, you missed the latest addition - AccessClassLibrary - Surf the Class library site with ease.

I post this update in response to the request for a "dictionary" class.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 11:09 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
OK. Interface is almost completed. I worked out the details to allow the most flexibility. I'm now rounding out the corners and wonder should ErrorLevel be set if an error exists.

Edit: I think I can use this same design to allow extending classes. So PLEASE, give feedback. This won't be something easy to change later.


Error1: The passed ClassObject doesn't implement the interface. I'm thinking that ErrorLevel should be set to "Class -> Doesn't implement interface".

Error2: The ClassObject implements the interface, but the dynamic function call fails (for any reason). See Functions -> Dynamically Calling a Function for details. In this case, set ErrorLevel to "Interface -> Dynamic call failed"


Without requiring v1.0.48 of AHK, to detect the second error, this is the only way to do it - that I know of.

Code:
;this is the general form for an interface function
AnInterface_functionName1(AnInterfaceObject, args...)
{
    ;if the object doesn't implement the interface,
    ;   the function returns the empty string,
    ;   and sets ErrorLevel to "Class -> Doesn't implement interface"
    if !ClassName := Class_implementsInterface(AnInterfaceObject, "AnInterface")
    {
        ErrorLevel := "Class -> Doesn't implement interface"
        return
    }
       
    if returnValue := "?" . %ClassName%_functionName1(AnInterfaceObject, args...)
    {
        ErrorLevel := 0
        return subStr(returnValue, 2)
    }   

    ;the dynamic call failed
    ErrorLevel := "Interface -> Dynamic call failed"
}


This works because if the dynamic function isn't successful (e.g. doesn't exist), then returnValue would be set to the empty string (there wouldn't even be the leading "?"). Otherwise, the actual return would be everything excluding the trailing question mark, so return the part of the string after the leading "?". This works even if the return is the empty string

ex
Code:
MsgBox, % func("")

func(Value1)
{
    CallFunc := "func2"
   
    ;this call will be successful
;     returnValue := "?" %CallFunc%(Value1)
   
    ;this one will not be
    returnValue := "?" %CallFunc%()
   
    if (!returnValue)
    {
        MsgBox, % "Dynamic call failed"
        return
    }

    MsgBox, % "Dynamic call successful"
    return subStr(returnValue, 2)
}

func2(Value1)
{
    return Value1
}

return


This however means that each call would have something extra appended, and then have to remove it.


The other option is to require v1.0.48 and check the parameter count.
ex
Code:
MsgBox, % func("")

func(Value1)
{
    CallFunc := "func2"
   
    if !paramCount := isFunc(CallFunc)
    {
        Msgbox, % "Function does not exist"
    }

    paramCount--
   
    MsgBox, % "This function requires " . paramCount . " parameters."
   
    ;this call will be successful
    returnValue := "?" %CallFunc%(Value1)
   
    ;this one will not be
;     returnValue := "?" %CallFunc%()
   
    if (!returnValue)
    {
        MsgBox, % "Dynamic call failed"
        return
    }

    MsgBox, % "Dynamic call successful"
    return subStr(returnValue, 2)
}

func2(Value1, Value2 = "")
{
    return Value1
}



The template would be setup so that you would specify the parameters passed and it would compare to the mandatory parameters (required by the dynamic function). This would be flexible to allow the case that the implementing class has additional madatory parameters that the interface didn't have.

In this case, ErrorLevel would be set to "Interface -> Didn't implement function" if the function doesn't exist. And set to "Interface -> Too few parameters passed" if too few parameters were passed. Since v1.0.48 would be required, passing too many parameters won't cause the call to fail.


In either case, ErrorLevel would be set to 0 upon success.


I'm looking for feedback on the how it should be implemented. Which error messages to use (if any), should a different message be used, should I use the first or second method? I'll create the interface template with these suggestions. So, if you want your opinion heard, please weigh in.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 11:18 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I feel that since OOP is a new concept in AHK anyway, you may as well utilize the latest features and require the latest version, at least in this early stage of development. I'd say go with the second method requiring the new version. Otherwise to support the newer method a change would have to be made later in the library's life, which might not be as easy.

I like the idea of returning the errorlevel as you've specified (at least until there are standardized Error/Exception interfaces that can be used to pass in a more OO-fashion :) )

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 11:37 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
OK, will do, unless someone gives a counter-idea before I post the update. The first release won't have the ability to extend classes. The idea just hit me, so I'll need some time to work out the details.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 9:09 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Sorry for the lack of updates, but I realized that my previous design (for interfaces / extending classes) was poorly done - not adaptive and very cumbersome. I've been spending this time trying to work out the details. The new design is adaptive to allow the same setup to be used for:

  1. Interfaces
  2. Extending classes
  3. "Virtual functions"


Right now, I'm looking for feedback on a crutial question - should multiple inheritence be possible? I'm a java programmer, so I'm used to the idea that a class can only extend one other class - but you can implement as many interfaces as you wish (most java classes DO implement multiple interfaces). However, there may be benefits to allowing extending multiple classes - I need feedback on this. If there is single inheritence, I can "optimize" certain necesary functionality. If multiple inheritence is desired, this is possible (I'm pretty sure, at least).

Please share your feedback.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 9:21 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I think for ease of use maybe multiple classes should be able to be inherited as well as interfaces. Although, I may not be entirely clear on the difference... If single inheritance is used, would there be a performance benefit? I'm sure most of my supporting classes will become interfaces when they are supported.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 10:48 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Single inheritence means a class can only extend one other class. Ex. Circle extends Shape. Multiple inheritence means that a class could extend multiple classes. The wiki article for multiple inheritance gives an example of a StudentMusician class which inherits "from a class named Person, a class named Musician, and a class named Worker". The wiki also mentions a major "obstacle" to multiple inheritance - the Diamond problem. Truthfully, I'd rather not have to learn how to implement multiple inheritance, if it can be advoided (honestly, it might be beyond my abilities). I brought up the question, so if there was a demand, I would give it a shot, but to implement it "just because" is too much work. Additionally, multiple inheritance is inheritently less efficient.

Actually, I revoke my question - I do that a lot, huh... :D. If the need arises, I'm sure I can modify the code and still provide backward compatability. I mean, structurely, they are the same. The difficulty is how to "merge" the classes (in the case of the diamond problem), how to "partition the classes" (to allow the getters / setters to work as expected - without modification to the getters and setters - instead, do the work in the Class_getValue function). So, it sounds like multiple inheritance would be "nice", but isn't needed. So, for simplicity, I'll do single inheritance, and I'll figure something out, if / when multiple inheritance is needed.


One of the major worries I have, is making sure the getters and setters work correctly for inheritance.

Ex. if Shape had a color value (in index "b1"), and Circle extended Shape, then Shape_getColor(myCircle) should function correctly (returning the color). Also, suppose that Circle put the radius value in its "b1" space, the Class_getValue function (after modification) needs to function, as expected, in the following cases.

Code:
;returns the Color of myShape
Shape_getColor(myShape)

;returns the Color of myCircle
;Circle_getColor would be an "alias" for Shape_getColor - see declaration below
Circle_getColor(myCircle)

;returns the Color of myCircle
Shape_getColor(myCircle)

;returns the radius for the Circle object
Circle_getRadius(myCircle)


/*
    Class functions
*/
Shape_getColor(ShapeObject)
{
    return Class_getString(ShapeObject, "b1")
}

;"alias" for Shape_getColor
Circle_getColor(CircleObject)
{
    return Shape_getColor(CircleObject)
}

Circle_getRadius(CircleObject)
{
    ;type is "uint"
    return Class_getValue(CircleObject, "b1")
}



This would allow a Class to extend another Class without worrying about changes in the base class. Class_getValue would sort the details concerning which index to use, and it would adjust by using the built-in and user-defined size of the base class and "partition" the object - via a wrapped call to the Class_getBuiltInSize and Class_getUserDefinedSize (to determine the size of the base class object).

In the "new" function, the allocation would include both the built-in size and user-defined size of the Class designed class and its base class (if any). The base class values would be initialized via the getters and setters (or via Class_setValue, directly).


Class functions in the base class could be implemented in one of two ways - "virtual" and "non-virtual". See the wiki page for virtual function for in-depth details.

Non-virtual would mean that BaseClass_myFunction(InheritedClassObject, args...) and BaseClass_myFunction(BaseClassObject, args...) would both evaluate BaseClass_myFunction. The function calls would function correctly, since the values (the getters and setters) would be as expected (see above example).

Virtual functions would mean that BaseClass_myFunction(InheritedClassObject, args...) would actually call (if it exists) InheritedClass_myFunction(InheritedClassObject, args...). The setup for virtual functions would be similar to an interface function (with some slight modifications). I will provide a template function that can be easily modified for all your Virtual function needs.


Functions would default to non-virtual (opt-in virtual), because it would require a little "extra" in the code to provide this functionality. It won't be long or complicated (it will call a Class library function which will handle the details), but it is required. Thus, virtual will be opt-in (like C++), not the default - like java.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 4:33 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Yeah, I'm fine without multiple inheritance.

My main question about the difference is related to Class vs Interface. For instance, right now I have things like an Error class and a Log class which I am using in most of my classes in some way or another.

I'd ultimately like to use inheritance with them, but I think things like that would work fine as interfaces, right?

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 259 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group