How to post code examples

Discussion in 'Pascal Logic Code Examples' started by Darren, Jul 5, 2005.

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

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    There are a few guidelines for posting code in this forum which will help greatly. I understand that everyone has their own preferences, but some consistency will make life easier for everyone :)

    Most of the following guidelines should be used when writing code anyway, as they make it easier for you to understand and maintain your own code.

    Formatting

    Firstly, please use the CODE formatting for any code snippets. To do this, click on the # button when entering code, this way you get nicely recognisable code with all of its indenting retained. Alternatively, you can enter [ CODE ] at the start and [ /CODE ] at the end of your code (no spaces between the brackets and "CODE").

    Indenting

    Please indent your code. It makes it much easier to read.

    Comments

    Please put comments in your code, or accompanying the code, otherwise it will be of no use to anyone.

    Use of Constants

    Where possible, use constants for Group Addresses instead of numbers or meaningless tags. This way anyone can quickly get the code working without having to change tags everywhere.

    Omitted Code

    Where code has been omitted for clarity, indicate this using an ellipsis { ... }, or a comment such as { switch loads here }.

    Variable Naming

    Please attempt to give your variables meaningful names. A variable called "x" doesn't convey much information and can make code very hard to understand.

    By following these guidelines, you will post pretty code like :

    Code:
    { constants }
    PressGroup = 5;   { this triggers the PressCounter to be incremented }
    
    { variables }
    PressCounter : integer;  { this counts the presses }
    
    { initialisation }
    PressCounter := 0;
    
    { module code }
    
    { When the button is pressed, increment the PressCounter. }
    { When the counter gets to 10, do stuff. }
    if GetLightingLevel(PressGroup) = ON then
    begin
      PressCounter := PressCounter + 1;
      if PressCounter = 10 then
      begin
        { do stuff here }
      end;
    end;
    
    rather than ugly (but equivalent) code like :

    x : integer;
    x := 0;
    if GetLightingLevel("Group 5") then begin
    x := x + 1; if x = 10 then begin
    { do stuff here }
    end; end;



    Example Projects

    If you are willing to post a whole project, this would make it even easier. If you choose to do this, please post a project archive so that all of the necessary images and the C-Bus project are included. Alternatively, if you use a C-Bus project installed with the software (such as "home" or "clipsal") and you don't use any image files, you can just post the CTD file.
     
    Last edited by a moderator: Jul 5, 2005
    Darren, Jul 5, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Thread Status:
Not open for further replies.