Long live the web.

Web browsers are a dated technology.

Today, most of the time we spend on a desktop computer is spent in a web browser. It’s not even unreasonable to spend all of one’s time in a web browser, hence the success of chrome os.

The web is great, but web browsers aren’t a great way to experience it.

The modern web is no longer a collection of static documents cross-referenced with hyperlinks. Today’s web is a collection of interconnected web services. The web pages that we use to access them are nothing more than web-based clients for those web-based services.

We still access those clients as we accessed the static documents of yesterday.

When I click on an email (mailto) link, it opens in the gmail web client because I’ve set that web-based interface to be my default email client. When I click on an http link in some other application, say a twitter client, it opens in my default web browser.

When I click on a link to a blog post, it opens in whatever client the person who posted the link was using. Maybe they were reading it on the blog’s native client (what we usually think of as the blog itself), but I want to view it in my favorite RSS reader. My browser should show me the content the way I want to see it.

Hyperlinks were designed to link static pages, but we rarely see static pages today. Instead we have web clients, which are technically the same thing but semantically very different. I don’t want a link to a client, I want a link to the resource itself; something that any client for the protocol can understand. I want blog://adrusi.com/post/5, not http://adrusi.com/post/5.

Browsers need to know how to handle links for foreign protocols. If I’ve set my preferred blog client, then when I open a blog URI, it should use my preference. Maybe if I haven’t set one, it could check whether the server hosting the blog service also hosts a blog client, and use that.

There is no browsing involved in what such a browser is doing. It’s not a web browser, it’s a web terminal.


P2P protocols for the distributed web

If we want a distributed web, and we do, then we need distributed media sharing services.

Tent, the distributed social network protocol, is focused on posts; JSON metadata with file attachments. This is great for sharing text posts with a couple hundred or thousand friends, but if you want to share media, as people often do, you’ll need a more powerful server. This is only because the poster’s server is responsible for serving the post to everyone.

I dream of a distributed web where people are encouraged to host their own nodes. A distributed protocol is nice, but if the result is a few major hosts each serving millions of users, that’s not orders of magnitude better than the situation today. But if people are to host their own nodes, running a server needs to be cheap. A good number of people are likely to host their own node if it’s easy to set up and costs no more than a raspberry pi and 250GB HDD.

A server like this is certainly capable of sharing images with 1000 friends, and probably even short videos, but what if someone shares an image publicly? What if that image goes viral? A measly home internet connection simply isn’t capable of handling that much activity.

What is needed is a p2p protocol for sharing media. Bittorrent is great and would work well for generic file sharing, such as a photo album, but it is not efficient for sharing single images. Bittorrent also isn’t good for audio and video because people don’t want to wait for the whole file to download before viewing it. Instead, there needs to be a specialized p2p protocol for small files and for streaming. Maybe these already exist but are in limited use, or maybe they need to be built from scratch. In any case, I believe that it is possible for small, personal node to handle the workload of today’s centralized servers.


A friend of mine suggested that facebook should notify you when someone downloads a photo either of you or that you uploaded. This would make sense, but it’s not as easy as it sounds. To the facebook servers, it looks not different when someone views a photo and when they download it. Moreover, since the photo cdns are accessed through subdomains of facebook.com, they are considered different origins and can’t access the session cookies to know which user is viewing the photo.

The cookie problem could be solved by having the server accessed through facebook.com act as reverse proxy for some request uris, maybe those prefixed with /cdn. This way the server would know who was viewing the photo.

The server could discriminate between views and downloads by notifying the server when the client is expected to download an image. The server could react with something along the lines of decrementing a “downloads” counter. Then when the client actually makes the request for the image file, it increments that counter. If that counter ever exceeds 0, then the image has been downloaded.

This is a very fragile solution, as browsers don’t always have the same behavior when requesting images. First, images could be disabled, which would result in the downloads counter being decremented too many times, and not incremented at all. This wold cause subsequent downloads (without viewing) to not register. Secondly, a browser may choose to repeat a request for an image (assuming that it is fetched using an http GET request) if it freed the downloaded image from memory. This doesn’t really happen in desktop browsers, but happens all the time on mobile devices with their limited memory. This would result in false positive downloads

It’s possible that these issues could be resolved, but I’m sure that it would always be possible to exploit the download notifications.


The objective-c Foundation library don’t allow you to have nil in collections. However, that doesn’t mean you can have other invalid pointers. Sure 0x0000000000000000 is certain to be invalid memory, but the same goes for 0x0000000000000001, so if you need a nil delimiter in you objective-c collections, just use this code:

[mutableArray addObject:(id)0x1];

(don’t actually though)

I’m not sure if this would work with ARC…


Go Multiple Return Values

I love the go programming language, but it’s not without problems.

I just encountered a little annoyance involving multiple return values. Here’s a very common pattern in go code:

db, err := sql.Open("sqlite3", "./foo.db")

In this example, sql.Open returns two values, one which is the database object and the other to represent any possible errors. The := syntax declares variables using type inference. It is the idiomatic way to declare all local variables. Here’s where the problem arrises:

var db *sql.DB

func initialize() {
    db, err := sql.Open("sqlite3", "./foo.db") // broken
    if err != nil {
        log.Fatal("Could not open database")

The issue is that := is redeclaring both variables, shadowing the global db. This isn’t necessarily obvious at first look because := does allow for redeclaration of variables in the same scope, provided that at least on of the variables being declared is new.

var x int = 9
x, y := 5, 7

This code compiles and works as expected, however, the following does not:

var x int = 9
var x, y int = 5, 7

This makes it relatively easy to be careless and move the declaration to a higher scope:

var x int = 9

func main() {
    x, y := 5, 7

func other() {
    fmt.Printf("%d\n", x)

This prints “9”, not “5” as might be expected.

The cleanest way to fix this is to declare y on its own and then use the reassignment operator:

var x int = 9

func main() {
    var y int
    x, y = 5, 7

func other() {
    fmt.Printf("%d\n", x)

This code will, in fact, print “5” and not “9”.

Fortunately, I noticed this non-obvious behavior when I encountered it and tested it out with the go playground. Had I not noticed it, and had my project been slightly larger, it might have taken me a little while to figure out why my global db object wasn’t getting initialized.


Is Algebra Necessary?

This is a response to an article that was pretty popular on HN a while back. It was popular on HN because everyone disagreed with it, but this is the sort of thing that resonates with a lot of people, and I’m disturbed to see that it was published in NYTimes.

A TYPICAL American school day finds some six million high school students and two million college freshmen struggling with algebra.

6 million high school students seems like a possible estimate; there are 17.53 million high school students in the US according to wolfram alpha. However 2 million college freshmen sounds like a vast overestimate. The annual birthrate is 4.29 million and nowhere near all people attend college. Assume 3 million college freshmen per year. 2/3 of college freshmen not understanding algebra is ridiculous, not only is a much larger percentage than the ~30% of high school students that don’t understand algebra, the expected percentage should be smaller for college students, since there is a positive correlation between the students that do not attend college and the students that do not understand algebra. This clearly false figure also makes me doubt the validity of the high school figure. Maybe the author just doesn’t understand the math?

Making mathematics mandatory prevents us from discovering and developing young talent.

5 hours a week of maths prevents developing young talent? If you’re willing to say that, then isn’t the next logical conclusion is to say that 35 hours a week of mandatory school also prevents developing talents. I doubt that many people would sympathize with the notion that school prevents students’ from developing talents.

To our nation’s shame, one in four ninth graders fail to finish high school.

And the solution is to make high school easier? This is like the way states treat standardized tests. So that the state can report higher scores on standardized tests for no child left behind, they make them painfully easy. Each year, at least once, I spend 3 hours in a room, taking a test that in reality takes only about 45 minutes, and which I could have passed with more than a 90% before stepping foot in the class that it is evaluating me in, and forbidden from doing anything other than sitting quietly and waiting after completing the test, not even when everyone in the room, and even nearby rooms, has finished (yes, I’m using this as an opportunity to complain). Making high school easier so that more students pass is also like printing more currency so that people have more money. It doesn’t actually give students more value, because even though they passed high school, that achievement is now worth less. Education is being inflated by jobs requiring more of it, let’s not inflate it more by decreasing it’s value artificially.

“There are students taking these courses three, four, five times,” says Barbara Bonham of Appalachian State University. While some ultimately pass, she adds, “many drop out.”

Well, how many students? Is this mainly referring to students who are mentally challenged or are more-or-less average but culturally or behaviorally inclined to refuse to learn anything? Sadly the vast majority of these students are destined to drop out anyway, and if they don’t, they are unlikely to succeed in jobs that require a high school education (or rather jobs that should require a high school education1)

The main impediment to graduation: freshman math. The City University of New York, where I have taught since 1971, found that 57 percent of its students didn’t pass its mandated algebra course.

Your school should teach math better. If more students are failing a course than passing it, it should be obvious that the professor and the curriculum need to be changed immediately. It is impossible that a competent professor would have that high of a failure rate, which makes the statistic irrelevant.

1 but that’s not something to fix by making high school easier, it should be done by somehow requiring employers to consider hiring burger flippers without high school diplomas.


Non-Technical Founders

"I have this great idea for a song, but I have no idea how to write or play music, so I need to hire an artist."

See the problem here? Good.

"I have this great idea for a website, but I have no idea how to program, so I need to hire a programmer."

See the parallel here? Good.

This is why I think the idea of a non-technical founder for a tech startup is bullshit. Sure there are things other than the actual programming of the project which need to be done, and they are integral to the success of the startup, but they are secondary. The fundamental components of a tech startup are the idea and the tech.

Which leads me to the issue of the idea. Ideas are great, but they are simple. The idea is the central component of any startup, but it can be expressed in only a few sentences at most. No one should be able to leach their equity off of the idea alone, and any other cofounder should feel deeply ashamed for letting them do this. Zuckerburg understood that, and while a lot of people think he was a dick for essentially stealing the idea for Facebook, I think that was the right choice.

If you have an idea, then you’d better have some other huge things going for you. If you have a bunch of contacts that you can use to get good contracts at good prices, that’s great. If you have 15 years of marketing experience for various successful startups, that’s great. But if you have an idea and no experience in any field which would be useful to the project, then (1) you’re probably not qualified to have the idea and (2) you don’t deserve to be part of the project.


Serverless: Part 1 of n

The web is a transition technology. The web is fundamentally tied to a centralized model where a single host is responsible for a service. This allowed for large scale innovation whilst we discovered what the internet would be used for. It turns out that we already had the kinds of systems that work best in place before the web. Instead of clients communicating with each other by way of a central server, the ideal system is distributed, where clients communicate with each other directly, bound by a common protocol instead of a server, and people can store their information wherever they choose. Email is a perfect example of this, and email is one technology which will never go away. Most people choose to host their email accounts on a remote server, such as gmail, but anyone can set up their PC to be an email server.

Email is not the most recent example of such a protocol. A project which has recently had some hype (granted only within communities with high geek concentration) is tent, which is a protocol for a distributed social network similar to facebook, which is technologically more similar to email.

Another familiar technology in the same spirit is RSS, which is essentially a standardized API for blogs. With that interpretation of RSS, blogs : email addresses :: wordpress.com : gmail.com :: RSS : the email protocol. Obviously RSS is not suited to be a protocol to replace modern blogs, as it lacks support for important features of blogs such as comments, multiple revisions, standardized sorting, etc.

One peculiarity of the web which users have come to love is that websites each have there own design. These designs help users quickly distinguish one site from others, and even convey information about the purpose of a site; a save-the-whales site is unlikely to have white text on a black background. We lose this with RSS, and to some extent with email, but nothing keeps us from having a protocol which transfers style information as well. The ideal protocol for transferring style information, would allow any level of customization; from none at all (defaulting to the client’s default styling) to styles making use of client extensions with explicit fallbacks to sane standardized alternatives.

Long ago, the web became much more than a technology, it became an economy, and this is the largest obstacle to creating a world of distributed standardized protocols. There are giants such as facebook and twitter with enormous momentum which will prove difficult to stop. It may be possible to use various APIs to make existing services compliant with new standardized protocols, which would allow for pioneer users to start making use of the new systems. Once these initial users exist, it would make it attractive to create services for them to use, giving them an advantage over those who use the original web-based services directly.

Some services are a poor fit for being made distributed, namely those in which the value is in computing with data rather than in the data itself (at least I think this is a good generalization, I’m probably missing something). For example, search engines are not a good fit for being distributed, although they would definitely benefit from having much of what is now the web being delivered via standard protocols specialized for different types of services.


PC Censors

This post was originally written as a comment on a facebook photo. I decided that I felt strongly about this and wanted a bigger audience, so I’m reposting it in verbatim here.

Banned: The server has automatically banned you for saying a bad word. You Said: "filipinos".

Ummm… I’m sure that this filter was created in good faith, but identifying a race is something completely different from being racist. And it’s certainly offensive to be told that your ethnicity does not exist.

I generally don’t approve of word filters anyway, especially the kind that punish you; if someone is offended by the presence of a word in a message, then maybe they actually deserve to feel offended because that’s a really stupid thing to be offended by. If someone is offended by the meaning of a message, that’s something completely different, but it should be up to them to take action, not a bot, because almost no bots do anything fancier than a word filter.

But this isn’t just a word filter that punishes you for saying words that are highly likely to be offensive (for example, you’d be hard pressed to find a situation in which “niggerfaggot” isn’t offensive) or even words that are generally considered “bad” for stupid cultural reasons. This is oppressive censorship.

I know that this is a computer game for kids, but it does manifest some problems we see in society accompanying the political correctness “movement” (for lack of a better word). Some people actually thought that it would be a good idea to automatically ban children from a game (which their parents may have paid for) for saying “Filipinos”.


Programming Competitions in Java

I’ve been looking into various programming competitions available to high school students, and every single one uses Java as it’s required language. A few also offer C and C++. I know both Java and C, but I don’t like either of them. I’ll use C on occasion, but only when I need to do some serious number crunching that can’t be parallelized (if it can I use Haskell).

I don’t like Java because it is so strongly focused on object orientation, requiring all functions to be methods and all callbacks to be anonymous classes. But despite how religious it is about OOP, it isn’t purely object oriented—”primitives” like numbers, characters and arrays are not objects, and therefore do not have a class, and therefore cannot be used in data structures that require class parameters (generics). This means that you have to “box” primitive values into a simple object in order to take advantage of the object oriented structures. The problem with these “boxes” is that you have to “unbox” values if you want to mess with them. So if you want to store an int in an ArrayList, you have to box it. And then when you retrieve the value from the ArrayList, you have to unbox it before you can add it to something, or do any kind of useful operation with numbers.

To make a long story short, Java’s type system is a fucking piece of shit.

I don’t hate on C as much because it’s minimalist, and that earns it some merit, but because it’s so close to hardware, you can’t do things like return an array from a function, you instead have to return the address in memory of the array.

Now I know that these complaints make me sound like a language snob (which I am), but on top of requiring the language, the competitions also require you to use an editor of their choice (!). This means that you’re required to use of the 4 competitions I looked into, only one allowed you to use anything other than Visual Studio or Eclipse, but the other editor that it allowed “manually editing code in a text editor and running it from the command prompt”, but it could only be a text editor preinstalled on their windows computers: Notepad.

Message to competition holders

  1. Let competitors use an editor of their choice. Have all the usual suspects preinstalled: Vim, Emacs, Eclipse, NetBeans, Notepad++, TextWrangler, edit (note that these are all free) and upon request, review teams that want to use other editors that are not-so-free, like TextMate, IntelliJ, Sublime Text, ETextEditor, etc.
  2. Let competitors choose their own OS. This could either be in the form of dual booting or offering various computers. Make sure to be very clear about the exact environment that the programs will be tested under.
  3. Allow competitors to use their own computers if they want. This would make the above 2 suggestions much easier, although I see why it’s unpopular. Competition hosts might be under the impression that allowing teams to use their own machines would give them an unfair advantage; their machine might be faster, it might have a large snippet library that others don’t have, etc. I think it’s fair to say that having a large snippet library is just part of being a good programmer, it’s not cheating unless the team somehow gets access to the problem sets and writes their programs beforehand. Having a faster computer could actually be considered a disadvantage because the team is less able to gauge how fast their program will run on the judges machines.
  4. Allow teams to use any language of their choice. Let them ask the judges to install a compiler or interpreter to run the programs. If they opt to write in python instead of C, they might finish writing their program faster, but it will run slower on the judge’s computer. I would love to apply for a competition that lets me write in Haskell much more than I would one that requires me to use Java.