08-15-2012 11:20 AM
Hi, I have always wondered for what should I go for, performance or cleanliness? Because most of the time in big projects you get stuck with this. An example could be using passing a cluster or array by reference (New Data Value Reference), and pass the wire through many loops, or just using a local variable to read the cluster/array in each loop? This is just one example just to get the idea, because there are many more examples of questions like this.
Thanks!
08-15-2012 11:26 AM
I often find that the performance updates I make cause more cleanliness. But in general, I go for the performance. But I'm also very OCD, so I still end up with a mostly clean diagram.
In your example, do not use the local. Those will just cause more problems. What you actually may want is an Action Engine.
08-15-2012 11:27 AM
Generally, cleanliness is preferred unless permance is a critical necessity for the system to function. At least thats what I've heard.
08-15-2012 11:34 AM
For your specific example, be aware that reading a LOCAL variable creates a COPY of the data. Every time.
That makes a difference in performance if the array size is large.
In general, go for performance, and cleanliness can follow.
It's a whole lot easier to clean up a well-performing code, than to speed up a clean, but ill-performing code.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-15-2012 11:38 AM
"...Premature optimization is the root of all evil..."
(c) Donald Knuth, 1974
08-15-2012 11:51 AM
@Andrey Dmitriev wrote:
"...Premature optimization is the root of all evil..."
(c) Donald Knuth, 1974
"God grant my the peace to acept the the non-optimized performance, knowlege to let me optimize and the wisdom to know when to optimize." (paraphrase of teh prayer of St Fancis)
WIth time and experience we learn when we have to optimize and we do not have to optimize.
When I develop my designs I am continually asking myself (how much data will be in this wire, how often, and what the end effect seen by the customer would be.
If you don't have that "feel" yet, start writing benchmarks to test your code any time you see a "big wire". After running benchmarks, playing "wack-a-dot", and learning how to optimize, you will remember what needs to be checked and what does not.
The other thing you can do is to keep the "Windows Task manager" open when you test your code. When you notice your code is killing the CPU, stop and figure what you just did, then don't do that again.
I am still learning and will continue to do so.
Have fun,
Ben
08-15-2012 12:17 PM
I prefer my code to be readable and not much care about the cleanliness. As you make your code readable that is suffiecient for the other developers because you are not going give the code to your customer but your front panel should be very good and easly understandable (tip strip). Rest -dtto Ben's post. Also don't forget to read this ( Ben you know this very well 🙂 )
08-15-2012 12:55 PM - edited 08-15-2012 12:59 PM
I always aim for clear, concise and readable code first and foremost. If you write spaghetti code it generally doesn't matter how fast it is because in the end you can't effectively maintain it. Focus more on good coding styles, modularization, frameworks and best coding practices. When necessary optimize. Unreadable codes quickly becomes more troublesome as it ages. Good clean code is easier to maintain and enhance.
It should be noted that good designs will often lead to pretty good performance anyway. As you modularize your code you tend to minimize the need for passing tons of data around. The data stays with the code that needs it. If you need to run wires through code just to reach subVIs then you probably don't have a very good design in the first place.
08-15-2012 07:39 PM
Thanks to all for the answers!
I use many Action Engines, I am still at college but I want to upload some of my programs for feedback.
So since the beginning I'll do my best to try to code clean, and like most of everyone said: Keeping it optimized will get the code clean 🙂
Thanks again!