Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Best approach for learning APIs?


  • Please log in to reply
8 replies to this topic
Miguel7
  • Members
  • 56 posts
  • Last active: Mar 20 2015 02:44 AM
  • Joined: 30 May 2014

Hi everyone,

 

This is a very general question, and I apologize in advance if it's too general or too long.  But I think once I can figure this out I can take my programming skills (in all languages, including AHK) to the next level.  I'm finding myself in a sort of plateau: I'm confident I can quickly learn just about any programming language you can throw at me.  The concepts (variables, loops, arrays, classes etc.) are all essentially the same, the only major difference being how the language expresses them.  This is great - I can go from AHK to C# to JavaScript to VBA and still know what I'm doing.  But it seems that to really be able to create great programs, knowing APIs is even more important than knowing how to write code.  In AHK this means knowing how to use DllCall, NumPut, OnMessage, "G-Dip" etc. but in other languages it's even more important.

 

In my experience so far, this seems to mean either:

 

1. Spend hours on MSDN (or Java's "Docs" or whatever), dig around endlessly and pray that someday you can make sense of it all

Documentation websites like MSDN are great for reference purposes.  They're the Wikipedia of programming, and I've occasionally found some good stuf on there.  But they seem to be more for reference than for learning... unless you're the kind of person who learns by memorizing entire databases of information, in no particular order. :lol:

 

2. Go on YouTube and learn how to get something done in half an hour, but never learn half of what can be done

This is a bit more helpful, depending on who did the video.  This has been my preferred method of tackling a project involving code I haven't used before.  It has obvious drawbacks - it can be dated, the guy may not speak English that well yet, and there's no time to get into any detail at all - but in general it's worked better than #1.

 

3. Just start writing code, blunder into the project and get bogged down in trying to figure out the latest brand of error.

I hate to admit it, but I do this way too often.  For example, I started a project awhile back that threw some kind of threading-related exception.  I know what a thread is and get the general gist of how they work, but the exception was new and bizarre to me.  So I go back to #1, and eventually found my way to this page... and end up more confused than before.  Apartment State?  My apartment's in the State of Florida, but what the heck does that have to do with my code?  :lol:

 

4.  Get old.

By using the same few APIs over and over again (WinForms in C#, for example), they eventually become more familiar gradually over time.  I know more now than I did last year, so maybe by 2077 I'll be that much better. :lol:

 

 

But for now, I can't seem to find a straightforward approach to tackle this 90-degree learning curve (more like a "learning wall").  But of course, many programmers have done it, so logically it can be done.  So my question for is, how do you do it?  Where do you even start?  Did you have to take a class or buy books, or attend workshops or something?  I'm glad to put the work in, and I realize to get good at anything it's going to be work - but it would sure be nice to know I'm actually getting somewhere.  If there's a better way than what I'm doing, I'd like to find out what it is.  Then maybe I can stop running around in circles like a mouse in a maze, lol.

 

Thanks. :)



nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Nr2 is probably the worst approach.

You will probably barely learn anything by browsing youtube.

 

You will get used to MSDN docs over time.

Also you can search for MSDN blog *insert topic name here*.

That way I understood the Clipboard functions.


Visit the new forum ahkscript.org.

http://ahkscript.org


Miguel7
  • Members
  • 56 posts
  • Last active: Mar 20 2015 02:44 AM
  • Joined: 30 May 2014

I didn't know MSDN even had a blog.  I checked it out and found a link to tutorials on MSDN - now we're getting somewhere!  :D  So I went on MSDN and did a search for "tutorial wpf", "tutorial oledb" etc. and found hundreds (if not thousands) of pages.  So between that and the blog I have a couple resources I didn't before.  Thanks for the tip nnik, very cool. B)



bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
Hi,
I basically have your same problem, I'd love to improve myself more straightforwardly.. I keep finding myself learning a lot of random stuff which help me get the job done every time but leaves me with a dissatisfaction of the true knowledge of something.
I was thinking about "giving myself out" for a pair of hours per day to more experienced programmers for free, just to learn, because I think other than knowing The True Stuff (e.g. Dllcall & co. , which are still a blurred area to me), one need to know some specific approach to coding to improve. I mean like when you magically understand how to reduce a 3 pages script into a 15 lines one with even better reliability.
But maybe thats just me, since I don t have a computer science background (I'm fully self-taught) and I don t have access to "technical brainstorming", except for forums on the internet.

nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Hi,
I basically have your same problem, I'd love to improve myself more straightforwardly.. I keep finding myself learning a lot of random stuff which help me get the job done every time but leaves me with a dissatisfaction of the true knowledge of something.
I was thinking about "giving myself out" for a pair of hours per day to more experienced programmers for free, just to learn, because I think other than knowing The True Stuff (e.g. Dllcall & co. , which are still a blurred area to me), one need to know some specific approach to coding to improve. I mean like when you magically understand how to reduce a 3 pages script into a 15 lines one with even better reliability.
But maybe thats just me, since I don t have a computer science background (I'm fully self-taught) and I don t have access to "technical brainstorming", except for forums on the internet.

Hey

I pretty much had the same problem some time ago.

I also learned most things I know by myself.

 

But if there is one thing I learned it is that nothing is done magically. If you want to shorten your code you should try to think about how to shorten it.

If you want to know how to do something better you should be aware of more possible ways to approach something. Maybe some other way fits better for this case?

Maybe some other way is shorter?

 

The most important thing when making code shorther is reusing code.

e.g. you want to control a media player:

Down::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,325 ;Presses the play/pause button
WinActivate,%LastWindow% ;brings back the last window 
return

Left::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,300 ;Presses the backwards button
WinActivate,%LastWindow% ;brings back the last window 
return

Right::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,350 ;Presses the forward button
WinActivate,%LastWindow% ;brings back the last window 
return

Can also be written as:

Down::
ShowMediaPlayer()
Click 200,325 ;Presses the play/pause button
ShowLastWindow()
return

Left::
ShowMediaPlayer()
Click 200,300 ;Presses the backwards button
ShowLastWindow()
return

Right::
ShowMediaPlayer()
Click 200,350 ;Presses the forward button
ShowLastWindow()
return

ShowMediaPlayer()
{
global LastWindow
WinGetTitle, LastWindow ;gets a window name
WinActivate,Media Player ;activates the media player
}

ShowLastWindow()
{
global LastWindow
WinActivate,%LastWindow%
}

Or finally also as:

Left::ClickMediaPlayer(200,300)
Down::ClickMediaPlayer(200,325)
Right::ClickMediaPlayer(200,350)

ClickMediaPlayer(CoordX,CoordY)
{
WinGetTitle, LastWindow ;gets a window name
WinActivate,Media Player ;activates the media player
Click CoordX,CoordY ;clicks somewhere
WinActivate,%LastWindow%
}

When you start to get really into programming it is way more important to learn how to reuse code properly rather than learning about DllCall, etc..

After you have spent a coniderable amount of time trying to figure out how to reuse code you will get to the next step.

 

The next step is to learn proper code encapsulation.

Your scripts will get more and more complex as you move on.

You won't have time to deal and remember every piece of code and every chunk of code you have written.

And if you forget or stop caring you can get a conflict between to methods.

You would also have a problem when you try to use to APIs that you didn't write yourself. 

Code encapsulation helps you deal with these problems.

 

You encapsulate code from the rest of your script so that it doesn't have any global variables (global vars are bad :)).

You can encapsulate code in a function (or a class (http://ahkscript.org).)

Now when you use this code somewhere else you can be sure that if you use it properly, the code will do what it should to do.

The easier it is to use, the easier it is for yourself.


Visit the new forum ahkscript.org.

http://ahkscript.org


nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Hi,
I basically have your same problem, I'd love to improve myself more straightforwardly.. I keep finding myself learning a lot of random stuff which help me get the job done every time but leaves me with a dissatisfaction of the true knowledge of something.
I was thinking about "giving myself out" for a pair of hours per day to more experienced programmers for free, just to learn, because I think other than knowing The True Stuff (e.g. Dllcall & co. , which are still a blurred area to me), one need to know some specific approach to coding to improve. I mean like when you magically understand how to reduce a 3 pages script into a 15 lines one with even better reliability.
But maybe thats just me, since I don t have a computer science background (I'm fully self-taught) and I don t have access to "technical brainstorming", except for forums on the internet.

Hey

I pretty much had the same problem some time ago.

I also learned most things I know by myself.

 

But if there is one thing I learned it is that nothing is done magically. If you want to shorten your code you should try to think about how to shorten it.

If you want to know how to do something better you should be aware of more possible ways to approach something. Maybe some other way fits better for this case?

Maybe some other way is shorter?

 

The most important thing when making code shorther is reusing code.

e.g. you want to control a media player:

Down::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,325 ;Presses the play/pause button
WinActivate,%LastWindow% ;brings back the last window 
return

Left::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,300 ;Presses the backwards button
WinActivate,%LastWindow% ;brings back the last window 
return

Right::
WinGetTitle, LastWindow ;gets a window name 
WinActivate,Media Player ;activates the media player
Click 200,350 ;Presses the forward button
WinActivate,%LastWindow% ;brings back the last window 
return

Can also be written as:

Down::
ShowMediaPlayer()
Click 200,325 ;Presses the play/pause button
ShowLastWindow()
return

Left::
ShowMediaPlayer()
Click 200,300 ;Presses the backwards button
ShowLastWindow()
return

Right::
ShowMediaPlayer()
Click 200,350 ;Presses the forward button
ShowLastWindow()
return

ShowMediaPlayer()
{
global LastWindow
WinGetTitle, LastWindow ;gets a window name
WinActivate,Media Player ;activates the media player
}

ShowLastWindow()
{
global LastWindow
WinActivate,%LastWindow%
}

Or finally also as:

Left::ClickMediaPlayer(200,300)
Down::ClickMediaPlayer(200,325)
Right::ClickMediaPlayer(200,350)

ClickMediaPlayer(CoordX,CoordY)
{
WinGetTitle, LastWindow ;gets a window name
WinActivate,Media Player ;activates the media player
Click %CoordX%,%CoordY% ;clicks somewhere
WinActivate,%LastWindow%
}

When you start to get really into programming it is way more important to learn how to reuse code properly rather than learning about DllCall, etc..

After you have spent a coniderable amount of time trying to figure out how to reuse code you will get to the next step.

 

The next step is to learn proper code encapsulation.

Your scripts will get more and more complex as you move on.

You won't have time to deal and remember every piece of code and every chunk of code you have written.

And if you forget or stop caring you can get a conflict between to methods.

You would also have a problem when you try to use to APIs that you didn't write yourself. 

Code encapsulation helps you deal with these problems.

 

You encapsulate code from the rest of your script so that it doesn't have any global variables (global vars are bad :)).

You can encapsulate code in a function (or a class (http://ahkscript.org).)

Now when you use this code somewhere else you can be sure that if you use it properly, the code will do what it should to do.

The easier it is to use, the easier it is for yourself.


Visit the new forum ahkscript.org.

http://ahkscript.org


bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Well, "magically" was kinda of a joke :) by that I meant that is like when you write your first script, than an year after (an year spent on programming) you re-read it and you "magically" understand all the flaws and short-hand that could be used. I know this is part of an "aknowledgement process" but it's very randomized (at least that is the impression that I get) or in another words one doesn't actually know what and when something will be useful (or if it will at all!). 

 

I totally agree on creating owned libraries of functions to reuse code. It is very very useful when you know what you are doing (in the beginning of my experience with functions I used to pass the results as global vars instead of returning them :) a lot of problems with doubled var's names lol).

 

I loved myself when I finally get to understand obj usage, the arrays "stack behavior", the Regex syntaxing and the Control stuff, which let me create a concrete parser-form filler for a company, very time saving (got also paid lol :p). I was particularly proud of myself since I never used code which wasn't made by me for this (not that there is something wrong in that, I also see now that sometimes one has to relay on others code or a life couldn't be enough to code everything by himself :p

 

 

 

The easier it is to use, the easier it is for yourself.

 

I guess it's true, but I also think that if you don't push yourself into going into "harder" stuff, you wont be able to expand/improve. E.g. now I want to mod some part of that above-said parser/filler with dllcalls just to learn how to use them, I want to learn bitwising stuff and the usage of that. It wont help me simplyfing my coding (at least it doesn t actually look like that, right now! :p) or my usage of that, to me it's just progressing on that "aknowledgement process" which brings you from high level languages to learning concepts of low level languages (which to me seems the biggest deal of all, but I'm not so sure of that as I was in the begnning).

 

P.S. I'm also not that young anymore (29) so I constantly feel like I have to hurry like the White Rabbit of Alice in Wonderland..



nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

I actually wrote a tutorial regarding this topic on ahkscript.org.

http://ahkscript.org....php?f=7&t=5567

I'd especially like to hear your opinion about this Tutorial since it was intended target group were people like you ^^.


Visit the new forum ahkscript.org.

http://ahkscript.org


bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Sorry for the late response, I'll definitley take a look at that in these days and I'll let you know asap.

 

Also thank you for taking the time to write it down! :)