What are the coding standards that must be followed while writing a TDL Code?

Discussion in 'Tally Developer' started by admin, Jan 24, 2013.

Thread Status:
Not open for further replies.
  1. admin

    admin Administrator Staff Member

    Coding Standards

    1.All the Definitions should be indented to the right except the Report, Form and Initial Parts within the Form

    The Definitions Report, Form and initial Parts within the Form need not be indented. All the further Definitions like Sub Parts, Lines & Sub Lines and Fields & Sub Fields including Optional Definitions must be indented to the right.

    For Example:

    [Report: {Report Name}]

    Form : {Form Name}

    [Form: {Form Name}]

    Parts : {Part Name 1}, {Part Name 2}

    [Part: {Part Name 1}]

    Lines : {Line Name 1}, {Line Name 2}

    [Line: {Line Name 1}]

    Fields : {Field Name 1}
    Switch : {Label}:{Optional Line Name 1}: {Condition}

    [Field: {Field Name 1}]

    Set As : {Contents of Field 1}

    [!Line: {Optional Line Name 1}]

    Add : Field : {Field Name 2}

    [Line: {Line Name 2}]

    Fields : {Field Name 2}

    [Field: {Field Name 2}]

    Set As : {Contents of Field 1}

    [Part: {Part Name 2}]

    Parts : {Part Name 21}, {Part Name 22}

    [Part: {Part Name 21}]

    Lines : {Line Name 1}

    [Part: {Part Name 22}]

    Lines : {Line Name 2}

    2.Assign Meaningful Names to Definitions, UDFs, Variables & Formulae and use appropriate Prefix to avoid unnecessary clash with Default Definition Names

    As far as possible, avoid using names like ABCField. Definition Names must clearly indicate their purpose or usage.

    Also, we must use appropriate Prefix to avoid unnecessary clash with the Default Definition Names.

    For example:

    /* Line & Field Definition for Bank Account No. of the Party is being added for the Company/ Client, Global Marketing Pvt Ltd. (GMPL can be used as a Prefix) */

    [Line: GMPL Bank Acct No]

    [Field: GMPL Bank Acct No]

    [Collection: GMPL List of Ledgers] ;; Collection Definition for List of Ledgers

    [System: Variable]

    Variable : GMPL Only Ledgers : Logical : No ;;; Include Groups

    3.As much as possible, align the colons among all the attributes within a definition

    The Colons among the attributes within a definition must be properly aligned for better readability.

    For Example:

    [Menu: DevpLang]

    Indent : "Basics of TDL"
    Item : Blank

    Key Item : "Language Components" : L : Menu: TDL Language Components
    Key Item : "Symbols & Prefixes" : S : Menu: Symbols and Prefixes
    Key Item : "Dimensions & Formatting" : D : Menu: Dimensions and Formatting
    Item : Blank

    [Form: Bottom Parts within Form]

    Parts : Default Dimensions
    Bottom Parts: BPWF Bottom Part
    Height : 50% Page
    Width : 50% Page
    Local : Field : Default Dimensions : Set as : "Sample code"

    4.Appropriate Case must be maintained –

    a.Logical Operators and Action Keywords need to be written in UPPER case

    The Logical operators AND & OR and Actions like DISPLAY, CREATE, ALTER, CALL must be in UPPER CASE.

    b.Keywords must be written in Sentence case

    Keywords like If, Then, Else must be in Sentence case.

    c.All others must be in Proper Case

    All others including Definition Names, Attributes & their Values must be specified in Proper Case.

    5.Maintain the following order of attributes –

    a.If a definition is re-used using Attribute Use, it must be the first attribute.

    For example:

    [Report: GMPL Trial Balance]

    Use : DSP Template
    Form : GMPL Trial Balance
    b.Subsequent attribute used must be the Main Container of the Definition

    For example:

    [Form: GMPL Trial Balance]

    Use : DSP Template
    Part : GMPL Trial Balance

    [Collection: GMPL Ledgers]

    Use : Alias Collection
    Type : Ledger
    Height, Width, Style, and other dimensional as well as formatting attributes can follow.

    c.All the Options/ Switches can follow subsequently after an empty line.

    For example:

    [Field: GMPL Particulars]

    Use : DSP Template
    Set As : $Name

    Switch : GroupLedger : CS Groups : $$IsGroup
    Switch : GroupLedger : CS Ledgers : $$IsLedger

    [!Field: CS Groups]

    Variable : Group Name
    Display : Group Summary

    [!Field: CS Ledgers]

    Variable : Ledger Name
    Display : Ledger Vouchers

    [Collection: CS Ledger]

    Use : Alias Collection
    Type : Ledger
    d.The Order in which attributes must appear in a Summary/ Extract Collection definition is as listed below:

    For example:

    [Collection: GMPL Vch Summary Collection]

    Source Collection : GMPL Vch Source Collection
    Walk : Inventory Entries

    By : PartyLedgerName: $..PartyLedgerName
    By : StockItemName : $StockItemName

    Aggr Compute : GMPLTotalQty : SUM : $BilledQty
    Aggr Compute : GMPLMaxQty : MAX : $BilledQty
    Aggr Compute : GMPLMinQty : MIN : $BilledQty

    Compute : StockGroup : $Parent:StockItem:$StockItemName
    Fetch : Date, VoucherNumber
    /* The above Fetch is meaningful if Grouping of Objects is not done which means if the Source Object Context were intact or to contain the first value */

    Search Key : $PartyLedgerName + $StockItemName
    Keep Source : ().

    Filter : GMPL Item Filter
    Sort : Default : $PartyLedgerName

    6.Coding Standards to be followed while defining a Procedure/ Function:

    a.The Order in which attributes must appear in a Function definition is as listed below:

    For example:

    [Function: GMPL Simple Interest Calculator]

    ;; Definition Block

    Parameter : P : Amount
    Parameter : R : Number
    Parameter : N : Number : 10
    Returns : Amount

    Variable : Interest : Amount

    Local Formula : Interest Calc : (##P * ##N * ##R) / 100

    ;; Procedural Block

    00 : SET : Interest : @InterestCalc
    10 : RETURN : ##Interest
    b.Right Indent the Actions within a loop. In other words, the Action which contains a Start and a corresponding End Action Statement, the Statements within the Action must be right indented to n levels.

    For example:

    [Function: GMPL Conditions]

    00 : IF: <Condition 1>
    10 : <Action Statement 1>
    20 : ELSE
    30 : IF: <Condition 2>
    40 : <Action Statement 2>
    50 : ELSE
    60 : IF: <Condition 3>
    70 : <Action Statement 3>
    80 : ELSE
    90 : <Action Statement 4>
    100 : END IF
    110 : END IF
    120 : END IF
    c.Actions must be in UPPER Case as shown in the above example where Action SET and RETURN are in UPPER Case.

    d.Sub-Routines or Sub-Functions must be called from within the Main Function wherever necessary to improve the performance

    For example:

    [Function: GMPL Import from Excel]

    00 : WALK COLLECTION : GMPL Excel Debtors
    10 : IF : $$IsEmpty:($Name:Group:$ExcelParent)
    20 : CALL : GMPL Create GrpLed : “Group” : $ExcelParent
    30 : ENDIF
    40 : IF : $$IsEmpty:($Name:Ledger:$ExcelLedger)
    50 : CALL : GMPL Create GrpLed : “Ledger” : $ExcelLedger : $ExcelParent
    60 : END IF
    70 : END WALK

    [Function: GMPL Create GrpLed]

    Parameter : Object Type : String
    Parameter : Object Name : String
    Parameter : Group Name : String : $$GroupSundryDebtors

    00 : ACTION : NEW OBJECT : ##ObjectType
    10 : SET VALUE : Name : ##ObjectName
    20 : SET VALUE : Parent : ##GroupName

    7.Insert proper comments, as and when necessary

    Comments improve the readability of the code. Give proper comments wherever required.

    For example:

    ;; Field definition to allow the user to enter the effective date of the voucher

    [Field: Chg VchEffDate]

    [NOTE: Default TDL is the best guide to know coding conventions]


    Attached Files:

Thread Status:
Not open for further replies.

Share This Page