09-20-2012 07:10 AM - edited 09-20-2012 07:15 AM
The idea behind this thread came up as a code sample that I posted as a potential Rube Goldberg code was actually one that touched the topic of good coding practice.
This was the snippet in question:
With a reference to an openG solution here
And a suggestion from Altenbach that would result in the following snippet:
Resulting in the following version of the openG RNG: The control should read "High-1". Or should it say "High+1", since 1000 would result in a range from 0 - 999. So high being 999, High+1 would be 1000. Humm... I wonder if that name would cause confusion..
09-20-2012 07:28 AM
@Ray.R wrote:
Resulting in the following version of the openG RNG: The control should read "High-1". Or should it say "High+1", since 1000 would result in a range from 0 - 999. So high being 999, High+1 would be 1000. Humm... I wonder if that name would cause confusion..
Ummm...the OpenG code has a +1 in there. So it is named correctly.
09-20-2012 07:43 AM - edited 09-20-2012 07:51 AM
You are right.. I was referring to the name in my snippet.
I should have kept reading further down from the original post. (Left my reading glasses at home... should prove to be an interesting day)
Here is the one from openG. I like the idea that it has the +1 built-in.
To avoid naming confusion with my snippet, the code becomes:
I also like the polymorphic capability from VI at the bottom of the page from LAVA.
However, let's keep the discussion on how to better write code, which is what I have learned in this thread. 🙂
09-20-2012 10:47 AM - edited 09-20-2012 11:02 AM
@Ray.R wrote:
And a suggestion from Altenbach that would result in the following snippet:
This code is still potentially incomplete, because you do not always get a 4 digit number (sometimes it is less than four digits). You should format using "%04d" instead if that is a concern. Now the output is always four digits in the range 0000-9999.
(It is interesting that the rounding operations don't allow output configuration. Since the output is actually always a whole number, an output configuration to a desired integer data type seems useful. I see an idea coming. :D)
09-20-2012 01:05 PM - edited 09-20-2012 01:09 PM
Yes, it would be great if we could format the numeric to string functions.
Something like this:
The other thing that would be nice is if the numeric functions like add, subtract, multiply & divide were polymorphic and automatically adapted to the representation that is wired into them. It would save one step by converting to the proper representation. It might also cause people to forget the importance of the proper representations.. Well... there's probably enough casting going on out there to justify it. The representations could be set in the property screen for each input and the output. (ie: DBL + INT32 = EXT).
09-20-2012 01:16 PM
@Ray.R wrote:
Yes, it would be great if we could format the numeric to string functions.
Something like this:
Put that in the Idea Exchange. I'll be more than happy to give it a KUDO. In the mean time, use Format String. You could put in a 4 for the width, but unfortunately it puts in spaces. For what reason? I don't know. I almost always want to pad with zeros.
09-20-2012 02:06 PM - edited 09-20-2012 02:06 PM
@Ray.R wrote:
Yes, it would be great if we could format the numeric to string functions.
It is called "format value" and is in the same palette. (They currently don't accept arrays, but that's why this idea exists. :D)
09-20-2012 07:22 PM - edited 09-20-2012 07:25 PM
How about this?
edit: I think I've missed the point of the thread. Never mind.
09-21-2012 07:49 AM - edited 09-21-2012 07:49 AM
@altenbach wrote:
It is called "format value" and is in the same palette. (They currently don't accept arrays, but that's why this idea exists. :D)
I need to use that function more often. Dunno why I left it alone... Maybe because you can't wire an array to it.. 😄
This thread is already useful.