- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
C# is better than Java these days. There, I’ve said it.
Admin
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?
Admin
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, checkingcurrentPage
against it is a WTF, sincecurrentPage
should be limited bypageCount
(ornumberOfPages
or whatever...Admin
TRWTF is that there is no wrap-around. <groan>
Admin
TRWTF is Java Beans
Admin
TRWTF is JavaBeans
Admin
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.
Admin
Java beans are terrible regardless of how you roast them.
Admin
That's basically what a Bean should be- Java's equivalent of a struct.
Admin
"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....
Admin
Appealing to Robert Martin is TRWTF. Slogans do not good software make.
Admin
I thought C# was better than Java any day.
Admin
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”
Admin
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.
Admin
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.
Admin
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...
Admin
Functional and object-oriented are not mutually exclusive. To wit, one can do functional programming in both Java and C#.
Admin
Is this title a reference to Gleaming the Cube?