• Pablo (unregistered)

    C# is better than Java these days. There, I’ve said it.

  • asdf876345834 (unregistered)

    If you can't do validation in JavaBean setters and getters, or any other actual functionality, you can't have non-setters/getters, and you can't do any initialisation in the constructor, what is the advantage of a JavaBean over a simple struct?

  • (nodebb)

    Well, one of the requirements for a Java Bean is that it needs to support no-argument constructors. This means that maxPages is set to 0, by default.

    Are you trying to say that a Java Bean no-argument constructor isn't allowed to explicitly initialise member variables to sane values?

    That said, depending on what it's supposed to indicate, maxPages might be badly named... If it's the maximum number of pages the Bean could ever contain, its name is not a problem, but if it's the actual number of pages currently in the Bean, it's an awful name.

    And if maxPages is the capacity of the Bean rather than the current page count, checking currentPage against it is a WTF, since currentPage should be limited by pageCount (or numberOfPages or whatever...

  • Industrial Automation Engineer (unregistered)

    TRWTF is that there is no wrap-around. <groan>

  • (nodebb)

    TRWTF is Java Beans

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    TRWTF is JavaBeans

  • akozakie (unregistered)

    TRWTF is that this setter guarantees an invalid state regardless of argument if no-argument constructor was used and maxPage wasn't corrected - currentPage will be 0.

  • (nodebb)

    Java beans are terrible regardless of how you roast them.

  • (author) in reply to asdf876345834

    That's basically what a Bean should be- Java's equivalent of a struct.

  • TheCPUWizard (unregistered)

    "The best option, however, would be to follow the single responsibility principle and have a validator object that verifies a correct object state later, after the object has been entirely initialized." - subjectively best - at best <grin>

    RAII would be better in many cases, and immutable objects might be an alternative....

  • Duke of New York (unregistered)

    Appealing to Robert Martin is TRWTF. Slogans do not good software make.

  • xtal256 (unregistered) in reply to Pablo

    I thought C# was better than Java any day.

  • Nick (unregistered)

    Hmm, seems like FinalGuy may not be all that familiar with how JavaBeans are normally serializad and deserialized. To be fair, the built-in serialization in Java is its own WTF (which is why newer versions of Java are introducing Record types), but normally, the default serialization entirely bypasses the getters and setters, and just sets the private members directly.

    It seems to me that instead, FinalGuy has decided to roll his own deserialization logic, and therefore decided to call the setters to set property values, without considering any dependency chains.

    Of course, if you’re rolling your own logic, there’s no reason you can’t add a second constructor that DOES initialise all the values… and there’s also no reason you couldn’t have a ‘setPages’ method that would set both Current and Maximum pages at once.

    “I’m going to do my own thing… and then complain when it’s more work than using the default implementation”

  • (nodebb)

    People like to pile on Java as if it were a terrible language. At the contrary, it's not -- it excels at its initial design of being a simple OO language that can be dropped on the lap of any inexperienced or incompetent programmer. And that's the core of the issue.

    Heck that's why schools loved Java as a 101 language (at least before Python took over).

    What we have in today's WTF is a core newbie design error than anyone can replicate in any language. Bad variable naming + bad validation + bad API. That probably covers 90% of all corporate software, and 200% of the Eclipse code base I've ever had the misfortune of working with.

  • LZ79LRU (unregistered)

    That is what makes it bad though.

    Java is a language designed with the false idea that if you make the tool blunt enough that an unskilled craftsman can't cut him self you can get a bunch of them to replace properly skilled ones. Early Java was especially bad at this because it lacked so many language features that it was silly.

    Over time two things happened. Firstly, the idea proved to be hilariously wrong as anyone with a brain would have told them. And secondly you have a whole generation of developers who grew up on Java and actually became somewhat skilled to the point where they needed all those extra features.

    From that point on Java started adding more and more stuff which on one hand makes it more powerful and usable but on the other goes against the original premise of it being simple, easy and blunt.

    In the end what you end up with is a language that resembles a butter knife that someone forcefully sharpened used by people who are under the wrong impression that it's blunt enough not to be dangerous or sharp enough to cut things reliably.

    Also, thank you for bringing up Eclipse. That useless thing still stalks my nightmares. It's literally the worst excuse for an IDE I ever had to work with. I would quite literally rather program using a text editor and standalone compiler.

  • Yoh (unregistered) in reply to LZ79LRU

    In addition to LZ79LRU's spot-on post: isn't it great how objects solved all our design problems? I grew up in the Time of Java when if you didn't accept the Gospel of Objects, you were obviously a heathen swine who deserved whatever bad things came your way...

    I sometimes look back and wonder what could have been. Mutability and band-aids like objects are TRWTF and have been for decades. What if we'd just gone functional back then? Maybe we'd be able to just support millions of network connections on a fairly standard machine (a lá Erlang). Maybe we'd have rock-solid, high-performance web applications (a lá Elm). Maybe we'd have provably secure critical systems, imagine that!

    Oh well. Nice to reminisce but I suppose we've got to live in the world we've got rather than the world we might've wanted...

  • Duke of New York (unregistered)
    Comment held for moderation.
  • binariesque (unregistered) in reply to Yoh
    Comment held for moderation.
  • kolik (unregistered)
    Comment held for moderation.
  • best motion sickness medicine (unregistered)
    Comment held for moderation.
  • nasch (unregistered) in reply to Yoh

    Functional and object-oriented are not mutually exclusive. To wit, one can do functional programming in both Java and C#.

  • Khabresach (unregistered) in reply to Pablo
    Comment held for moderation.
  • lomendil (unregistered)

    Is this title a reference to Gleaming the Cube?

Leave a comment on “Paging the Bean”

Log In or post as a guest

Replying to comment #:

« Return to Article