• theunknownmuncher@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    2 个月前

    Whenever you sit back and smile proudly to yourself about how clever the block of code you just wrote is, your next move should be to delete and rewrite it.

    This is a clever block of code! Great job, now rewrite it to be sane 😂

  • CookieOfFortune@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    2 个月前

    This isn’t sufficiently enterprisey for Java. There should be a Roman numeral factory followed by relevant fromString and toInteger methods.

    • vithigar@lemmy.ca
      link
      fedilink
      arrow-up
      1
      ·
      2 个月前

      Ugh. Literally refactored multiple factories into straightforward functions in the most recent sprint where I work.

      Someone saw a public factory method which was a factory for a reason and just cargo culted multiple private methods using the same pattern.

    • dfyx@lemmy.helios42.de
      link
      fedilink
      arrow-up
      0
      ·
      2 个月前

      There could be a hidden quadratic cost because the string needs to be reallocated and copied multiple times.

          • Cethin@lemmy.zip
            link
            fedilink
            English
            arrow-up
            0
            ·
            2 个月前

            Recursion is amazing for a small selection of problems. Most of the time you don’t need, or want, it. When it is useful though, it tends to be really useful.

            I don’t understand people’s issue with it. I always found it easy. Maybe that’s why I feel this way. Maybe if you find it challenging you want to avoid it, even when it’s a good solution.

            • kamstrup@programming.dev
              link
              fedilink
              arrow-up
              0
              ·
              2 个月前

              Most devs I know like recursion. Trouble is that many popular languages don’t support tail recursion, but throw a stackoverflow error after a few thousand levels. So you have to keep track of max recursion depth manually, and it starts to look like a complicated solution

    • grue@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      2 个月前

      Code gulf, you say?

      public static String
      convertRomanNumeral(String numeral) {
          numeral = numeral.replace("America", "Mexico");
          return numeral;
      } 
      
    • trxxruraxvr@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      2 个月前

      No, M will be replaced by DD and then CD will be picked up, so it will go

      1. CM
      2. CDD
      3. CCCCD
      4. CCCCCCCCC