Saturday, February 12, 2011

Unmatched Parenthesis!

Until today morning I believed I was the only one whose stomach would give a lurch when I saw unmatched parenthesis. Now I know I'm not alone.  Today I read a comic strip that prompted me to express my concerns about unmatched parenthesis in colloquial communication (emails, chats) we have...
If you are a hardcore programmer (probably C / lisp), or if you have ever written a lexical analyzer... you must have faced this dilemma...
If you wanted to put a smiley at the end of your sentence that is inside a pair of parenthesis, do you leave the open parenthesis unclosed? Or do you close it? If so, then how?
I'm not making this up for the sake of a post, this is a very practical dilemma that I face very often...
Problem:
(This is a sample statement with a smiley at the end :)?
Now what do you substitute '?' with? Nothing? Or a ')' or a ']' ?
Solution 0: Textbook solution: Just don't freakin' do it!
Like most of the textbook solutions, the simplest of answers is to avoid the problem altogether!  Just don't do it. Never end your sentences inside a parenthesis with smilies!
 Sample Solution:
(There is no need to put a smiley at the end of a sentence inside parenthesis)
Solution 1: Leave the opening parenthesis unmatched!
But we all know how different the real world is from the ideal ones in the textbook.  So the fact is you often want to end sentences in parenthesis with a smiley.  This particular solution banks on extremely short attention span of humans and hopes that nobody will ever notice a missing parenthesis. They won't even realize that you opened a parenthesis. And that makes perfect sense, in a world where billions of dollars and hundreds of people vanish without a trace, who on earth would care for one measly missing parenthesis. Ain't it!
Sample Solution:
(There is no need to close the parenthesis when you end statement with :)
Solution 2: Always semantically correct,  every parenthesis should match.
If a programmer happens to read it, your unmatched parenthesis is going to bother him through rest of his day.  If you don't want to unnerve your programmer friend, I strongly urge you to always match all your parenthesis!  
Sample Solution:
(If your programmer friend is going to read it, you better match every single open parenthesis, no matter how ugly the end result looks to you :))
Solution 3: Semantically correct and indented!
If the reader is an expert C programmer who has wasted inhuman hours of his precious life debugging and maintaining someone's unforgiving poorly indented code, you DON'T want to piss him off with lousy indentation (don't even think about not closing an open parenthesis, ever! This particular bread of programmers loathe with their utmost intensity the code that doesn't compile), lest you will be the target of his unwelcome wrath that he has been carefully suppressing through years of frustration with sloppy code he has had to read for the life of his programming career!
Sample Solution:
(
    If your programmer friend is paranoid about indenting, then this is your best way out :)
)  
Bonus Solution: MBA's Lame Solution!
Add a square bracket ']'!
Lame! Yes, that is what MBA's of the world do! Impossible solution, often to problems that don't even exist! Not to mention that solution are wrong in every possible way, no matter how you interpret the problem!
Sample Solution:
(If you are an MBA, you want to complete the statement like this :)']'

Note: Never ever let your programmer friend see you close a bracket that does not match what you opened with! Do that and you will loose him forever!  Not to forget the look of contempt on his face every time he sees your name. 
Also, don't get me started on quotes. As an ardent fan of shell scripts, I have very strong and often fussy views about it.