Minha (Ex-)Corretora Quer Que Eu Perca Dinheiro!

Corretoras de valores não prestam. Faturam os tubos em cima de um modelo de negócio baseado em cobrar X por transação, e em troca você tem à sua disposição (sic) sistemas de home broking toscos que caem toda vez que Ben Bernanke dá um espirro.

Me interessei pelo mercado acionário em 2003, quando esse hype em cima da bolsa de valores brasileira estava ainda começando. Hoje a maioria das corretoras cobra um valor fixo por transação do cliente (geralmente na faixa de 10 a 20 reais). Na época o modelo de cobrança mais comum, e que era (e ainda é) usado pela corretora que eu havia escolhido era o de cobrar uma porcentagem sobre o valor transacionado. É a tal da tabela de preços sugerida pela BOVESPA que hoje só é seguido por algumas corretoras jurássicas e corretoras de vinculadas a bancos. Desde o ano passado eu passei a operar também por outra corretora, justamente por causa desse problema do custo por transação, mas por razões pessoais preferi manter uma parte dos meus recursos na corretora antiga.

Bom, já deu para perceber que o faturamento de uma corretora é influenciada diretamente pela quantidade de transações que seus clientes efetuam. Cliente que não compra e vende ações não dá dinheiro para a corretora. O modelo de negócios de uma corretora gira em torno do “fazer o cliente efetuar transações”. Quanto mais melhor. Videozinhos, tutoriais, fóruns repletos de imbecis pedindo dicas de investimento, cursinhos de análise técnica, tudo isso é feito para se criar uma atmosfera em que o cliente se sinta “O” mega investidor e opere cada vez mais.

Mas aqui cabe uma pergunta: qual a razão que leva uma pessoa a procurar uma corretora de valores para negociar ações ela mesma ao invés de, por exemplo, simplesmente colocar tudo num fundo de ações e esquecer? Um bom motivo é poder ter controle sobre sua estratégia de investimento. Só que existe uma estratégia que consiste em simplesmente ficar fora do mercado. Sim, isso mesmo, ficar fora. Ou você, leitor desse blog, acha uma decisão coerente ficar comprado e ver seu rico dinheirinho ir para o buraco enquanto o mundo inteiro está caindo?

Bom, acho que os analistas da minha ex-corretora acham que sim. No mês de maio, um pouco depois da euforia causada pelo investment grade resolvi vender tudo. Foi um pouco antes da BOVESPA atingir o topo histórico e entrar na tendência de baixa de curto prazo que se mantém até agora. Foi então que comecei a receber telefonemas insistentes (vários) de uma pessoa que se dizia gerente da minha conta, dizendo que “por uma política interna da corretora, não é permitido ficar com recursos parados em conta”. Ora bolas, quer dizer que eu, cliente, não posso utilizar uma estratégia perfeitamente comum e racional que é ficar fora do mercado, enquanto está tudo caindo? Ou ela espera que eu, cliente, permaneça comprado e veja meu patrimônio se desvalorizar?

Para ilustrar melhor, vamos observar o gráfico do IBOVESPA desse período:

A seta verde indica mais ou menos o período em que vendi tudo e fiquei 100% líquido. As setas vermelhas são os dias em que me ligaram da corretora. Foram no total 4 (quatro!) ligações da tal gerente de contas me questionando por que eu estava vendido, blá, blá, blá, e querendo me oferecer “dicas”, afinal dinheiro parado em conta não rende… Pode se ver pelo gráfico acima que realmente eu fiz um péssimo negócio ficando fora do mercado…

A gota d’água foi depois de algumas semanas de encheção de saco e várias ligações da inconveniente gerente de contas, quando recebi o seguinte e-mail:

Pois é… fui expulso da minha corretora por não querer perder dinheiro! O final da história? Bem, eles perderam um cliente, e a Wintrade ganhou um novo (pelo menos enquanto eles não implicarem comigo por deixar a conta parada… rs).

PS: achei melhor omitir o nome da corretora. Mas caso estejam curiosos, vocês podem imaginar uma famosa e tradicional corretora que “obriga” os clientes a usar a versão HTML do sistema porque a versão com atualização em tempo real é uma Applet Java tosca cheio de memory leaks que deixa o sistema lento e trava o browser a cada meia hora :)

Be Agile with Scrum and… iPhone?

