• moosh@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    Is this a good thing I’m looking at or a bad thing? I don’t get it but then again, I’m not a programmer.

    • Eugene@waveform.social
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Java is a programming language that is notorious for being verbose, the joke is that you need a massively wide monitor to view it without the text being cut off

    • 1stTime4MeInMCU@mander.xyz
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      The joke is Java is verbose. It takes many characters to accomplish simple routines. Depending on your view that could either be good or bad for reading the code later.

      • Anomandaris@kbin.social
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Sure, but most of the lines in the screenshot break down to:

        object1.setA(object2.getX().getY().getZ().getI().getJ().getK().getE().getF(i).getG().toString())

        Aside from creating a method inside the class (which you should probably do here in Java too) how would another language do this in a cleaner way?

        • Blackthorn@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          Well I guess the point is that you shouldn’t need all these method calls to achieve simple goals. Most of those “getF” are calls to some SystemFactory to get a GenericObjectFactory and so on and so forth.

          • Anomandaris@kbin.social
            link
            fedilink
            arrow-up
            0
            ·
            1 year ago

            This just tells me you don’t use Java. Factory classes are just used to create objects in a standardized way, but this code isn’t creating anything, it’s just getting nested fields from already instantiated objects.

            • Square Singer@feddit.de
              link
              fedilink
              arrow-up
              0
              ·
              1 year ago

              Thos code is obviously nonsense to show the issue.

              But other languages would simplify stuff. For example, some languages call getters implicitly, so .getField() becomes .field. Same with list indexing, which could be done with operator overloading, so x.get(i) becomes x[i].

              In this situation that would be able to reduce the character count a fair bit.

              • biddy@feddit.nl
                link
                fedilink
                arrow-up
                0
                ·
                1 year ago

                The new convention in modern Java is to use .field() instead of .getField().

                What you’re complaining about isn’t Java, it’s object oriented programming, which Java basically forces on you. Verbosity is a flaw of OOP.

                • Square Singer@feddit.de
                  link
                  fedilink
                  arrow-up
                  0
                  ·
                  1 year ago

                  Compare:

                  x.field[5]

                  with

                  x.getField().get(5)

                  Both are exactly the same level of OOP, but the Java version is roughly twice as long. Add operator overloading to the mix and it becomes much worse:

                  x.getField().get(5).multiply(6).add(3)

                  vs

                  x.field[5] * 6 + 3

                  All this has nothing to do with OOP, but with syntactic sugar that is applied.

                  • biddy@feddit.nl
                    link
                    fedilink
                    arrow-up
                    1
                    ·
                    1 year ago

                    As I said, the convention is now x.field() not x.getField()

                    What language are you comparing against here? x.field[5] is valid Java if field is a public array, but that’s not OOP, at least not in a pure sense.