Tales from the jar side: ChatGPT and GitHub Copilot are too helpful, Function composition, The rise of Mittens, Chess Bot of Death, and other amusing posts
Guy got admitted to the hospital after swallowing multiple plastic horses. He is described to be in stable condition <rimshot>
Don’t feel like reading this newsletter? That’s fine — I’ll read it to you on the companion YouTube channel. Today’s newsletter is tomorrow’s video.
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of January 1 - 8, 2023. I taught my regular Functional Programming in Java course on the O’Reilly Learning Platform this week, and completed another Medium post on Mockito for the pipeline.
Regular readers of (and listeners to, and now even viewers of) this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader (or listener, or viewer). If you wish to become a jarhead, please subscribe using this button:
As a reminder, when this message is truncated in email, click on the title to open it in a browser tab formatted properly for both the web and mobile.
ChatGPT and GitHub Copilot Being Too Helpful
As AI (artificial intelligence) pattern-matching algorithms go these days, ChatGPT gets most of the press. I’ve used it myself several times, including while writing this newsletter. This week, in fact, I was talking to a friend (And a jarhead! Hi Jim!), and he told me how he used ChatGPT to submit progress reports inside his current organization. You just sketch out what you want to say, and it comes up with a way to say it.
While we were talking, I tried asking ChatGPT to generate an abstract for a conference talk on Mockito (the subject of my latest book, Mockito Made Clear), and it spit out something actually plausible.
Hmm. Not sure what it means by “complex hierarchies and third-party dependencies,” but I can modify that. It’s a little sales-y, too, but that’s not too unusual for conference abstracts.
The phrase “intimidating for developers who are new to mocking” makes me want to include this image of Nelson:
But, you know, I could live with that abstract, especially because it took me zero time to generate. I may have to submit it somewhere and see what happens.
That’s not why I wrote this section, however.
GitHub Copilot
I’ve also talked about GitHub Copilot in this newsletter before. That’s “Your AI pair programmer,” as the propaganda on the web page says, but that’s not a bad description. It’s a neural network trained on lots of projects at GitHub (exactly which ones and whether they really granted GitHub the rights to do that or not is the subject of some current lawsuits) as well as your own code. That means the results it suggests always look plausible, even if they aren’t necessarily right.
This week I taught a class called Functional Programming in Java, and I got to the part where I cover function composition, or at least the very limited form of it built into the Java libraries. For that, I usually go to the Predicate<T>
interface in the java.util.function
package, where you’ll find default methods add, or, and negate:
As a code example, I generally do something like:
That also both the and
method from Predicate<T>
and the uses the default andThen
method from Consumer<T>
. The Java library lets you combine consumers with consumers or predicates with predicates, or even functions with functions. What it doesn’t include is any easy way to combine consumers with functions with predicates, or any combination like that.
One of the students, who clearly had more of a mathematical background than most, asked about true composition, which basically means if a function f
maps type A
to type B
, and a function g
maps type B
to type C
, then the composition of f
and g
should map type A
to type C
. That’s exactly the sort of thing Java doesn’t have built into the library.
I reproduced his statement of the question in a comment in the code, which looked like:
// f: A -> B, g: B -> C, (g.f)(x) = g(f(x)), A -> C
That’s pretty much how he wrote it in the question. I then said, “you could write a function in Java that did that. Let me think a minute,” and then hit the carriage return.
GitHub Copilot (integrated into my copy of IntelliJ IDEA) immediately suggested:
I stared at it a moment, and said, “or, you could just do that.”
Whoa. Yeah, that’s composition, in a nutshell. It is restricted to Function<T,R>
instances, but that’s probably okay in most cases. What really freaked me out is that it even called the method compose
given no hints at all, which is actually what I wanted.
For the first time, I wondered out loud whether this AI thing is going to put developers out of a job. But no, it really won’t. You have to know a fair amount to understand that code, or even just to state the problem in a way that GitHub Copilot can understand enough to generate a solution.
I just went back to ChatGPT and asked it to generate a test case for this function. Here’s what it produced:
I mean, yes, but no. It works, and it’s correct, but it uses Integer
everywhere. Part of the point of this exercise was to have the first function go from one type to another, and the second function go from that result to a third type.
I wrote the following test myself:
I’d like to believe that’s better. I especially like that the word even has an even number of letters and odd has an odd number, but maybe that’s my own sense of humor at work.
I may, however, just be deluding myself. I went back to ChatGPT again and said:
That test used Integer for the input and output types of both functions. Can you come up with a different test that uses different types?
It replied:
Certainly! Here is an example of a test case that uses different types for the input and output of the functions being composed:
Of course it did. That’s a good thing, right?
Aw, nutbunnies. I quit.
The Rise of Mittens, Chess Bot of Death
Another theme I tend to revisit in this newsletter is the chess world, especially when it breaks through to what we euphemistically call the real world. This doesn’t (quite) qualify there, but there’s been an event, and I want to let you know about it.
I have accounts on chess24.com and lichess.org. The former I use mostly to watch major Grandmaster tournaments, because their broadcast commentators tend to be excellent. I know they also normally simulcast those shows over YouTube, but I’m comfortable going to the home site and watching from there. Admittedly, I don’t do much else there, and I still haven’t played anybody there.
(As an aside, last month Magnus Carlsen played in the World Rapid Championships and the World Blitz Championships. The dreaded Hans Niemann, he of the $100 million lawsuit against Magnus and others for accusing him of cheating, was also playing. While Magnus was in excellent form and wound up winning both tournaments (!), Niemann was pretty good but not great. That meant Niemann didn’t play well enough to get paired against Magnus. You know Magnus had something prepared for that, but we never got to see it. Oh well.)
The lichess.org site is a free, open source server that I really like. I upload all my OTB (over-the-board) tournament games there into lichess “studies,” which allows me to request a computer analysis and see how often I screwed up. Which is a lot. Ugh.
I also have an account on chessable.com, where I purchased a few courses, worked hard on them for a while, but haven’t visited in long enough it made me log in all over again. Sigh.
I even have an account on the Internet Chess Club, chessclub.com, because a few of the online tournaments I played last year (officially rated by the USCF) took place there.
The only major site where I never had an account was chess.com. I’m not sure why I’ve resisted it. Maybe it’s because they’re the biggest, and I tend to root for the underdog (which is kind of depressing — underdogs, being underdogs, tend to lose a lot). Maybe it’s because I’d already subscribed to so many servers and didn’t want to go with yet another. A month or two ago, when the company behind chess.com bought Magnus Carlsen’s Play Magnus group, I almost jumped in, but not yet.
Then along came Mittens.
This image, taken from this link at esports.gg, kind of says it all.
The subtitle in the article is, “Meet Mittens, an adorable pure evil who wreaked cat-astrophe in the Chess dimension.”
Apparently, at the beginning of the new year, chess.com added a series of computer opponents. They all use cute cat avatars, and play to different strengths. According to the article:
Scaredy Cat (rated about 800)
Angry Cat (1000)
Mr. Grumpers (1200)
Catspurrov (1400 — for those who don’t get the reference, that’s a pun on Garry Kasparov, the former World Champion and one of the greatest players who ever lived)
Mittens (1)
Yes, technically Mittens has a rating of 1, which is actually impossible. It is, however, nearly invincible, and it knows it.
It harasses you during the game while destroying you. I watched a couple of YouTube videos of Hikaru Nakamura (one of the top 5 players in the world) getting trounced by Mittens and then barely hold it to a draw, all while complaining that it’s not that good even though he kept getting bad positions against it.
Anyway, now I have an account on chess.com. I played the bots, and I’m probably a bit better than Catspurrov but that’s about it. If you’re on that server, my handle is kennethkousen. Maybe I’ll see you there.
My plan is to avoid Mittens. It seems that Magnus Carlsen hangs out there, however. I know because I watched him play blitz for about an hour when I should have been finishing this newsletter.
News and Other Jokes
It’s been quite a week.
Speaking of the House
Like most people, I was absorbed in the ongoing disaster in the US House of Representatives as the Republicans tried 15 times to elect a Speaker of the House before finally getting their guy. That was appalling, but the social media posts were pretty good.
Or this one:
Or even this one:
This image brought back some memories:
There was a good one about Kevin McCarthy finally getting his quinceañera, but I don’t seem to have saved it. I also liked the one about Republicans being incapable of a peaceful transfer of power even when it’s for their own party. This does not bode well for the future, but we already knew that.
Other Funny Posts
Tom Gault posted his latest cartoon:
I thought this was clever:
Somehow, I don’t think that’s going to work.
I thought this was great:
I loved this list of murder weapons in the new “woke” version of Clue:
And finally, this proposed idea:
Excellent responses included:
I Will Survive (Gloria Gaynor)
Another One Bites The Dust (Queen)
Hit The Road, Jack (Ray Charles)
At Last (Etta James), and, of course
Ding Dong, the Witch Is Dead (Wizard of Oz)
One more thing: Thanks, everybody, for the kind words during my COVID convalescence this week. It wasn’t fun, but much milder than many of my friends had to deal with. I finally tested negative on Saturday. I posted at the time that now if I get out of breath going up the stairs, I have only myself to blame. Several people responded, however, to say it can easily take a month to really recover, so I’m going to continue to blame the disease for as long as I can get away with it.
The video version of this newsletter should be uploaded on the companion YouTube channel tomorrow.
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:
Functional Programming In Java, on the O’Reilly Learning Platform
Write Medium post to support Mockito Made Clear
Publish video reading the newsletter on the Tales from the jar side YouTube channel on Monday.
This week:
Getting Started with Spring and Spring Boot, on the O’Reilly Learning Platform