Difference between revisions of "Talk:Record"

From Free Pascal wiki
Jump to navigationJump to search
(→‎Record: Variable structure: sign previous comment; add reply)
Line 19: Line 19:
 
# Also it's good practice to prefix your enumerated type identifiers like: <code>bsSolid, vk_Escape, pf32bit</code>. Why not show good programming style to new users?
 
# Also it's good practice to prefix your enumerated type identifiers like: <code>bsSolid, vk_Escape, pf32bit</code>. Why not show good programming style to new users?
 
# There is nothing ''simple'' in not using the last mentioned point. Instead, this would improve the readibility of the code - that is simple.
 
# There is nothing ''simple'' in not using the last mentioned point. Instead, this would improve the readibility of the code - that is simple.
 +
 +
<small>—&nbsp;Preceding unsigned comment added by [[User:Crore|Crore]] ([[User talk: Crore#top|talk]] • [[Special:Contributions/Crore|contribs]]) 2020-07-29T16:46:15</small>
 +
: Parentheses <syntaxhighlight lang="pascal" inline>(…)</syntaxhighlight> don’t delimit a ''set'', but in this case an ''enumeration'' type definition.
 +
:#Actually, I didn’t notice that. I have protanopia (red-green color blindness) and red is the worst color for highlighting. Anyways, <syntaxhighlight lang="delphi" inline>single</syntaxhighlight> is a Borland Pascal extension. The fact that GeSHi apparently colors this identifier differently doesn’t make it “more” Pascal-ish, nor is it any kind of special.<br/>It is good practice to name identifiers in a straightforward manner, no negations and no ingenious synonyms just to avoid name clashes. There is a sophisticated scoping system in place, so use it.<br/>I adapted this example from a (20+ year old) Pascal book. We may of course use a different example which still many people understand, i. e. ''why'' it is designed like ''that'': I assume all people understand you’re either single, married, widowed or divorced. If you have a just as good example, don’t hesitate to insert it instead.
 +
:#Au contraire, I would recommend to use <syntaxhighlight lang="pascal" inline>real</syntaxhighlight> as much as possible. It is defined by Pascal thus ''guaranteed'' to be available with ''every'' compiler. I would hard-code the floating-point number’s precision (i. e. use <syntaxhighlight lang="delphi" inline>single</syntaxhighlight>) only if I knew I required ''precisely reproduceable'' results across various platforms (e. g. some statistics application).
 +
:#Please don’t resort to whataboutism. The given examples are considered to be correct in their own right.
 +
:#''Manually'' prefixing identifiers is actually a ''terrible'' practice, especially in a cryptic manner like that: There is <syntaxhighlight lang="pascal" inline>{$scopedEnums on}</syntaxhighlight> which will ''automatically'' prepend the type’s name. However, this is “kind of” an advanced topic, so I wouldn’t like to clutter examples about ''record'' type definitions with details about enumeration type definitions, so it’s better to show a straightforward implementation of a <syntaxhighlight lang="pascal" inline>person</syntaxhighlight> record and not bother about that.
 +
: [[User:Kai Burghardt|Kai Burghardt]] ([[User talk:Kai Burghardt|talk]]) 18:15, 30 July 2020 (CEST)

Revision as of 18:15, 30 July 2020

Concerning the variant record example. The last bit reads: "It doesn't harm, whether the field marriageDate ist defined multiple times."

I cannot get FPC (3.0.0) to compile TPerson specifically because of the "Duplicate identifier "marriageDate"" error. Could you show us how it's done? the previous unsigned message was made by Finchley on 2017-07-09T13:42:25Z

True dat. Kai Burghardt (talk) 23:02, 11 February 2018 (CET)

Record: Variable structure

Single was used as identifier in a set! This is not recommended in Pascal. So I changed all identifiers in set 'maritalStates' to be prefixed with 'ms_'.

Response from User:Kai_Burghardt for undoing this change: keep it simple [and Pascal does not define “single”, so there’s no reason not to name an identifier like that]

  1. Take a look at Record#Variable_structure and you notice that single is colored red. So this item has a meaning in pascal formatting. This is not good in an example, because noone should wonder why a maritalState is related to ObjectPascal.
  2. Take a look at Data_type#Floating-point_types: in freepascal real is platform dependent. I would not recommend to use it. In the whole unit math you wouldn't find any real. Also Single is defined in fpc/3.0.4/source/rtl/win64/system.pp according to Lazarus hint, although you are free to redefine it as it is done here. Also not good in an example. And then you should at least mention it.
  3. If you paste the example in a new application and define somewhere:
    Income : Single;
    
    the user gets: Error in type definition. Why would you introduce a source of unexplainable errors to new users?
  4. Also it's good practice to prefix your enumerated type identifiers like: bsSolid, vk_Escape, pf32bit. Why not show good programming style to new users?
  5. There is nothing simple in not using the last mentioned point. Instead, this would improve the readibility of the code - that is simple.

— Preceding unsigned comment added by Crore (talkcontribs) 2020-07-29T16:46:15

Parentheses () don’t delimit a set, but in this case an enumeration type definition.
  1. Actually, I didn’t notice that. I have protanopia (red-green color blindness) and red is the worst color for highlighting. Anyways, single is a Borland Pascal extension. The fact that GeSHi apparently colors this identifier differently doesn’t make it “more” Pascal-ish, nor is it any kind of special.
    It is good practice to name identifiers in a straightforward manner, no negations and no ingenious synonyms just to avoid name clashes. There is a sophisticated scoping system in place, so use it.
    I adapted this example from a (20+ year old) Pascal book. We may of course use a different example which still many people understand, i. e. why it is designed like that: I assume all people understand you’re either single, married, widowed or divorced. If you have a just as good example, don’t hesitate to insert it instead.
  2. Au contraire, I would recommend to use real as much as possible. It is defined by Pascal thus guaranteed to be available with every compiler. I would hard-code the floating-point number’s precision (i. e. use single) only if I knew I required precisely reproduceable results across various platforms (e. g. some statistics application).
  3. Please don’t resort to whataboutism. The given examples are considered to be correct in their own right.
  4. Manually prefixing identifiers is actually a terrible practice, especially in a cryptic manner like that: There is {$scopedEnums on} which will automatically prepend the type’s name. However, this is “kind of” an advanced topic, so I wouldn’t like to clutter examples about record type definitions with details about enumeration type definitions, so it’s better to show a straightforward implementation of a person record and not bother about that.
Kai Burghardt (talk) 18:15, 30 July 2020 (CEST)