LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Coercion dots, do you even care in the "real" world (eg. you 'fix' them all)? Why or why not and when or when not?

Like many an eager young LV pupil, I was initially taught "coercion dot = BAD!!!".

 

After many years of LabView I lean the other way (eg. Coercion dots are much ado about nothing among professionals). After years of viewing code written by people that I considered far more advanced than myself, even pillars of this forum that we all know and acknowledge to be god-like experts, not bother with "fixing" coercion dots, at some point I too stopped bothering with thinking twice about them. And yet, I have never, NEVER, been bit a single time for not "fixing" one (which, is exactly what coercion does except in cases that only arise from other poor decisions or root causes). This further reinforces to me that coercion = shmoercion, who really cares? Noobs? Haha, right?

 

On the one hand it seems obvious to me that one should understand why there's a coercion of type, and there are times where that should alert you to something very bad, but in most cases it means you chose the wrong data type initially.

 

Now you might recall some physical catastrophe caused by such a programming error, but that's an argument for a more strict type system in Labview (ie. broken run arrow), and I'm not saying get rid of coercion dots, just wondering out loud whether the hoopla about them, the scarlet letter 'C' you are made to believe you will wear if you don't fix them, is possibly outdated. Remember how an error case structure around every VI used to be orthodoxy? How many years of cumulative developer time has been wasted on that? Seems sort of the same for coercion dots on mundane and inconsequential coercions. To say nothing about the additional clutter of explicit conversions wherever a coercion dot exists.

 

soooo... agree, disagree? Thoughts, comments? And be honest, in real life, do you actually consider code with scarlet dots unacceptable? I'll go microwave some popcorn and get my fire extinguisher in the meantime...

😉

0 Kudos
Message 1 of 15
(678 Views)

I tend to be pretty serious about avoiding coercion dots and they are set to be bright red. But I’m not fanatical about it. There are places where a coercion dot is evil and if I see them on such places I know the original programmer was a noob and would not hesitate to say so straight in their face.

 

-on an array, especially if it can get really large

- inside of loops that can run millions of times

- in FGA code if not carefully reviewed to be neccessary

 

Anything else such as small arrays and especially on scalars is usually harmless, but it doesn’t mean you should mix and match every possible datatype on a diagram, keep it consistent and if you see a diagram with more than a few coercion dots stop and think for a minute how to change it to avoid some of them. Sometimes it’s easy and changing one or two things can get rid of half a dozen or more coercion dots. But when you start to get one new coercion  for dvery one you can extinguish you reached the point where you have to stop. There is a good chance you implemented a rather bad algorithm too in such a case, but sometimes bad is good enough if it works (and you can proof it with unit tests). 😀

 

It all depends on what it is used for too. A one off test routine or proof of concept requires less perfection than a routine for an application! But if if is for a reuse library you need the highest perfection you can possibly handle!

 

”Fixing” coercion dots with an explicit conversion is usually not only nonsense but can be even harmful. In terms of performance it is the same extra overhead as the coercion dot you replace but in a diagram with shift registers or feedback nodes it can be very helpful if you can force the datatype to a specific type that might magically fix many coercions at once with a single conversion. Use of conversion nodes AWAYS should be deliberate and after serious consideration, NEVER just to fix a coercion dot!

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 15
(646 Views)

Why not start reading my discussion from 15 years ago 😄

 

Read the entire thread....

 

(Sometimes an explicit conversion is less efficient than a coercion dots)

0 Kudos
Message 3 of 15
(608 Views)

It's like the engine warning light on your car, sometimes it pops up because you need an oil change, other times it means you will soon need to re-build your entire engine. 

snip.png

hmm the snip does not capture the second coercion dot, curios. 

Screenshot 2024-10-12 at 10.25.22 AM.png

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 4 of 15
(603 Views)

Coercion dots are warnings.  That's how I treat them.  If I see one, I make sure that I understand why it's there.  I don't try to get rid of it unless keeping it would cause trouble.

0 Kudos
Message 5 of 15
(578 Views)

@DoctorAutomatic  a écrit :

Like many an eager young LV pupil, I was initially taught "coercion dot = BAD!!!".

 


This is why I always say that learning LabVIEW as the first programming language is not the best idea. It's better to learn a classical old-school typed language first, (where variables are required to have a declared type), and where you would get a normal warning in such cases:

 

Screenshot 2024-10-13 07.36.11.png

 

Personally, I have had a more or less "classical" education path: Fortran -> Pascal -> C -> ... and because of that, the question "What are coercion dots, why and how should I deal with them, etc?" has never been raised for me at all.

 

0 Kudos
Message 6 of 15
(551 Views)

A coercion dot is much better than a broken wire and chances are that LabVIEW knows what needs to be done and just tells you that something happened. Long ago, you had to take a wild guess, but now you can even hover over the coercion dot and it tells you want it got and what it actually wanted. (There are many exceptions where it does not work, but this was not possible at all in ancient version!).

 

As a result, we can often quickly patch something together and validate the correct result, then do cleanup, simplification and optimization  later. This is better than broken code because of a mismatch that does not really matter. (E.g. sometimes we see an orange shift register initialized with a blue zero, That zero could be blue because it started out as orange and the user typed a zero without a decimal point and it adapted to the entered data and the beginner has no idea what happened.)

 

I am always amazed to see really, really bad LabVIEW code that still works fine. 😄

0 Kudos
Message 7 of 15
(480 Views)

@altenbach  a écrit :

A coercion dot is much better than a broken wire and ...

I am always amazed to see really, really bad LabVIEW code that still works fine. 😄


Yes, agree. There are lot of discussions about weak vs strong typing as well as static vs dynamic... For me this puzzle was completed once I've touched Ada and Haskell and then the Rust programming languages. For more deep diving into theory I always recommend to read about Hindley-Milner which is an algorithm for inferring value types based on use. In general (in my humble opinion) the strong - typed language like Ada are not a "silver bullets" for "safe" code (on the other hand may be helpful for the cases like happened with Ariane flight V88), but the overall and correct algorithm for complete system is much more important (just remember incident with Boeing and MCAS), which can be technically correct also with "red dots" and could be completely wrong without any coercion.

0 Kudos
Message 8 of 15
(419 Views)

@rolfk wrote:

 

- in FGA code if not carefully reviewed to be neccessary

 


FPGA Coercion dots range from completely irrelevant (U8 to FXP +8,8) to very problematic (requiring both saturation and rounding logic).

 

I really wish we could have more differentiation between different types of coercion dot....

0 Kudos
Message 9 of 15
(417 Views)

My general take on coercion dots is that they are a warning. Many times, it just takes me changing the data type of an upstream constant or control. These I definitely take care of as it is a simple optimization. Every once in awhile, I run into a situation where the coercion is not what I need and so I have to explicitly coerce a value to the type I actually need. And then there are a lot of times where a coercion of some type is unavoidable. I tend to leave these coercion dots alone.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 15
(390 Views)