Search

  • 001-Core Programming: Why Bother to Improve Your Coding?

    There are ways to produce self-documenting code. For instance, if you have an array of differing values, you can self-document the elements.

    If your language permits defining constants, you can do this:

    #define hQUIRIN 1
    #define hSPEED_RACE_1 2

    local aValues := {}

    // SIZE the array in your language here

    aValues[hQUIRIN] := MY_FILE->QUIRIN
    aValues[hSPEED_RACE_1 := MY_FILE->SPEED_1

    If your language does not support defining constants (most do), use a variable with the variable type denoted in the variable name. In this case, I use "n" as the prefix for a "number" and "a" for "array".

    local aValues := {}
    local nE_Quirin := 1
    local nE_Speed_Race_1 := 2

    // SIZE the array in your language here

    aValues[nE_Quirin] := MY_FILE->QUIRIN
    aValues[nE_Speed_Race_1] := MY_FILE->SPEED_1

    Do not reference the array like the following because it will be very difficult to read later:

    aValues[1] := MY_FILE->QUIRIN
    aValues[2] := MY_FILE->SPEED_1

    You could end up with this unreadable code:

    nMyCoolNumber := aValues[2] / aValues[1]

    Instead, write it like this:

    nMyCoolNumber := aValues[hSPEED_RACE_1] / aValues[hQUIRIN]

Please register to see more

Forum Members always see the latest updates and news first. Sign up today.