The International Simutrans Forum


Author Topic: Code quality: Unify variable names  (Read 1166 times)

0 Members and 1 Guest are viewing this topic.

Offline Spike

  • *
  • Posts: 1361
  • First Simutrans Developer and Graphics Artist
Code quality: Unify variable names
« on: February 27, 2012, 03:02:53 PM »
Some classes have variables of the same purpose, but all with different names. I suggest to unify the names.
From hausbauer_t:

Code: [Select]
 * Diese Tabelle ermöglicht das Auffinden einer Beschreibung durch ihren Namen
static stringhashtable_tpl<const haus_besch_t*> besch_names;

From tunnelbauer_t:

Code: [Select]
static stringhashtable_tpl<tunnel_besch_t *> tunnel_by_name;

From brueckenbauer_t:

Code: [Select]
static stringhashtable_tpl<const bruecke_besch_t *> bruecken_by_name;

From vehikelbauer_t:

Code: [Select]
static stringhashtable_tpl<const vehikel_besch_t*> name_fahrzeuge;

From warenbauer_t:

Code: [Select]
stringhashtable_tpl<const ware_besch_t *> warenbauer_t::besch_names;

From wegbauer_t:

Code: [Select]
static stringhashtable_tpl <const weg_besch_t *> alle_wegtypen;

These variables all serve the same purpose - to hold all besch_* objects of this one type, and allow to look them up by name. So they should be named very similar like "all_abc_by_name" with abc being the type of object stored. This would help a code reader to understand that these variables are functionally equivalent.

At the moment there are three naming schemes in 5 classes being used for the same thing.

Also, only one has a comment that explains what it does. (Assuming a code reader can read german).

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9565
  • Languages: De,EN,JP
Re: Code quality: Unify variable names
« Reply #1 on: February 27, 2012, 08:10:04 PM »
Sound very reasonable ...