Pascal Hartig

Writing code at Twitter

Read this first

Simpler Android APIs with AutoParcel

Simpler Android APIs with AutoParcel

I have made a small change to one of the Android libraries I maintain and was quite happy with how it turned out, so I wanted to write a few words about it.

Strings! Strings everywhere!

5560914199_f1219deea4_o.jpg

One of the things I like the least about the Android framework is its tendency to use Strings in all the wrong places. Java already has a (rightfully) terrible reputation for its type system. The Android SDK, however, goes a step further by forcing people to serialize their well-typed data structures and handing back nothing but a String in return. If you’ve ever accidentally called IntentgetStringExtra on an Integer you’ll know what I’m talking about. There is nothing preventing you from doing this at compile time. The only mitigation is manual careful checks that you’ve passed the corresponding constants on both sides of the serialization boundary.

Breaking

...

Continue reading →


2.5 Million Installs Later, R.I.P. Downloader for SoundCloud

TL;DR: SoundCloud changed their terms of service and politely asked me to remove my Android app from the Play Store. I’m open sourcing it today and you can get it from GitHub.

unnamed.webp.png

It was an amazing journey and I’m very grateful for the services SoundCloud provided for free. More than 71 releases, 2,571,289 installs, 11,257,885 downloaded songs, 5,498,590 swipes on the tutorial screen and 22,233 reviews later, Downloader for SoundCloud is no more.

The Idea

SoundCloud always had a great feature in its desktop web version. You can directly download any song to your hard drive. That is, if the artist is so kind to tick a checkbox during the upload flow. Depending on the genre you’re into this is more or less common, but especially for longer mixtapes it’s still quite prevalent.

0.png

Unfortunately neither the mobile web version nor the official native clients allow this. Data storage and file...

Continue reading →


Building Vim from 1993 today

Because of a conversation I had on Twitter earlier today, I felt compelled to compile the oldest version of Vim I could find.

As it turns out, compiling a C program from more than 20 years ago is actually a lot easier than getting a Rails app from last year to work. If you want to try it yourself, these are the steps you need to take:

$ docker run -i -t mugen/ubuntu-build-essential bin/bash
$ apt-get install -y wget gdb file
$ wget ftp://ftp.vim.org/pub/vim/old/vim-1.24.tar.gz

According to Wikipedia, vim 1.22, released in 1992, was the first version of vim to run on Unix and thus compete with vi. I couldn’t find a tarball of that release, so I went with vim 1.24 instead which was released a year later.

$ tar -xf vim-1.24.tar.gz
$ cd vim-1.24/src
$ make -f makefile.unix

unix.c: In function 'mch_settmode':
unix.c:361:23: error: storage size of 'ttybold' isn't known
unix.c:362:20:
...

Continue reading →


Don’t Fear the Reader

I was hesitant to publishing this article right from the beginning and even more so after reading Letter to a Young Haskell Enthusiast. I wrote this post mainly for myself, because explaining a concept to someone else is oftentimes the best way of understanding it yourself. I decided to still put it out there because I’ve personally benefitted a lot from similarly written articles, but please bear this in mind while reading and complaining about the article.

People who’ve worked with me will undoubtedly know that I’m a big fan of dependency injection[1]. Ease of unit testing is one benefit, but the biggest win in my opinion comes from forcing yourself to be explicit about the dependencies every component in a system has and the ability to easily swap them out.

Prior Art

But I’m not the first one arguing for DI. This is why we find different tools and libraries for nearly every...

Continue reading →


Partial Application in JavaScript using bind()

There is a pattern in JavaScript that I consider highly underused, because it leads to more concise code that is both easier to write and read. You probably all know of Function.prototype.bind. It’s used most of the time to get rid of all these var that = this or var self = this assignments you used to see everywhere. A common example would be:

this.setup = function () {
   this.on('event', this.handleEvent.bind(this));
};

The first argument passed to bind will serve as this within the scope of the function it returns. A lesser known property of bind is that it accepts more than one parameter. Every parameter to bind after the first will be prepended to the list of parameters when invoking the bound function.

That means we can create partially applied functions like this:

var add = function (a, b) {
  return a + b;
};
var add2 = add.bind(null, 2);

add2(10) === 12;

Exciting, eh...

Continue reading →