Tales from the jar side: A great review for my book, Audiobook progress, Java map vs flatMap, another chess tournament, and some funny tweets
It's been over an hour and I haven't checked Amazon's top new releases lists yet. See? I do have at least some willpower.
Welcome, jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of August 8 - 15, 2021. This week I taught an NFJS virtual workshop called What’s New in Java, as well as week 2 of the O’Reilly Learning Platform course called Spring Boot in 3 Weeks. I then taught the first day (of three, this is getting to be a habit) of a Spring course for a private company.
If you’re not one already, please consider becoming a jarhead by subscribing to Tales from the jar side using this link:
Hey, I Wrote A Book!
Let’s get my sad obsession out of the way right now. At Amazon, my book Help Your Boss Help You is currently #3 in New Releases in Business Communication and #4 in New Releases in Business Ethics. I thought we had begun the long, low slide into oblivion already, but no, for a few days this week the book was at #1 in both categories. Maybe we’re finished the initial flurry and I can stop paying attention to what are arguably meaningless statistics.
Those statistics are updated hourly. I don’t check them hourly, but I do check too often to be entirely healthy.
Sunday Update: Hey, back to #1 in both categories again! I don’t know what triggered that, but I’ll bet it’s related to this awesome review by Geertjan Wielenga, announced this morning in a tweet:
If that great review really is the cause, I need to start harassing all my friends to do the same. Unfortunately, and I say this with sincere regret, there’s no way I’d actually do that. Oh, well. If, however, you are interested or willing to write a review, let me know and I can get you a complimentary ebook copy.
(Notice the root word compliment in complimentary? I just thought I’d mention it, for no reason.)
Audiobook Progress
Frequent readers of this newsletter know that I’ve been recording an audiobook version of HYBHY as well. The Prags tweeted about it this week:
I knew I would be traveling this weekend and part of next week, so I pushed through and finished recording all the chapters. Officially I need to add some front- and end-credits and a “retail sample” consisting of an excerpt that’s a few minutes long, but that’s it.
Right now I made the files available for a friend to do a sanity check on the quality. It’s sadly too late to do a sanity check on the content, though, since that matches the text already in production.
If you would also like to help do some quality control on the chapters, let me know and I’ll try to arrange something. There’s no fixed deadline, but I wouldn’t mind having the book available by the end of August. I should be doing more quality control myself, but that would mean listening to myself. A lot. One of the ebooks I read on audiobook production said the solution to that problem is “Get over it,” but I’m still struggling with that.
Other related items:
I’m appearing at the Atlanta Java Users Group on Tuesday night to talk about the advice given in the book. They will have a live audience limited to 40 masked, socially distanced people, but will also broadcast the talk live online. I’ll have a lot of print copies at the meeting, so those who attend will have a good chance of getting one for free. :)
Updates for our 8/17 meeting: We'll welcome @kenkousen, author of "Help Your Boss Help You," for our first #hybrid event! Register below for 1 of 40 #inperson tickets or to access the #virtual link. 1/2 Tue 8/17 at 6:45pm EDT Register: atlj.ug/Aug21ATL we've missed you! You've heard of managing your manager--but how about directly applied to tech? Don't miss our return to #inperson with @kenkousen! He'll speak from his new book "Help Your Boss Help You." 8/17 @ 6:45pm Register: https://t.co/EbG5iOH1Xy Hangout after for🍕&👋 https://t.co/24149m7mK1Atlanta Java Users Group @atlantajugI recorded another podcast about the book, this time for the OffHeap Podcast. That’s four different podcasts I’ve recorded that have yet to appear, since apparently unlike the Groovy Podcast that I cohost, everybody else has actual production values. I’ll mention it when it becomes available. Heck, I’ll say something when they all become available over the next few weeks.
This Friday I’m doing a free webinar for NFJS:
It’s only an hour and I promise to be at least mildly entertaining. Hopefully I’ll see some of you there, too.
Adventures in Chess
As I write this, I’m participating in the Continental Open, a chess tournament held in Sturbridge, MA, over the weekend. My results suggest I have a distinct style when I play:
Me: Hey, if I do this, then you do that, then I do this, then I’ll get a big advantage!
My Opponent: Maybe, but if I then do this, you’re in trouble.
Me: Oops. Right. Aw, nutbunnies.
The best thing that can happen to my opponents is I get the initiative and see an opportunity, since I’m really good at coming up with ultimately self-destructive combinations. There’s a metaphor for life in there somewhere.
Sunday Update: Here’s how the tournament went:
Round 1: Loss.
Round 2: Loss, to an 11 year old kid. He looked so young I couldn’t help asking. Serves me right.
Round 3: There’s an odd number of players in my division, so I get a bye! Back in the win column, baby! Oh wait, you want me to play anyway, against a person from a lower division? Sigh, I guess so … (time passes) … It turns out I’m not the only person who makes silly blunders! Back in the win column, baby!
Round 4: Draw, against the highest rated person in the Under 1800 division. I’ll take it.
Round 5: Another draw, again against a highly rated opponent, but I blew a win at least twice. Grr, but could have been worse.
Round 6: Ran into an opening trap but found my way through it. Got what I thought was a very even position. Lost anyway. Still have a lot to learn, apparently.
Total: 2.0 out of 6. My rating may go up, though. If so, I’ll call it a successful tournament.
Functional Java: map vs flatMap in Optional
In my Java courses, I make sure to talk about the difference between the map operation and the flatMap operation. Most developers encounter them when learning about Java streams, because the Stream interface has both methods.
The map method takes a Function that transforms a generic type T into a generic type R, so the map method converts a Stream<T> into a Stream<R>. For flatMap, the Function argument maps a generic type T into a Stream<R>. The method therefore produces a Stream<Stream<R>>, which it flattens into a Stream<R>.
The example I use in my courses uses a Customer class, where each Customer has a single String name but a List<Order>, and an Order is just a wrapper around an int id. Given a List<Customer>, I want the List<Order>.
The interesting part is to invoke a map operation vs a flatMap operation:
The first one prints out the names. The second one prints out a list of lists. That’s three lists of orders, the last of which is empty. The third one prints out some weird ReferencePipeline$Head with a hex address, which is what happens when you print a stream that doesn’t have a terminal operation. The last one, flatMap, gets you what you want.
That’s all well and good. What a lot of developers don’t realize is that the Optional<T> class also has both map and flatMap, and while the Function argument in map is just like the corresponding one in Stream, the Function argument in flatMap takes a Function that converts from T to Optional<R>. A lot of devs have the idea that you use flatMap if you have a 1-to-many operation, but that’s not it. You use it when the function produces a wrapped object, whatever that wrapper might be, and then need to flatten it.
So if Department has a getManager method that returns a Manager, you use map, but if it returns an Optional<Manager> (yes, I’m dreaming), you use flatMap:
Either way, you get back an Optional[Manager{name='Mr Slate'}].
Random Tweets
Here’s a nice little puzzle:
It took me a few minutes as well. A hint (in case you need one) is that they were very careful about the font they selected.
One does not simply bake cookies:
To be honest, I don’t think it’s possible to add too much butter or sugar, but my recipe is written in the language of Mordor, which I shall not utter here.
This may seem obvious:
What I like most about this figure is that Pluto is included as a planet, the way the Good Lord Intended It To Be. I had a shirt like this for a while:
You tell them, little guy. After all, a dwarf planet is still a planet.
I’m tempted to get this T-shirt, but I’m way too much of a coward to wear it:
Add your own size joke here. For example: If you’re not wearing a mask because your nose is too big, I’ll just say that I still somehow wear pants.
As a reminder, you can see all my upcoming training courses on the O’Reilly Learning Platform here and all the upcoming NFJS Virtual Workshops here.
Last week:
Latest Features in Java, an NFJS Virtual Workshop.
Week 2 of Spring Boot in 3 Weeks, on the O’Reilly Learning Platform.
Day 1 of an online private Spring course.
This week:
Java Testing with JUnit 5 and Mockito 3, an NFJS Virtual Workshop
Week 3 of Spring Boot in 3 Weeks, on the O’Reilly Learning Platform
Day 2 of an online private Spring course.
Reactive Spring, on the O’Reilly Learning Platform
NFJS webinar on HYBHY, Friday at 1pm EDT.