ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Naming Convention for constants

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Naming Convention for constants

    Does anybody have a good naming convention for constants? I've used a prefix of const-, but I am open to something better.

    Code:
    01  const-Transfer            constant '1'. 
    01  const-Sale                constant '8'.

  • #2
    Re: Naming Convention for constants

    I use a suffix of uppercase characters, as its easier on my eyes. I try to avoid special characters in field names. This method also helps to identify data structures (input and output).

    TransferCONST

    SomeFileDS
    SomeFileDSI
    SomeFileDSO
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

    Comment


    • #3
      Re: Naming Convention for constants

      I use mixed case with my variable names. So if I have a constant I name the constant in all upper-case.

      Code:
           D SQLSUCCESS      c                   '00000'
           D SQLNODATA       c                   '02000'
           D SQLFILENOTOPEN  c                   '24501'
      as an example

      Comment


      • #4
        Re: Naming Convention for constants

        Never ever start variables or constant names with SQL, those names are reserved for the SQL Precompiler (for example for defining fields within the SQLCA or SQLDA). Eventhough there is today no field named SQLYourVar, IBM may enhands the data structures tomorrow and integrate a new subfields with exactly the name of your variable or constant.
        The "best" thing that can happen is that your program will no longer compile. If the compile won't fail it is even worse, because wrong information is moved to your or the SQL variables.

        Birgitta

        Comment


        • #5
          Re: Naming Convention for constants

          Was not aware of this. Thank you for the information and I'll share it with my group.

          Comment


          • #6
            Re: Naming Convention for constants

            To add to what Birgitta said, don't use identifiers that begin with SQ (which includes identifiers that begin with SQL), RDI or DSN.

            https://www-01.ibm.com/support/knowl...ajprpiamco.htm

            Comment


            • #7
              Re: Naming Convention for constants

              Funny how this discussion in the Cobol forum has somehow turned into an RPG discussion, including RPG sample code and a link to the "embedding SQL in ILE RPG" section of the Embedded SQL manual.

              Anyway, my opinion is to use ALL_UPPERCASE for constants, with underscores to separate words in the CONSTANT_NAME. I use this across all of the languages I work in (C, C++, Java, JavaScript, PHP, RPG, etc.) So I wouldn't like to put dashes or dots in the name, since only certain languages support these. Using all caps for constant names (with mixed case or lowercase for variables) seems to be the de-facto standard way of doing this across all languages, since you stt it everywhere you go.

              Comment


              • #8
                Re: Naming Convention for constants

                I agree. All uppercase for a constants. I even make things that aren't constants but are functioning as constants uppercase.

                This is an example.
                Code:
                       Dcl-Ds CARDTYPES Qualified;
                         AX Char(4) Inz('AMEX');
                         DI Char(4) Inz('DISC');
                         MC Char(4) Inz('MAST');
                         VI Char(4) Inz('VISA');
                         UNKNOWN Char(4) Inz('UNKN');
                       End-Ds; 
                
                       Dcl-Ds CARD LikeDs( CARDTYPES ) Inz( *LikeDs );

                Comment

                Working...
                X