speaking online – presentation vs panel

I’ve been declining most speaking opportunities from home. I find it a lot harder and more tiring to speak when I can’t see anyone in the audience. It’s stressful enough being at home so much without adding more voluntary stress! I’m also worried about outside noise distracting either me or the audience. For example, sometimes a fire engine “doesn’t go by” (cars don’t/can’t let it go by so it stays at my corner for 20-30 seconds and I can’t hear anything).

I’ve done two “public” things successfully on video from home:

  • Intro trivia and moderating Q&A for the NY Java Sig. (This isn’t the main part of the meeting so I know someone can take over for me.)
  • A panel on architecture. The panel mitigated both my concerns. I could see the moderator and other panelists. So I could see reactions and wasn’t speaking to nobody.
  • When there was excessive noise at my end, I could mute until it went away. Other panelists were still talking so I wasn’t messing up the whole presentation.

java is smart – using var

I was working on some code and seeing how many local variables I could substitute with var. I was a little surprised to learn that the below compiles. It makes sense to me that mags is good because the type is there. It’s cool that years and sorted can infer the type of Integer as well.

package lists;

import java.util.*;

public class Magazines {

    public static void main(String[] args) {
        var mags = new HashMap<String, Integer>();
        mags.put("People", 1974);
        mags.put("Readers Digest", 1922);
        mags.put("The Economist", 1843);

        var years = mags.values();

        var sorted = new ArrayList<>(years);
        Collections.sort(sorted);

        int first = sorted.get(0);
        System.out.println(first);
    }
}

The Importance of Knowing Your Language – Micro Edition

I was reading about “fast” vs “slow” programmers and came across the assertion that there’s no such thing as fast or slow programmers given the same coding activity. And that being able to find an example of the same/similar problem. And solving the right problem.

I agree that being able to find an example is important. But knowing the language/API well saves a lot of time. As an experiment, I solved the same problem in Java (which I know fluently and use almost every day) and Python (which I know enough to cobble stuff together and don’t use often). As a “handicap”, I used vi for both so the IDE wouldn’t make me faster in Java.

The problem

Read a file and remove all the lines that have “slow” in any case.

Java

This took me just under 4 minutes. About half of which was spent looking up the imports and dealing with stupid stuff the IDE would have handled (throwing the exception and mispelling “output”

The solution:

import java.nio.file.*;
import java.util.*;
import java.io.*;

public class Process {
  public static void main(String... args) throws IOException {
    Path input = Paths.get("input.txt");
    Path output = Paths.get("output.txt");
    List<String> lines = Files.readAllLines(input);
    lines.removeIf(s -> s.toLowerCase().equals("slow"));
    Files.write(output, lines);
  }
}

Python

The same task in Python took just over 7 minutes.

The solution:

input = open("input.txt", "r")
output = open("output.txt", "w")
for line in input:
  if  line.lower().strip() != 'slow':
    output.write(line)

input.close()
output.close()

Conclusion

I didn’t become a slower programmer between writing the Java and Python examples. But I was slower. Because I had to look up more in order to accomplish the task. Someone who programs in Python more often could have whipped it out faster.

I’ve interviewed people who couldn’t have done it in either language in under 10 minutes.(I don’t ask this question at interviews but I have questions of comparable difficulty).

Plus people think and type at different speeds even if they know everything without looking anything up.

And a Funny Story

I was pair programming with a junior developer recently. When he was typing, we needed to read a file and do something with the contents. As evidenced by the above, I’m very familiar with the idiom for reading a file. When he said, “I’ll google reading a file”, I asked to take a turn at the (virtual) keyboard. As I typed the Path/readAllLines() idiom, I commented, “I”ll be google”. I have full confidence my teammate could have Googled this. And that he would have gotten correct code. But it was faster for me to type it. And he still got to observe the idiom either way. (Plus my way didn’t risk him finding the pre-Java 1.7 way and learning that)