cancel
Showing results for 
Search instead for 
Did you mean: 

Global vs Local Variables

JanMastalski
Level 2
Hello there.   I have been wondering which one makes more sense in Blue Prism processes - using global (as in not hidden from other pages) variables or passing them to each page and having the same variables for more than one page within the process. Say I have a three pages which use the same variable and I want to use it in page 1, then perform one validation (and possibly change) on the variable in page 2, then perform another validation in page 3, and then use the validated variable again on page 1. Does it make more sense to have the variable on page 1 and unhide it to other pages? Or maybe just have the same variable on each page and pass it? I know in programming it's generally assumed that global variables are 'bad' and you should usually use local ones - but I wonder which practice is better in Blue Prism, both performance-wise and when it comes to the readability of the processes.   Thanks in advance.
2 REPLIES 2

david.l.morris
Level 15
Hi Jan, Just giving my two cents... In general, I think what matters is that each organization come up with a policy of either (1) using global data items for those data items that need to be used across multiple pages or (2) using I/O on each page to pass in and out. As far as my preference, the way I see it, there are benefits to both... Global Data Items Benefits Requires less development time because complex I/O within the same component is not necessary Requires less refactoring in the case that the I/O across pages needs to change Drawbacks The list of data items available when working with expressions could have a lot of items in it, making it difficult to find needed data items and possible confusing one data item for another (I think this does not matter if your naming conventions are solid) It can be difficult to step through in DEBUG mode because you cannot easily glance at all the values of various data items without jumping to the main page It can be impossible to DEBUG if all the global data items are not on the same page Local using Input/Output Benefits (basically the opposite) The list of data items when working with expressions is limited in scope so easier to locate your needed item It is much easier to DEBUG because all your data items are on the same page with you Drawbacks Extra development effort to configure I/O for each page Extra refactoring when that I/O needs to change ...but I prefer Local Data Items with I/O on each page. The decreased development effort is nice for global data items, but I have found that it is FAR too easy to reference the wrong data item at the wrong time and then as I mentioned above, it is way easier to DEBUG a process that uses Local Data Items. I personally still name them exactly the same across pages though. I guess I just like the concept of doing everything on purpose and only dealing with what is in scope at the time. For example, I know what data items I have, so I pretend as if they are global and I type out something like [Parent Data.Item Key] and if I get an error, I know I need to 'import' that collection onto the current page through an input parameter. I suspect that the Functional Programming folks out there would approve of this approach as well. =) Respectfully, Dave

Dave Morris, 3Ci at Southern Company

MetVonghiran
Level 4
I personally prefer local variable and agree with Dave's post.   Using local variable is so much easier for debugging and testing purposes (you change the input value and can run that page alone immediately). When working in a team you can also show your team members what is the setting value and the result by just looking at one page.   Regards, Met Vonghiran