Archive for May, 2008

31
May
08

Why jQuery Rocks

I wanted to see whats the deal behind in-place-editing with ajax (IPE). More specifically, I have a list of DOM elements with similar *class* and I want to enable IPE for all of them at once. First place I looked was Prototype, even though I’ve only used jQuery, and thats because I know Ruby on Rails uses a ‘component’ which does that automagically, and that uses Prototype.

Short story long, I ended up with 10 lines, 3 errors on the way, and 20 minutes deep, which included browsing for the source, copying the files, troubleshooting and reading Prototype documentation. Which isn’t bad at all.

Then, with the remaining 20 minutes I had dedicated for this little research I’ve decided to see what kind of stuff jQuery offers.

Enter jEditable

I can go along and say how great it is, how it does justice for jquery, and how it fits the mentality.

But i’ll just say this: it took me 1 line of code, 1 minute.

Goal

Hopefully you won’t waste time researching javascript frameworks for your next project. Just pick jQuery.

EDIT: I’ve cut this post 70% down.

24
May
08

Web MVC Frameworks

A while ago I’ve started playing with Ruby on Rails again. The last time I did that was pre-v1.0, so it really has been a while. Now days however, the MVC framework world is much different. The difference is that the first time I saw Rails, I (and most of the people back then) did not know very much of ORM, and there simply weren’t any such rapid framework around. So, with MVC.NET, django, pylons, and more around.. what has changed?

More importantly, now that we have the luxury of choosing, by what criteria can one examine alternatives.

I’m trying to compile a list, as I go over each of the frameworks, this is a work in progress so it is incomplete.

  • Model: how coupled is the framework and the ORM? how easy is it? what databases does it play with? (see: ActiveRecord)
  • View: which template engines are there? how coupled? whats the performance of rendering one? how clear is the syntax? (see: Haml, Breve for template beauty)
  • Helpers: what kind of syntactic sugar is there?
  • Forms: how easy is it to handle forms, read: are we able to load a model object from a POST directly, can we drop a model object to a form directly? can we generate an object from a request directly? can the framework generate the form in html for us?
  • Validation: what kind of validation is there? how capable is it? can we bind it to the model? to the form? how easy is it to add validation rules?
  • Authorization and Authentication: does the framework have a built-in module for that? how fast can we configure and run it? can we extend it?
  • Javascript/ajax: what libraries are supported? if none, how well will it play with one?
  • Scalability: apparently, no one knows about scalability, I will not pretend to know what its all about. But one can gather information about how scalable is a framework, for better or worse (worse, see: twitter )
  • TBC…
17
May
08

yielding

While reviewing xUnit’s sourcecode, I’ve stumbled upon this:

static IEnumerable<string> SplitLines(string input)
{
while (true)
{
int idx = input.IndexOf(Environment.NewLine);

if (idx < 0)
{
yield return input;
break;
}

yield return input.Substring(0, idx);
input = input.Substring(idx + Environment.NewLine.Length);
}
}

Thats a very nice use of yield. I’ve translated it to python just for fun:

Python

>>> def split(str):
while True:
idx = str.find(‘\n’);
if(idx < 0):
yield str
break

yield str[0:idx]
str = str[idx+1 :]

>>> g = split(“hello\nworld\nyea”)
>>> g.next()
‘hello’
>>> g.next()
‘world’
>>> g.next()
‘yea’

17
May
08

Asp ValidationSummary Alerts

If you want to use ASP.NET’s ValidationSummary, you have two options: display a div inline with the summary of the validation errors, or display an ugly alert() box.

There are a couple of guides which explain how to make ValidationSummary display the errors in a modal of your choice, but all are annoyingly incomplete. One even required you to change the ASP.NET core files, which is a hassle if you ask me.

I’m going to take a different, easier path.

Since ValidationSummary uses alert, I’ll replace alert with the modal of my choice.

function alert(msg) {   mymodal(msg); }

Now all you have to do is find a nice modal box.

11
May
08

Javascript Revelations #1

I’m starting to find out that javascript isn’t a crappy language at all. Did you know it’s closer to lisp than it is to Java?.

Heres currying in javascript.

>>> var c = function (b) { return function (a) { return b + a;}};
>>> var add5 = c(5)
>>> add5(3)
8