Alan Fineberg

If you blog it they will come?

Sunday, December 27, 2009

What's wrong with PHP?

Just as it's easy to completely write off a band you don't care for (because they sold out? or their singer meets with world leaders and has a terrible op-ed album in the New York Times), the same often happens with technologies and languages.

For example, there was some point in my life where I told myself I would avoid any project heavily involving PHP.

But why? What's wrong with PHP? Yahoo and Facebook use it...and I haven't used it enough to warrant such strong feelings.

I wanted to explore this (baseless?) apprehension further, and I thought of this characteristically absurd/profound quote from Perl creator Larry Wall:

"Perl is worse than Python because people wanted it [to be] worse."



Larry Wall

The goodness of Perl v. Python is a common religious argument. The above quote squelches the debate once and for all, but begs further questions.

Who is they? Why did they want Perl to be worse? Do the words I added ([to be]) change what Larry actually meant?

Consider this Mind Hacks post about trends and their origins; the concepts extend to any sort of idea that can grow legs. Trends in technology are the same way, and spread because a distant idea reached some critical mass of connectivity and settled in with your own circle of peers.

Developers can vote for or against any technology by speaking for or against it, but their most powerful influence is in choosing which technologies to devote their energies toward learning and improving. Enthusiasm for a project leads to expertise contribution, and contribution leads to enthusiasm.

Conversely, people who have a distaste for a technology will discourage others. They (the technologies) will languish if their community does not grow.

In other words, labeling a technology good or bad is a self-fulfilling prophecy given enough influence and/or critical mass. Soon companies using the "good" technology will flourish with resumes and job postings for "bad" technologies will receive lesser attention, serving only to reinforce existing stereotypes.

I'm largely paraphrasing Paul Graham. He wrote a great essay on this phenomenon, which he calls "The Python Paradox".

I believe this is what Larry was getting at. And it explains my own PHP aversion, as my experiences were underwhelming at worst, but the number of developers I've heard lament PHP convinced me to stay away, as if it's the bad part of town.

Arguing over which language is better or worse is a waste of time; what matters is the consensus of the larger community (see wikiality). Even if it's unjustified. But just like a neighborhood can turn around, opinions change, and that's why phrases like "JavaScript Renaissance" are thrown around. And although I can't shake all the PHP prejudice, I wouldn't make a point of avoiding it (PHP that is), either.

Thursday, December 24, 2009

Easy hexagonal tiles with css

I just started building an online game with appengine as a learning exercise, and I'm attempting to do so without flash, java, or any other plugin.

There's nothing to play yet, but I already have something that is generically useful: a hexagonal tile layout purely in html and css. It's pretty clean too, check it out:

The Django Template:

{% load mod %}

<html>


<head>


<link type="text/css" rel="stylesheet" href="/stylesheets/board.css">


</head>


<body>


<div id="board-container">


{% for i in rows %}


<div class="row {% if i|mod:2 %}offset{% endif %}">


{% for j in rows %}


<span class="hex">


<img src="/img/hexagon.png" />


</span>


{% endfor %}


</div>


{% endfor %}


</div>


</body>


</html>




The mod filter came from here.

All this does is create a grid of hex images (100x100 transparent pngs, edited from this source image). Every other row is "offset" so that the hex pieces nest together.

Here's the css:

#board-container {
border: solid black 5px;
width: 875px;
height: 700px;
}

.row {
/* This has to be .hex width * # of cols */
width: 800px;
}

.hex {
/* The width and height depend on the size of the hex image. */
width: 80px;
height: 65px;
border: none;
float: left;
}
.offset {
position: relative;
/* half of the hex width. */
left: 40px;
}


And the final result for a 10x10 grid:
hex tiles

The next step is to implement the game rules, ajax calls, and draw a sidebar with the playable pieces.


Thursday, December 3, 2009

TechFlash's credulous hackery

TechFlash is dedicated to covering the Seattle tech scene, just as TechCrunch is focused on the Silicon Valley tech scene.

Unfortunately TechFlash is TechCrunch's insecure younger step-sibling and apparently needs to issue one-sided press releases poorly disguised as blog post reportage in order to maintain its insider access.

Case in point:
Microsoft escalates war on piracy

War on piracy? Really? Is that like the war on terror? Or the war on drugs? Or the war on poverty?

Anyway, the article quotes Microsoft only, and offers no analysis or commentary on why piracy is rampant or whether this strategy is the an intelligent one. It offers no commentary beyond Microsoft's slant on the story.

The Microsoft source claims that everyday consumers are opposed to piracy "because they're increasingly frustrated and angry about the connection to viruses and malware."

