HNHacker News
TopNewBestAskShowJobs

KrisJordan

1,721 karma · joined May 4, 2008

I teach computer science at UNC.

http://krisjordan.com

http://twitter.com/KrisJordan

submissionscomments
KrisJordan··on The Micro PHP Manifesto's Missing Tenet
Very interesting. How has this not gotten more attention? On first glance this is pretty much exactly what I was describing would be valuable. Are you the author?
KrisJordan··on The Micro PHP Manifesto's Missing Tenet
It's definitely bloody on the bleeding edge :)

Here's a link to the node_modules loading algorithm since v0.4, if you haven't checked it out, it's worth the quick read: http://nodejs.org/docs/latest/api/modules.html#loading_from_...

This module loading algorithm is what opens the door for npm to install nested dependencies in recursive node_modules subdirectories.

KrisJordan··on The Micro PHP Manifesto's Missing Tenet
Node.js and npm made a pretty vicious, backwards compatibility breaking change in its symbol loading algorithm in the move from 0.3 to 0.4. It was a weird and frustrating blip for those who were programming for node before that. What they now do with dependency management is pretty genius, since 0.4. Dependencies are installed locally to the package that depends on it, not globally on your system, and can be fulfilled recursively. Say you depend on Package B.1 and A.2, B.1 can simultaneously depend on A.1 and everything works out fine. It's perhaps the most interesting approach to the dependency problem I've seen (and, unfortunately, a system that couldn't be replicated in PHP without really shaking the foundation). (edits)
KrisJordan··on Show HN: multimethod.js - a Clojure-inspired multimethod library for JavaScript
Great question, probably worthy of its own post. Rather than trying to think of times you want to construct switch statements dynamically, try to think of times you'd like to specialize how a generic function call will respond to arguments it may not even know about.

In object-oriented programming, you can define a base class "Animal" with a method "makeNoise" and subclasses with a method "makeNoise" with that will return "bark" if you call a Dog's makeNoise or "meow" if you call a Cat's. When you first defined the Animal's "makeNoise" method you didn't need to know how anything about the subclasses that would eventually implement it. Your algorithms could depend on "makeNoise" returning the noise specific to the animal in question.

Multimethods are a functional approach to polymorphism without a class/prototype hierarchy. The second example in the post shows how you might implement a multimethod that calculates the area of shapes. Perhaps a separate module introduces new kinds of shapes (like new kinds of subclasses in OO). These shapes can register their area implementations with the 'area' multimethod. Other algorithms that use the 'area' multimethod will now be able to operate on these new kinds of shapes. Multimethods provide a means to polymorphism while keeping data and functionality decomposed.

Like swannodette says more beautifully and concisely, though, it's an even more generic/flexible dispatch than thinking in terms of OO polymorphism.

KrisJordan··on Show HN: multimethod.js - a Clojure-inspired multimethod library for JavaScript
While fib is a good example of concisely illustrating the control flow of a multimethod, it is a bad example of where it makes sense to use a multimethod. What is interesting about a multimethod is you can change your dispatch logic and bind new cases well after your multimethod function is constructed. In situations like fib where you know every case you need to handle up front you should certainly use 'switch'.

To illustrate this flexibility in the context of fib, multimethod.js, and CoffeeScript:

   > fib = multimethod()
           .when(0, 0)
           .when(1, 1)
           .default (n) -> fib(n)
   > fib 20
   6765

   > fib.dispatch (n) -> n.numberVal or n
   > fib 20
   6765

   > fib { numberVal: 20 }
   6765

   > fib.when 2, 1
   > fib.when 3, 2
   > fib 20
   6765 (now "optimized" with fewer recursive calls than before)
KrisJordan··on Show HN: multimethod.js - a Clojure-inspired multimethod library for JavaScript
Good question.

Performance will depend on a number of factors, such as how complex your dispatch function is, how complex your dispatched values and match values are (deep equality becomes more expensive as the compared objects grow in complexity), and how many methods are registered. In general, it is much more expensive than native switch statements or prototype chain lookups.

If performance is of utmost importance and you can substitute a switch statement or prototype hierarchy for a multimethod, you should. Multimethods are a useful pattern for achieving things that either aren't possible in switch (add/remove cases dynamically, deep equality case matching) or are not naturally/painlessly expressed with a prototype hierarchy.

KrisJordan··on Show HN: Hacker News Mobile - A fast and readable mobile HN website
I wrote the server-side portion of this app. It's actually a tiny coffee script program that caches iHN.net's API calls in redis. We cache/proxy the successful responses and toss out the 500s. When a cached copy of the content is available it'll be served immediately from redis. We refresh the cache on-demand in the background. This allows us to buffer out delayed / erroneous 500 errors the iHN API sometimes responds with.

This is running on a 256mb Ubuntu virtual server and it's overkill for both processor and memory. Kind of neat watching the story climb HN (currently #4) and watching `top` without being able to tell anything is happening on the server at all: 0,0,0,0%user,100%idle -- a testament to the light weight beauty of node,redis,nginx.

KrisJordan··on [dead]
Felt in Carrboro, NC, too.
KrisJordan··on Rackspace cloud beats Amazon EC2, by a lot
Linode to S3 is not apples to apples. If you want to compare to S3 you would need multiple linode boxes and a system for redundancy in the face of image corruption or hardware failure.

One of the things you are paying for with S3 is a pretty solid guarantee that your files will A) not get lost and B) always be available.

KrisJordan··on Rails 3.1 shipping with CoffeeScript
After a few months of CoffeeScript development I vastly prefer it to JavaScript. Jeremy, et. al., have done a beautiful job with it. I've used Sass/Less as well and believe the JavaScript/CoffeeScript divide is even more valuable.

Edit: I wrote about some of my favorite features of CoffeeScript when we added CoffeeScript support to our CMS app HiFi... http://www.gethifi.com/blog/hosted-cms-coffeescript-support

tl;dr:

1) Lightweight function declarations (with default values!)

2) Implicit Returns

3) Everything is an Expression

4) Object Literal YAML-like syntax

5) Simple, Classical OO Features (you don't have to use them and can still directly access prototypal features, too)

6) (Not in the post) Binding 'this' to the scope's 'this' using => is awesome.

KrisJordan··on Inline PHP-FPM Server Running on Node.js
Being able to pop into terminal, create a directory and a PHP file, then run node-php to get a test server running in this new setup is an efficient way to try code out. If the built-in PHP web server were standard this would be less useful.
KrisJordan··on iOS 4.3 Not Providing Nitro Engine To Web Apps Launched Full Screen?
When a public component uses one JavaScript engine over another it is probably not a bug or an oversight. My guess is it is an internal dependency and scheduling issue at Apple. The team behind UIWebView is probably downstream from the Safari/Nitro team and they didn't get the new bits in time to ship with 4.3. Full screen mode may well depend on UIWebView and not the Safari app components.
KrisJordan··on Re-using Backbone.js Models on the server with Node.js and Socket.io
Symmetry between code on client and server has long been the promise of server-side JS. I'm working towards a similar goal of reusing Backbone's model/collection structure server-side. It does not attempt to pub/sub events to all clients with an instance of a model/collection, at least not yet.

My project simply proxies client fetch/save/destroy calls via Backbone.sync to the server. Through a RESTful URL convention and Express.js the model and collection of the client's request are recreated, any transformations applied and persisted, then sent back down the pipe. Server-side, models and collections extend their client-side bases and introduce additional functionality (i.e. per-user access control). Models and collections are not kept in memory server-side beyond the duration of a request.

KrisJordan··on Production is Red, Development is Blue
To get a red prompt drop this line in your ~/.bashrc file on your production server:

PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '

We use this in our production environments and the red prompt, though not as jarring as a red background, is still scary enough to serve its purpose.

One upside in setting this up on the server, as opposed to local like the OP, is that all connections in will get the red prompt.

KrisJordan··on First we built an API, then we built a CMS
Yes, and thanks to tptacek's advice on HN we have used bcrypt for passwords from the get go.
KrisJordan··on First we built an API, then we built a CMS
Re: authentication.

There are three paths to authentication presently.

1) Anonymous - Anonymous is a subject in the system with explicit permissions. When no authentication is presented the system assumes you are the anonymous subject. This is the common case because most website content, for the types of websites we've seen on HiFi, are made up of entirely publicly readable content.

2) Cookie Based - We use your typical web app SHA1 hash with generated salt. Not the greatest form of authentication, susceptible to replay, but preferable to HTTP Basic.

3) HTTP Basic Based - Want to get rid of this sooner than later. Need to invest in digest but it has its problems. This is not used in the app but is useful for server-server API consumption, cURL scripts, etc.

As Joel mentioned, the backend is largely XHR driven. Results are rendered primarily with an evolution of Resig's JS templates (http://ejohn.org/blog/javascript-micro-templating/). When time permits we'll move to the now official jQuery templates (http://api.jquery.com/jquery.tmpl/). Most website frontends consume the API directly in template while still server-side. Some go further and leverage the API from JS/XHR to make pages more interactive.

KrisJordan··on First we built an API, then we built a CMS
HiFi and its API are running on Recess. The Recess database code is fundamental to making the data model / API possible.

Recess has been somewhat dormant while focusing on product. I've slowly and infrequently been readying the 5.3 branch. 5.3 has so much upside and has now been out for over a year I see very little value in doing new work. The 5.3 branch packages modules for individual consumption rather than taking a kitchen sink approach. It feels more functional, in the lambda-y sense, given 5.3's anonymous function support. I've started a new SQL generation layer that is in the same spirit as Recess' SQLBuilder but much more powerful and flexible with heavy inspiration from Arel.

I don't want to make any promises but its my full intention to package up the lessons of the last year or so into a great set of 5.3 libraries of Recess lineage.

KrisJordan··on Damning Zuckerberg IMs confirmed
"f them in the ear" was not in the context of users, it was in the context of ConnectU and competing websites. It's more obvious in the New Yorker article.
KrisJordan··on Godaddy.com up for sale. Could fetch $1 Billion
Surprising to read between 800-900M 2009 revenue and a price tag of 1B.
KrisJordan··on LinkedIn's Data Infrastructure
Surprised to read LinkedIn's "People You May Know" MapReduce pipeline takes 82 jobs.

From what I've read Google's index runs in around 20 MapReduce jobs.

KrisJordan··on Adobe Buys Swiss Company Day Software For $240 Million
Interesting tidbit from their about page "Day Software has been a leading force in the open source community. Day Chief Scientist Roy Fielding was co-founder of the Apache Software Foundation, author of the Apache Software license, and creator of the Apache web server." - Roy Fielding also being the PhD behind REST
KrisJordan··on Reboot PHP: keep the philosophy, improve the syntax (PHP on the JVM)
Re: "The $ before all variables is a feature [...] but we think it adds readability."

The argument for the $ sign is not readability. If it were you'd see JavaScripter's prefixing all of their variables with a dollar sign, too. var $foo = 'bar'; is completely valid JavaScript. (Aside: $ prefix is handy in JS when holding references to jQuery objects ie $container = $('#container');)

The argument is for simplified string manipulation with magic quotes and is an homage to unix shell scripting.

Without the $ prefix string manipulation would be reserved to concatenation/printf/replacement/etc. With the $prefix you can do things like:

   $base = __DIR__;
   $user = (object)array('name'=>'Foo','dir'=>"foo");
   $size = "lg";
   $image = "$base/users/$user->dir/images/$size.jpg";
vs:

   image = base + "/users/" + user.dir + "/images/" + size + ".jpg"
When doing a lot of string manipulation and scripting the $ is quite handy.

The dollar sign also enables variable variables and dynamic property access. i.e.

   $foo = 'Hello, world.';
   $bar = 'foo';
   echo ${$bar}; // 'Hello, world.'
- and -

   $user = (object)array('name'=>'Foo','dir'=>"foo");
   $prop = 'name';
   echo $user->{$prop}; // 'Foo'
The dollar sign for variable variables is weak because variable variables is usually an indication of code gone awry. Dynamic property access, on the other hand, is much more useful in a dynamic language like PHP/JavaScript. That said, I believe JavaScript's solution is much more elegant. i.e.:

   var user = {name: "Foo", dir: "foo"};
   var prop = "name";
   alert(user[prop]); // 'Foo'
By overloading the index operator on objects to accept a string that dereferences to an object's property you get the same benefit in a much more elegant way.

Thus the $'s primary justification is magic strings and string manipulation.

KrisJordan··on Reddit explains their architecture, scaling and recent downtime
"It turns out that this one little decision makes it so that we can't horizontally scale that layer of our architecture without losing all the data already there (because all of the keys would point to the wrong server if we added a new one)."

I'm surprised they're looking to switch stacks entirely as opposed to a consistent hashing / distributed hash table (a la chord, dynamo, etc.)

http://en.wikipedia.org/wiki/Consistent_hashing

http://en.wikipedia.org/wiki/Chord_(peer-to-peer)

KrisJordan··on Facebook makes HipHop for PHP open source
Some notes from Facebook's UStream event this evening: http://www.recessframework.org/page/notes-from-facebooks-hip...

High points:

the performance numbers were against PHP with APC op-code caching enabled

eval, create_function, and preg_replace with /e (basically eval), and conditional flow based on the existance of functions are the only features not supported.

Currently PHP5.2 with a roadmap of 5.2.12 compliant in the next month and 5.3 being the focus after that.

KrisJordan··on Facebook makes HipHop for PHP open source
Some details not in the official announcement:

Currently works off of the PHP 5.2 language specs

Compiles to a stand-alone libevent-driven web server or CLI executable

Not based on Zend's runtime/code

Currently no windows support

Intended for 'drop in' PHP replacement - if it runs on PHP and doesn't use a few things like eval() it will compile with HipHop

KrisJordan··on Facebook makes HipHop for PHP open source
"It has it's own built-in web server when you compile it, via libevent." from Ben Ramsey who attended the demo at FB Campus.
KrisJordan··on Droid: iDon't Understand Search Engine Optimization
How about every term that they use to position themselves against the iPhone in their ads?

"droid keyboard"

"droid apps"

"droid camera"

"droid development"

"droid customization"

"droid widgets"

"droid batteries"

KrisJordan··on Droid: iDon't Understand Search Engine Optimization
You're missing the point: try searching for something you want to know about the Droid... "droid preorder" "droid screen" "droid apps" "droid keyboard"

All of these subjects are covered in their Flash and they have content for but Google can't index or link you to any of it. So instead of Verizon owning these terms, which they easily could be, you're taken to 3rd party sites on the internet.

Even in their first result of "Droid" their misuse of a meta description (it's way too long) means you get 0 relevant information in the result Google displays.

KrisJordan··on Regular Expression Tool for Live Editing/Testing of RegExps made with jQuery
Wow, reAnimator is incredible. Great links.
KrisJordan··on Regular Expression Tool for Live Editing/Testing of RegExps made with jQuery
This is my first jQuery "app" (mini-app). After going through numerous write/print debug loops writing Regular Expressions and being inspired by Crockford's "JavaScript: The Good Parts" this seemed like a fun tool to try and write in JavaScript/jQuery. Appreciate any feedback.

Hope this Regular Expression tool is useful to other HN readers!

← PreviousPage 2 of 5Next →