My employer started to adopt Scrum in the entire company some months ago, but we have been missing card decks in the planning poker sessions. My co-worker and iPhone addicted, Marco Túlio, came out with a simple and interesting solution:

Use the iPhone as a virtual planning poker card :)

Check out his work: http://www.coders.com.br/iplanning/

Widgets Can Kill Your Website

Today, it is very common for people to embed widgets in their website, blog, etc. Usually these widgets are provided by social apps who want to promote their service by inserting their widgets in most sites, in exchange to providing some kind to benefit to the site owner, like improving visibility by using some kind of ranking, etc.

However, using a poor engineered service can degrade your website’s performance substantially. One real example I just faced is with the CHR Investor website. It is a brazilian blog I read and like very much, about stock market. They put a widget from Rec6, a brazilian Digg-like website. This widget is a Digg-like voting widget: it shows the number of votes the article has, and a button to vote on it.

However, the Rec6 servers have been very slow to respond and this is degrading the blog’s performance very much. As you can see in the next screenshot, taken from Firebug, the widget is loaded from an external javascript, which takes ~9 seconds to load (actually, in my tests the response time is varying between 5 and 12 seconds)!

Those who already read the excellent High Performance Web Sites book (chapter 6, more precisely) know what this means: an external javascript blocks everything until it is entirely loaded. This can be seem clearly in the picture: only after the widget is loaded, the rest of the page is downloaded.

The result from the visitor point of view is also very noticeable: the beginning of the page is loaded and rendered, everything freezes for ~9 seconds (the amount of time it takes to load the javascript from Rec6), and only then the rest of the page is rendered, very quickly.

So, if you intend to embed some kind of external service in your website, it is important to measure if they can handle the load of thousands (millions?) of users using their service.

I use some services here, like Google Adsense, Google Analytics, and the Google Reader Shared Items. The Google Analytics and Google Reader are a little slow (~200-400ms), but they don’t hurt because I can move them to the end of the page. The more problematic is Adsense because it writes content in the middle of the page, so you cannot move it. But the response times (~300ms each ad) don’t hurt, and are just fine.

More reading:

http://developer.yahoo.com/performance/rules.html#js_bottom

Playing with OpenSocial: Memory Game

I’ve been playing with OpenSocial APIs in Orkut since the 0.5 release, and now that they finally opened access to all your friends data in 0.7 release (previously you could only access data from those who also signed in for the Orkut sandbox), I started to play more seriously.

Inspired by Aurelio’s EmoMemory game, I created a little memory game using your friends thumbnail images. It uses OpenSocial APIs to get the images from your list of friends.

Try it here!

How Web Standards Evolve

For a long time, we had the ACID2 test.

Then Web 2.0 came, and brought a new set of requirements to web browsers. As such, the ACID3 test debuts.

As humanity evolves, the web standards follow. Now, we have the Homer test.

Is your browser capable of rendering Homer correctly? :)

java.net.URL is Evil

This is something I wanted to blog about since long time. Although some people had already talked about this beast before, this is not a well known issue, and spreading this information is never enough.

From java.net.URL.equals() javadoc:

Compares this URL for equality with another object.
If the given object is not a URL then this method immediately returns false.
Two URL objects are equal if they have the same protocol, reference equivalent hosts, have the same port number on the host, and the same file and fragment of the file.
Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can’t be resolved, the host names must be equal without regard to case; or both host names equal to null.
Since hosts comparison requires name resolution, this operation is a blocking operation.
Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP.

Now, the java.net.URL.hashCode() javadoc:

Creates an integer suitable for hash table indexing.
The hash code is based upon all the URL components relevant for URL comparison. As such, this operation is a blocking operation.

Note the highlighted phrase. Yes, that’s it… I know exactly what you are thinking…

OMFG!!! java.net.URL.equals() and hashCode() DO A NETWORK CONNECTION!!!

That is one of the biggest traps and horrendous mistakes I’ve seem in JDK code. That is a totally broken example of equals()/hashCode() implementation. An unadvertised developer may be tempted to innocently use URL objects inside some collection and get some headaches…

Actually, that’s what happens in Eclipse update manager (at least until Eclipse 3.3; 3.4 will [hopefully] have a new one). Their code use maps of URL objects as keys to compute update sites from each installed feature. The result is a well known hang in code that was supposed to be very quick:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=117708

https://bugs.eclipse.org/bugs/show_bug.cgi?id=121201

https://bugs.eclipse.org/bugs/show_bug.cgi?id=164211

https://bugs.eclipse.org/bugs/show_bug.cgi?id=205001

http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html

So, the lesson today is: be very careful with URL objects. NEVER use them as keys in HashMaps or elements in HashSets. NEVER use them in a context where you need to compare them. If possible, work with the String representation of the URL, so you are safe from its evil side effects.

Eclipse Plugin Development Tip and Tricks

Some quick and dirty nuggets of information I got while doing plugin development in Eclipse platform. For most of them I didn’t find documentation, so I hope Google will index this for others stumbling on similar needs.

Need to create a dialog for displaying and selecting from a list of items with filtering support, similar to Open Type/Resource?

Subclass FilteredItemsSelectionDialog (since Eclipse 3.3). Override methods to define your providers and filtering policy.

Similar implementations are Open Task dialog from Mylyn (Ctrl+F12) and Open Plug-in Artifact from PDE 3.4 (Ctrl+Shift+A). You can take a look at their source code to see how they were implemented. If using Eclipse 3.4, use the cool Plugin Spy (Alt+Shift+F1) while dialog is open to discover and get linked to the class source code.

spy_opentype.gif

How to make an ToolItem produced by an IAction show both text and image when working with IToolBarManager?

When working with raw SWT ToolBar/ToolItem this is easily accomplished. But when you are working with JFace IToolbarManager/IAction, you will see that even if you define both text and image for an IAction using #setText(String) and #setImage(ImageDescriptor), the resulting control will show only the image. No need to curse JFace developers!

The ToolItem creation itself is delegated to an IContributionItem. When you invoke IToolBarManager#add(IAction), the action is encapsulated inside an IContributionItem implementation instance, ActionContributionItem, whose policy is: if the IAction defines only text, the ToolItem has only text; if the IAction defines an image, use only the image, regardless of text presence.

If you want to display text and image, you need to manually create an ActionContributionItem and override the default policy calling ActionContributionItem.setMode(ActionContributionItem.MODE_FORCE_TEXT).

IAction action = new MyAction();
ActionContributionItem ci = new ActionContributionItem(action);
ci.setMode(ActionContributionItem.MODE_FORCE_TEXT);
IToolBarManager tbm = new ToolBarManager();
tbm.add(ci);

This way, the ToolItem will display text and image, positioned according to the ToolBar style: text under image by default; text after image, if using SWT.RIGHT style.

Palm drops Java VM

As of January 12, 2008, Palm stopped the distribution of the JVM for Palm OS.

