Jump to content
Sign in to follow this  

Question About Functions

Recommended Posts


I'm really new at program. I have a question about function

I have a my main where i call the function menu() the function menu calls function like Button1, Button2 and Button3.

For example button1 itself call functions Like "Move FIile A to B" in this function Move File A To B i call a function "Prepeare directory" and so on.

Is this a good way to programm? Or is it better to call function successively in the right order at my main?

Thanks to all


Share this post

Link to post
Share on other sites


Welcome to the AutoIt forums. :)

There is absolutely no problem with calling functions from within other functions. The only thing is to be careful that you return from a function before it gets called again or you can run into recursion problems, as explained in the Recursion tutorial in the Wiki. :)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

You have to learn to think about where the responsibilities should be. Do you think a function called "Move File A to B" should also be responsible for "Prepare directory"? Or could that cause confusion to someone who is not familiar with your code? Or is that not relevant to the process of "Move File A to B"?
A simple example will help. For example, we have a humanoid robot which we want to program to wave his left arm and then say "Hello!". We define the functions Main, WaveArm and SayHello. In terms of functionality, it doesn't really matter if we let Main call WaveArm and let WaveArm call SayHello. But should a function called WaveArm also be the trigger for saying "Hello!" afterwards? Or should we let Main call both WaveArm and SayHello in the order we want it to happen?
If we choose to keep the responsibility of waving the arm in the method WaveArm and the responsibility of saying "Hello!" in SayHello, we can easily ask a different programmer later to change the code to make the robot say "Hello" first and then wave his arm (the reverse of what we wanted) by changing the Main. He will be done in a few seconds, rather than having to drill into the long and complicated WaveArm function which mainly deals with motor control.
It therefore helps with clarity too: If we want to understand the order of the robot's actions, we don't have to drill down into the specifics of how the robot waves his arm by reading the whole WaveArm function, we just have to know that WaveArm will wave the robots arm and let other code deal with the order of the robots operations. In this way, we can create functions which are essentially abstractions of the code we write. We can stop thinking of WaveArm as a series of operations of motor control, but instead think of it as a robot waving its arm (and only that). This helps us write and maintain bigger programs without having to understand every line of code in the system.
Placing correct responsibilities is a main principle in software development and is often referred to by the larger term Separation of Concerns, though I find it easier to explain and understand as thinking of placing responsibilities.

Share this post

Link to post
Share on other sites

Some of the soundest advice is presented by the author of the post above. You have to manage your code sensibly. There may be the odd occasion where a programmer might break from convention, but getting the right functions to perform appropriate tasks is a most flexible approach which will make your life a lot easier in the long run.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...