xsharp.eu • what is the preferred way - functions/static methods or extension methods - Page 2
Page 2 of 4

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

Posted: Mon Sep 10, 2018 11:51 am
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

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

Posted: Mon Sep 10, 2018 11:55 am
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

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

Posted: Mon Sep 10, 2018 12:01 pm
by Karl-Heinz
yes, of course 3,5:1,5 :-)

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

Posted: Mon Sep 10, 2018 12:55 pm
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 ;)

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

Posted: Mon Sep 10, 2018 1:03 pm
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

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

Posted: Mon Sep 10, 2018 1:25 pm
by FFF
Wolfgang,
i don't quite see the difference, wethere you have a file/lib "MyFuncs", vs. "MyExtensions" ;)

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

Posted: Mon Sep 10, 2018 1:52 pm
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

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

Posted: Mon Sep 10, 2018 3:13 pm
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

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

Posted: Mon Sep 10, 2018 3:18 pm
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

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

Posted: Mon Sep 10, 2018 3:25 pm
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