BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Good Coding Practice

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:

 

 

Discussed here

 

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..

 

Download All
0 Kudos
Message 1 of 9
(13,263 Views)

@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.


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
Message 2 of 9
(13,258 Views)

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.  🙂

 

 

0 Kudos
Message 3 of 9
(13,255 Views)

@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)

0 Kudos
Message 4 of 9
(13,230 Views)

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).

 

0 Kudos
Message 5 of 9
(13,212 Views)

@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.


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 6 of 9
(13,204 Views)

@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)

 

Message 7 of 9
(13,195 Views)

How about this?

 

one way

 

edit: I think I've missed the point of the thread. Never mind.

0 Kudos
Message 8 of 9
(13,174 Views)

@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.

0 Kudos
Message 9 of 9
(13,147 Views)