NthField and API 2.0

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.

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)

Thanks Alberto.

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

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.

[quote=465229:@Rick Araujo]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.[/quote]

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

[quote=465163:@Ramon SASTRE]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.[/quote]<https://xojo.com/issue/56629>

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…

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?

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)

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.

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

Worry about it then.

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

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

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

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 :frowning:

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

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: