functions in different libraries

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

functions in different libraries

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

functions in different libraries

Post by TerryB1 »

Hi Wolfgang

Suggest you put the static functions in different namespaces.
Otherwise, if I understand correctly, things will always clash.

Terry
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

functions in different libraries

Post by wriedmann »

Hi Terry,

yes, I had this always.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

functions in different libraries

Post by MathiasHakansson »

Hi,

The normal thing to do is to always state the classname when using static methods.

NiceClassInLib1.NiceStaticMethod()

/Mathias
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

functions in different libraries

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

functions in different libraries

Post 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
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

functions in different libraries

Post by Jamal »

I agree with Mathias.

Creating a namespace with its classes will avoid conflicts and also bugs!
PaulB

functions in different libraries

Post 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
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

functions in different libraries

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply