MrAnderson Posted January 30, 2015 Share Posted January 30, 2015 Hallo, 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2015 Moderators Share Posted January 30, 2015 MrAnderson,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. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jvanegmond Posted February 2, 2015 Share Posted February 2, 2015 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. czardas, jaberwacky and MikahS 3 github.com/jvanegmond Link to comment Share on other sites More sharing options...
czardas Posted February 2, 2015 Share Posted February 2, 2015 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. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now