Hi,
In our company (programming mainly Beckhoff PLCs) we are establishing internal coding guidelines for ST. Until now, the conventions were always project specific.
We don't use Hungarian notation & we are consistent with using PascalCase for internal variables of a FB.
Trouble arises when you wish to expose a particular variable via property as you cannot use the same name.
In the past we've used _ prefix in the internal variable, to make the property look pretty, but I feel that this makes internals of a FB harder to read.
Is there any established way to name the properties?
For example if I have an internal variable MotorPosition, I can expose it via property "MotorPositionProperty" (snippet below)
Alternative is to prefix internal variable with _ and keep the property as MotorPosition.
I feel like the second approach makes for less readable code while the first one adds additional clutter to the property name.
Any ideas on how to handle this elegantly?
How do you handle this in your coding?
In our company (programming mainly Beckhoff PLCs) we are establishing internal coding guidelines for ST. Until now, the conventions were always project specific.
We don't use Hungarian notation & we are consistent with using PascalCase for internal variables of a FB.
Trouble arises when you wish to expose a particular variable via property as you cannot use the same name.
In the past we've used _ prefix in the internal variable, to make the property look pretty, but I feel that this makes internals of a FB harder to read.
Is there any established way to name the properties?
For example if I have an internal variable MotorPosition, I can expose it via property "MotorPositionProperty" (snippet below)
Code:
FUNCTION_BLOCK FunctionBlock
VAR
SensorReadback : INT := 0; (* Internal variable)
MotorPosition : INT := 0; (* Internal variable *)
DeviceState : BOOL := FALSE; (* Internal variable *)
END_VAR
PROPERTY MotorPosition[B]Property[/B] : INT
GET : INT
RETURN MotorPosition;
END_GET
END_PROPERTY
Alternative is to prefix internal variable with _ and keep the property as MotorPosition.
Code:
FUNCTION_BLOCK FunctionBlock
VAR
SensorReadback : INT := 0; (* Internal variable)
[B]_motorPosition[/B] : INT := 0; (* Internal variable *)
DeviceState : BOOL := FALSE; (* Internal variable *)
END_VAR
PROPERTY MotorPosition : INT
GET : INT
RETURN _motorPosition;
END_GET
END_PROPERTY
I feel like the second approach makes for less readable code while the first one adds additional clutter to the property name.
Any ideas on how to handle this elegantly?
How do you handle this in your coding?