Just ask it to rewrite the shitty code you wrote in a language you barely understand to “follow standard best practices in <language>” or something like that and it will add advanced typing features, functional programming for iterables, advanced exception handling, proper concurrency handling, optimize control flows, use better equivalent functions, etc.

As long as you understand the foundations of these concepts in at least one language anybody can become pretty close to an expert in most languages instantly. Especially since most of them are C based and pretty similar

The output will sometimes change the logic but I mean that’s pretty easy to catch and fix

Rip C++ nerds that memorize the entirety of each releases manual to shave off 3ms in every single function

  • Hermes [none/use name]@hexbear.net
    link
    fedilink
    English
    arrow-up
    11
    ·
    3 days ago

    Don’t you know that all programming languages are the same, except each uses a different set of symbols and keywords? Since all languages are the same, we can use an LLM to efficiently translate code from one language into another where it will perform optimally. /s

    • footfaults@lemmygrad.ml
      link
      fedilink
      English
      arrow-up
      7
      ·
      3 days ago

      “Computer, replace all the whitespace indentation with curly braces and put a semicolon at the end of every line, in order to convert my Python program to Rust”

      • invalidusernamelol [he/him]@hexbear.net
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 days ago

        Python also allows you to override what operators do meaning I can write

        int.__add__ = lambda self, other: print("hello world")
        
        >>> 1 + 2
        'hello world'
        

        And that’s totally valid code. Don’t think many other languages allow that, and translating that would be a mess.

        • footfaults@lemmygrad.ml
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          1 day ago

          It’s technically operator overloading, the wacky thing that Python allows you to do, is overload operators for base types like int which I’m not sure if other languages allow you to do for base types.

          • invalidusernamelol [he/him]@hexbear.net
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 day ago

            That’s what I meant, you can modify the behavior of code by directly over riding the operator implementation for base types. What it really reveals is that Python int is not at all a C int or really any other int.

            Directly translating syntax without knowing that the Python type is so vastly different from say, the C type is a recipe for latent disaster.

              • invalidusernamelol [he/him]@hexbear.net
                link
                fedilink
                English
                arrow-up
                1
                ·
                24 hours ago

                My favorite weird Cpython implementation detail is that -5 to 256 are pre-cached when the interpreter is initialized. So identity checks using those numbers return True, but return False for other numbers:

                >>> x = 1
                >>> y = 1
                >>> x is y
                True
                
                >>> x = 100000
                >>> y = 100000
                >>> x is y
                False
                

                At least in newer versions of Python it screams at you for doing identity checks with integers

                • footfaults@lemmygrad.ml
                  link
                  fedilink
                  English
                  arrow-up
                  2
                  ·
                  edit-2
                  12 hours ago

                  Yes, but that is a common optimization, caching primitive types and common values. I believe the JVM has that behavior, as well as a couple Ruby implementations (MRI, possibly YARV but it’s been a while since I looked at Ruby implementations)

                  • invalidusernamelol [he/him]@hexbear.net
                    link
                    fedilink
                    English
                    arrow-up
                    2
                    ·
                    6 hours ago

                    Yeah, cashing the 8 bit values means using integer flags is a lot faster. Implementation details like that are always a kicker. Especially when Python’s syntax kinda makes you want to say “val is 1” since it’s more “human readable” than “val == 1”.

                    This is actually abused for True and False too which are a subclass of integer with Sentinel values equal to 0 and 1.

                    Since they’re technically different objects, True is 1 is False, but int(True) is 1 is True. True == 1 is True though.

                    Basically every language with an interpreter will do stuff like this, but it’s usually not super well documented behavior as it’s considered implementation detail or private API stuff.