Java never was a very popular platform for Palm OS development, neither Palm -> Palm Source -> Palm Inc promoted its use very much. The distributed JVM was actually a licensed version of IBM's J9. The latest version (released in 2005) supports MIDP 2.0 with some optional JSRs: JSR-75 (PDA Optional Packages) and JSR-172 (J2ME Web Services). It didn't come pre-installed with your device (at least it didn't in my Zire 72) or available in the installation CD; you had to manually register and download it from Palm support website.

While its competitors support Java ME out-of-the-box, Palm never cared about taking advantage of its superior PDA UI against the limited phone UI from its concurrents, and it took very long for developers to have available at least a descent JVM supporting the lowest common denominator of mobile widget toolkits which is the MIDP.

Some people may complain about the relevance of this fact, arguing about the relevance of Java ME itself, which may be somewhat true regarding its limitations and the amount of very cool MIDP applications versus very cool native applications available on market. But I believe it can have its niche, maybe quick-and-dirty internal corporate applications, for example. And I still believe strongly that the power of a platform is directly proportional to the amount of developer support you provide (developer diversity included).

So, apparently now you are on your own. If you downloaded it before January 12, congratulations. If you didn't, it's time to look for alternatives. I don't know if it's possible to license it directly from IBM. But looking at Palm's strategy over the last few years, perhaps it's time to search for a platform alternative…

Remembering the Logo Language

Jeff Atwood from Coding Horror just posted about the Logo language. Like him, and many of the commenters in his post, that language had a great influence in my own career. I could say that my contact with Logo was responsible for making me gain interest for software development. And yes, I didn't know it was a easy-to-read LISP language too…

Everything began in 1990, when I was 10 years old. I started to have computer classes in my college. At that time, computer classes meant to learn a programming language: the first year was Logo, some Basic variant on next year. After that, we would learn to use Wordstar and then some database programming with dBase III. Ah, good old days!

It was my first contact with computers. We used a Apple II clone, Exato, with a Logo implementation called MLogo. According to my professor, it was Microsoft Logo; unfortunately I couldn't find any references on this to confirm… If you have some MLogo disk image lost somewhere that can be emulated, please comment! 

Exato PROThanks to Logo is was able to learn and practice things "normal people" only learn years later, for example, mathematical concepts like angles and some basic trigonometry. I remember being surprised to know that a circle is just a polygon with some many sides you just don't notice. I also learned procedural programming by breaking bigger problems into small procedures.

It was very funny to spend some hours just drawing pictures and playing with the repeat command. 

In 1999 I had another contact with Logo during my graduation in Computer Science. Apparently my C professors were fans of Logo too, and they proposed a exercise to make a simple Logo interpreter, consisting of a simple shell and basic drawing operations: forward, left, right and the repeat command.

I was so excited while implementing it, that I ended up implementing a lot more features than previously planned. I implemented most drawing functions, color changing, pen modes, and repeat (loop) command with nested blocks.

That code was left hibernating in my old HD until now. After reading that nostalgic post from Jeff, I decided to release it under GPL at Google Code, so it doesn't got lost someday. It uses a portuguese Logo dialect, and the source code comments are also in portuguese.

I don't plan to evolve that code, but maybe I would rewrite it in another language or platform when I have time. The source is just for study purposes (but don't forget it is a beginner C programmer's code, so be aware that it may contain some WTF code Embarassed).

Impressively, I was able to run the original 1999 executable using DOSBox, an MS-DOS emulator. I was even able to run RHIDE, the IDE which comes with DJGPP I used to develop the original code! It is not just for running old games :)

I did some minor modifications to make it work in win32. Originally the code was written using the free DJGPP/GNU toolchain and the GRX graphics library for DOS environment, so the executable was not working in Windows Vista.

Thankfully, GRX is multi-platform, and with some little modifications I was able to make it compile and run under Wascana (an Eclipse/CDT/MinGW bundle). So, the executable available for download can be run directly on Windows.

You can download it and see some screenshots here

Credit for the Exato PRO photo: Idalio Manuel

New GMail App for Nokia E61 – A step back?

I'm a heavy-user of GMail Mobile App. I consider it one of the best and useful Java ME applications ever made. However, I'm very disappointed with the latest version they launched in mid-october.

Although it was released in october, I just made the upgrade few weeks ago, and for my surprise, the new version (v1.5.0.1187) introduced some usability issues:

Startup time

It is incredibly slow to open. It takes at least 10 seconds to open, but sometimes it takes longer.

Changes in shortcut keys

The previous version used the number keys as shortcuts, like * – star, 9 – archive, 3 – mark unread, 8 – mark spam; and although the Nokia E61 has a full keyboard, you hadn't to hold the "blue" key (a kind of Shift-key) to activate the shortcut; you just pressed the corresponding "letter" key.

In the new version, I presume they tried to use the same shortcut keys used in normal GMail website: S – star, Y – archive, ! – spam.

Although it is a minor change, it is annoying when they change something you are used to.

Removal of shortcut key

The previous version had a shortcut key of "3" to mark a message unread. This is useful when you want to take a quick look at some big message and want to mark it unread, so you can read it later in your desktop machine.

In the new version they just removed this shortcut key! Please, don't remove features users are used to!

Introduction of not-so-shortcut keys

Some shortcut keys now requires you to press 2 keys simultaneously! For example, the shortcut to "search" is "/", but it doesn't respond if you just press the corresponding key for "/", because in Nokia E61 keyboard "/" is "Blue" + "I". To report spam, you have to press "blue" + "Q" (= "!"). They made it harder to report spam!

The previous version required only 1 key press! 

Conclusion

The previous version worked very well with the Nokia E61 keyboard and was very quick and simple. The new version is slower and commands are hard to activate due to the changes they made in shortcut keys.

These are serious issues (IMHO) because we are talking about a mobile application. In fact, I'm desperately trying to find some place to download the previous version. If you know where to download it, please post a comment.

PS: If someone from Google is reading this, please take it as a constructive criticism, and please, fix these issues :)