Friday, April 24, 2009
Fake stuff
There was a rather famous similar experiment in Youtube, and of course, fake people in social networking sites are nothing new.
Having a shred of a scientific mind (i.e. automatically calling bs on everything) seems to be becoming more and more useful in this age of information overload.
Wednesday, April 22, 2009
Something is missing
Looking at my RSS aggregrator, I came to a realization, it looks an awful like what a newspaper or magazine would: lots of catchy headlines for topics that interest me. The difference is, of course, I choose where the headlines come from, whereas news go through editors. So, there's an certain inherent bias to what is presented to me via RSS, and there's a different bias to what news make the final cut on a newspaper or magazine.
What is common about both is that this bias converges into a culture of sorts. There's a certain level of expectations from things that appear on News.YC, and there's a certain level of expectations from things on the New York Times. The great thing about the Internet is that there's enough choices out there to make a pretty varied selection; the sucky thing is that we're stuck with them once we make them. (Well, not really, but let me explain what I mean).
As Malcolm Gladwell says in his TED talk, you can't really ask people what they want. We don't know what we want, we only know if we like what we have or not. Out of sight, out of mind.
The thing about content (at least for me), is that "how-much-I-like-content-from-any-given-outlet" is a bell curve: there are some great things and a lot of useless junk. The catch is that this applies to stuff outside of my preferred cultures as well. Meme sites usually irk the hell out of me and I'd not want one in my RSS aggregator, but I can't deny that they do have some pretty nice content every once in a while (considering what the intentions of meme sites are, anyways).
Do you see where I'm going? We are stuck with the choices we make in our readers because we're asking the wrong question: what is the perfect culture for me? There is no perfect culture. Only many noisy ones with some perfect content (and there may or may not be a correlation between the culture's voting patterns and what would actually please me). My netvibes page wouldn't know that though. All it can do is map one culture to one portion of the screen.
One could say that content aggregators would solve the problem, since they grab the best of all worlds, but, again, look at News.YC. It obviously has a very strong culture. You'd never see a clever lolcat picture with a great geek culture reference in News.YC. Similarly, you'd never get a paper about JVM internals on StumbleUpon. It seems every site develops a culture by virtue of its own history of posts, even when they encourage randomness.
How does one develop a fitness function that takes Internet content as an input and that evolves into a filter that gives me what I like (as opposed to giving me stuff that is roughly in the direction I expect from a given culture)? Is that even possible?
Sometimes I wish my aggregator had a magic "Surprise me with something nice" button. But I have no idea if the fitness function to power it can even be done. I must be missing something.
Tuesday, April 21, 2009
Small world
I stumbled upon this talk again. Funny thing, a co-worker just recommended Gladwell's book when we had a casual conversation about my MSN message. Small world.
Variable interpolation in javascript strings
I came across this fairly old attempt at making variable interpolation work in javascript.
The conclusion was that it could only be made to work with object properties or global variables.
But as it turns out, we can make interpolation of local variables work:
var expand = function(string) {
return '"' + string.replace(/"/g, '\\"').replace(/\{/g, '"+').replace(/\}/g, '+"') + '"';
}
new function() {
var hello = "hello world";
alert(eval(expand('say "{hello}"')))
var quote = '"';
alert(eval(expand("a quote looks like this: {quote}")))
}
I'm not checking for escape sequences for curly braces, but adding support for that shouldn't be too hard.
Monday, April 20, 2009
WYSIWYG Strings
You may have noticed that lately my posts have been related a lot to programming language syntax. That's because I'm playing with a parser right now.
I've been thinking about WYSIWYG strings and heredoc strings.
There are at least a dozen different ways of denoting a string, each with it own limitations: The common quote delimited strings with escape sequences become unreadable when there are too many escape characters, heredocs can't be written in a single line, strings with exotic delimiters (like D's backquoted strings) are vulnerable to delimiter collision.
I like heredocs because their flexibility makes it possible to avoid demiliter collisions in just about every possible scenario (except random infinite strings), and multiple quoting, which looks like a compact variation of heredocs (except that we can't make a string with one of every possible character).
<<HEREDOC some text HEREDOC qq^some text^
I also like Ruby's "<<-" heredoc, which allows the end token to be indented, as well as YAML, which lets the body of text itself to be indented.
<<-HEREDOC
some text
HEREDOC
- text: |
some text
How can we mix all of these together? Something like this (note the indentation)?
//Multiline: //standard idiom @@ some text @ //handling edge cases @HEREDOC email@email.com HEREDOC @@@ email@email.com @@ @# email@email.com # //Single line: //standard idiom @@:some text@ //handling edge cases @HEREDOC:email@email.comHEREDOC @@@:email@email.com@@ @#:email@email.com#
So basically, an "@" followed by a heredoc token followed by either a colon or a line feed, depending on whether you want single line or multiline. Indentation characters up to the level of the closing token are discarded from the actual string's byte array.
Do those examples look readable? Would they play well with common indentation patterns in actual code? Would you be able to guess what the syntax is if you didn't know it?
Another random idea
How about we interpolate this heredoc notation into a regular string via an escape sequence?
"here's an example: \@@:"""some python doc comment about the backslash ("\")"""@"
"here's another: \@@@
"""this is about the at sign ("@")"""
@@"
I think making it available only as an escape sequence, rather than as a stand-alone token, would make the syntax more discoverable. The down side is, of course, that we need at least 7 characters to make a stand-alone heredoc string (compared to 4 with a stand-alone token).
"\@@:hello world@"
That in itself is not really a problem, just a minor annoyance. The bigger problem with my mix-of-everything idea is the whole thing about tabs and spaces. Unless we force an arbitrary rule for indentation (like YAML does), there's no good way of making indented heredocs work nicely when different people press tab on different text editors.
Also, what happens when the text is indented less than the closing token? What should happen there? How do we describe trailing whitespace at the end of a heredoc string?
Maybe we should forget the YAML-like text indentation.
What if whitespaces are acceptable token characters?
Then this is valid
var bla = @ --- my heredoc ---
And so is this
var bla = @ """ another heredoc here """
Here the heredoc tokens are "\n---" and '\n\u0020\u0020"""' respectively and there are no indentation problems. Cosmetically, in the second example, the non-whitespace tokens align with the rest of the code, since they are merely indented. The only caveat is that the actual heredoc string is outdented back to zero - perhaps that's better; after all, indenting it manually is what would break it.
I like how the second style looks. Indentation good practices are directly in line with what a parser would expect as correct syntax and the position of the non-whitespace part of the tokens give enough information about the string's indentation level in relationship to the rest of the code. Meanwhile, the body of the string remain intact (which is good, since it can often be a whitespace-sensitive copy-and-paste from somewhere else - e.g. a Python script). Another benefit of keeping the string intact is that it can be diffed in source control systems.
Agree? No? Maybe?
Sunday, April 19, 2009
Monkeypatching and eggs
So monkeypatching - or more generically, multiple versions of code and multiple dependencies - can break stuff. It kinda reminds me of the GPL's virality: once you "pollute" a scope, everyone after you will likely have to rewrite code to fix some edge case you haven't thought of.
Saturday, April 18, 2009
I just had one of those silly realizations
I just realized something silly:
//C add(1, 2, 3); ;;lisp (add 1 2 3)