Actually maybe the problem is that users can have something for free instead of paying for it, and it dents the bottom line of Microsoft's current business approach (which may or may not still be relevant). But you won't see such a nuanced view in this article, or any other quid-pro-quo TechFlash articles to be frank.

I criticize because I care--I want the Seattle tech scene to flourish, I want TechFlash to be informative and critical instead of parroting the mouthpieces of the region's big players. And I speak for myself only, of course.

In summary, I just posted a critical blog post, about a blog. What has my life come to?

Saturday, November 7, 2009

I just finished reading Goedel Escher Bach

GEB alternates dialogues and essays on the author's staggering range of fixations and obsessions in which Hofstadter adds his own remarkable insights and comparisons on topics including music, art, mathematics, genetics and philosophy. GEB's sprawling nature follows tangled paths but eventually loops back to the question of intelligence, souls, free will and self-awareness.

The unorthodox structure is what sets the book apart, but the braiding of ideas may lead to a takeaway of: "Ok, that's interesting, and you're clever, but what is the chief takeaway here?"
This is a common criticism which led led Hofstadter to author the psuedo-sequel "I Am a Strange Loop" (which I haven't read), in which he distills his arguments more directly and concisely (and personally -- he imagines a low-resolution "simulation" of his wife's mind within his own after her death).

Anyone who completes GEB comes away with an honorary computer science degree, as there's a heavy focus on computability theory, data and data structures, natural language processing, AI, recursion, memory, hardware, software, all under the guise of philosophy and investigating what gives rise to self-awareness and intelligence.

On top of this, the GEB reader receives an introduction to the art of Escher, Magritte, Bach, John Cage, as well as some basics of neuroscience, boolean logic, zen philosophy, number theory, music theory and molecular biology.

Although the number theory and biology chapters dragged, I was fascinated by the discussion of the Goedel incompleteness proof and the implications it had for the mathematics community at the turn of the century. There is also a fascinating section on AI that starts with Turing tests and pattern recognition and ends with the remarkable conclusion that a truly AI may be terrible at all the things that people may struggle with as well, such as rapid computation or chess playing.

At the least, GEB presents a multitude of ideas and food for thought. At its best, it instills lucid notions of how our minds work and what gives rise to life, language and intelligence.

Thursday, September 17, 2009

Zip those lists

A lot of people know about zip() in python but did you know it operates on a variable argument list?


a = [1,2,3]
b = [4,5,6]
c = [7,8,9]

>>zip(a, b, c)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]


Don't roll your own list transposition functions....
It's also useful for iterating over a couple of related lists:


for message, email in (messages, emails):
hdrs, body = parse_email(email)
assert message in body

Sunday, August 16, 2009

When a band I like comes to town, I'll know

The List is a comprehensive listing of all the known shows coming to the Bay Area listed by artist and by venue.

There are hundreds of concerts and nearly 1500 bands in the list so I threw together a script to scrape it and intersect those bands with the artists in my iTunes library.

The result is, I now know that these acts are playing in the near future:

atmosphere
bat for lashes
beirut
blink 182
butthole surfers
calexico
cat power
collective soul
dan deacon
deerhoof
deerhunter
dropkick murphys
elvis costello
fever ray
flipper
ghostface killah
girl talk
green day
grizzly bear
in flames
kenny rogers
lil wayne
m.i.a.
mastodon
meat puppets
mirah
modest mouse
mstrkrft
no age
nofx
pearl jam
placebo
porcupine tree
sunny day real estate
tenacious d
thievery corporation
tv on the radio
weezer
yo la tengo


The next step is to scrape the concert details as well, use fuzzy matching, run it automatically, and set up alerts.

But this only took 15 minutes to write in python and it would have taken me way longer to parse manually.

EDIT:

Instead of doing a set intersect, I now use difflib to find "close matches." It's slower but still runs start to finish in about 10 seconds, which is fine considering especially that the data changes infrequently.

I also unescape the ampersand in the iTunes xml, and filter out "The " because:

>>> import difflib
>>> difflib.get_close_matches('foo', ['the foo', 'foods'], n=1)
['foods']

...an exact match preceded by 'the' is penalized more than a suffix. So 'pixies' would match 'pixiestickers' instead of 'the pixies' in the case where I only select the top match (since ideally there's a one-to-one mapping).

Instead of writing my own fuzzy matching algorithm, for now I'll just chop off 'The ' and live with the results. Although some of the matches aren't useful, it does better at finding bands such as ...and you will know us by the trail of dead and The Ting Tings.

Tuesday, August 11, 2009

timsort visualization

This blog post is quite effective at illustrating the timsort algorithm, found in python (and soon java)