From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Type naming conventions: Any_Foo Date: Fri, 6 Dec 2019 23:55:59 +0200 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net XMh81+wgs9Dpzr3Z53RmAQYIeN8WyENiyldp7lbuNHl3n+MlgZ Cancel-Lock: sha1:qf3iYeknQN4n0xQ4msjxSuWdue8= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57678 Date: 2019-12-06T23:55:59+02:00 List-Id: On 2019-12-06 22:11, Jeffrey R. Carter wrote: > On 12/5/19 10:33 PM, Niklas Holsti wrote: >> >> But if a value of the type Weapon_Id is an identifier of a Weapon, how >> can you defend saying >> >>     Weapon : Weapon_Id; >> >> The variable Weapon does not represent a Weapon; it represents an >> identifier of a Weapon, so the name Weapon is IMO a little misleading. > > Obviously there are no weapons in the S/W; there are only bit patterns > that you have decided to interpret in various ways. But if you're > modeling the problem space and it contains something called Weapon, then > your software had better have something named Weapon it in, too. Agreed. > I would probably write something like > > type Character_Info is record >    ... >    Available_Weapons : Weapon_Lists.Vector; >    Current_Weapon    : Positive; >    ... > end record; > > but it sounds as if you think those fields should be named Vector and > Positive. No, no, when a variable or component has a specific role, such as being the "current weapon", this role should be reflected in the chosen identifier, here Available_Weapons and Current_Weapon. The problem with having to distinguish variable/component names from type names arises only for variables/components that do not have such specific roles. For example: function Is_Lethal (Weapon : Weapon_T) return Boolean; The ARM often uses "Item" for such subprogram parameters, but that fails when there is more than one (or if the type is called "Item"...). Unfortunately, such non-specific cases are not rare, and new ones come up during SW development and evolution, so it feels safer to prepare for them by avoiding such identifier conflicts, for example by the "_T(ype)" suffix on type names. Some people have suggested decorating the variable/component name instead of the type name, for example function Is_Lethal (The_Weapon : Weapon) return Boolean but (as you say) such prefixes are worse than suffixes. I have also seen coding rules that require specific suffixes on formal parameters, such as: function Is_Lethal (Weapon_P : Weapon) return Boolean; but they tend to also require suffixes (like "_T") on type names, so there were are again. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .