totalcross icon indicating copy to clipboard operation
totalcross copied to clipboard

4D method in Convert class

Open jeffque opened this issue 5 years ago • 4 comments

4D method in Convert class

AFAIK, 4D methods has been deprecated and should have been removed. However, investigating GitLab's TotalCross/totalcross#583, I found a 4D method in Convert.java here and here

Describe the bug

Code style suggests that 4D methods and classes should be abolished

Additional context

The Convert.toString4D(long, int) has an almost identical code to Convert.toString(long, int). The exception been that toString(long, int)adds a validation in it's third condition,&&useNative, that doesn't exists in toString4D(long, int)`.

newLauncherInstance() has some misterious comments about "applets" not initializing correctly, so it was necessary as some kind of backup tool. Also, besides judging if should create or not a new Launcher instance, it also calls to instance method Launcher.fillSettings() too. I dunno why there is a reason to call this method always, why it isn't a new Launcher() instruction, nor why it is wrote out from native code (newLauncherInstance4D() is an empty method).

jeffque avatar Aug 23 '20 05:08 jeffque

The Convert.toString4D(long, int) has an almost identical code to Convert.toString(long, int). The exception been that toString(long, int)adds a validation in it's third condition,&&useNative, that doesn't exists in toString4D(long, int)`.

You're right, the 4D method and the useNative flag can both be removed. 👍

newLauncherInstance() has some misterious comments about "applets" not initializing correctly, so it was necessary as some kind of backup tool. Also, besides judging if should create or not a new Launcher instance, it also calls to instance method Launcher.fillSettings() too. I dunno why there is a reason to call this method always, why it isn't a new Launcher() instruction, nor why it is wrote out from native code (newLauncherInstance4D() is an empty method).

Launcher is only available when running on the JDK. I guess we could make an empty native method to remove the 4D, but that would be lazy. I guess I left it that way to annoy me into a better solution in the future, possibly rewriting the Launcher and/or Convert. Creating an empty native method feels like sweeping it under the rug for me, I'd rather keep it that way.

flsobral avatar Aug 24 '20 13:08 flsobral

I guess I left it that way to annoy me into a better solution in the future

Well, I think that I called the future Fábio now 🤭

jeffque avatar Aug 25 '20 03:08 jeffque

Maybe instead of an empty native a simple check if it is in a Java env should work as intended.

jeffque avatar Aug 25 '20 03:08 jeffque

To avoid the TotalCross/totalcross#583 issue, the Convert.toString(long) code could be replaced with a a call to Long.toString(long), as the Conert.toString(int) code is a call to Integer.toStirng(int)

jeffque avatar Aug 25 '20 03:08 jeffque