Using Default namespace for object base

I am developing an object containing Object, Base and Peripheral as usual. In my Base there are some constants defined for usage in Object and also in Peripheral e.g.:

MyBaseConstants

{attribute 'qualified_only'}
VAR_GLOBAL CONSTANT
  MY_DEVICE_PAR_COUNT : DINT := 5;
END_VAR

In some examples I found different approaches how to access this constant from object or peripheral:

  1. Use directly MyBaseConstants.MY_DEVICE_PAR_COUNT.
  2. Use namesapace OC_MyBase.MY_DEVICE_PAR_COUNT. Probably without attribute 'qualified only'.
  3. Use namesapace +ย  global variable list OC_MyBase.MyBaseConstants.MY_DEVICE_PAR_COUNT. Too long for coding.

What is the right way how to handle it?

Best reply by MarvinW

In ATMO we are also using option 1. We have a object creation guideline (on top of the coding guideline) that says that everything that's not INTERNAL has to be prefixed with the object name, including the GVLs. The object name itself is unique, although not prefix-free. But we have never run into a naming conflict and I predict we never will.

I have seen option 2 before but it causes problems if the library namespace will change. We did change namespaces before, and I am happy we didn't use option 2 at that time ๐Ÿ˜›

Option 3 is for purists only, I think ๐Ÿ˜‰

View original
3 replies
Resolved