Thursday, April 30, 2009

Clojure

I've been seeing quite a few jabs at clojure lately. Sometimes I wonder if people actually tried to use the things they claim to hate.

On a related note, there's a book about it in beta now. I hear it's geared more towards Java programmers than CL ones - which is a plus imho since CL users are apparently (at least from the attitudes I've seen) the best thing since sliced bread :)

Maybe I should go buy the book.

How bad is the Swine flu so far?

Swine flu - 9 deaths so far.

Heart disease - 34 deaths in the last second.

Hmmm.

SHA-1 collisions down to 2^52

Heh.

Overreacting

They might as well kill everybody to prevent regular flu, car accidents and alcohol related deaths...

Tuesday, April 28, 2009

Rails drama

So there was this presentation in a conference that was sorta inappropriate and some people that got offended, and a then things sorta derailed a bit (no pun intended).

On the comments of a rant post, the presenter rethorically asked what is it that makes IT less friendly to women. He says:

"Try asking young teenage girls why they don’t want to become software developers. Again I’d be surprised if they say, because of the macho environment."

Well, so would I. We can't just ask people to explain out what they feel is a cultural issues. On the off chance that they are actually able to explain out in words what the root of the phenomenon is, there's still the chance that people involved in that culture won't agree with the conclusion that there is a problem to begin with.

On a somewhat related topic, I never really understood why is it that some people feel compelled to associate software with this idea of "end of a journey": being a rock star, being a ninja, whatever. You don't see rock stars calling themselves "ninjas". Does being a real life programmer suck so much that we need to pretend to be something else? Where's the focus? Where's the pride?

Miracles and rationality

Old blog post, but interesting nonetheless.

The definition of miracle seems rather fuzzy, imho.

On the one end, people say splitting a sea in two is a miracle. On the other, gravity and tides are known natural phenomena and it is theoretically possible to split a sea in two, given that a bunch of highly unlikely events happen simultaneously and someone is paying attention.

Often, an event is called a miracle because it's very personal, e.g. a loved one surviving cancer or a gruesome accident. I'd say the explanation for these cases just happen to be beyond comprehension, but not they're certainly not necessarily beyond the forces of nature.

There are those who say that miracles are things that can never happen because there are very specific scenario constraints, e.g. walking off the top of a building and expecting not to turn into a flattened pancake. But hey, it can be done. Voluntarily, at that.

I tend to be pragmatic and go more by the street usage of the term miracle (i.e. that it can happen), so I figure that since miracles only escape our understanding but not necessarily laws of nature, yes, we can be rational and believe in miracles.

As the saying goes, I only know that I know nothing.

Friday, April 24, 2009

Watching TV

nod nod.

Fake stuff

So someone set out to show that you can get away with spreading misinformation quite easily in Twitter.

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

QuelSolaar

Looks like a neat 3D modeling tool for games.

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

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)

Friday, April 17, 2009

On tabs vs spaces

If I understand the debate correctly, the problem of tabs vs spaces arise only when there are both in the same file:

1 if (a_condition &&
2     another_condition)
3 {
4     do_something(variable1,
5                  variable2,
6                  variable3)
7 }

The indentation doesn't really matter. It works either way. But the alignment would break in spectacular fashion if we aligned lines 2, 5 and 6 with tabs.

So always tabbing won't work.

People like to be unique, and everyone has their own favorite tabstop settings. I've seen different co-workers use 2, 4 and 8, for example. Tabs make the files automatically look nicely indented to you in your favorite editor(tm). Spaces make it look nice only to some people (doesn't that remind you of the three bears fairy tale?). Also, having a key insert not only a different character than it states, but also several of them, is weird. So pure spaces don't quite work either.

No editor I'm familiar with can smartly figure out what portion of the leading space is supposed to be tabs and what is supposed to be spaces AND do the conversion automatically when you press tab and/or spam the spacebar. And we're assuming we can't rely on the programmer to remember to check (a fair assumption imho).

So tabs for indentation and spaces for alignment doesn't work either.

Solution?

Well, if there was one, we'd all be using it. What if we just avoid aligning things altogether?

//with alignment
doSomething(var1
            var2
            var3)

//indented
doSomething(
  var1,
  var2,
  var3
)

//with alignment
if (foo == true &&
    bar == true &&
    baz == false)
{
  //bla
}

//refactored
var isNameValid = foo == true
var isEmailValid = bar == true
var isDateValid = baz == false
if (isNameValid && isEmailValid && isDateValid) {
  //bla
}

Then again, that's javascript. Probably doesn't work so well for C or lisp.

But the question is: why do people align stuff, rather than indent it? I can see that it'd look ugly in the case of the if statement, but time and time again I've seen huge parameters lists for some OpenGL call being aligned to some random column for no particular reason when they could just break the line after the opening parens and indent the parameters (and they'd even fit in the screen!).

For things like huge if statements, I find that the refactored pattern above is nice especially when the code is dense (e.g. when expressions are queries to data structures, like in LINQ or Python comprehensions), since the variable name describes what information is being pulled out of the data structure.

Back to the topic

Anyways, coding patterns aside, I still don't know what's a good way to tie spatial code organization more closely to the abstract syntax tree (and in the case of alignment, to the metagroups of data) that provides a consistent coding style convention that works everywhere and for everyone.

Is bickering about which ASCII character is better the best we can do?

Thursday, April 16, 2009

Lisp without parentheses

So apparently, every lisp newcomer and their dogs has had the fabulous idea of making a version of Lisp that uses indentation instead of the derided parentheses.

The most common proposal I've seen is to make each line with a deeper level of indentation be a new form.

(0 (1 2))
becomes
0
  1 2

Simple enough. The problem is that the idea breaks when we have a form that looks like (0 1 (2 3) 4 5 (6 7)) or (if condition some-long-form another-long-form). The first breaks because once you indent, there's no syntax to close the current form and return to the parent, since outdenting requires moving to a new line, which closes both forms.

The second form is more subtle: in Algol-like languages, you'd normally some-long-form on a new line and indented. We can't do that with the lisp-without-parens proposal unless we add another symbol to escape line feeds or something like that.

if (foo bar) \
  do-something \
  do-something-else

That just looks plain stupid. Let's scratch that.

Another idea would be to make outdenting return to the parent form, i.e. a line feed does not close a form.

(0 1 (2 3) 4 5 (6 7))

0 1
  2 3
4 5
  6 7

(if condition some-long-form another-long-form)

if condition
some-long-form
another-long-form

Bla. Looks dumb and we now need something to denote when a form closes and a new one opens.

(if condition (+ 1 2) (+ 2 3))

if condition
  + 1 2
  =====
  + 2 3

Or something equally bizarre. Scratch.

Ok, let's stop with the toying around a bit

In case you haven't noticed the pattern, the problem here is that even though regular lisp has two pieces of syntax (open-parens and close-parens), and python-like syntax has three (line feed, indent and outdent), indent and outdent can't always be written out (e.g. in the last example they cancel out and thus we need a fourth symbol to go around that edge case).

So can Lisp without parentheses work without bolting on weird characters to make edge cases work? I don't see how.

Piracy

Is it just me or is everyone obsessed with pirates these days?

Thursday, April 9, 2009

Java is so not dead

So since Java is now supported on Google App Engine, a gazillion languages become supported too. We can now play with Javascript, Ruby, Lisp and even Lua in GAE. Talk about bang for a buck.

Tuesday, April 7, 2009

The most dangerous person in the world

Pretty sure I've seen the numbers before. I just like to read about this topic for some reason. Putting things in perspective I guess.

Nukes

Scary, the US radius is so large it doesn't even fit in the map.

Friday, April 3, 2009

The User

I was working on an internal app today and caught myself saying "when the user does x". Dude. I *AM* the user.

Wednesday, April 1, 2009

Ignore teh Intahtubez day

Habits question: do we really need a spammy day to ignore the Internet? I've been noticing that I've been spending a bit more time than I probably should online. Interestingly, that realization only really clicked because of the wacky nature of April's Fools. Hmm.

Competence

Jeff's question: Should competent programmers be mathematically inclined?

My question: what does one have to do with the other? Does writing a 3D engine automatically make you a competent programmer? Does working almost exclusively with databases make you not competent? Mental exercise: Let's swap these two hypothetical programmers for a day and see how it goes.