Timeline for What are the best practices to follow when using global variables when you must use them?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 28, 2021 at 9:02 | comment | added | Filip Milovanović | Do you have an option to create group (composite) nodes with defined inputs and outputs? That's very similar to creating an encapsulated object with local vars. Check your docs if you're not sure - many node-based systems/editors support this (e.g. UE blueprints have macros, Blender has node groups). You attach a global var to an input - which effectively copies the value inside; then you manipulate the internal copy. | |
| Nov 27, 2021 at 22:47 | comment | added | rvs | Ah that makes sense - thanks @Chris for satisfying my curiousity. | |
| Nov 27, 2021 at 19:01 | comment | added | cwallach | Have a set of global variables dedicated to passing parameters. It reduces confusion. | |
| Nov 27, 2021 at 16:17 | vote | accept | Chris | ||
| Nov 27, 2021 at 14:55 | comment | added | Erik Eidt | Also, avoid recursion, since using global variables as parameters and locals will not automatically stack as in other languages. In other languages parameters and locals are sometimes called automatics, as they are dynamically created upon invocation, and so recursive invocation means each one has its own copy of those variables. | |
| Nov 27, 2021 at 13:29 | comment | added | amon | @rvs and sometimes languages grow organically. E.g. Ansible (2012) is a tool for devops/configuration management that is driven via YAML files. It has “roles” that behave like subroutines. But it has no scoping, so that the convention is to prefix every variable with the role name. It's extremely tedious, but Ansible is still better than the alternative tools. | |
| Nov 27, 2021 at 13:22 | comment | added | Chris | @rvs it is a modern language, but it's a DSL with a graphical interface rather than a code interface. My pseudocode above is an approximation of the problem rather than how it's literally written (which is drag drop wisiwig stuff). The application of this is to build product tutorial videos - the gist is that when your UX changes, these scripts know how to rebuild your docs from scratch by following procedures you've written. The users are product people, not devs, so it's not practical to switch to a "better" language like Java. This is pretty advanced usage for this tool though. | |
| Nov 27, 2021 at 12:58 | comment | added | rvs | Out of curiosity, what domain is this? Not sure if I ever saw modern language without local variables. | |
| Nov 27, 2021 at 12:47 | comment | added | Chris | Different languages is something I have looked at, but every other language that is capable of doing the job doesn't meet other technical criteria. One alternative language for example does not even have procedures. I realise this looks like an X-Y problem without further background, but explaining for pages and pages why this really is the problem wouldn't help solve it. | |
| Nov 27, 2021 at 12:42 | answer | added | amon | timeline score: 7 | |
| Nov 27, 2021 at 12:25 | comment | added | Doc Brown | What about getting rid of that language? | |
| Nov 27, 2021 at 11:36 | history | asked | Chris | CC BY-SA 4.0 |