Just wondering...how do you names your set ?
Just wondering...how do you names your set ?
TItem = (one, two)
TItems = set of TItem;
or
TItems = (one, two)
TItem = set of TItems;
I'm always troubled by TTextFormat(s) for instance
TItem = (one, two)
TItems = set of TItem;
or
TItems = (one, two)
TItem = set of TItems;
I'm always troubled by TTextFormat(s) for instance
I always use the former.
ReplyDeleteNaming logic is following: enumeration variable always holds single value therefore its type should be in singular form. Set can hold multiple values so it is logical that its type is in plural form.
TTextFormat is a bit confusing.
I have to emphasize that I am not native English speaker, so what makes sense to me does not have to be correct from the language perspective.
I guess that for a native English speaker (or at least the guy who created TTextFormats) TTextFormats is a list of text formats, so they are multiple values and should be pural...but then TTextFormat should have been called TTextFormatsCollection for instance (TCanvasState use also the same convention)
ReplyDeletePaul TOTH But each item in a list of text formats is text format, so still does not make sense.
ReplyDeleteIt probably comes from Windows DrawText function declaration
int DrawText(
HDC hdc,
LPCTSTR lpchText,
int cchText,
LPRECT lprc,
UINT format
);
format - The method of formatting the text. This parameter can be one or more of the following values...
Here parameter format is represented as unsigned integer and not as some set type, so using format was logical although it can hold multiple - combined values - set. It could be named formats just as well.
I have a fairly standard naming convention:
ReplyDeleteType
TTextFormat ( tfNormal, tfHighlight,...);
TTextFormats = set of TTextFormat;
I am also not scared of doing my own enumeration that are then mapped onto specific integer constants (say, for example, Windows APIs).
In other words, I make my own life easier by not necessarily mirroring what I am using but by making my own conventions that work for me in the project.
TItem and TItemSet
ReplyDeleteA spade is a spade.
TItems =TArray;
For me
ReplyDeleteTItemNumber=(un,deux);
TItemNumberSet=set of TItemNumber;
Lars Fosdal I actually have both TItems and TItemSet. Depends on the type purpose and whether having array makes sense.
ReplyDeleteI always append "Set" to the set type.
ReplyDeleteAs an example:
ReplyDeletetype
TSyntaxLink = (slXXX, slYYY, slZZZ, ...);
TSyntaxLinks = set of TSyntaxLink;
TSyntaxLinksArray = array of TSyntaxLink;
const
SpecialLinks: array[0..3] of TSyntaxLink = (slYYY, ...);
var // local variables inside a method
currLink: TSyntaxLink;
selLinks: TSyntaxLinks;
procLinks, newLinks, links: TSyntaxLinksArray;
iprocLinks: TSyntaxLink; // index for procLinks array
etc.
Actually, I don't use TItems for type plurality, but TItemList, TItemArray, etc. Plural variable names can end in an s, though.
ReplyDeleteLars Fosdal Actually, I use those, too. I am not very consistent and naming is hard :P
ReplyDeleteDitto for adding the "set" to the set type
ReplyDeleteMe too. I also add "Set" to the set type.
ReplyDeleteIf the occurence of only single values makes no sense you can still do:
ReplyDeleteTSomething = set of (one, two, three);
I have been creating a complete mess of plural s:es during 30 years of coding. I do much more XxxxSet, XxxxArray than Xxxxs starting now. Thanks.
ReplyDelete