Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Coding Best Practices

tstevic
2019-03-28
2019-04-01
  • tstevic - 2019-03-28

    I am working on an existing project. This project has a number of function calls with the format:

    String3 := CONCAT(STR1 := String1, STR2 := String2);

    This works properly. My preference would be:

    String3 := CONCAT(String1, String2);

    This also works. Is there a mention in any coding style documentation that suggests one style or the other?

    Could there be a performance difference between the two?

    First Style
    CPU Step 1: Assign STR1 the value of String1
    CPU Step 2: Assign STR2 the value of String2
    CPU Step 3: Call CONCAT with STR1 and STR2
    VS.
    CPU STEP 1: CALL CONCAT with String1 and String2

     
  • tvm - 2019-03-28

    As far as performance goes, there doesn't seem to be a difference:

    As for style, I agree with you, that CONCAT(String1, String2) is more readable, but on more complex functions where the inputs might not be as intuitive, I'll use the names.

    IMG: Capture.PNG

     
  • Anonymous - 2019-03-29

    Originally created by: rickj

    Adding to what TVM said, for large function calls it's common to list parameters on separate lines as shown below. Also note the different notation for input and output parameters.

       Result := SomeFunction(
          Input_01 := in01,         // Input parameters
          Input_02 := in02,
          Input_03 := in03,
             "        "
          Input_99 := in99,
          Output_01 => out01,      // Output parameters
          Output_02 => out02,
       );
    
     
  • tstevic - 2019-04-01

    rickj hat geschrieben:
    Adding to what TVM said, for large function calls it's common to list parameters on separate lines as shown below. Also note the different notation for input and output parameters.

       Result := SomeFunction(
          Input_01 := in01,         // Input parameters
          Input_02 := in02,
          Input_03 := in03,
             "        "
          Input_99 := in99,
          Output_01 => out01,      // Output parameters
          Output_02 => out02,
       );
    
     
  • tstevic - 2019-04-01

    Thank You!

     

Log in to post a comment.