From time to time, if you feel the need to piss someone off for their own good, let me assure you that it’s a perfectly natural thing. If you see someone living their lives without getting pissed off even for few minutes, do them a favour by pissing them off, at least once. Just like eustress people need eupiss for a long healthy life. Besides, it shakes things a little bit which helps people to bring some variety to their monotonous existence. So, if the conventional wisdom has shown you that pissing people off is bad, well, it’s because it’s conventional. Make a note on your todo lists, or your GTD system and make it an items that you could do in less than 2 minutes. Then do it. After all it’s for their own good.
Now, let me show you a very easy method to piss someone off. This works extremely well if the pissee is a tech guy. More specifically a programmer. It’s a well tested and trustworthy method which people used in mailing lists from time to time to start holy wars. This method is most successful if the pissee uses a big stupid language and actually LIKE it. All you have to do is utter “my language is better than you one” phrase in a slightly offensive tone and throw an example on their face. It’s that simple. Lemme give you one example.
Artificial examples on blogs sucks. So let me take some code which I was playing with today and explain.
I was writing some Ruby code this afternoon with WSF/Ruby. In order to talk to an SSL endpoint you need to supply the CA cert to the client as an option. Rampart expects you give the cert with the certificate delimiters removed (first and the last line of a certificate). WSF/Perl will read the certificate for you and do the right thing when you pass the filename. But not WSF/Ruby (note to self: make this part of the lib).
client = WSClient.new( { "to" => "/your/end/point", "ca_cert" => "cert content as a string" }, logfile )
The beauty of the language you’re using spring up in situations like this. Without further ado, here’s the one liner to get the cert content as a string with certificate delimiters removed,
File.open('server.cert').readlines[1..-2].join.gsub(/\n/, '')
You got to appreciate the beauty of the above line. Although I’m quite fond of it I prefer the Python version over it. Here’s one way to do it,
"".join([line.strip() for line in open("server.cert")][1:-2])
Yes, the list comprehension beats it all. It’s simple and elegant. Most importantly beautiful and pleasing to look at. My first exposure to list comprehension has been via Erlang. Purely due to the fact that I started reading about it before Python.
Anyhoo, all you have to do now is find someone who uses a big stupid language and throw an example like above to their face and tell them to beat it. See if they can write it more elegantly using their language. The beauty of the trick is that there’s no way in this world that’s gonna happen. So, you’ve already won. One word of caution though. When taking an example take something slightly more complex than a single function call. Like opening a file. In both Ruby and Python it’s one function call. DON’T take this type of examples. Why? Because there’s a very high probability that the other person, yes, the one who’s using a big stupid language, will get so angry and beat you up. You don’t want this. So, avoid at all costs.
There you go. Do some good to the world by pissing off few people with this technique. It’s good for your karma too. Happy pissing!
Update: Ok, I admit that I got a bit carried away with that example which made it artificial, hence sucked. When you write an SSL client using WSF/Ruby you only have to give the filename of the certificate, none of the certificate delimiter removal plus newline removal is necessary. But, I’ll keep the examples to keep the central theme in alignment. BTW, here’s the correct SSL client example with WSF/Ruby,
client = WSClient.new( { "to" => "/your/end/point", "ca_cert" => "server.cert" }, logfile )
Update 2: Before it gets a bit out of hand, let me reiterate if it was not evident from the first reading. This whole thing was meant to be a joke. Don’t take it too seriously, have a laugh and return to you editors, grow some sense of humour for chrissake. Oh, one more thing, I’m no Erlang wiz. I’m just started to grok the Erlang landscape.
Doing stupid repetitive work for extended periods of time can cause serious drain bammage. Coming up with a static HTML page for WSF/PHP samples is just tedious work. If you’re like me, you use Emacs for everything you do including HTML editing. I was trying to create a page which listed all the samples. You could view the code as well as run it once you install WSF/PHP. The default was a standard directory listing by the web server. Trying to write a static HTML page with Emacs for that many samples is madness. Luckily with very few lines of Ruby, stupid repetitive work can be a source of fun.
A table listing a link to the script and showing the code would be nice. I could write a table in Emacs but filling it with content for all the samples is the problem.
<tr> <td> <a href="script_name.php">script name</a> <div> <code> code here </code> </div> </td> </tr>
Oh, I need to get a description up there as well. The README.SAMPLES file that’s in the samples folder has a description for each sample. Great, I could use that. Let’s throw some Javascript goodness with my favourite light weight JS framework mootools as well. It’s really easy to generate that for all the samples. Prettify was used to get the syntax highlighting. I did tried the syntaxhighlighter but after combining with moo the page got messy when the slide up happens. Anyways, FWIW, here’s the no brainer Ruby code.
#!/usr/bin/env ruby require 'cgi' lineno = 1 desc_row =<<E <tr class="%s"> <td class="desc">%s</td> </tr> E code_row =<<E <tr class="%s"> <td> <a href="%s">%s</a> (<a href="#" id="%s">show code</a>)<br /> <div id="%s"><br /> <pre class="prettyprint"> %s < /pre><br /> </div> </td> </tr> E js =<<E var %s = new Fx.Slide('%s'); %s.hide() $('%s').addEvent('click', function(e) { e = new Event(e); %s.toggle(); e.stop(); }); E File.open('README.SAMPLES', 'r').each do |line| if line =~ /^([a-z].*\.php)/ then (filename, description) = line.split(/[ \t]+-[ \t]+/) php_code = (File.open(filename.strip, 'r').readlines.collect do |l| CGI.escapeHTML(l) end).join.gsub(/\r/, '') row_state = ((lineno % 2) == 0) ? "even" : "odd" run_link = (filename.strip =~ /client/) ? "Run client" : "WSDL" class_toggle = "toggle-#{filename.strip.gsub(/.php/, '').gsub(/\//, '-').gsub(/_/, '-')}" class_code = "code-#{filename.strip.gsub(/.php/, '').gsub(/\//, '-').gsub(/_/, '-')}" js_var = "#{filename.strip.gsub(/.php/, '').gsub(/\//, '').gsub(/_/, '')}" if ARGV[0] == "-html" then printf(desc_row, row_state, description) printf(code_row, row_state, filename.strip, run_link, class_toggle, class_code, php_code) elsif ARGV[0] == "-js" then printf(js, js_var, class_code, js_var, class_toggle, js_var) end lineno += 1 end end
Had to do a bit of copying and pasting here and there and the page was done.
Besides having the ability to provide a high level and a more developer friendly API, making a scripting language binding to an existing C library could make the testing of the library a less painful process. Initially I was under the impression that exposing low level C functions to the scripting language will make it flexible so that you could build a high level module in that scripting language encapsulating those low level functions. True. But the big downside when you have, say, 3 different language bindings for your C library all exposing low level functions is, a) you need to spend a lot of time writing the module in the respective scripting language b) too much overhead when it comes to debugging. If you find a subtle bug which you have overlooked in the Ruby binding, now you need to change the same thing on your Python and Perl bindings as well.
This was a real issue that we came across developing the Ruby and Perl bindings for the WSF/C framework. Also having the Python binding in sight. We use SWIG to generate language bindings. Having learned the price you have to pay exposing the lowest level functions, I’m gonna look into refactoring the existing code limiting the stuff that’s exposed to the scripting language to a minimum. So, code that goes into the module which need to be written in the respective scripting language is very small.
At the end of the day it’s about making you feel sooo comfortable when you program in your favourite scripting language, exposing your services with the doublew ess death star goodness with a few lines which will call the C library for maximum performance which will then give the result back to your favourite scripting language scripting language. It’s a deadly game out there
Yes, you can breathe now.