quinta-feira, 5 de julho de 2012

Why I don't send email receipts

I don't usually let my email reader send out email receipts. If you have sent an email to me expecting to get a read- or a return-receipt, please don't. I don't mean to be rude. I simply don't like them. They're broken in several ways: they aren't reliable and they can be misused. So, why bother?

If you want to know if and when I read your email, please, say so. A simple "Please, acknowlege this." at the end of the message will trigger an instant reply. But please, don't make it a part of your signature. Not every message needs an acknowlegement and if you always require them I'll soon start to avoid replying. Few things annoy me more than a signature with a "I look forward to your reply" (or an equivalent "Aguardo retorno" in Portuguese) in it. I think that's rude.

 

quinta-feira, 28 de junho de 2012

Programming languages start-up times

I don't remember the last time I wrote a substantial program in anything but Perl. It fills almost all of my needs as a sysadmin and diletante programmer. But there are situations in which I write bash scripts. Two, to be precise.

One situation in which I feel more like using bash than Perl is when the script is small and function as a driver to invoke other programs. Bash (any shell, in fact) syntax to invoke other programs is more succint than Perl's. As you know: succinctness is power.

The other situation, is when the script in question is short and is going to be invoked lots of times. In this case, I worry about its start-up time, because it may very well dominate the overall system performance. I always assumed that Perl's start-up time was much larger than any shell's start-up time. However, as Knuth wisely said: Premature optimization is the root of all evil. You should always verify your assumptions with a profiler or, at least, a stopwatch before investing in any optimization work.

These days I'm studying the implementation of Git hooks and I'm constantly struggling to decide if I should write them in Perl or bash, because they tend to be frequently invoked when you setup a Git server serving lots of developers.

So, I decided to check exactly that. What's the real difference between the start-up time of Perl and bash. My testing platform is bash. I simply timed one thousand invokations of bash and Perl telling them to do nothing. This is what I got in my Dell Latitude E6410 laptop running Ubuntu 12.04:

$ (time for i in `seq 1 1000`; do bash -c :; done) 2>&1 | grep real
real 0m2.858s

$ (time for i in `seq 1 1000`; do perl -e 0; done) 2>&1 | grep real
real 0m3.326s

Not that different at all, is it? Perl takes just 16% more time to do nothing than bash. I sure was expecting Perl to take much more time than bash. Of course, a script doing nothing isn't that useful, although it can inspire a blog post. But while in order to perform useful work a bash script needs to invoke other programs, a Perl script can do many things in a single process just by useing (sic) Perl modules. So, I guess that after starting-up behind a bash script, an equivalent Perl script is going to catch up and finish the run first almost all times.

I found this very interesting. So much so that I decided to extend my investigations to other scripting and compiled languages as well. Just out of curiosity. But the results were startling.

The other three main scripting languages fared much worse than Perl. I wasn't expecting such a huge difference:

$ (time for i in `seq 1 1000`; do ruby -e 0; done) 2>&1 | grep real
real 0m5.628s

$ (time for i in `seq 1 1000`; do python -c 0; done) 2>&1 | grep real
real 0m27.373s

$ (time for i in `seq 1 1000`; do echo exit | tclsh; done) 2>&1 | grep real
real 0m10.991s

Ruby is 1.7 times slower than Perl, TCL is 3.3 times slower, and Python is 8.2 times slower!

What about compiled languages? They should be faster, right? Of course they are. Let's C:

$ cat >null.c <<EOF
#include <stdlib.h>
int main()
{
    exit(0);
}
EOF

$ gcc -O -o null null.c

$ (time for i in `seq 1 1000`; do ./null; done) 2>&1 | grep real
real 0m1.185s

This is interesting, because I rekon that this C program must have one of the shortest possible start-up times. So we can use it as a yardstick with which to compare every other language.

What about Java? I don't speak Java, so I googled "java helloworld", found a good example and stripped it of every non-essential work:

$ cat >Null.java <<EOF
public class Null
{
    public static void main(String args[])
    {
    }
}
EOF

$ javac Null.java

$ (time for i in `seq 1 1000`; do java Null; done) 2>&1 | grep real
real 0m58.231s

What?!? Almost one minute for doing nothing one thousand times? I did it again and again just to be sure. I realize Java isn't a vanila compiled language. At least, not like C. The Java compiler generates byte codes that are interpreted by the JVM. But since scripting languages in general have to perform the source to bytecode conversion just before the interpretation I thought that Java would be at least a little faster than most. So much for enterprise languages...

So, to sum it all up, here is the final score of the game:

terça-feira, 1 de maio de 2012

On being sure and right

Being sure isn't the same as being right.

Being sure is a state of mind whereas being right is a state of the Universe.

These things don't correlate as well as one would hope, unfortunately. So, next time you feel so cock sure about something, remember this and be humble.

quinta-feira, 26 de abril de 2012

What is Pinto?

I can't resist the fun of this... I was searching for some module in CPAN and serendipitously found out Pinto.

I'm almost sure the author doesn't speak Portuguese and doesn't know that "pinto" means "dick" here in Brazil.

As soon as you realize that a whole other dimension of meaning springs from Pinto's documentation. How can you not giggle when you read that:

  • Pinto supports several usage patterns
  • Pinto does not understand author permissions
  • Pinto supports team development
  • Pinto can be extended
  • Pinto is not secure
:-)

sábado, 21 de abril de 2012

sábado, 31 de março de 2012

Aos 45 do primeiro tempo...

Aconteceu semana passada à noite, depois de eu ter passado uma hora e meia no super-mercado.

O contexto é relevante, pois pode explicar minha aparência cansada.

Saindo do super-mercado eu fui à farmácia comprar umas coisinhas. Ao chegar ao caixa a atendente me olha e pergunta:

- O senhor tem o cartão da farmácia?

- Acho que sim... você pode verificar pelo CPF?

- Pois não, senhor. O seu cartão é o "privilege"?

- Como assim? Qual é a diferença?

- É de aposentado ou é normal?

...

Hesitei uns dois segundos e respondi desanimado:

- É normal...

A moça não percebeu, mas o meu desânimo deve ter ficado muito claro.

Por trás dela havia uma janela na qual eu podia ver meu reflexo. Analisei minha fisionomia e meus cabelos brancos já dominantes nas laterais e constatei que a dúvida dela não era absurda.

Um dia isso ia ter que acontecer. Aconteceu na primeira vez que me chamaram de "tio" e de "senhor". Mas já faz tempo e esses termos já não me afetam. Agora, "aposentado"... ainda tenho mais de uma década pela frente pra chegar lá... acho que quando chegar eu já vou estar acostumado.

sexta-feira, 27 de janeiro de 2012

Estudar é divertido!

Estou estudando sobre trânsito porque levei 20 pontos na CNH e vou fazer prova amanhã. Pois é... de novo.

Não acho que eu dirija mal e nem de forma perigosa. Minhas multas foram todas de excesso de velocidade. Mas todas foram de limite de 60 km/h e eu estava sempre um pouco acima dos 70 km/h. Mas a regra é clara e eu não posso reclamar se sou distraído.

Anyway... ler sobre leis de trânsito, placas, gravidade das infrações... digamos que isso não foi o ponto alto das minhas noites recentes. Mas fazer os simulados da prova, ah, isso sim é que é diversão. A maioria das perguntas é bem fácil. Mas também, as opções erradas são geralmente óbvias e muitas vezes hilárias. Vejam essa: