Pairing, but not as you know it

We’ve all heard of the benefits of pairing when it comes to coding, many of us have done it in our jobs and reaped the rewards, but have you ever paired to write English?

code-with-me.png

The agreement

Last week I suggested that we, Trisha Gee and I, do exactly that. We were both struggling to get into the zone of some written content that needed creating, and I’ve always wanted to try pairing on writing. I’ve benefited myself from pairing on code and, as a sole technical writer in the past, I’ve watched with envy as developers paired on their deliverables as I cracked on with me, myself and I for collaboration. Trisha agreed that we could try it so here’s the honest account of how pair-writing went, and what I learned.

We set aside two hours for the process. We were writing the content in IntelliJ IDEA, so we opted to use the new Code With Me functionality, so we could share our session in real-time with audio and video for the full 2021 remote-pairing experience. First up, we installed the plugin (currently experimental) and then we joined the Code With Me video call.

We spent a few minutes messing about with Code With Me, working out what we could and couldn’t do and then Trisha talked me through the pairing model of a driver and a navigator. In this model, one person drives (types) and one person navigates (thinks and talks). At this point, we both agreed I would drive, and Trisha would navigate because she knew the subject well, and I can type pretty fast on a good day. With the roles assigned, I put on my racing helmet, got into my rally car, and strapped myself in. While I was amusing myself with my fantasy car world, Trisha was creating a Scratch file to dump notes in that she wanted to come back to as she was navigating us around the track.

 

The pairing

Okay, so, we’re off. I was quite nervous about how it would work given I had pushed for it, but I kept up with the musings from Trisha and adopted shorthand where necessary. I surprised myself at how few mistakes I made. I was keen to ensure that what I noted down would be legible and understandable because I would be using my notes to turn the content into customer-facing content later. If I couldn’t do that quickly and easily, then this whole process wouldn’t be worth it. It would still be useful in that we would know that pair-writing doesn’t work, but that would be about it.

I kept an eye on the clock, and I think we were probably chatting for about 35 minutes in total. We were rudely interrupted by a phone call from my solicitor, which I had to take to try and keep my impending (and exceedingly stressful) house move on track. That is the point that we pulled off the race track. I think I’m probably done with that analogy now.

Image by Dimitris Vetsikas from Pixabay

 

ooops.jpg

The mistake

 

Before we finished the pairing session, Trisha was keen to get some inline code working that was being pulled in from another project. She talked me through how to add an attribute for the Asciidoc Plugin so that the code would be pulled in. Unfortunately, it didn’t work, so, after much discussion and bemusement, we decided that the experimental Code With Me plugin might be the problem.

We left that call and hopped on a different video call to troubleshoot. It’s entirely possible that Code With Me was not in any way the problem, and the problem was that the code I was trying to grab hadn’t been pushed, but we’ll just leave that one there!

Image by Craig Steffan from Pixabay

 

keyboard.jpg

The write-up

Skip ahead three days, and it was time to write up the notes from the pairing session. I was apprehensive because I was worried I wouldn’t understand my notes, but I was pleasantly surprised! Of course with a typical code pairing session, you wouldn’t walk away from it with half-baked, non-compiling code, but I was hopeful that my brain could make the notes I’d written previously into effective content; the equivalent of compiling code.

The first thing I did was commit the notes from the pairing session locally. Yes, I could have just deleted them and then used IntelliJ IDEA’s Local History, but I thought I’d go down the commit route for posterity and longer-term tracking. Once I’d committed it, I started hacking up the content. I went paragraph by paragraph reworking my driver notes into useful pros. It took me 30 minutes on the dot. I committed the updated topic and felt extremely pleased with myself. It had worked!

Image by Daniel Agrelo from Pixabay

 

wine-cheese.jpg

The learnings

It’s not just wine and cheese that go exceptionally well together as it turns out! Pairing works for writing too! In fact, it works really well. If you have one person who knows a lot about the subject they might make a great navigator (not exclusively).

You don’t need to have the same experience, or even the same job role, to pair on something; I recommend you try it. I wish I’d done more of this as a Technical Writer, I think it would have been very successful in a number of professional situations where I needed to create the content and didn’t (yet) have much subject knowledge. I will certainly be doing more of it now!

Image by Oldiefan from Pixabay

 

Generating Code with IntelliJ IDEA

One of the super cool things about IntelliJ IDEA is how much code you can generate with minimum effort. Yes, it’s not the 1990s anymore, we’re no longer measured on how many lines of code we generate (thankfully), but you also know that Java has its fair share of boilerplate code.

Well, there’s a shortcut in IntelliJ IDEA that generates a lot of code for you:

  • ⌘N on macOS

  • Alt+Ins on Windows and Linux

These shortcuts load the Generate menu! Here’s a quick tour of where you can use it in Java projects in IntelliJ IDEA. It’s not a complete list; let me know where else we can use it please!

New Java Class

In the Project Window, you can use this shortcut to create a whole host of things which are project and folder specific. If you use the shortcut on your directory that is marked as your sources root (usually src) in a Java project you get the option to create a new Java file (among other things). You’re then asked to select between a Class, Interface, Record (Preview), Enum or Annotation. It’s a speedy way of creating new classes for your project.

Before we move on, a closely related shortcut is the one we use for a new Scratch File. It’s ⌘⇧N on macOS, or Ctrl+Shift+Alt+Ins on Windows/Linux. You can select to create a new Scratch file using ⌘N on macOS, or Alt+Ins on Windows and Linux in the Project Tool window, but it’s worth committing the scratch file shortcut to memory too as it’s handy to be able to dump some code or notes in an area outside your project and share it across IntelliJ IDEA projects.

Constructors

Now that you’ve got your class, you may want to generate a constructor or two. However, before we do that, let’s add a couple of variables to our class:

public class GenerateCode {
   private final String name = "Helen";
   private int age;
   private String mood;
}

We can use the same shortcut to make ourselves a constructor. We get some options here because we’ve got some fields in our class:

generate-constructor.png

IntelliJ IDEA is asking us if we want to pass our fields into our Constructor.

If we select both and click OK we have our Constructor with the parameters passed in.

public class GenerateCode {
   private final String name = "Helen";
   private int age;
   private String mood;

   public GenerateCode(int age, String mood) {
       this.age = age;
       this.mood = mood;
   }
}

Other Class-Based Generate Options

We don’t need to stop there either. There’s a whole host of code that IntelliJ IDEA can generate for us at this stage including:

  • Getter

  • Setter

  • Getter and Setter

  • equals() and hashCode()

  • toString()

  • Override Methods

  • Delegate Methods

  • Test

While we’re here, Java Records are coming and IntelliJ IDEA is ready. Another way you could generate code if you’re not ready to move to Java Records is to use the Generate shortcut to create a new Java record, and then you can convert the Java record to a normal Java class with ⌥⏎ on macOS, or Alt+Enter on Windows and Linux with your caret on the class name.

Implement Methods

When our Java class implements an interface, we need to ensure that we implement that interface’s methods. The Generate menu helps us here too. Let’s say that our code looks like this, and we’re implementing NewInterface:

public class GenerateCode implements NewInterface {
   private final String name = "Helen";
   private int age;
   private String mood;
}

When we use ⌘N on macOS, or Alt+Ins on Windows and Linux this time, we see select a new option call Implement Methods:

implement-methods.png

The keyboard shortcut is ⌃I on macOS, or Ctrl+I on Windows/Linux.

This allows you to generate the code required to implement the methods in the Java interface that we’re implementing with the @Override annotation.

Now IntelliJ IDEA has generated that code for us:

public class GenerateCode implements NewInterface {
   private final String name = "Helen";
   private int age;
   private String mood;

   @Override
   public void doSomething() {
   }

   @Override
   public void goSomewhere() {
   }
}

This also works for overriding methods from superclasses/super abstract classes. 

Add Parameters / Arguments

Another useful trick you so is to use ⌘N on macOS, or Alt+Ins on Windows and Linux when you’re in a dialogue, and you need to add more rows or data. For example, we added a default constructor to our class, but we now want to refactor it to change the signature. Our code currently reflects the default constructor:

public class GenerateCode{
   private final String name = "Helen";
   private int age;
   private String mood;

   public GenerateCode() {
   }
}

Let’s refactor the Constructor with ⌘F6 on macOS, or Ctrl+F6 on Windows/Linux. In the Change Signature dialogue, you can use ⌘N on macOS, or Alt+Ins on Windows/Linux to add a new parameter. This saves you using your mouse to click the little + icon.

This trick works in all the dialogue boxes that require additional lines to be added that I’ve found so far.

Generate Test Methods

Finally, everyone loves a good test and rightly so. We’ve already mentioned that you can use the Generate menu from a Java method to generate a corresponding test class. However, once you’re in the test class, you can use ⌘N on macOS, or Alt+Ins on Windows and Linux again to create much of the boilerplate code you might need, including (for JUnit5 at least):

  • Test Method

  • SetUp Method

  • TearDown Method

  • BeforeClass Method

  • AfterClass Method

If you are working with a different testing framework, your Generate menu will give you other relevant options.

Summary

Java may be a little clunky on the boilerplate side of things, but IntelliJ IDEA takes the heavy lifting out of that to a large extent so along with the shorcut for intention actions, it’s a compelling combination.

What 2020 Taught Me

I’ve never given the word normal that much thought before, but 2020 has made me challenge my perceptions of normal. Normal is just a word used to describe the current social status quo. Normal right now is facemasks, excessive soap, and social distancing. If you’d have mentioned phrases like lockdown, covidiot, or keyworker in 2019, most people would have tilted their head to one side, given you a quizzical look and wondered just how large the wine was you had at lunchtime.

Equally, if you’d have said they’d be a fundraiser to buy Chris Whitty his own ‘next slide’ clicker, that Jonathan Van-Tam would become famous for comparing yoghurts to vaccines, or that Brexit would not be the biggest story of 2020 (in the UK), people would have likely nodded slowly and pretended that they had to leave to take an urgent call.

However, all of this is now entirely normal for me. Along with teachers giving kids grades because exams are cancelled, hugging loved ones through transparent shower curtains, and me waving manically at my webcam several times a day. Normal is a word that describes a constant state of flux. I’ll be using it more thoughtfully in the future. I’ll also be checking if I’m on mute.

These are my top three learnings from 2020.

I’m still a Java fan-girl

I pivoted my career from Technical Writing to Developer Advocacy in 2020 (via Product Owning). I did Java at university, it was a long time ago, but as it turns out, I still rather like it. Unlike the more prepared of my peers, I turned up at Sussex University to study Computer Science with virtually no knowledge beyond how to plug a computer in, and a bet to get a degree that I was determined to win. Retrospectively, I probably could have drunk a little less, and applied myself more, but I was 19 and somewhat lacking in life experience and foresight.

Fast-forward 20+ years, I’m no longer 19, I have some life experience, and occasionally I have foresight. This has meant that as my career comes full circle and back to Java (which, much like me, has changed a lot), I’m finding it much easier to work with the language and apply myself. It’s made me realise how much I love the language; although I think a good portion of that love is also attributed to the invention of IDEs such as IntelliJ IDEA. Wow do they make life easier when it comes to learning to code; I wish they’d been around in the ’90s!

I guess age isn’t all that bad after all (aside from pulling muscles doing mundane tasks around the house which seems to be part of the package). Coming back after a period of evolution is really enjoyable, especially in a role where I can learn and share with others who are on the same journey.

I enjoy speaking at (currently virtual) events

Honestly, before 2020 this terrified me. However, 2020 brought this new normal, which involved speaking from the safety of your dining room table/box room/kitchen/sofa to an audience. I’d never done a conference talk of any sort before except internally at places I worked. I joined the London Java Community, and I started with a 5-minute lightning talk. I got the bug; I got it really bad actually. I was offered the chance to moderate a YouTube panel through work and took it, and this week I’m giving a longer presentation to code nation, and I can’t wait. Oh, I’m also doing a podcast episode in a couple of weeks!

I really enjoy speaking, and I’m looking forward to being able to do it in person, so I can better learn the craft and meet more people. I’m sure that’s a completely different skill-set, but one I look forward to working on.

Time is a gift

2020 gave me the gift of time. It gave me an hour of commuting time back a day (at least), it gave me all my social commitments back (I’m still in mourning for these, but I hope they’ll be back one day), and it meant that the phrase “set the alarm” was a fairly pointless one. The 2020 commute to work could be managed in about 7 minutes providing I didn’t have bed hair.

There was no requirement to go anywhere, in fact, it was mostly against the law to go anywhere except the supermarket, and the one thing that needed to happen (work), felt oddly more manageable as a result. Of course, this is just my experience, for many people the 2020 experience robbed them of time, especially for those with children which I recognise.

Initially, I was a little bit confused with what I should do with all the time that I wasn’t used to having, but gradually I became rather accustomed to it. I have read more books this year than in the past five years combined, I have created myself a platform (this site), I have embarked on learning new things both for fun and in my job, I have crafted house-based gym routines that even the most sadistic gym-goer would be proud of, I have made quilts for friends and colleagues, I have contributed to open source projects, and I’ve started writing regular blogs on a variety of subjects too.

Summary

I know for many that 2020 has been an incredibly tough year. I have definitely had many low points as well, but these are the learnings that I’m taking from the year for myself, and I hope I can build on them in 2021; whatever that looks like.