Page 1 of 1
functions in different libraries
Posted: Tue Sep 18, 2018 8:51 am
by wriedmann
Hello,
when writing function libraries: what is the best approach to write function libraries?
I have Lib1, namespace Lib1 with a static Functions class
then Lib2, namespace Lib2, with a static Functions class
and in the application I would like to use functions from both classes, using
using Lib1
using Lib2
and not using
static using Lib1
static using Lib2
Wolfgang
functions in different libraries
Posted: Tue Sep 18, 2018 9:08 am
by TerryB1
Hi Wolfgang
Suggest you put the static functions in different namespaces.
Otherwise, if I understand correctly, things will always clash.
Terry
functions in different libraries
Posted: Tue Sep 18, 2018 9:11 am
by wriedmann
Hi Terry,
yes, I had this always.
Wolfgang
functions in different libraries
Posted: Tue Sep 18, 2018 12:28 pm
by MathiasHakansson
Hi,
The normal thing to do is to always state the classname when using static methods.
NiceClassInLib1.NiceStaticMethod()
/Mathias
functions in different libraries
Posted: Tue Sep 18, 2018 1:46 pm
by wriedmann
Hi Mathias,
yes, but I would let out the static class name... And in different libraries I need to specify different class names.
It would be a nice thing if for every library a static class couldbe defined that delivers the available functions.
Wolfgang
functions in different libraries
Posted: Tue Sep 18, 2018 2:16 pm
by MathiasHakansson
If the functions are organized in different classes the namespace + classname + method name is the reference to the method. This is highly related to the old question about function naming.
ArrayHelper.Add()
IntegerHelper.Add()
In the example above the class name makes the code more readable and makes it possible to use shorter method names. What are the alternatives?
Helper.ArrayAdd()
Helper.IntegerAdd()
?
When using third party libraries sometimes class name collisions occur. In that case you have to use the namespace to refer to the correct class. This is similar to that problem.
/Mathias
functions in different libraries
Posted: Tue Sep 18, 2018 4:51 pm
by Jamal
I agree with Mathias.
Creating a namespace with its classes will avoid conflicts and also bugs!
functions in different libraries
Posted: Tue Sep 18, 2018 6:37 pm
by PaulB
Wolfgang,
You could use:
Static Myfunction()
Static Global MyProperty
Visible only to the Module. But not a class. Can implement difference behavior without all the renaming of common functions.
I get your desire to have a standard approach to library behavior. I think thats what you want at least.
Cheers,
Paul
functions in different libraries
Posted: Wed Sep 19, 2018 3:57 am
by wriedmann
Hi all,
using the own namespace for every library was always planned.
But I tought I could build a static "Functions" class in every library to have the static methods usable as functions in the dependent applications.
But since I use the Core dialect, probably I had to read the documentation first.
For the Vulcan and the VO dialect, the topic "Function class name" says:
"<AssemblyName>.Functions (DLLs)
<AssemblyName>.Exe.Functions (EXEs)
<AssemblyName>.Exe.$<ModuleName>$.Functions for static functions and globals"
whereas for the Core dialect:
"Functions
X$<ModuleName>$Functions for static functions and globals"
But I will make a static class in every lib, with a different name:
Lib1, namespace Lib1, static class Lib1Funcs
Lib2, namespace Lib2, static class Lib2Funcs
Strung functions for example will be in their own static class, but the problem may be that in the large VO functions library we have only to remember the function name. If the functionality is splitted over too many static classes, there is much more to write and much more to remember.
Wolfgang