Hey there, my name's Mitch and I'm a software/web developer at N.C. State! Check out the about page or see below for my most recent blog posts.

Why bubble sort is bad

This is a graph of runtime versus input size. Grey is bubble sort, all other colors are merge sort, quick sort, and radix sort.

caption

Vim tip: view file state from a certain amount of time ago

I found a nice little productivity hack in vim:

:earlier 30m

This resets the file currently being edited to the state it was in 30 minutes ago. Cool! You can also use :earlier 30s for 30 seconds ago, and :earlier 30h for 30 hours ago.

:later or :later 30m will reset the file back to the latest state.

Also: if you’re itching to go home early from work, just open the files you’re working on for the day and try :later 8h

:wq

Pipe dream: a post-mobile app world

I was doing some research today on how subnet masks work for a project involving building a VPN, and one of the random internet articles I read referenced RFC 1918, which is basically a chapter in the Internet specification that talks about private IP addresses. I thought to myself, “What does RFC stand for?”. I then proceeded to open a new Chrome tab, type in the question, and click a few links to figure out what it was.

This kind of trivial process in learning stuff on the internet is really common for me. I have a question, I open the 24th tab in my web browser, type something, click a few links, figure it out, and then get back to what I was doing. Now, this is incredibly inefficient. Time-wise no, it doesn’t take a lot of time to do all that; probably less than 20 seconds in most cases. But the real cost is interruption of flow. When you’re “in the zone” reading something and you have a question, you have to break your mental focus and go through the arduous process of searching and clicking and what not, and then get back to what you were doing.

Is there a way to fix that?

Well, Siri/Google Now/Cortana are kind of getting there. You just have to click a button, talk into your phone, and you usually get a result. The specific use case I’m talking about isn’t super well-suited for their current capabilities, but they are rapidly improving. But still, the issue with clicking the button on the phone and talking to it and diverting attention to your phone to look at whatever came up still breaks your mental focus. On top of that, I’m sitting here at my desk in my dorm room with my roommate. Although he’s a pretty tolerant guy, me uttering random nonsense into my phone every few minutes would get annoying. I wish there was a way to look up these little research-y questions without bothering anybody, i.e. silently, and without forcing you to break focus.

Meanwhile, researchers are busy working on technology that can transcribe thoughts into text. Think about that for a second.

Transcribe thoughts into text.

That’s powerful.

With the rapid improvement of natural language processing, artificial intelligence, and the aforementioned thought transcription technology, I see not only a solution to the meager “oh I have to look this thing up and break my focus” problem, but a solution which could represent a fundamentally new way to interact with mobile technology; one which doesn’t require looking at a screen and awkwardly typing into the miniscule keyboard, or getting out your phone from your pocket only to click a few buttons and carefully utter some words towards the bottom in a hushed tone in order to not bother anybody.

What I’m talking about is this: the majority of your interactions with your mobile device are carried out through thought. What I mean is when I ask myself “what is RFC?”, I don’t ask myself anymore - I ask the Siri or Google Now of the future that is always listening through some unobtrusive headset (as unobtrusive as, say, a bluetooth earpiece).

Just imagine, you’re sitting at the dining hall eating breakfast and you want to know how much sugar is in your bowl of Lucky Charms. As soon as you want to know, the Siri in your ear tells you. Or you walk out of a meeting at work and think to yourself, “I should review the stuff we just went over later today”. The Google Now in your ear asks you what time to set the reminder.

We have quite a ways to go before this sort of thing is technically feasible. With the departure of the AI winter, Siri and Google Now type systems are getting a lot better a lot faster, and I’ll be honest, I know almost nothing about thought transcription technology, other than the fact that the istudy referenced above achieved a whopping 25% error rate in their best case. Natural language processing has gained a lot of traction in recent years in correlation with artificiaul intelligence. It may seem far out today, but the technology we have today is akin to magic compared to what we had in 1916.

I think I’ll get back to my VPN project now. I’ve sufficiently broken my focus.

A tidbit of Java magic - integer caching

I came across a code snippet on StackOverflow:

Integer a = 42;
Integer b = 42;
System.out.println(a == b);
Integer c = 555;
Integer d = 555;
System.out.println(c == d);

The first print statement prints true and the second one prints false.

Wait, what?

The second comparison makes sense. == in Java compares references to see if they are the same object in memory (and primitives are compared by their literal value). So c == d should return false, since they’re not the same object in memory. The Object.equals() method is a functional comparison, but it doesn’t check actual reference equality, e.g. it doesn’t check the addresses of the reference variables. So why does the first comparison equate to true?

The answer can be found in the Java Langauge Specification, chapter 5. Two primitives being autoboxed into references via a boxing conversion may qualify to be cached for optimization purposes. Caching the more commonly used primitive values leads to faster access time, so these certain commonly used primitives are cached:

  • true, false
  • byte or char in the range \u0000 to \u007f
  • int or short in the inclusive range of -128 to 127

So in the snippet above, a == b is true because a and b are between -128 and 127, so when a new Integer a = 42; is created, it simply points to a previously cached Integer object.

Note that this only works when primitive ints are autoboxed to Integers. If two Integer objects are created (not autoboxed from the primitive type)…

Integer e = new Integer(4);
Integer f = new Integer(4);
System.out.println(e == f);

…then the comparison will be false, since both Integer references were explicitly initialized as separate objects.

Interesting stuff!