what is the preferred way - functions/static methods or extension methods

This forum is meant for questions and discussions about the XSharp Tools libraries, which contain code written by XSharp users that they want to share with others,
The development team is not responsible for this code

Moderator: wriedmann

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

what is the preferred way - functions/static methods or extension methods

Post by Karl-Heinz »

Guys,

I demand on being counted, so the current score is not 3:1 but 3:1,5 ;-)

BTW. thanks Chris :-)

regards
Karl-Heinz
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

what is the preferred way - functions/static methods or extension methods

Post by wriedmann »

Hi Karl-Heinz,

sorry, then the current score is 3,5 : 1,5.

You were half for extension methods on classes and against on basic datatypes.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

what is the preferred way - functions/static methods or extension methods

Post by Karl-Heinz »

yes, of course 3,5:1,5 :-)
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

what is the preferred way - functions/static methods or extension methods

Post by FFF »

Guy,
that i see similiar, as long as you "extend" "your" class - but then, why not write the functionality as part of the class directly.
Wolfgang adds to existing, i.e. , "system classes/types" - here i'm with Chris, usually one knows more or less what to expect from e.g. a string object - and has to wonder, why on earth now there's new functionality; and not to forget: "where" is the definition?
Nothing really wrong with this, but make it a 3.5:2.25 ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

what is the preferred way - functions/static methods or extension methods

Post by wriedmann »

Hi Karl,
and has to wonder, why on earth now there's new functionality; and not to forget: "where" is the definition?
this is also the question with all these functions.

An if I have to put one static class "Functions" or "Funcs" or whatever in the library: this one will be contain a lot of functions/static methods that are not related at all.

With extension methods, the source code can be much better organized - and it is less to write. And maybe the names could be shorter.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

what is the preferred way - functions/static methods or extension methods

Post by FFF »

Wolfgang,
i don't quite see the difference, wethere you have a file/lib "MyFuncs", vs. "MyExtensions" ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

what is the preferred way - functions/static methods or extension methods

Post by wriedmann »

Hi Karl,
i don't quite see the difference, wethere you have a file/lib "MyFuncs", vs. "MyExtensions"
There is a class "StringExtensions", a class "ArrayExtensions", a class "ObjectExtensions" and so forth.

With extension methods code like this is possible:

Code: Select all

if oObject:IsProperty( cPropertyName )
and this works on every object.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Guy Deprez

what is the preferred way - functions/static methods or extension methods

Post by Guy Deprez »

Extensions methods VS Functions for existing classes. Ex:String

LOCAL cString:="xTE12y45ST " as STRING

//Using Functions. The "Russian dolls" model

cString:= ToUpper(ExtractLetters(left(strTran(AllTrim(cString),"x","a"),6)))

//Using Extensions Methods. The "Chaining model"

String:=cString:Trim().Replace("x","a").Left(6).ExtractLetters().ToUpper()

Result: "ATEY"

Witch style/model do you prefer?
Guy
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

what is the preferred way - functions/static methods or extension methods

Post by wriedmann »

Hi Guy,

IMHO such a "sausage" of code is very bad coding style - impossible to understand and impossible to debug, and error prone.

But with extension methods is is a lot easier to read than with the "russian dolls" model.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

what is the preferred way - functions/static methods or extension methods

Post by FFF »

Guys,
this results in left to right vs. right to left reading - to "like" is neither.
If i' d need that more than once, i'd write an access or a func, properly named ;)
See my request to Robert for a switch to access Dataserverfields "cleaned"...

Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply