Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

what is the preferred way - functions/static methods or extension methods 08 Sep 2018 18:37 #6140

  • wriedmann
  • wriedmann's Avatar
  • Topic Author


  • Posts: 3367
  • Hi All,

    what do you prefer: extension methods or functions/static methods?

    The first would be called
    aTarget := aSource:SubArray( nStart, nLength )
    and the second
    aTarget := SubArray( aSource, nStart, nLength )

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 09 Sep 2018 09:42 #6141

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Wolfgang,

    no final decision made, but currently i would use extension methods to extend e.g. gui classes, but not to add functionality to types like string, int etc. Ok, in .net everything is an object, but maybe i´m too old and worked too long with the VO mixture of objects and pure funcs ;-)

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 06:12 #6145

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • Hi Karl-Heinz,

    for myself I prefer the extension methods, even to basic types likes strings, because .NET already uses them und they are easier to read and write.

    When you use an extension method you will understand immediatly on wich data the method is used.
    The code
    nPos := aBuffer:IndexOfBytes( aPattern, nOffset )
    IMHO is easier to understand than
    nPos := IndexOfBytes( aBuffer, aPattern, nOffset )

    And Intellisense is another advantage of extension methods: they are shown on the data types on which they can be applied.

    I've asked because the VO style is to use functions, and maybe all of you prefer this style.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 11:09 #6148

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • Would you use the prefix name (discussed earlier) both for extension methods and functions?

    VO used usuals if the same function could be used with different data types. In .net you have the option to use overloading instead.

    In .net if feels more natural to use extension methods.

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 11:19 #6149

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • Hi Mathias,

    Would you use the prefix name (discussed earlier) both for extension methods and functions?

    No, I would not use them.

    VO used usuals if the same function could be used with different data types. In .net you have the option to use overloading instead.

    we are in the .NET world, so I would use overloading (which is a great thing IMHO).

    In .net if feels more natural to use extension methods.

    Thank you for your comment!

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Last edit: by wriedmann.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 11:30 #6150

    • Otto
    • Otto's Avatar


  • Posts: 174
  • I prefer (extension) methods over functions in an object oriented environment.

    If you go to a functional programming style/language, it becomes somewhat different.

    Please Log in or Create an account to join the conversation.

    Last edit: by Otto. Reason: typo

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 11:34 #6151

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • Hi Otto,

    thank you! So we are currently at 2:0 for extension methods (if I don't count the answer from Karl-Heinz).

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 12:43 #6152

    • Guy Deprez
    • Guy Deprez's Avatar



    Extension methods.

    I prefer encapsulate fonctionality around an object. It seems to me more "accurate" when the methods are attached to a clearly defined class, when they make part of a structured set.

    New Score is 3:0

    Guy

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 13:31 #6154

    • Chris
    • Chris's Avatar


  • Posts: 3984
  • I do not have a strong preference, but since the score goes too high and I usually support the losing team :), I'll mention that I usually prefer using a static method of a "Funcs" class (yes, similarly to what an extension method is under the hood) for that, because sometimes when I read some code that calls an (extension) method that I am not aware of, I am left wondering what that is.

    I prefer things to be obvious how they are working, rather than being hidden behind implementation details, so I usually avoid extension methods. I understand they are also a nice thing, too, though, so I am not against using them either.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 13:39 #6155

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • Hi Chris,

    one could not say that the members of the devteam may have another weight. If we attribute then 5 points to you, you would be on the winners side <g>.

    But for now I would let it to 3:1 for extension methods.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 13:51 #6156

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Guys,

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

    BTW. thanks Chris :-)

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 13:55 #6157

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 14:01 #6158

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • yes, of course 3,5:1,5 :-)

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 14:55 #6159

    • FFF
    • FFF's Avatar


  • Posts: 1422
  • 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 (X# 2.16.0.5; Xide 2.16; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF. Reason: typo

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 15:03 #6160

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 15:25 #6161

    • FFF
    • FFF's Avatar


  • Posts: 1422
  • Wolfgang,
    i don't quite see the difference, wethere you have a file/lib "MyFuncs", vs. "MyExtensions" ;)
    Regards
    Karl (X# 2.16.0.5; Xide 2.16; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 15:52 #6162

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • 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:
    if oObject:IsProperty( cPropertyName )
    and this works on every object.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 17:13 #6163

    • Guy Deprez
    • Guy Deprez's Avatar



    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

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 17:18 #6164

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3367
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    what is the preferred way - functions/static methods or extension methods 10 Sep 2018 17:25 #6165

    • FFF
    • FFF's Avatar


  • Posts: 1422
  • 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 (X# 2.16.0.5; Xide 2.16; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2
    Moderators: wriedmann