Thread: Multiple Files
View Single Post
  #4   Spotlight this post!  
Unread 29-03-2005, 11:47
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Multiple Files

Quote:
Originally Posted by Ewilliams2006
Can anyone explain what the benefit of multiple files is?
In a word organization...this was mentioned before, but I'll expand a bit....

There are 14185 lines written for the Wildstang robot (including comments, headers and some of the default ifi provided files) If we were to put this into a single file, it would quickly become unmanageable (not to mention uncompilable due to mcc18 limitations).

To make this more manageable, we have broken this into 33 C files and 26 H files. Each file contains functions and/or definitions for a specific portion of our robot.

For example, ws_drive_input.c handles joystick input as it relates to the drive train (i.e. left speed, right speed, shifter positions) as well as acceleration.

ws_lift.c handles joystick input as it relates to the lift (i.e. height, tilt, top/bottom spear positions).

As you can see, we have a naming convention for our files such that any custom code is prepended with a ws_. The names are also well named such that as long as you know what it is you're trying to accomplish, you should be able to determine which file to modify. For example, if you want to use tank steering instead of single stick, you could easilly tell you wouldn't want to modify ws_lift.c, but rather ws_drive_input.c.

The modularization of your code (i.e. multiple files) also allows more programmers to be involved. With this type of system, one person can go off and write lift code while another works on drive code. Since these modules are completely independent, there is no risk of duplicating effort.

All in all, making your programs modular will make your code more readable and maintainable.