The extremely annoying text editor bug

This bug exists in all text editors I tried so far, with the exception of iWorks Pages… (they have their own set of issues anyway…)

To recreate the bug:

  1. Type text in the text editor really fast. You may even type random text if you’re not such a fast typer…
  2. Immediately after, start deleting with backspace
  3. Still moving quickly, press ctrl-Z (or command-Z on a Mac) for undo
  4. You thought the editor would undo your deletes, right? Hah!

I’ve been kicked by this nasty thing so many times. I type something. ADHD kicks in and I change my mind half way through, starts deleting, changes my mind again and presses cmd-Z. And it undoes everything instead of just the deletes.

Word does this, Scrivner does this… every simple text editor does… apparently 99% of text editor users does the index finger waltz?

One thing to avoid when using Objects. requireNonNull in Java 8

Consider the following singleton:

public enum MyVeryImportantSingleton {
  INSTANCE;

  private String a;
  private String b;

  public void set(String a, String b) {
    this.a = Objects.requireNonNull(a);
    this.b = Objects.requireNonNull(b);
  }
}

If it would be called in the following manner:

try {
  MyVeryImportantSingleton.INSTANCE
    .set("Hello world", null);
}
catch (Throwable t) {
  ...all sorts of recovery operations
  ...leaving the system running
}

MyVeryImportantSingleton‘s a-field is set, but the b-field is left in its previous state. This, of course, could turn into really bad news.

The right way to implement set() would be:

public void set(String a, String b) {
Objects.requireNonNull(a);
Objects.requireNonNull(b);
this.a = a;
this.b = b;
}

This is also a great praxis for all form of input error checking. It should first be finished, and then the object state can be updated once all input is ok.

You never know when your method will be called from inside a catch-block by a programmer that, incorrectly assumes the object state is okay even if an exception was thrown.

Pretending it never happened

Contrary to popular opinion, pretending [insert problem here] never happened isn’t going to make it go away. It’s going to make it come back…

 

Update: After watching a documentary about the alt-right movement I’ve decided to include my original thought:

Contrary to popular opinion, pretending the second world war never happened isn’t going to make it go away. It’s going to make it come back…

Is Life on Earth Early?

I’ve discussed the Fermi Paradox before, as well as answers to it pertaining to computer simulations.

Astrophysicist and cosmologist Avi Loeb offer another possible solution to it:

“We used the most conservative approaches to understanding the appearance of life in the universe, and our conclusion is that we are very early in the process…”

That is, aliens haven’t visited us yet, because, in fact, it’s our job to visit them… We’re the ancient and old and nasty and scary ones Hollywood is warning everyone about…

That actually makes sense to me… 😀


The Fermi Paradox:

There are billions of stars in the galaxy that are similar to the Sun, and many of these stars are billions of years older than the Solar system. With high probability, some of these stars have Earth-like planets, and if the Earth is typical, some may have developed intelligent life. Some of these civilizations may have developed interstellar travel, a step the Earth is investigating now. Even at the slow pace of currently envisioned interstellar travel, the Milky Way galaxy could be completely traversed in a few million years. According to this line of reasoning, the Earth should have already been visited by extraterrestrial aliens.

In an informal conversation, Fermi noted no convincing evidence of this, leading him to ask, “Where is everybody?”

%d bloggers like this: