4 Replies Latest reply: Jan 13, 2017 6:18 PM by Oleg Troyansky RSS

    Script Syntax Conventions

    Garrett Tedeman

      Hi all,

       

      Since I'm learning Qlik coming from a business intelligence background, but from another product, it's been really interesting to see how for lots and lots of different situations, Qlik experts have worked-out a number of best practices, or at least preferred approaches.  Could anyone comment if/whether they use these on their jobs or current projects?  Thanks!

       

      Some conventions found in QlikView Your Business, Qlik Sense Official Guide, etc. -- Any other good ones?:

      • Constant-type variables and/or conditional/boolean flags, etc. --->  Start name with "c" (e.g. "cSpeedofLight")

      • Normal, dynamic-type variables, such as looping variables, etc. (For Counter = 1 to 10), --->  Start name with "v"  (e.g. "vLoopCounter")

      • Measures or number-only variables --->  Start name with "#" (e.g. [# of Widgets Sold])

      • Key Fields --->  Start name with "%" (e.g. [%CustomerID])

      • ** Alternate start character for Flags --->  Start name with underscore "_" (e.g. "_cFlag1")
        • Re: Script Syntax Conventions
          Damian Waldron

          Hi Garrett,

           

          this thread could get very interesting.

           

          Tabs versus Spaces - YouTube

           

          My belief is that as long are you have conventions that promote software patterns and drive consistency you are on a great path.

           

          I have been using the following:

          Field Naming

          _ - System fields. i.e. flags or section access fields. e.g. _SECTIONACCCESS

          _ID - ID fields i.e. _IDEmployee

          m- expression fields i.e. mRevenue - however i have stopped doing this with sense because of the master library

           

          Table Naming

          FACT, EMPLOYEE - i like shouting when defining a table.

          tempFact - temp prefix for temporary tables

          mapCountryCode - map prefix for mapping loads

           

          Variable Definitions

          • c – Colours
          • d – Dates
          • m – Measures or alternatively e - Expressions
          • sa – Set Analysis
          • a – Application
          • t – Text
          • v – Generic I.e. Counters

           

          I also externally store variables in the following files.

          • Vars.Colours.csv – colour definitions
          • Vars.Measures.csv – measure definitions
          • Vars.Calendar.csv – date and period defintions
          • Vars.ETL.csv – ETL definitions
          • Vars.Text.csv – textual string definitions
          • Re: Script Syntax Conventions
            Oleg Troyansky

            Hi Garrett,

             

            thank you for reading and mentioning QlikView Your Business 0 I'm glad people are learning something from it...

             

            Here are my two cents about naming conventions:

             

            Fields:

             

            - Fields that are likely to be used a Dimensions (Customer, Product, Supplier) should be spelled in the most user-friendly way, with no special characters and no extra qualifiers. This is done to avoid renaming in the Layout.

             

            - Key fields are often being hidden, so it's good to settle on a single Hide Prefix in order to allow easy hiding. The commonly used "%" works just fine.

             

            - All other fields are likely to be used in Expressions. Since most developers prefer typing their expressions (as opposed to using drop-down lists) and relying on IntelliSense auto-completion functionality, it's handy to start them with a common character:

                - Starting all "measures" with the #-sign allows you to type # and get a short list of all "measures"

                - Starting all "Flags" with the underscore "_" allows you to type _ and get a short list of all flags.

             

            Variables:

             

            All variable names usually start with a lower case letter, followed by a camel-case field name. As a minimum, people use lower case "v" to differentiate variables from fields.

             

            Many developers use different prefix letters for different purposes - c for color, f for filters, e for expressions.

             

            Personally, I like to spell out the whole word instead of remembering what letter is used for what purpose. For example, "c" could be used for Color, or Condition, or Constant. You need to remember your abbreviation strategy...

             

            In my own practice, I use the following:

             

            color_Variable  - for colors

            exp_Variable - for expressions

            filter_variable - for Set Analysis filters

            fmt_Variable - for Format strings

            ...

            vVariable - for common, general use Variables, typically carrying a value rather than a formula.

             

            Cheers,

            Oleg Troyansky

            Upgrade your Qlik skills at the Masters Summit for Qlik - coming soon to Munich, Germany!

              • Re: Script Syntax Conventions
                Garrett Tedeman

                Hi Oleg,

                 

                Thanks for the informative reply, and of course, also for so much fantastic info. in QlikView Your Business.  Also, for any other readers/followers of this thread, I'd certainly add that the book is equally valuable, both QlikView and for those of us interested in Qlik Sense -- the key logic is the same, and equally applicable.

                 

                Cheers!

                 

                P.s.  Thought of one more yesterday:  The pipe-character ("|"), which seems to be the preferred special character to use for concatenating composite keys