I don't see a consistency problem if this would go, but besides that, just ask yourself:

1. How many times do I have a situation like that ?
2. How often do I not want to control the exact format of the resulting
   string representation of the number in case ?
3. In that remaining cases, how inconvenient would it be to have to
   explicitely call toString() on the number ?
4. How hard would a bug introduced by this autoconversion be to track ?
5. How confusing/suspicious would the code be to another programmer
   working on your code ?

At least to me whether this is worth it pretty much answers itself.

Cheers,
mg

On 24/11/2019 08:31, Angelo Schneider wrote:
Hello everyone,

That is an interesting example (actually I was not aware that groovy does that)

Am 24.11.2019 um 01:28 schrieb Simon Sadedin <ssade...@gmail.com <mailto:ssade...@gmail.com>>:

Chiming in late here, but the only one I would passionately argue about is the string <=> numeric conversions. The implicit conversions to / from String already in Groovy have been responsible for a large proportion of the impactful bugs that have come out of my complex groovy code. For example, the fact that this code both compiles and passes the assertion:

@CompileStatic
class Foo {
    String bar() {
        return 3
    }
}
assert new Foo().bar() == "3"

I guess removing this implicit conversion would break things, but I personally would gladly take the hit in transitioning to Groovy 3.x :-)

Cheers,

Simon

JavaScrip haters are hating it because of the implicit conversions between strings and numbers/bools (I don’t remember the details, there seem to by many odd cases). In the above example, one could agree that it is still ok, as a literal is converted. And it is basically just one line away from the return type declaration, however if the literal was a variable of static type int, I would not agree that it is automatically converted. Then again on the other hand, the literal is a java.lang.BigInteger, right? And the compiler most likely simply calls .toString() … We have to strive for consistency … it is early in the morning here and I have jet lag … so not really sure what is consistent at the moment :P

Regards,
Angelo

privat: -------------------- www.oomentor.de <http://www.oomentor.de> --------------------------
Angelo Schneider                 OOAD/UML
                           Patterns/FrameWorks
angelo.schnei...@oomentor.de <mailto:angelo.schnei...@oomentor.de> C++/JAVA          Mob: +49 172 9873893


Reply via email to