Tramp Variables Posted by: Jordan in Object Oriented Programming on
I was reading an OOP design pattern book and it mentioned creating Tramp Variables.  This was the first time I'd heard this particular term used to describe a function variable and it actually made me laugh.  I did a search on google for "Tramp Variable" and couldn't find anything relating to what I'm fixing to write so this term must be relatively new, extremely old (and unused), or something the author of the book made up. 

Anyway, we should start by defining a tramp.  Wikipedia describes it as this:

... a tramp is a long term homeless person who travels from place to place as an itinerant vagrant, traditionally walking or hiking all year round. They often left chalk signs on houses or at various points along their traditional routes. They also developed a slang language of their own.


Reading the definition above it is easy to deduce what a tramp variable is:  a variable that is passed from function to function to function. 


 
  1. function someFunc(int var) {
  2.       // Some Code Here
  3.       someFunc2(var);
  4. }
  5.  
  6. function someFunc2(int var) {
  7.    // some code.....
  8. }
  9.  
  10.  
  11. void main() {
  12.       int myVar = 2;
  13.       someFunc(myVar);
  14. }



A tramp variable is not a good thing.  You can avoid it using certain design patterns and if you find yourself creating a bunch of tramps, you may want to reconsider you code! 

If you've heard this term before, post what you know! 

Trackback(0)
feed1 Comments
WingedPanther
October 12, 2008
4.152.204.197
Votes: +0

I hadn't heard that term before, but it reminds me of some of my VERY bad early coding on a Yahtzee/Triple Yahtzee program I wrote in Pascal. I had variables bouncing all over the place due to stupid design decisions. Of course, I shudder at a lot of my early code smilies/smiley.gif

report abuse
vote down
vote up

Write comment
 
 
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger
 

security image
Write the displayed characters


busy