AutoHotkey Community

It is currently May 26th, 2012, 5:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 93 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 7  Next
Author Message
 Post subject:
PostPosted: April 26th, 2009, 2:25 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
I've been hearing murmurs to the effect that no one has a clue how to use the Class library. To be honest, I have no idea where to start explaining it. The info on the site reflects the question I would have. If your question is unanswered there, PLEASE bring it up here (or PM me). I mean, I can't make promises on how fast I'll update the site, but I'll post here quickly. I have a weird "phobia" with writing docs - they take FOREVER to write.

I'm a programmer, so the questions I would ask may be different than the ones you have. Since my background and yours are different, please share your questions. I love keeping busy - mainly writing code. I only break from code to write docs when I feel I have something worthy - and even then it's difficult not to code - it's an addiction :P.

In other words, I rely greatly on feedback to bring "focus" to my work. I have way to many projects that I'm working on, so I prioritize based on feedback. When writing long docs, I get bored - so they take a while for me to write. However, if you ask me questions, I can easily build an FAQ by combining posts into a meaningful format.

Thus, instead of banging your head against the wall, please post any questions here. This project is my pride and joy as an OOP programmer. I personally can no longer program in non-OOP form because of my love for OOP. Now, I don't expect you all to be OOP manics like me, but this mania of mine means that I want this project to keep growing - your input dictates where it goes. I leave it up to you.

_________________
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 26th, 2009, 8:12 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
animeaime wrote:
I've been hearing murmurs to the effect that no one has a clue how to use the Class library. To be honest, I have no idea where to start explaining it. The info on the site reflects the question I would have.

I know that I (and probably a reasonable number of AHK users) don't have a lot of OOP programming experience/knowledge, so we would probably have different questions - I'm not even sure I know the right questions to ask.

Maybe it would be useful to create a small tutorial illustrating basic OOP concepts in AHK. Or perhaps adapt an existing tutorial (there are quite a few out there, according to a quick google search).

I personally would like to learn more about OOP, so I wouldn't mind helping. I think that it could go a long way to helping people understand what it's about and how to use it.

If anybody knows of a good beginner's OOP tutorial with code samples, I could take a crack at translating it to AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 10:31 am 
I fully agree on what you're saying about the way (semi)-noobs are feeling about DllCall(), RegEx...(), Ternary Operators, VarSetCapacity, Bitshift&COM-Voodoo.

Let's call it the 'Puffer-Fish-Syndrom'. Someone is telling you about (SEAN, [VxE], <your name here>, ...] that super-dupper-tasty kinda thing, while offering you the full equipment to prepare one on your own. Unfortunately without a (semi)fool-prove advisory. You're simply feeling lost. Of course you won't die if you're not able to handle OOP - but it feels like starving in front of a tasty Pizza, or <your favourite food here>. :cry:

Btw, sinkfaze's RegEx-Tut (the one I kept in mind, beside others) gives a nice example how to set up something a noob should be able to deal with.
8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:07 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
OK, so if I'm hearing this right, there are more questions about OOP, than the Class library, per se. Did I understand correctly? If so, as mentioned, there are tons of "intros to OOP" on the web. I will find some and add them to the website.

Thanks for the input - it's those kind of things I easily overlook. I didn't even think that the questions on the Class library would be more questions on OOP, in general.


I'm going to add a section that shows how to "convert" from traditional OOP to AHK OOP. This way, yal can research OOP to your hearts content (I'll provide some links), and then the website will show how to convert from standard OOP to AHK OOP - since there are some subtle syntax related differences.

There would be examples of constructors, destructors, interfaces (which are done, just need to whip up an example of its use), etc. For each OOP concept, there would be the "AHK version" of the same code - similar to what I've seen on wiki when it shows the same code in several programming languages.

_________________
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 27th, 2009, 4:41 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
I just thought of this while writing the intro to OOP tutorial, would it be useful to have a script that would convert from traditional OOP to AHK OOP? This would allow programming in a mix of traditional OOP and AHK OOP, and then convert the code to AHK OOP.

You would run the converter, specify the AHK to convert, and it would convert each traditional OOP statement to the equivalent AHK OOP statement.

