Daniel Friesen

(Dantman, Nadir Seen Fire)

Programmer, Web Developer, Animanga Fan

Posts in 2009

I realized one of the old reasons why some don't consider server-side JS ready could actually already be considered a fun little mistake.

One of the old cited reasons why server side js isn't ready is "Lack of libraries". Ya, io needs some standardization (and perhaps more clean APIs), and there are various low-level things which need building. However there is one thing I think we can actually nicely tick of as mistake.

General libraries for different types of markup and so... Templating? JSON-Template is in JavaScript, Python, Java, PHP, and the list is growing. Markdown? Showdown. Textile? Theres two or three of these I think, at least one is GPL which could be troublesome, another is not marked but it looks like the authors are open enough a poke should be all needed to give it a real license.

[Read more...]

For those who haven't seen the statement yet, the with() statement in JavaScript allows an object to be pushed onto the scope chain.

In short the common reason for it to be useful is if you had something like foo.bar.baz.a and foo.bar.baz.b then instead of typing that over and over you could use something like with(foo.bar.baz) { a; b; }.

Unfortunately nearly every example people show is a poor example of how to use it, and then Crockford went and published a classic "Considered Harmful"[2] article describing a single very bad example of how to use with(), why with() is bad because of that one poor use, and as a result most people's opinion about with() is that the statement is evil "cause Crockford said so" without even thinking of good uses for the feature.

[Read more...]

Man, forgetting to add my little error catching trick inside of one app I was writing made me realize how much I take such a simple trick for granted.

app = proc do |env|
  begin
    # Application code
  rescue Exception => e
    r = Rack::Response.new
    r.status = 500
    r.header["Content-Type"] = "text/plain"
    r.body = e.to_s << "\n" << "-" * e.to_s.length << "\n" << e.backtrace.join("\n")
    r.finish
  end
end

run app

I basically write all my rack code in a way similar to that. Normally I'll probably throw in another error catching level that catches special formated ErrorPage classes for things like NoPage to generate a 404. But this here is the big absolute fallback, if at any point inside of my code I make a mistake in syntax or anything this completely catches it, and renders the full error message and a full backtrace letting me actually see the error right away instead of looking through a horrid apache log.

[Read more...]

This one is a little bit old, but if any of you are familiar with rails' views you'll probably have seen bits of view code like:

<% form_for @user do |f| %>
  ...
<% end %>

And if you've ever jumped into erb in your own ruby you've probably made an attempt at doing something similar trying to put something into the buffer without the use of =. This is of course because ERB doesn't let you use blocks when you make use of =.

[Read more...]