NthField and API 2.0

  1. 2 weeks ago

    Ramon S

    Nov 28 Pre-Release Testers, Xojo Pro UPC, Europe (Barcelona, Spain)

    In API 1.0 I had a code like this:

    Dim mystring As String = "tomatoes,pears,apples"
    Dim t As String = NthField(mystring, ",", 2)

    and now with API 2.0 I must write:

    Dim mystring As String = "tomatoes,pears,apples"
    Dim t As String = mystring.NthField(",", 2)

    In API 1.0 I could also write (in a single line):

    Dim t As String = NthField("tomatoes,pears,apples", ",", 2)

    but now with API 2.0 I cannot write

    Dim t As String = "tomatoes,pears,apples".NtField(",", 2)

    but I can write in a single line

    Dim t As String = Str("tomatoes,pears,apples").NthField(",", 2)

    Is it normal? Is it a bug?
    Is it the way it should be?

    I am a bit lost with this.

  2. Alberto D

    Nov 28 Pre-Release Testers, Xojo Pro

    For now, that is the way it was designed.
    There is a feature request to let you do things like:

    Dim t As String = "tomatoes,pears,apples".NthField(",", 2)
  3. Ramon S

    Nov 28 Pre-Release Testers, Xojo Pro UPC, Europe (Barcelona, Spain)

    Thanks Alberto.

  4. Karen A

    Nov 28 Pre-Release Testers

    When they decided to get rid of such global methods imo they made the mistake of prioritizing "elegance" over usability/coding convenience... a danger when one is trying tp come up with an ideal or striving for philosophical purity...

    It some ways it is like Apple losing sight of one of the biggest pluses of the Mac when they started prioritizing looks over functionality/practicality/discoverability etc.

    I hope those API 1 global functions never really go away...

    -Karen

  5. Rick A

    Nov 28 Pre-Release Testers (Brazil. UTC-3:00)
    Edited 2 weeks ago

    @Karen A mistake of prioritizing "elegance" over usability/coding convenience

    To be true, this vision, once well structured, will be the useful, convenient and elegant way.

    This is the modern way of doing things, chaining in sequence, easier to read, with less parameters and firing the autocomplete options.

  6. Karen A

    Nov 28 Pre-Release Testers

    @Rick A To be true, this vision, once well structured, will be the useful, convenient and elegant way.

    This is the modern way of doing things, chaining in sequence, easier to read, with less parameters and firing the autocomplete options.

    I have no issue with having that capability and I do like being able to do that , but sometimes the other way is more convenient... thus both should be available...

    This is supposed to be a practical RAD tool to get stuff done, not an example of academic elegance/purity...

    - karen

  7. Norman P

    Nov 28 Pre-Release Testers, Xojo Pro under THE bus

    @Ramon S In API 1.0 I had a code like this:

    Dim mystring As String = "tomatoes,pears,apples"
    Dim t As String = NthField(mystring, ",", 2)

    and now with API 2.0 I must write:

    Dim mystring As String = "tomatoes,pears,apples"
    Dim t As String = mystring.NthField(",", 2)

    In API 1.0 I could also write (in a single line):

    Dim t As String = NthField("tomatoes,pears,apples", ",", 2)

    but now with API 2.0 I cannot write

    Dim t As String = "tomatoes,pears,apples".NtField(",", 2)

    but I can write in a single line

    Dim t As String = Str("tomatoes,pears,apples").NthField(",", 2)

    Is it normal? Is it a bug?
    Is it the way it should be?

    I am a bit lost with this.

    Feedback Case #56629

  8. Rick A

    Nov 28 Pre-Release Testers (Brazil. UTC-3:00)

    @Karen A This is supposed to be a practical RAD tool to get stuff done

    And it is, and faster, and easier, you are just a bit refractory to accept it in name of "it's not what I am used to".

  9. Karen A

    Nov 28 Pre-Release Testers

    @Rick A And it is, and faster, and easier, you are just a bit refractory to accept it in name of "it's not what I am used to".

    No...

  10. Kem T

    Nov 28 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    I'm a bit confused as to the issue. Wouldn't either version of that code work (or fail) the same in 2019r1.1 as in r2.1?

  11. Norman P

    Nov 28 Pre-Release Testers, Xojo Pro under THE bus
    Edited 2 weeks ago

    IF you move to API 2.0 then there is no global version of NthField(string, string, integer)
    Thats an API 1.0 method which is now deprecated

    so this line

    Dim t As String = NthField("tomatoes,pears,apples", ",", 2)

    has no direct equivalent in API 2 without introducing new local variables and possibly new bugs in a much more complex case
    To not get deprecation warnings you have to rewrite this entirely as something more like

    Var tmpStr as string = "tomatoes,pears,apples"
    Var t As String = tmpstr.NthField( ",", 2)

    API 1.0 had both NthField(string, string, integer) and NthField(extends string, string, integer)

    API 2.0 only has NthField(extends string, string, integer)

  12. Kem T

    Nov 28 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Since nothing has been removed, and likely will never be removed, the code works but with a deprecation warning that you can turn off or ignore.

    Just to be clear.

  13. Norman P

    Nov 28 Pre-Release Testers, Xojo Pro under THE bus

    If its never going to be removed why bother marking it deprecated ?
    There's no sense in doing that IF there is no plan to ever remove it

    The API 1.0 global method _could_ easily be removed

  14. Kem T

    Nov 28 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Worry about it then.

  15. Norman P

    Nov 28 Pre-Release Testers, Xojo Pro under THE bus

    If you knew how easy it could be removed you might as well

  16. Derk J

    Nov 28 Pre-Release Testers, Xojo Pro

    It's already removed if you create a new project in r2.x right?

  17. Norman P

    Nov 28 Pre-Release Testers, Xojo Pro under THE bus

    the global method version like this

    Dim t As String = NthField("tomatoes,pears,apples", ",", 2)

    no. its still there and will compile
    but in a project started in 2019r2 if you type
    Dim t As String = Nth and press tab it wont show in autocomplete and you will get deprecation warnings when you analyze
    But if you started the project in 2019r1.1 or earlier & open it in 2019r2 it will show in autocomplete and doesnt get warnings about being deprecated either

    Since it is marked deprecated and could be removed those warnings should be something to deal with

  18. Wayne G

    Nov 28 Pre-Release Testers, Xojo Pro Auckland, New Zealand
    Edited 2 weeks ago

    I just did the obvious and moved those text literals to constants and now I can add alternative languages to the app. Unfortunately NZ Maori is not a supported language :(

  19. Jean-Yves P

    Nov 29 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    creating this method in a global module also works fine ...

    Public Function NthField(aString as String, aSeparator as String, anIndex as Integer) as String
      Return aString.NthField( aSeparator, anIndex)
      
    End Function
  20. Tobias B

    Nov 29 Pre-Release Testers, Xojo Pro Bern, Switzerland
    Edited 2 weeks ago

    @Jean-YvesPochez creating this method in a global module also works fine ...

    that confuses me. This signature should be ambiguous to the deprecated-but-still-available API 1.0 function.

    Edit: I tried it and as expected the compiler is giving an error as soon as you try to access the method:

    There is more than one method with this name but this does not match any of the available signatures.

  21. Newer ›

or Sign Up to reply!