From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Type naming conventions: Any_Foo
Date: Fri, 6 Dec 2019 23:55:59 +0200
Date: 2019-12-06T23:55:59+02:00 [thread overview]
Message-ID: <h5013fFua8dU1@mid.individual.net> (raw)
In-Reply-To: <qsecl2$6t8$1@dont-email.me>
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
. @ .
next prev parent reply other threads:[~2019-12-06 21:55 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-04 13:56 Type naming conventions: Any_Foo Alejandro R. Mosteo
2019-12-04 14:52 ` Lucretia
2019-12-04 16:42 ` Alejandro R. Mosteo
2019-12-05 10:51 ` AdaMagica
2019-12-05 17:27 ` Jeffrey R. Carter
2019-12-05 17:45 ` Dmitry A. Kazakov
2019-12-05 20:03 ` Jeffrey R. Carter
2019-12-05 21:51 ` Dmitry A. Kazakov
2019-12-05 23:12 ` Randy Brukardt
2019-12-06 20:20 ` Jeffrey R. Carter
2019-12-07 1:19 ` Randy Brukardt
2019-12-06 20:18 ` Jeffrey R. Carter
2019-12-06 20:35 ` Dmitry A. Kazakov
2019-12-07 0:57 ` Randy Brukardt
2019-12-07 10:28 ` Jeffrey R. Carter
2019-12-07 12:36 ` Niklas Holsti
2019-12-08 12:04 ` Jeffrey R. Carter
2019-12-07 10:13 ` Jeffrey R. Carter
2019-12-07 11:21 ` Dmitry A. Kazakov
2019-12-08 11:55 ` Jeffrey R. Carter
2019-12-08 12:38 ` Dmitry A. Kazakov
2019-12-08 14:31 ` Shark8
2019-12-08 21:58 ` Jeffrey R. Carter
2019-12-09 22:47 ` Shark8
2019-12-07 23:24 ` Jere
2019-12-08 12:14 ` Jeffrey R. Carter
2019-12-09 22:07 ` Randy Brukardt
2019-12-05 19:49 ` Niklas Holsti
2019-12-05 20:47 ` Jeffrey R. Carter
2019-12-05 21:33 ` Niklas Holsti
2019-12-06 11:44 ` Lucretia
2019-12-06 20:23 ` Jeffrey R. Carter
2019-12-06 20:11 ` Jeffrey R. Carter
2019-12-06 20:46 ` Dmitry A. Kazakov
2019-12-06 21:55 ` Niklas Holsti [this message]
2019-12-07 10:19 ` Jeffrey R. Carter
2019-12-07 12:05 ` Niklas Holsti
2019-12-08 11:59 ` Jeffrey R. Carter
2019-12-06 8:57 ` AdaMagica
2019-12-06 9:55 ` J-P. Rosen
2019-12-06 15:30 ` Optikos
2019-12-07 3:34 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox