AutoHotkey Community

It is currently May 25th, 2012, 6:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: August 27th, 2007, 6:23 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade

_________________
Image


Last edited by majkinetor on December 19th, 2007, 3:58 pm, edited 8 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 9:39 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8660
Location: Salem, MA
cool. I know a few ask for help questions that can be solved by this.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 9:44 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
I posted something similar to this a while back

http://www.autohotkey.com/forum/viewtopic.php?t=21346&start=0&postdays=0&postorder=asc&highlight=loadini

Ive added a few extra functions for my own use too.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 10:20 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Ini files are so simple you should be able to parse them without regex. That would make scripts with large datasets launch a lot faster with less memory.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 11:20 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Titan

mine was originally written for an addition to a template designed to help newcomers.

The idea being just by adding three function calls they can load and save any variables at will.

I agree they are simple enough to use, and for large data sets this isnt the way to go, but for medium size and small size it will cut the need for writting all the reads and writes.

I guess it was also brewed out of lazyness lol

Or did i completely mis interprete what you mean and was you suggesting stringsplit would be a better way to go ??

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 11:35 pm 
Offline

Joined: July 29th, 2005, 5:32 pm
Posts: 179
This will come in phenomenally useful in a number of applications; thus far I have created specialized ini handlers for various projects. This is an open ended solution that can replace most of them!

Thanks for sharing!

_________________
.o0[ corey ]0o.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 2:14 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Ini files are so simple you should be able to parse them without regex

Its fast enough for 99% of usagees and the code is elegant. You don't need to be concerned about ultimate speed everywhere. The functionality is more important here.

I intenionately avoided String functions cuz I don't see much benefit over RegEx in normal Ini files. I care about code sophistication more and leave optimisation for time critical things. IMO, its wrong to optimise everything.
Also if you cheked out the carefuly you would see that the most frequent task is done without single RegEx.

Its also faster then multiple IniReads. Low number of RegExes are used.

Again, to quote Laszlo, how far you want to go in optimisation ?
Ultimately I can provide machine code, but that is hardly the point.

This is basicly configuration automation. So you can load your entire configuration in global vars in one step instead of series of IniReads.

Its probably not suitable for special cases but again, nothing is.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 10:44 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
String functions are more elegant, regex is cryptic and takes time to learn. By using the standard set of parsing functions not only will scripts perform better but your code will be easier to follow and modify - another checkpoint for stdlib candidates.

Anyway the only reason I posted is because I'll be using these functions. I will modify them to suit my needs since like Skan, you prefer compact code over anything else. Thanks.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 11:36 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
LOL TITAN.

I had quolity laugh now :)

And if we talk about cryptic lets talk about Anchor :)
Anyway, you can argue that RegEx is cryptic, but the one there is fairly trivial, can be decifered by ppl knowing RegEx in several minutes, and basicly that is the only thing to care about in this code.

Code:
Since like Skan, you prefer compact code over anything else.

My coding is nothing like Skans. I don't practice obfuscation and I know very well that "code size" has nothing to do with speed. Skan got it all wrong when short code philosophy is in question. Nevertheless, I prefer recursion instead itereation because of its ultimate elegance. I don't know if you ever programmed in Prolog, but there even the very complex tasks can be coded in 3 lines. Not obfuscation if you know rules of the language, as much as RegEx crytpic patterns are not obfuscation once you did your lessons.

RegEx... I just love that thing. It makes me happy. :D
I am not sure how AHK lived up so long without it, I find it ridiculous that lanugage having primarly strings as types doesn't have the most sophisticated way to handle them.

Quote:
String functions are more elegant

Not if I have to use 5 instead of 1 RE. 1 against 1, you are right :)

Quote:
Anyway the only reason I posted is because I'll be using these functions

Nice to hear that. I can't wait to see your update. After all, if somebody else is willing to update anything I did, especialy you, I am happy. Due to your speed concern I checked the speed of the functions, and even with very large ini files (I tested on wincmd.ini, hardly any AHK script will have that much options) to get values from 0 - 10 ms. OFC, I can imediately spot problematic places, like StringTrimLeft in 2Var when all sections are iterated.

Then we come to idea that I force: Do I really want to spead up something that takes 10ms in worst case ? Do I really want to do that without debuger, without appropriate IDE and stuff like that. Do I really want to lose enormous amount of time to get small benefits, as currently, in AHK, i miss like 1000 libraries and I am slowely writting them as I need them. Imagine I optimise like crazy.... that would be horror.

On the other hand if somebody entusiastic enogh, like you, with your fanatic optimisation skills (not sarcastic, I learned alot from your and Laszlos optimisation skills), I can be only happy. I am more concerned currently about API that is extremely practical and easy to use in most cases.

Then if you do update them, please add the folowuing I missed - list of sections. If this is to be used with 3th party INIs keep in mind that some of the section names may not be valid variables (contain spaces, dots and sht like that).

Also, I am not sure if reverse opeerations shold be done (vars to sections) for ultimate config handling. Superfraggle did it as saveini but that way is not possible here, because first, you don't know what globals should be saved. I imagine you give a prefix of globals, and section, and it does the job, but that is not possible as you can't find out the full name of the variable. If listvars exists in some more advanced forms, that could be used... for instance listvars cfg_* but Chris doesn't wont to cooperate here so its just dreaming. Arrays will probably do good here, but again, when ?

Thx

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 12:13 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
majkinetor wrote:
if we talk about cryptic lets talk about Anchor
Commenting that is somewhere on my informal todo list.

