@dirceu

Mini-Review - Erlang Programming

Erlang Programming is probably the best book I’ve ever read about a programming language, and is worth reading even if you don’t plan to use Erlang.

The exercises in this book are helping me a lot to learn more about functional programming and recursion; also, it’s been a very good experience to use processes and “pure” functions instead of threading and shared-state.

Book contents

  1. Introduction: story, high level overview and cases
  2. Basic Erlang: data types, shell and patterns matching
  3. Sequential Erlang: BIFs, conditionals, recursion, libraries and error handling
  4. Concurrent Programming: process creation and managing, message passing, benchmarks and some theory
  5. Process Design Patterns: client / server, finite state machines, event managers and handlers
  6. Process Error Handling: process linking, exit signals, monitors and supervisors
  7. Records and Macros
  8. Software Upgrade: hot code swapping
  9. More Data Types and High-Level Constructs: anonymous functions, list comprehensions, binaries and references
  10. ETS and Dets Tables
  11. Distributed Programming in Erlang: communication between erlang nodes
  12. OTP Behaviours: introduction to generic servers, supervisors and other applications
  13. Introducing Mnesia
  14. GUI Programming with wxErlang
  15. Socket Programming
  16. Interfacing Erlang with Other Programming Languages
  17. Trace BIFs, the dbg Tracer, and Match Specifications
  18. Types and Documentation
  19. EUnit and Test-Driven Development
  20. Style and Efficiency
  21. Appendix - Using Erlang: installing erlang, editors and other tools

The good

  • The book have a great structure that teaches the language, functional and concurrent / distributed programming with baby steps;
  • It’s very well written and formatted;
  • Exercises! Every programming language book should provide exercises like these - short, well defined and that sometimes challenging.

The bad

  • The EUnit chapter should be in the beginning. It’s boring to compile and test things manually in the shell. Of course, you don’t need to read it in order, but still.
Mini-Review - Erlang Programming

Dealing with distractions

Most developers have trouble with distractions. The 5 minutes you take to check Twitter / Hacker News / Google Reader can quickly become 1 hour, and sometimes you need to force yourself to actually do something. This post lists some techniques I’ve been using to get more focused time.

Blocking websites

I’ve been using Alex Payne’s “Get-Back-To-Work Hack” with success for almost two weeks. It’s very simple and while I can easily edit /etc/hosts and un-block everything, I don’t do it. In fact, I’m spending much less time on twitter, email and feeds.

Don’t guess, measure

I use the Rescue Time daemon to track how I’m using my time. It have some pretty cool reports on the web interface and that is helping me a lot to see what distract me most.

Stop notifications

I’ve disabled Growl, changed the clock to analog and now I just keep Dropbox, wi-fi status, volume and the clock on the top bar. The digital clock distracts me more than the analog one (since I cannot see the exact time without clicking on it).

Automate what you can

I use Dropbox to automatically backup my dotfiles (/etc/apache2, .zsh*, .bash*, .ssh/config, etc), ebooks, pictures and other important files automatically - it’s really cool that you can use symlinks instead of copying / pasting.

I also schedule tasks using Things so I always remember to do repeating tasks and stuff in my calendar.

Don’t use IM

Most of the time I don’t use any IM software. I have google talk and skype accounts, but I only use it to talk to my co-workers (when I really need it). I think that a good (and short) meeting at the beginning or at the end of the day is way better then staying online all day on google talk, for example.

This “rule” have at least two good exceptions: Skype (for pair-programming) and IRC. IRC it’s nice because you don’t get windows jumping on your face and you can give attention to it when you want; also reading the logs is easier than on Skype.

I’m working on a project with a friend and usually we don’t work at the same time, so IM don’t work well. We’re using the Co-op app, a twitter-like application with cool additions like a solo / group agenda to communicate about the project.

Take breaks

When you simply can’t work on something, try taking a break away from keyboard. Sometimes I feel my concentration going away because I’m too tired, so I take a break, drink some water (or tea, caffeine FTW) and just rest for some minutes. Sometimes a “power nap” is a good idea too, if you don’t overdo it.

Dealing with distractions

Installing Erlang, Yaws and Erlyweb on Mac OS X

This is a short how-to showing how to install Erlang, Yaws and Erlyweb on Mac OS X via MacPorts.

Installing Erlang, Yaws and Erlyweb on Mac OS X

I'm a Mac (again)

Almost three years ago my boss sent me an iBook G4 to work with. It was an absolutely awesome machine: fast, great battery life, beautiful hardware, beautiful OS. I loved it, but after 1,5 years using it some problems arise.

First, the battery just died - it just worked when connected to the charger. Second, I work(ed) with Zope and Plone on a daily basis, and things like running the entire gocept.zeoraid test suite took about 40 minutes. Even PloneTestCase with some functional tests was painfully slow. A Macbook was too expensive for me at that time, but I needed a new laptop.

Linux

Before using that iBook I used Linux for almost 4 years, so I brought an inexpensive laptop to run Linux. The laptop has an Intel Core 2 Duo 1.66GHz, 2 GB of RAM and 120 GB of disk space - a reasonably good machine, except for the video and the wireless card. It took me almost 6 hours to install Ubuntu on that laptop (which came with Satux Linux installed by default) and much, much more time to get everything right.

I was reasonably happy with that setup, but every now and then I needed to fix something in the OS. One day I decided to buy a second monitor, and so I did it. Big mistake.

Windows

It seems that the SiS Mirage 3 video card is a Windows fanboy and I couldn’t get the new monitor to work with Linux. It worked out of the box with an Asus eeePC running eeeBuntu, but not on my laptop. Damn it. After that and some other minor annoyances I decided to give Windows Vista a try, following some advice from Sidnei.

Windows Vista surprised me. It’s a good OS, every piece of hardware on my machine worked without “serious” configuration. As I can’t live without a Unix I installed andLinux, but it was not enough: using Linux to manipulate a NTFS filesystem is a PITA.

Mac OS X - Again

After so much trouble I realized I was losing time with all these annoyances; then I saved money, did some freelance work on my spare time and voila: last week I brought a white Macbook.

I can’t tell you how much I’m happy with it. It took me less than 1 hour to download and install every application that I need - well, almost all of them, since XCode is really big and the download took almost 2 hours itself.

One good surprise is XCode / iPhone Simulator. XCode is a very good IDE and it’s been a lot of fun to learn Objective-C and how to develop iPhone applications.

If you need to buy some tool (be it hardware or software), buy the best tool your money can buy. Some programmers hesitate to spend some money on a good chair, on a good editor or on a good computer (like me, before all this) but damn, we spend 8-12 hours a day using these things! Every single thing that can save you time or give you more comfort is worth it.

I have a profile on iUseThis that shows the apps that I have on my Mac. If you have any recomendations please leave a comment!

I'm a Mac (again)

Usando Emacs

Desde que comecei a programar eu pulei de editor para editor (sempre usando com mais frequência o VIm), mas nunca parei para me aprofundar de verdade no uso de nenhum deles. Alguns meses atrás eu decidi me dedicar a resolver esse problema e desde então tenho usado diariamente o Emacs.

Por que o Emacs? Pelo mesmo motivo que me levou a aprender Zope e Plone: tem muita gente realmente boa usando o Emacs, o que significa que algo de bom ele tem. Além disso o Emacs é multiplataforma, o que é importante pra mim, já que pretendo voltar a usar Mac OS X em breve.

Logo que voltei a estudar o Emacs eu assisti o screencast Meet Emacs, do PeepCode.com (altamente recomendado, aliás), o que me ajudou muito. O screencast apresenta os principais comandos, major / minor modes, color modes, eshell, ido-mode, textmate.el, vc-mode (para controle de versão), magit (para usar git) e vários outros recursos interessantes.

A coisa mais útil do screencast, na verdade, foi apresentar o Emacs Starter Kit. O ESK é um diretório de configuração para o Emacs (.emacs.d) cheio de major e minor modes muitos úteis e vários defaults melhorados. Vale a pena testar.

No github existe uma grande variedade de forks do Emacs Starter Kit; eu mesmo mantenho meu .emacs.d como um fork desse projeto. O meu fork adiciona algumas coisas interessantes como o yasnippet (com snippets variados para Python, Ruby e outras linguagens) e o whitespace.el (muito útil pra programar em Python).

O Emacs é muito flexível. Abrir diversos buffers lado a lado, fazer commits, verificar sintaxe, fazer diffs e funções como a jump-to-symbol do ido-mode sem dúvida me proporcionaram uma maior produtividade. O contraponto disso é que é fácil ficar “perdendo tempo” personalizando o .emacs.d e brincando com elisp :-).

No geral estou bastante satisfeito com a minha escolha de editor. Pretendo me aprofundar mais e assim melhorar minha produtividade - afinal de contas um dos requisitos para entrar no estado de “flow” é usar bem e intuitivamente as ferramentas que mais usamos.

No meu delicious tem alguns links interessantes sobre Emacs: http://delicious.com/dirceu/emacs.

Usando Emacs

Why you should switch to Git

Over the last few months I’ve switched from Subversion and Bazaar to Git. I’m using Git on a daily basis now and I’m much happier with it than I was when using Subversion. In this post I’ll try to explain why and provide some useful links.

When using Git you don’t work on a “working copy” of the last revision (as you do with Subversion) - using “git clone URL” you clone the entire repository: all commits, merges, branches, everything.

With Git I can clone a remote repository, create branches, try things out and never ever send anything back to the origin repository. I can do pretty much everything without getting permission, without bureaucracy.

Also it allows you to make “pull requests” (a way to poke someone and let them know youíve got some code they may want) and get your code on the main repository.

Why you should switch to Git

Creating RSS feeds with rssifier

Two of my favorite webcomics doesn’t have official feeds - Malvados and The Order of The Stick (this one actually have a feed, but the images aren’t shown in the feed items). I didn’t like to visit these sites manually, so I quickly wrote a script (which is now a very simple Ruby lib) to create these feeds for me: rssifier.

The lib code is ugly at some points, but it’s working for me. Here is an example script (malvados.rb) that uses rssifier to create a feed:

(Link of the Gist).

And this is the result; I have a cronjob calling the malvados.rb periodically, so this XML gets updated from time to time.

Any contributions via�github are obviously welcome :-).

Creating RSS feeds with rssifier

Quick Tip - Testing Django send_mail

I’ve been working on a Django project lately and I had the need to send some emails from my application. I was trying to figure out how to write a mocked version of django.core.mail.send_mail when I read about django.core.mail.outbox, which apparently is a new feature of Django 1.0.

django.core.mail.outbox is a list of all instances of emails sent with django.core.mail.send_mail that is available only in the testing framework. With it you can do things like these:

(Link of the Gist)

Quick Tip - Testing Django send_mail

Browsers gone wild!

Dois lançamentos recentes estão deixando o povo que ‘mexe com web’ agitado: o Mozilla Ubiquity e o Google Chrome.

Uma das coisas que eu mais achei interessante é a facilidade de manipular conteúdo; vocÍ pode, por exemplo, selecionar um texto qualquer em uma página, abrir o ubiquity e digitar ’email this to fulano’ - isso irá abrir uma tela do gmail já com um email parcialmente preenchido para o ‘fulano’ (que deve estar nos seus contatos).

O Chrome foi desenhado pensando nessa ’nova web’: entre outras coisas, cada aba é um processo. Isso faz com que esse navegador seja mais seguro (uma aba não consegue acessar os dados das outras), mais rápido (uma aba lenta não afeta as outras) e trave menos (se uma aba travar, é só ela que vai travar). A interface é minimalista: a idéia é que o navegador seja ‘invisível’, que o usuário só preste atenção no conteúdo que está acessando.

Mas como assim p*rra? O Google e a Mozilla não tinham um ‘caso’?

Pois é. Como bem disse o Sidnei, o Chrome tem tudo pra ‘roubar’ usuários do Firefox. De qualquer forma, a bagaça é open source - se a Mozilla quiser pode ‘deitar e rolar’ com o código do Chrome - inclusive pode aproveitar e começar a usar a engine javascript do novo browser, que é bem mais rápida que a do Firefox.

E vejam que beleza: migrei do OS X de volta pra Linux há menos de uma semana. O jeito é usar o VirtualBox.

sigh

Browsers gone wild!

Usando o git-svn

Nos últimos dias venho trabalhando em uma app Django e, como sou iniciante no uso desse framework, todos os dias aprendo algum feature novo para melhorar meu código (como generic views, por exemplo). Para testar esses features o ideal é criar um branch, usar os features no código e, se valer a pena, fazer o merge. O problema: usamos svn na empresa, e fazer branches no svn é bem chatinho (principalmente se comparado ao git). Para resolver isso estou usando o git-svn.

Segue abaixo meu fluxo de trabalho no git-svn:

Link do Gist, para quem não consegue ver no feed.

Enfim, esse é um post pra que eu mesmo não esqueça como fazer isso. Alguns links e tutoriais interessantes sobre o git e o git-svn estão no meu del.icio.us: http://delicious.com/dirceu/git.

Usando o git-svn