How to keep track of code...

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
DaveT1
Posts: 218
Joined: 07 Oct 2014, 11:23

How to keep track of code...

Post by DaveT1 » 24 Nov 2021, 13:55

...so, it seems that I have a very poor memory. I can develop a script and forget that it already has functions and code to undertake the same or very similar. Meaning I'll write new code to largely do what is already covered by something existing (which could be in the script or in code brought in via #include).

My Qs is (are):

1. How to defend against forgetting what code is already there (other than downloading and installing a better memory!)?
I've toyed with the idea of adding tags and coments which are then searcheable. Suffers from the usual problem with tags of trying to remember them (could list these in a separate place?), and they clutter up the code - though I guess that's mainly a problem only if I ever shared any code?

2. When to abstract a distinct chunk of code from a script to a library?
- ie., at what point do you look at code and think ah-ha this could be used across mutiple un-connected scripts? And then what happens if you see a way to improve that library function - Ideally you'd re-test across all the scripts that use it - is that practicable and how do you know which scripts use it (search for library name across all scripts?)? And I guess there'd have to be a fairly high bar against changing library code because of knock-on consequences?

I'm sure that approaches to this are quite subjective, but interested to hear thoughts / views / best practice.

Many thanks.

SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: How to keep track of code...

Post by SandyClams » 26 Nov 2021, 19:02

DaveT1 wrote: How to defend against forgetting what code is already there (other than downloading and installing a better memory!)?
if you don't remember what code you already have available, this probably means you aren't trying to solve problems in those domains very often. If you don't need the code very often, it's not really that big a deal if you forget about it, or even rewrite it. On the other hand, if you need it often, and you use it often or rewrite similar code often, I promise you're going to start remembering it eventually!
DaveT1 wrote: When to abstract a distinct chunk of code from a script to a library?
you basically already answered this question yourself. Whenever you realize the code might be general enough to use it in different circumstances, that's probably a good time to start separating the code so that you can use it in different circumstances. You can also aim to write your code this way from the beginning, if you have some idea of what types of things you want to accomplish with the code.
DaveT1 wrote: And then what happens if you see a way to improve that library function
you will understand this better if you look into the concepts of interfaces vs. implementations. The general idea is that you will write your library with clearly defined entry points, so that, when other code accesses the library, it's always being accessed in the same ways (in other words, an API). Then if you need to change or improve the code of the library, you can mess around all you like with the internals, but you leave the entry points alone, so that the entry points still expect the same kind of data sent to them, and they still return the same kind of data when you query them. That way, any code that uses the library can continue using it in the same way without changing anything, so long as the code is using them from the same entry points and not trying to access the internals. The more you write, the more you'll get a sense of things like this, it just develops naturally over time as you get more practice solving your own problems.

cheers!

cheeseontoast
Posts: 3
Joined: 11 Nov 2020, 09:41

Re: How to keep track of code...

Post by cheeseontoast » 28 Nov 2021, 15:50

As a newbie, I'm finding Notepad++'s 'Find in Files' helpful for searching through my script folder for examples of commands I'm about to use again.

DaveT1
Posts: 218
Joined: 07 Oct 2014, 11:23

Re: How to keep track of code...

Post by DaveT1 » 29 Nov 2021, 14:44

@SandyClams thanks so much for these thoughts - I guess it's a question of practice and familiarity then!

@cheeseontoast yep I think searching is the way to go - looking in the current file, in your library and then possibly within all your scripts (i'm just re-indexing on file contents to make this possible!) to see if you have done something similar.

Thanks both for your thoughts.

Post Reply

Return to “General Discussion”