There would be a gui which would prompt for each replacement. It would show the line(s) as seen in the code, and below it would show the replacement. Before replacing it, you could modify it as needed. Or, you could skip it, if it shouldn't be converted.


For example,

Code:
MyClass_functionName(aMyClassObject, myBook, book2)
{
    this.myValue = 5
    ;MyClass_setMyValue(aMyClassObject, 5)

    MsgBox, % this.aMethodName(1, 2)
    ;MsgBox, % MyClass_aMethodName(aMyClassObject, 1, 2)

    BookTitle := myBook.getTitle()
    ;would prompt for the class of <title>. ex. Book
    ;BookTitle :=  Book_getTitle(myBook)

    if BookTitle.compareTo(book2.getTitle()) = 0
        MsgBox, % BookTitle

    ;for this, the converted would first ask what the Class is for book2 (ex. Book)

/*
then, compareTo would ask for the Class of BookTitle.

for compareTo and equals, it will first treat them like a function.

There would be a way to state that it's not a function call, but a simple compare.  compareTo <= 0 is the same as "<=", compareTo = 0 is the  same as "=", etc. For this example, this option was selected.
*/

;given the above selections, the output for the if statement (you could modify it before replacing it)
if BookTitle = Book_getTitle(book2)
    MsgBox, % BookTitle


Since AHK doesn't support the ".", it shouldn't conflict. Also, to prevent interference, the "this" would have to be specified, even if it were implicit. Otherwise, each variable and function call would have to prompt a user response, since it MIGHT be a class value. Specifing the class object each time avoids this problem.

Additionally, for static functions, you would use the class name with the ".". Ex. MyClass.someFunction(). It would check the library folders for a Class of that name. Or, if the Class name is the current class, it would work too. There would still be user feedback, since there might be a variable name that has the same name as a Class. Therefore, if it were a variable name, you could easily tell the converter.


Any traditional OOP syntax will cause a syntax error. In this case, the
converter would have to be run before running the AHK code. The converter would have the ability to convert the current line in a text editor - I should be able to figure out how to do this. This would allow writing in traditional OOP and converting to AHK OOP after each line.


Now, this is just an idea, if it's a crazy idea, please tell me. I will still work on it, because I want to code experience, but it won't be a priority.

_________________
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 27th, 2009, 6:24 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
Very interesting. I like it and think it could be very useful.

In fact, how about the following (now it's my turn to throw an idea out there :) ):

Instead of programming in what you call a "mix" of OOP and AHK OOP, you could write some basic class specs in a markup language (ini, json, xml).

Take your Rectangle class for example:

Code:
[Class]
Name=Rectangle
Wrapper=1
Cloneable=1
BuiltInValueCount=2
BuiltInMethodCount=1
UserDefinedValueCount=0
UserDefinedMethodCount=0

[BuiltInValue1]
Name=Width
Type=UShort

[BuiltInValue2]
Name=Height
Type=UShort

[BuiltInMethod1]
Name=Area


Where UserDefinedMethods could include parameters, etc. (JSON or XML might be a bit better for this purpose, given their hierarchical natures).

And then you "Class"ify the the ini, which can create a skeleton of the class for you, and stub out with "TODO:" comments anything it can't flesh out.

What do you think?

Also, a quick question: is there an easy way to do inheritance with your Class library?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 7:11 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
Another question - if I use a class in a script, must I destroy the object before the script exits, or will that memory automatically be cleared up?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 7:40 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
rulfzid wrote:
Instead of programming in what you call a "mix" of OOP and AHK OOP, you could write some basic class specs in a markup language (ini, json, xml).

I like, I like. That would DEFINITELY make creating a class much easier. This would be a great improvement over the current design.

Just to clarify, user-defined values are not part of the class' ahk file. Rather, they are extensions to a class as specified by the user. These values / functions can differ between projects, and provide a way to associate extra values with a class object. However, I could probably add support for user-defined values / functions. It would be in a separate file from the built-in values / functions. I would also work out a "standard" structure for user-defined values, because right now specfying user-defined values isn't as structured as I would like.

Also, your idea could be extended to allow specifing constants - via the constants method. I'll figure something out that's "neat". Read-only constants would be created by specifing "ReadOnly" after the variable (see example below). To allow specifying multi-line text values, the format will mimic the Class_setConstant function which will be released with the new updates. By specifing "Code" after the variable name, the specified text will be copied as code. This allows initializing a value based on some code. The value will only be initialized once - which I forgot to do in the Browser Class...oops - I'm going to fix this, thanks.

I'll also add a "static" option to specify a function as static. If not specified, the function is presumed to be non-static (which most will be).

For parameters, I don't think xml is required (see below example). Param1, in all cases, is the first paramater. For non-static, you don't specify the ClassObject - it is added automatically. Param1 would be the first parameter after the Class object on which to act.

Code:
[Class]
Name=Rectangle
Wrapper=1
Cloneable=1
BuiltInValueCount=2
BuiltInMethodCount=1
UserDefinedValueCount=0
UserDefinedMethodCount=0
;specify to have the constants function included, but left empty
;if any constants are defined below, this setting is ignored
;omitting this setting (with no constants defined below) would have the constants function omitted from the resulting source.
;Constants = 0(/false/no)

;optional section - if omitted the constant function will be omitted.
[Constants]
`value1 = 5.0
;a read only constant
`value2 ReadOnly = 7
;a constant copied as code (ReadOnly)
;will use ":=", not an "="
`FireFox ReadOnly Code = Browser_new("Firefox", "(?:<<<URL>>> - )?Mozilla Firefox", "^l")

[BuiltInValue1]
Name=Width
Type=UShort

[BuiltInValue2]
Name=Height
Type=UShort

[BuiltInMethod1]
Name=Area
;static = true/false
;Param1 = arg1
;Param2 = arg2
Source=Rectangle_source.ahk


On a side note, would it make sense to to allow specifing the source code's source? For example, you would have the ini, and specify an ahk file that contains the functions source. Then, the converter would "merge" the ini with the source. This would be, for example, mimicing C++ .h file. The ".h" would be the specified source code file. You could store all the functions in one big ahk "source" file (e.g. MyClass_source.ahk), or split the source in how ever many files you want - even one for each. Since the files are AHK files, you can use the syntax highlighting from your text editor (if applicable).


Additionally, the "tradional OOP -> AHK OOP" converter could be applied to the different functions (via the specified source file) on merge (this could be disabled). For me, at least, I miss the OOP syntax, and this would allow writing the source in the format that suits the writter (whether tradional OOP, AHK OOP, or a mix).

Then, on merge, it is all grouped together in the resulting MyClass.ahk file. If you keep the source in a separate file(s) (ex. MyClass_source.ahk), then the original source remains in whatever form you specify. To avoid having to tell the converter each time how you want it converted, after converting something once, it would store the converted version (in a comment) above the actual version (as seen in the ahk file). It would only be a "linking message" - recognized by the converter - ex. ";OOP Converter 1". This way, it doesn't become a distraction if the result is long or complicated. Addionally, using this method means that even as the code gets modified, the link remains. Deleting the link will void the "cached" conversion.

The "cache" file would be the mirror of the original source, but converted. It would contain the same "linking message" as the original. This will point the original to it's cached conversion (if it exists). If the filename were SomeCode.ahk, the cache file would be SomeCode_cache.ahk. It's just the start of an idea, so the final result will probably differ, at least in part, from what I just said.

rulfzid wrote:
Also, a quick question: is there an easy way to do inheritance with your Class library?

This is in the works. I have interfaces done (haven't uploaded it yet - been distracted). Interfaces are "skeletons" of a Class - as seen in Java.
Still writing examples and working on the docs for it. Was waiting til I got that done. I'll work on that and post it soon.

True inheritence will be built from this same idea. There may be some limits to inheritence, due to AHK not being an OOP language, but they shouldn't be of much concern. I think I can support multiple inheritence, but no promises.

Thanks for this awesome feedback - I'll start on 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: April 27th, 2009, 7:41 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
rulfzid wrote:
Another question - if I use a class in a script, must I destroy the object before the script exits, or will that memory automatically be cleared up?

When a script closes, windows automatically frees any memory. So, no you don't have to worry about destroying them. However, if you no longer need an object, you can destroy it and it will free the used memory.

_________________
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 27th, 2009, 9:01 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
animeaime wrote:
Just to clarify, user-defined values are not part of the class' ahk file. Rather, they are extensions to a class as specified by the user. These values / functions can differ between projects, and provide a way to associate extra values with a class object. However, I could probably add support for user-defined values / functions. It would be in a separate file from the built-in values / functions. I would also work out a "standard" structure for user-defined values, because right now specfying user-defined values isn't as structured as I would like.


Gotcha, thanks for clearing that up.

animeaime wrote:
For parameters, I don't think xml is required (see below example). Param1, in all cases, is the first paramater. For non-static, you don't specify the ClassObject - it is added automatically. Param1 would be the first parameter after the Class object on which to act.


You're right - I was just thinking about it in terms of reading from the ini using the native AHK functions: as long as there is a ParamCount set, it would be pretty easy to handle.

animeaime wrote:
On a side note, would it make sense to to allow specifing the source code's source? For example, you would have the ini, and specify an ahk file that contains the functions source. Then, the converter would "merge" the ini with the source. This would be, for example, mimicing C++ .h file. The ".h" would be the specified source code file. You could store all the functions in one big ahk "source" file (e.g. MyClass_source.ahk), or split the source in how ever many files you want - even one for each. Since the files are AHK files, you can use the syntax highlighting from your text editor (if applicable).


Additionally, the "tradional OOP -> AHK OOP" converter could be applied to the different functions (via the specified source file) on merge (this could be disabled). For me, at least, I miss the OOP syntax, and this would allow writing the source in the format that suits the writter (whether tradional OOP, AHK OOP, or a mix).

Then, on merge, it is all grouped together in the resulting MyClass.ahk file. If you keep the source in a separate file(s) (ex. MyClass_source.ahk), then the original source remains in whatever form you specify. To avoid having to tell the converter each time how you want it converted, after converting something once, it would store the converted version (in a comment) above the actual version (as seen in the ahk file). It would only be a "linking message" - recognized by the converter - ex. ";OOP Converter 1". This way, it doesn't become a distraction if the result is long or complicated. Addionally, using this method means that even as the code gets modified, the link remains. Deleting the link will void the "cached" conversion.

The "cache" file would be the mirror of the original source, but converted. It would contain the same "linking message" as the original. This will point the original to it's cached conversion (if it exists). If the filename were SomeCode.ahk, the cache file would be SomeCode_cache.ahk. It's just the start of an idea, so the final result will probably differ, at least in part, from what I just said.


This sounds interesting, especially if using more "standard" class syntax is desirable - make the edits the way you feel comfortable and then just convert.

I'd definitely like to see how it turns out - that last set of things sounds incredibly complex right now, but could very well turn out to be something incredibly useful once implemented.

You're doing some very cool stuff with AHK OOP - I've got a couple of projects that I'm working on with it, and am excited by its potential. Keep up the awesome work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 3:22 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Quote:
You're right - I was just thinking about it in terms of reading from the ini using the native AHK functions: as long as there is a ParamCount set, it would be pretty easy to handle.

Well, I wasn't going to use the built-in AHK functions, because, for example, they won't work for the Constant section, since a value might extend to multiple lines. Addionally, a ReadFile Loop has the benefit of keeping the file open for the entire operation.

So, for the paramaters, I would store each in a variable, and then keep track of which paramaters are used (for a certain section). Then, sort the paramaters, and itterate from 1 to the end. If the numbers "skip" an index (e.g. 1,2,3,5), It would only read 1-3 (since 4 is missing). I think, in this case, alerting the user that a parameter is missing might be useful. This way, if the user wants, the code won't be converted, and the user can fix the mistake.

_________________
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: May 13th, 2009, 4:52 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
This thread has been too quiet with my move to Portland :)

I'm making several Gui-related classes. Right now I'm working on the core Gui class that sort of wraps the AHK Gui command, while providing flexibility in being able to create and store a Gui window object without ever actually creating the window (although you can create it at the same time, or whenever). If you use the GuiManager class to manage Gui objects, it'll take care of finding and assigning an available GuiNum to each one as necessary, cleaning everything up as needed, effectively managing an unlimited number of windows.

Anyway, I'm getting ahead of myself. I'm storing two dictionaries, one for enableOptions (Gui options with a + sign) and one for disableOptions (Gui options with a - sign). I don't know what options the user is going to specify in either dictionary.

I need to find a way to either:
- Loop through the dictionary by an arbitrary index (the first key, the second key, etc) along with a way to look up the key name of an index, or
- have a Dictionary_getKeys() command that returns an array or vector of all keys in the dictionary

Are either of these either already possible or simple to implement?

Edit:
FYI, found a neat use for the _constant() function in my GuiManager class.

Each GuiManager has a GuiNums property, which is an array of references to guis associated with guinums (1-99).

Then, the GuiManager class has a guiNums constant (read/write), which is another array of guinums referencing which GuiManager object is using which guinum.

In this way, I can automatically trace back calls such as GuiClose, GuiSize, etc. to a specific GuiManager, and a specific Gui object, with just a GuiNum value, and without having to add anything special to the gui itself to identify it.

So now even more-so than before, you can use an unlimited number of GuiManagers to manage an unlimited number of guis (of course, it wouldn't make sense to have more than 99 guimanagers, or anywhere near that. usually you will only need 1 to manage all your windows)

Edit2:
Interestingly, using the Gui class I can now clone a Gui (thanks to you :) ). So I made a helper function in GuiManager that clones a Gui and gives it a new GuiNum... simple but amazingly effective :) You can make a "template" Gui for your windows that you never actually display, but clone as the base for all other windows.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2009, 5:00 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Thanks for the positive feedback - always glad to hear how the class library is helping to enhance the AHK experience.


Also, thanks for "waking me up". I got distracted and completely forgot I haven't finished the Interfaces yet. Right now in the process of adding the final tweaks, and I'll have that uploaded "soon".

As for bmmclure's request, I added a getKeys function to both Dictionary and SDictionary. Download the updated zip. I also modified the examples for Dictionary and SDictionary (located in the "Class Examples" subfolder) with an example of the getKeys function.

The syntax is as follows:

Code:
;returns an Array object (of String objects) which contains the current keys in the specified Dictionary object (in the order added to the dictionary object)
keys := Dictionary_getKeys(DictionaryObject)


Note: any modification to the Dictionary object's keys/values will NOT be reflected in the returned list (i.e. it's not synced). Remember to destroy the returned Array object when you no longer need it (via the Array_destroy function).


On a side note, I won't be able to contribute much more to the library. I'll still get emails, and try to add specific features, on request, but I'm not able to focus on this project anymore. I'm working on a different project - my dream project (not to say I don't enjoy working on the class library). Also, I'm going to be looking for a job, moving out of my parents house (it's about time), and starting my life.

So, I won't be putting too much time into this project, and I won't be documenting the site any. If anyone else wants to document, I will happily post your work, and give due credit. You can use the pages already uploaded on the website as a template. The code should be easy to understand (except maybe some internal stuff). However, the magic behind the class library (the internals), although inefficient at times, should be like all magic - kept a secret and marveled (or something like that).


As such, I say goodbye, but not a parting goodbye. Rather, a goodbye that says I'm here, just that you won't be hearing as much from me.

_________________
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: May 18th, 2009, 9:47 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Thanks for all of your development work so far. It has helped leaps and bounds with my major in-development scripts, and now I just write classes all the time instead of libraries. It's simple, neat, and allows me to keep everything organized and OO.

Just wanted to clarify--are you actively working in Interfaces, or will it be a while, given that you're not working much on this anymore? It's one of the final pieces I think I will need to really get my DOM implementation off the ground, so I'm just checking if I should find a workaround or how soon "soon" might be :)

Testing out SDictionary_getKeys now; sounds like it will be perfect for my needs.

Anyway, good luck with the dream project; hopefully the Class library helps as much there as it has in my projects so far.

Thanks again!

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2009, 10:11 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
bmmclure wrote:
Are you actively working in Interfaces, or will it be a while, given that you're not working much on this anymore.

I'm psudo-actively working on it. Actually, I've been at a loss of words how to describe it without "limiting" it. It's done (minus some testing) and small enchancements.

So, here's my idea. I'll finish testing of it, finish up the example interface (Coin and the two implementing classes Nickel and Dime), and we'll go from there. I'll rely on yal to ask questions, if there are any.

_________________
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  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 93 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, G. Sperotto, Google [Bot], Google Feedfetcher, Miguel, Mtes, rafaelloureiro, Yahoo [Bot] and 73 guests


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