Go to Post We have not always been a winning team but we have always tried to be a quality team. - WynS [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-11-2011, 09:43
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 747
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Re: How to go from simple working code to professional code

I agree with most of the comments here, but I'm very surprized that noone has mentioned SubVIs (OK, sorry, a small mention .

If you have a large program that is starting to fill the screen, the BEST way that I know to simplify it is to start thinking of which parts could be best moved into a SubVI.

I beleive that moving from one large program into a programming structure that uses smaller, smarter components is the KEY step which differentiates a "rookie" programmer from a "professional" programmer.

The main reason is that creating good SubVis, or Subroutines, or Libraries requires a certain abount of forethought and planning. Developing your own set of "rules" for this is a real growth experience.

But... for somone just getting started, there are probably two easy ways to know when to create a SubVI:

1) Do you find yourself cutting and pasting code? If so, then STOP! and create a SubVI to embody the function that you are duplicating. Figure out what is common in every copy you were creating and what was changing. Put the common parts in the SubVI, and make the changing parts inputs to the SubVI. LabVIEW makes it very easy to create SubVIs. Just rubber-band ther parts that don't change and select... Edit/Create SubVI. Once you have one, personalize it with your own custom Icon and don't forget to add a description.

2) When you find yourself making one section of your program more and more complicated, to the point where you are moving things around to make space for it..... STOP!, and put that functionality into a SubVI. This way the overall program can stay simple, and the complexity can be hidden in the SubVi .. Then when you need to change the complax part, just drill into the SubVI.

Phil.
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor

Last edited by PhilBot : 17-11-2011 at 10:00.
Reply With Quote
  #2   Spotlight this post!  
Unread 17-11-2011, 10:29
Boydean's Avatar
Boydean Boydean is offline
The Blue Alliance
no team
Team Role: Alumni
 
Join Date: Apr 2007
Rookie Year: 2003
Location: SC
Posts: 319
Boydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant futureBoydean has a brilliant future
Send a message via AIM to Boydean
Re: How to go from simple working code to professional code

I have little experience with Labview but this subject interests me, and a lot of this advice can be applied to other areas of software development.

Echo what is being said above. Simplify. If something is too complex to explain in plain english then you need to break it down more (more SubVis).

Your code (or blocks) should be explicit as possible. Variables should state what its used for in plain english. Remember that code is read more then it is written – so take the time to actually type "map" and not something like "mp". You ain't special for naming something other people won't understand.

Functions and methods (SubVis) should state what they do in plain english. Use verbs and nouns if the function does something. Example "set_motor_speed" vs "motor_speed".

Comments. Abusive commenting is abusive to the reader. No one wants to read an entire paragraph of comments in the middle of some code. Changing focus from reading coding to interrupting comments with code is annoying. If your code is explicit enough then comments should only be used to explain why you are doing something.

Bad:
Code:
// Set motor speed to 0.5.
set_motor_speed(0.5);
Good:
Code:
// Anything greater then 0.5 will destroy our arm. Monkeys are awesome. – @brandondean Nov 17
set_motor_speed(0.5);
EDIT: Global variables are bad. Don't use them. Although, if I recall correctly with Labview this is unavoidable...I think.
__________________

Last edited by Boydean : 17-11-2011 at 10:41. Reason: ninja edit
Reply With Quote
  #3   Spotlight this post!  
Unread 17-11-2011, 23:00
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: How to go from simple working code to professional code

Quote:
Originally Posted by Boydean View Post
Global variables are bad. Don't use them. Although, if I recall correctly with Labview this is unavoidable...I think.
I agree with everything in the post, except for the global part. I'm not going to claim globals are the best overall mechanism for sharing data, but they have their place, they are simple to understand, and that makes them a reasonable place to start out. This is why they are used in the LabVIEW template code.

Just to be clear, LV has many other data sharing mechanisms, and it is not necessary to use globals. If you feel that you are ready for it, read up on queues, notifiers, rendezvous, occurrences, or perhaps the RT FIFO. Finally, the sharing I personally use the most often is the functional global -- a custom subvi critical section wrapper with just the read and write operations I need. You may be tempted to use events because you have heard about them elsewhere, but since they are primarily for UI operations, they are not appropriate for RT, and the notifier or FIFO is the equivalent choice.

Greg McKaskle
Reply With Quote
  #4   Spotlight this post!  
Unread 17-11-2011, 23:33
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,100
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to go from simple working code to professional code

Quote:
Originally Posted by Boydean View Post
EDIT: Global variables are bad. Don't use them.
I realize that statement was made in the context of FRC and LabVIEW, but in case a reader might think it is a universal principle it should be noted that there are contexts in which it is not true.

Global variables are often indispensable for software for high-volume automotive applications with penny-pinching hardware. If managed meticulously, they can be essential for a successful product.


Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 20:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi