- 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
Wow. O(N^3) on the number of visitors. Excellent.
Overall, it's O((N^3)*P*Q*R) where N is the number of visitors, P is the number of schedules, Q is the average number of days per schedule, and R is the average number of slots per day, and it could be frist, oops, O(N*P*Q*R).
Admin
To be fair to Clarence, streams are a bit confusing if you're not used to them and haven't been exposed to FP or similar concepts in e.g. JavaScript. Evaluate-on-demand in particular is something that people often trip over.
Not that that excuses re-iterating the same collection multiple times for an O(n^3) WTF.
This is why we have code reviews though. Everyone has brain farts now and then.
Admin
Oh indeed, twice daily in my case, but this is full on cerebral explosive diarrhoea.
Admin
Eeeeeeesh... maybe I shouldn't read TDWTF before my morning coffee, but this really got on all my nerves at once. It's so ignorant! Java doesn't have C++-style copy constructors - I mean, of course you can write a copy constructor (all the built-in collection implementations have them!), but it won't get invoked automatically, so that's one that's already way off. As for the last, streams can be more performant than loops, so that's two, and an extra bonus WTF for giving implementation-level performance advice without profiling.
But the middle point is honestly the worst, because it's legitimate misinformation. The idea that creating temporary objects was Bad and To Be Avoided was good advice several JVM versions ago. These days, so much R&D has gone into memory management/the garbage collector/escape analysis (okay, escape analysis won't help here, but I'm mentioning it for completeness's sake).
Btw,
orElseThrow
takes aSupplier<X extends Throwable>
so it can avoid filling in the stack trace for no reason.orElseThrow(() -> new NotFristException())
.Admin
TRWTF is using streams when all you need is a for loop. They're a powerful tool when you want e.g. a map()/filter()/collect() pipeline, but in this example they contribute exactly nothing (note that Java also supports someCollection.forEach(item -> { ... }) syntax).
It's also funny how they've doubled up the forEach loops on each line to try to disguise how deeply nested the code really is :D
Admin
It will if I run fast enough!
Admin
Another bonus is that when they added streams to java, they also added a little-known forEach method to Iterable, which means that all of those calls to .stream() are superfluous anyway (as well as the isEmpty checks because looping over an empty iterable is already comparatively free/cheap).
Admin
You need to optimize the stream pipeline before it can run fast at all!
Admin
TRWTF remains the lack of a preview function, Remy!
:P
Admin
When I first saw streams in use it looked like Java's answer to LINQ->SQL and we happily used it everywhere to avoid messy/hard-to-test-and-debug HSQL queries. Then we discovered what happened when used on a table with millions of rows :facepalm:
Admin
This site is dying a painful death
Admin
Monads or applicatives?
Monads process input to build a function. Applicatives build a function to process input.
Sequence or transverse?
Sequence will error out the entire array. Transverse will error out the individual items in the array.
That's all the decisions you really need.
Admin
You can run, but you can't hide :-)