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

Comments

  1. I always use the former.

    Naming 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.

    ReplyDelete
  2. 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)

    ReplyDelete
  3. Paul TOTH But each item in a list of text formats is text format, so still does not make sense.

    It 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.

    ReplyDelete
  4. I have a fairly standard naming convention:

    Type

    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.

    ReplyDelete
  5. TItem and TItemSet
    A spade is a spade.

    TItems =TArray;

    ReplyDelete
  6. For me
    TItemNumber=(un,deux);
    TItemNumberSet=set of TItemNumber;

    ReplyDelete
  7. Lars Fosdal I actually have both TItems and TItemSet. Depends on the type purpose and whether having array makes sense.

    ReplyDelete
  8. As an example:
    type
    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.

    ReplyDelete
  9. Actually, I don't use TItems for type plurality, but TItemList, TItemArray, etc. Plural variable names can end in an s, though.

    ReplyDelete
  10. Lars Fosdal Actually, I use those, too. I am not very consistent and naming is hard :P

    ReplyDelete
  11. Ditto for adding the "set" to the set type

    ReplyDelete
  12. Me too. I also add "Set" to the set type.

    ReplyDelete
  13. If the occurence of only single values makes no sense you can still do:

    TSomething = set of (one, two, three);

    ReplyDelete
  14. 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

Post a Comment