Posts de March, 2010

[Alexandre Martins] Clojure: Integrating With Java

Thursday, March 18th, 2010

Currently I am learning Clojure. It is a functional programming language, but not a pure one, since you can both write code that share state (mutable) and also ones that doesn’t.

Why Clojure?

The main reason why I chose Clojure is its easy interoperability with Java, still one of the most used languages, bringing to it the power of Lisp. It’s fast, since the code is compiled, and it supplements some of Java’s weakness, such as the Collections framework and concurrent programming. It is pretty straightforward to write concurrent programs, everything is automatic, no manual lock management!

Integrating With Java

Importing classes

A single class:

(import java.util.List)

Multiple classes from the same package:

(import '(java.util List Set))

Creating instances

Using Java’s new keyword:

(new java.util.ArrayList)
(new ArrayList) ; after importing

Assigning a new List to a Clojure variable:

(def list (new java.util.List))
-> #'user/list

Syntactic Sugar:

(ArrayList.)

Accessing fields

Static fields:

(. Math PI)

Syntactic Sugar:

Math/PI

Invoking methods

Static Methods

(.currentTimeMillis System)

Syntactic Sugar:

(System/currentTimeMillis)

Non-static Methods

(. list size)
(. list get 0) ; returns the object stored at index 0

Syntactic Sugar:

(.size list)

Mixing Them All

Clojure provides a macro called memfn that makes possible execute Java methods as functions. So, for a list of String objects, if I want to make all of them upper-case, all I have to do is:

(map (memfn toUpperCase) ["a" "short" "message"])

The map function applies the function/method toUpperCase to each element in ["a" "short" "message"]

You can also use the bean function to wrap a Java bean in an immutable Clojure map.

(bean (new Person "Alexandre" "Martins"))
-> {:firstName "Alexandre", :lastName "Martins"}

Once converted, you can manipulate the new map using any of Clojure’s map functions, like:

(:firstName (bean (new Person "Alexandre" "Martins")))
-> Alexandre

The code above extracts the firstName key, originally from the Person object.

[Alexandre Martins] Retrospectives: Analogy For Developers

Thursday, March 18th, 2010

One day, while reading Esther Derby’s book, preparing for a retrospective session, I came across a great analogy between retrospective and development life-cycle:

While continuous builds, automated unit tests, and frequent demonstrations of working code are all ways to focus attention on the product and allow the team to make adjustments, retrospectives focus attention on how the team does their work and interacts.

Indeed it helps people improve practices and focus on teamwork. That’s why it is one of my favorite meetings.

[Alexandre Martins] Ping Pong Pairing: Even More Fun!

Thursday, March 18th, 2010

The agile software development practice I like the most, and at the same time, the one I find the most difficult is pair programming. Each individual has his/her own way of working, and characteristics such as motivation, engagement, habits, open-mindedness, and coding/design style varies a lot from individuals. Sometimes, to get a balance between these differences is quite hard. I am still not an expert in pair programming coaching, but I’ve been learning a lot on my current assignment.

And from this experience, it seems that clients are definitely more involved and amused when it comes pairing following the ping pong pattern.

Ping Pong Pattern

It happens when the developer 1 from a pair implements a test for a given feature and see it failing, then passes the keyboard to developer 2 who makes the test pass, do some refactoring on the code and implements another test, passing the keyboard back to developer 1 to do the same thing and continue until the feature is done.

Why Do We Like

  • Challenge - Each time a developer writes a test for you to make it pass, it sounds like a challenge, then you do it and write another one, challenging him back.
  • Dynamics - The worse thing is a developer that just hogs the keyboard, making you feel a useless. Ping pong pairing makes you swap keyboard more frequently.
  • Engagement - Developers are much more engaged because they are constantly coding, not only observing.
  • Fun - It is so much fun when you have all the above items together!

[Alexandre Magno] jqswfupload 1.1

Thursday, March 18th, 2010

 
Depois de fazer um esforço para mudar a estrutura do plugin em como é chamado e não mais depender dos parâmetros do swfupload, refiz toda a lógica de opções do plugin e abstrair todas as opções do upload.
Sendo assim, o plugin agora só tem um parâmetro que são as opções do plugin. Antes passando as [...]

[Alexandre Magno] jQuery irá migrar do SVN para o Git

Thursday, March 18th, 2010

Gostaria de repassar para todos uma mensagem que recebi do John Resig enviado para todos os comitters do jQuery que o jQuery não irá mais usar o SVN como controle de versão. Todos o seu core será passado para o Git e todos que tinham acesso ao svn para enviar plugins (como eu) terá de [...]

[Alexandre Magno] jqswfupload - jQuery e swfupload em uma linha

Thursday, March 18th, 2010

 
Gostaria de anunciar o lançamento da versão 1.0 beta do plugin que desenvolvi, o jqswfupload. Este plugin atende a uma evolução do plugin que desenvolvi que ajudou muita gente a implementar upload múltiplos utilizando o swfupload. Ele se tornou obsoleto com a versão 10 do flash player, que mudou a forma de como enviar requisicoes [...]

[Alexandre Magno] Calendário para jQuery em português

Thursday, March 18th, 2010

Há um tempo atrás escrevi um post do plugin jCalendar em português. Ele é bastante visitado e gostaria muito de oferecer uma solução atual para este plugin usando o próprio jQuery. Muito tempo passou e atualmente existem soluções melhores para ter uma ferramenta de escolhas de datas. o jQuery UI veio como uma luva para [...]

[Alexandre Magno] Utilizando fontes alternativas sem ferir a semântica

Thursday, March 18th, 2010

Já tem um tempinho que não escrevo nada no Blog. Estava realmente muito ocupado tanto como tempo tanto com a cabeça por causa da recente mudança para o Rio de Janeiro, cidade realmente maravilhosa, mas meu amor por Belo Horizonte ainda permanece. O motivo da mudança é que agora estou trabalhando no desenvolvimento de interfaces [...]

[Alexandre Magno] A maioria das suas visitas vêm de ferramentas de busca?

Thursday, March 18th, 2010

Quando você analisa seu website, uma grande fatia da sua pizza vem de ferramentas de busca? Sua taxa de rejeição é alta? Esses dois fatores estão intimamente ligados, e seus resultados podem ter uma variedade de interpretações. Muitos usuários chegam ao seu site usando ferramentas de busca, acham seu objetivo e logo saem novamente. Algumas [...]

[Alexandre Magno] Navegação em um site - Topo, esquerda ou direita?

Thursday, March 18th, 2010

Muitas discussões foram levantadas para escolher a melhor forma de navegação em um website. Alguns tem preferência pelo topo (muitas vezes utilizando abas e menus drop-down), outros pela direita (que possibilita maior escabilidade) e ainda a navegação pela esquerda (que é a mais recente, tendo em vista o seu uso recorrente em Blogs). Existe a [...]