06-16-2021 02:43 AM
@garthenar wrote:
If you're into OO or libraries, you can make the Globals private. This is much better (or much less bad) than a global. The scope prevents using the global out of the library.
Functional Globals can prevent a lot of harm Globals can do (race conditions) but only when designed well. I avoid them as well, as in principle they are just globals.
- My first language was Java so I have some experience with OOP and It's on my research list for LabView.
Keep in mind that OO is not harder, it just requires a different mindset.
In fact, people choose to use it because it's easier (for them).
There's more to learn, that's for sure, but the gained power and structure is well worth it (to me).
06-18-2021 11:33 AM - edited 06-18-2021 11:35 AM
Once again I wrote a reply, and it did not get posted. I'm short on time (other problems in the system I'm working on), so I'll have to be blunt.
First; You misunderstood/made improper assumptions about almost everything I wrote.
Second; Variables & Global variables (Because I want to understand why some people hate them)
- seems two sides; those that use them sparingly, and those who think they are demon spawn.
- seem to have same problems as in other languages
- I follow the rule of using a wire whenever possible, If I use a variable, I write to it in one place and read it into code, let the code execute accordingly, and store the data (Not back into a variable).
----------------------------------------------------------
Edit for sources
https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/using_local_and_global/
--------------------------------------------------------
Current code progression
- Experimenting with channel wires
- Improving sections of code with shift registers
- *fixing other shenanigans with the code I inherited.
06-18-2021 02:19 PM - edited 06-18-2021 02:30 PM
Ok, I'll give you my spin. I have been working with LabVIEW since the mid '90s. I can count on one hand how many times I've used global variables. My background is in computer science and I have been coding since the '80s. For me, global variables are lazy. While there can be some uses of them that are not horrible, one thing they do is tightly couple code that uses them. This makes re-use of code much harder. I work on very large projects and my team focuses on code re-use. Ours systems contain 100s of reuse libraries. Each library accomplishs one very specific set of functionality. It does what it does very well and implements a good API. We also make extensive use of OOP. Libraries and OOP in LabVIEW are very similar in concept and practice when done thoughtfully. Any way, what I am trying to say is that we would never reach this level of modularity if we were using global variables. Over time you can build up an impressive set of reuse libraries that can make future projects much easier to do. Yes, there is an up front investment to really think things through but it pays off in the long run. Included in our re-use libraries are some that were written 15 years ago. They are still in use today and haven't required significant changes during there lifetime.
As soon as you put global variables in your code, you now have code that is forever coupled to each other. When you go to try and reuse some of it you end up either dragging a bunch of other unnecessary code along (just so the global variable works) or you end up making copies of your code and reworking them so that they don't rely on that global variable that will not exist in the new system.
06-21-2021 02:36 AM
@garthenar wrote:First; You misunderstood/made improper assumptions about almost everything I wrote.
Please press the reply button, so we know who you're responding to.
Also, maybe address the issue with some details? If 'we' are not on the same page, you're the person to correct this.
@garthenar wrote:Second; Variables & Global variables (Because I want to understand why some people hate them)
- seems two sides; those that use them sparingly, and those who think they are demon spawn.
There's also those who (mis)use them for everything.
@garthenar wrote:- I follow the rule of using a wire whenever possible,
So... always?
There are 3 types of data in LabVIEW:
+ By wire \ by value
+ By wire \ by reference
+ Global
You can always use a wire. Everything can be made with the first 2 types.
Almost everything can be done with just the first type.
If you want to, is all about preference.
I learned I had to avoid using globals and by reference wires. They simply didn't scale up well in my situation. Avoidance is my solution to my situation. There are plenty of situations where you won't get these problems, and there are other solutions too.
06-22-2021 10:34 AM - edited 06-22-2021 10:35 AM
Sorry, I did click the reply button for GerdW buy something went wrong and I didn't notice. I'm getting ready to post more code with comments and planned improvements today.(I've been delayed by hardware problems at work). And I was very tired so I think I could have phrased that post better.
@wiebe@CARYA wrote:
There are 3 types of data in LabVIEW:
+ By wire \ by value
+ By wire \ by reference
+ Global
You can always use a wire. Everything can be made with the first 2 types.
Oh God. I was thinking that variables (global and local) were how you pass by value and wires were like pass by reference. I'll correct that thinking right away.
I have moved away from globals and I'm in the process of replacing them with clusters which appear to be like structs in C. (and I'm planning on moving to OOP for my project at some point, and from what I have read you use structs for data in LabVIEW OOP).
While I have pushed back because I wanted to understand why everyone is telling me to not use globals, I trust all of your experience and began investigating the alternatives you all recommended immediately. (Structs, channel wires, OOP).
@wiebe@CARYA wrote:
Also, maybe address the issue with some details? If 'we' are not on the same page, you're the person to correct this.
I apologize. I'm learning more and more new vocabulary every day but I still have so much to learn about the subject and how to properly communicate what I am doing as an Engineer. (I will be a junior next year so I'm technically not an engineer yet).
Eddit: No, I don't know why the quotes in this reply look funny. Yes, I tried to fix them by editing the post.
06-22-2021 11:39 AM
@garthenar wrote:
(and I'm planning on moving to OOP for my project at some point, and from what I have read you use structs for data in LabVIEW OOP).
Well, kind of. A LabVIEW class's private data is required to be a cluster, which is like a struct.
So, your idea is correct, but the LabVIEW terminology is different.