Navs
Code Smells Catalog
Tramp Data

Last Revision — April 19, 2022

2 Min Read


  • Also Known As

    ---

  • Obstruction

    Data Dealers

  • Occurrence

    Data

  • Expanse

    Between Classes

  • Related Smells

    - Message Chain (family)
    - Long Parameter List (co-exist)
    - Dubious Abstraction (co-exist)
    - Global Data (antagonistic)

  • History

    Steve Smith in course (2013): "Refactoring Fundamentals"

    Steve McConnell in book (1993): "Code Complete"

Tramp Data

This is very similar to the Message Chains code smell, but with the difference that there, the pizza supplier was ordered to go through a long chain of method calls. Here, the pizzeria supplier additionally delivers "pizza" through that long chain of method calls, with "pizza" present in each of the method parameters. This is an indicator of Dubious Abstraction code smell - the data that pass through long chains of calls, most likely at least one of the levels, are not consistent with the abstraction presented by each of the routine interfaces. [1]

Causation

This can happen due to a cheap way of Global Data code smell refactorization.

Problems

Law of Demeter Principle Violation

The functionality should be as close to the data it uses as possible. This doesn't seem to be the case when Tramp Data is present.

Examples

Smelly


class Game:
    timer: int
    match: Match

    def start_turn():
        match(timer).field(timer).players(timer).troops(timer)

Refactoring:

  • Extract Method
  • Hide Delegate
  • Move Method

Exceptions

In the context of the system as a whole, some communication between modules must take place. All possibilities should be properly balanced so that none of the smells dominate (Global Data, Tramp Data, Message Chain, Middle Man) to make the entire codebase as straightforward as possible.


Sources
  • [1] - Steve McConnell, "Code Complete" (2004)
  • [Origin] - Steve Smith, "Refactoring Fundamentals" (2013)
  • [Parentage] - Steve McConnell, "Code Complete" (1993)