majkinetor wrote:
RegEx crytpic patterns are not obfuscation
Actually in most cases they are, e.g. (?<=(["']))[^\1]*(?=\1\b) is an optimized version of "(.*?)".

majkinetor wrote:
I can't wait to see your update.
They're too specific for my usage now but I might post them later.

majkinetor wrote:
Do I really want to spead up something that takes 10ms in worst case ?
Well I think if you can, why not? It could just be my perfectionist nature but I don't feel comfortable releasing scripts whilst knowing they can be much improved. I'm sure Chris and other developers feel the same way.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 12:51 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Commenting that is somewhere on my informal todo list.

And updating Ini module is on my Todo list.

Quote:
Actually in most cases they are, e.g. (?<=(["']))[^\1]*(?=\1\b) is an optimized version of "(.*?)".

True. Optimisaion of REs is anoying even to me, the biggest fan.

Quote:
Well I think if you can, why not?

Because, it always can and you have to stop somewhere. I am sure Anchor can be lot faster and without some suspicious/problematic functions like InvalidateRect. But hey, it does the job (in 99% of cases), nobody complains.
If I wanted to use uber fast code I would programm in ASM, not in AHK.

Quote:
It could just be my perfectionist nature but I don't feel comfortable releasing scripts whilst knowing they can be much improved.

The life, the universe and everything else requires delicate measure of balanse. I am constantly updating my own. I find fairly biased for you to comment like this, knowing that your main prog environment is C# & dotNet the king of low speed. If you really want to talk to me about how things should be done, switch to ASM instead of dotNet. After all, you can't go lower then ASM... or ....

The truth is bitter - higher level of abstraction makes code slower, yet not enough abstraction makes code fast and hard to use. Balance again.

Quote:
I'm sure Chris and other developers feel the same way.

Well, then I don't agree with you, Chris & other developers. But who cares? We definitely don't have same priorities in life. Something like dolphins and humans.

Quote:
They're too specific for my usage now but I might post them later.
I see.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 1:46 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
majkinetor wrote:
it always can and you have to stop somewhere
It's up to the author to exercise reasonable discretion. Mine goes as far to suggest using simple string functions over cryptic overzealous regex for something as basic as INI. I never ordered you to do anything or stated anywhere that optimization was an absolute necessity. If I had that mindset I most probably would program in ASM.

majkinetor wrote:
I find fairly biased for you to comment like this, knowing that your main prog environment is C# & dotNet the king of low speed
That's another common misconception. I don't use reflection and much polymorphism and inheritance so my C# apps are quite fast once compiled to CLR.

majkinetor wrote:
I don't agree with you, Chris & other developers. But who cares?
For an extra five or so minutes of work I would push for quality. If I was ignorant and had low substandards I could make-do with anything, so its a question of personality I suppose.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 3:23 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
That's another common misconception.

Its not common misconecption. Its a fact. I love dotNet but I know my beast. That tech will shine in few years.
Ye, its proven that C# can be as fast (and even faster) as C++ app, but only if you are programming guru and have no life other then optimising things (something like WoW episode of South Park). Even Rusinovich stated that he is scared about dotNet. So if even one of the biggest Windows gurus out there is "commonly missconcepted" what makes you think you are the one that is not ? Other then that, you don't have to measure programs running in dotNet VM. I can noticed their slow speed and large memory footprint as soon as I start them.

Quote:
I don't use reflection and much polymorphism and inheritance so my C# apps are quite fast once compiled to CLR.

So you don't use framework at all ?

Quote:
For an extra five or so minutes of work I would push for quality.
Perhaps its 5 minutes for you. I don't beleive anything in this world is possible in 5 minutes.

Quote:
Mine goes as far to suggest using simple string functions over cryptic overzealous regex for something as basic as INI

I think AHK REs are very fast based on personal experience and some measures.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 5:38 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
majkinetor wrote:
its proven that C# can be as fast (and even faster) as C++ app
You've just contradicted yourself.

majkinetor wrote:
...only if you are programming guru and have no life other then optimising things
I'm no .NET optimization expert (those who are often get paid a lot for it) but there are truths in both of our statements. AutoHotkey is a different story, here optimization techniques are pretty much common sense to anybody with prior programming experience, and there is nothing much that needs to be studied and learned; i.e. use commands over functions, avoid dynamic variables and expressions for simple assignments, parsing loop instead of StringSplit etc.

majkinetor wrote:
I don't beleive anything in this world is possible in 5 minutes.
I believe anything is possible. Perhaps this reflects our contrasting philosophies on many of the issues that's been discussed.

majkinetor wrote:
I think AHK REs are very fast based on personal experience and some measures.
Orly? From my experience and benchmarks I found that string commands outperform regex in almost any case.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 12:09 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Made it all purpose now (would you believe if I said I wrote it in 3ish mins?):

Code:
/*
   Function: Ini_GetVars
      Loads variables from an INI file.
   
   Parameters:
      src - INI file path
      sec - filter variables by sections with this name
      pre - common variable name prefix
      d - separator for section name and prefix
   
   Returns:
      Number of variables loaded.
   
   About: Examples
      - Ini_GetVars("settings.ini") ; load all variables indiscriminately
      - Ini_GetVars("application.ini", "window") ; load variables under 'window' section
      - Ini_GetVars("test.ini", "", "") ; use no prefix
   
   About: License
      - GNU General Public License 3.0 or higher <http://www.gnu.org/licenses/gpl-3.0.txt>
   
*/

Ini_GetVars(src, sec = "", pre = "", d = "_") {
   local s, p, v1, v2, t, at
   static x = " ,   ,``,¬,¦,!,"",£,%,^,&,*,(,),-,=,+,{,},;,:,',~,,,<,.,>,/,\,|,,,"
   at = %A_AutoTrim%
   AutoTrim, On
   If pre !=
      pre .= d
   Loop, Read, %src%
   {
      If InStr(A_LoopReadLine, "[") = 1
      {
         StringMid, s, A_LoopReadLine, 2, InStr(A_LoopReadLine, "]") - 2
         If s contains %x%
            s =
         Else If s !=
            s .= d
      }
      Else If !(sec != "" and sec != s) and p := InStr(A_LoopReadLine, "=")
      {
         StringLeft, v1, A_LoopReadLine, p - 1
         v1 = %v1%
         If v1 contains %x%
            Continue
         StringTrimLeft, v2, A_LoopReadLine, p
         %pre%%s%%v1% = %v2%
         t++
      }
   }
   AutoTrim, %at%
   Return, t
}


I'll wait on you for the reverse functions lol.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher, kiropes, lblb, nothing, rbrtryn and 41 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