It’s a point that I have, and will continue to, drive home on this blog: In professional software engineering, code readability is paramount. Its importance is second to none.
When you’re evaluating a language, especially, it’s important to consider more than just whether the programming language is turing complete (or, more generally, whether it can do all the things you need it to). You should also consider how conducive the language is to being read or reviewed. Case in point: The snippet at the head of this article.
While you decipher it, I’ll give you a handy hint and note that the two brown wires coming in from the left are the outputs of a for loop, and that the first index of each one are equal (for those non-LabVIEW-programmers out there, these are analogous to arrays of tuples).
We can even look at the last paragraph: I had to describe variables as “the two brown wires.” As I describe this to you, the reader, I lack the ability to accurately describe variables without saying “this” and “that”. The first loop just splits “the brown wire coming from the bottom,” and passes it to the second loop (running it through “that” sub-VI in the middle) where “it” gets subtracted from the output of “that.”
Compare that to this code:
offset = max([y for (x,y) in values]) new_values = [(x,y - offset) for (x,y) in values] is_below_limit = all([y < limit for ((_, y), (_, limit)) in zip(values, limits)]) display_limit = [ (x, -20 if y < limit else -25) for ((_, y), (_, limit)) in zip(values, limits) ]
Or, if you prefer the iterative approach:
is_below_limit = True offset = max([y for (x,y) in values]) new_values =  display_limit =  for ((x,y), (limitx, limit)) in zip(values, limits): assert x == limitx new_values.append(y - offset) if y < limit: display_limit.append(-20) else: display_limit.append(-25) is_below_limit = False
Now we can speak using words. This code takes some X/Y values and normalizes them based on their maximum, comparing them against the limits (asserting that the Xs match, for good measure).
is_below_limit will reflect whether the values are, in fact, below the limit.
If you don’t know what a function does - say the
max function or the
append function - you can google “python max” or “python append” and arrive at the answer fairly quickly. “LabVIEW coffee cup VI” doesn’t get you anything useful.
I don’t mean this to excoriate graphical programming languages (or even LabVIEW) as a whole. But, in this instance, I happened across a perfect (extreme) example of unreadable code, and it so happens that it’s a good example of how choice of programming language can affect our code in ways beyond simply “can this programming language do what I need.”
This blog series updates every week at Programming for Maintainability