Metaphysics on programming

By | 2006-06-25

Mirror by Jesús One of those things which sometimes made me crazy while programming are quotes (single ‘ and double ” quotes). Let me explain…

Most of the modern programming languages include a way to manage strings, normally it’s surrounding them with quotes (for example, in PHP: $response=”Hi there!”). The question arrives when you want to add a quote as a part of the string… because every language has its own way (and it’s a little problem if you usually program in different languages). For example, in PHP this is correct: \”, but this doesn’t work: \” (instead, you must directly use ), and it’s not exactly the same in Javascript. Next, the real problem happens when the user of your program starts to write lots of quotes as part of the input… you have to be really careful, programming some filters.

I imagine a string looking at itself, thinking “is this quote a part of myself or my end?” ;-), like the mirror in the clever drawing made by Jesús (he is a really fantastic artist, you should take a look at his new drawings). What happens when the limit of something is a part of itself? What happens when you see your limit is a part of yourself? Then you can change it, openning it!

By the way, most programmers do the laziest focus: to not allow the user to introduce quotes. But I think it’s the wrong solution, because it’s not a solution at all, but a patch. The professional way to do this is to implement a real solution, so the user can do what he/she wants. You are the person who has to spend time thinking, and not the opposite. This is the reason of this post: I spent the whole day trying to solve this problem in the most elegant form, in a AJAX-powered CMS I’m working on.

Update: At Sunday night I got it. Now I have an “edit in place” system with support of quotes marks, with an easy plus elegant code 🙂