Sunday, July 27, 2008

Spellchecker (Levenshtein distance)

1 comments
Have you ever wondered how the spellchecker suggestions are computed? I had no idea, and found out that the editing distance between words is calculated to come up with a list of words that are "close" to the one you are typed. Those with the fewest number of edits are displayed. The algorithm, known as Levenshtein distance, was devised in 1965. It uses dynamic programming, and it is a very clever and simple solution.

Friday, July 25, 2008

Apple Update annoyances

2 comments


First Apple not only suggests that you install Safari, but keep it checked. Everytime I have to uncheck this box. But now that was great. They release a new update with a bug in the updater: the description is displayed as "WhichDescription()".

Monday, July 21, 2008

Java benchmark: String, StringBuilder, and StringBuffer

1 comments
Some results first comparing String, StringBuilder and StringBuffer, with and without pre-allocation.

100000 times
String: 30786
StringBuilder (no pre-alloc): 5
StringBuilder (pre-alloc): 3
StringBuffer (no pre-alloc): 6
StringBuffer (pre-alloc): 5

The results clearly show how bad String is if you need to change it constantly in comparison to StringBuilder or StringBuffer. Now, let's remove String and compare StringBuilder and StringBuffer further:

1000000 (one million) times
StringBuilder (no pre-alloc): 58
StringBuilder (pre-alloc): 42
StringBuffer (no pre-alloc): 142
StringBuffer (pre-alloc): 122

This benchmark seems to prove to me that StringBuilder, introduced in Java 1.5, is really the best option when running in a single thread. And one can see that the overhead of running StringBuffer, which is synchronized, is actually huge.

Excerpt of my code to run this benchmark (*):
  final int n = 100000;
final String a = "a";

String s = "";
Date start = new Date();
for (int i = 0; i < n; ++i)
{
s = s + a;
}
Date end = new Date();
System.out.println("String: " +
(end.getTime()-start.getTime()));

StringBuilder sb = new StringBuilder();
start = new Date();
for (int i = 0; i < n; ++i)
{
sb.append(a);
}
end = new Date();
System.out.println("StringBuilder (no pre-alloc): " +
(end.getTime()-start.getTime()));


(*) Based on this post, which does not compare StringBuffer

Immigration and other golden cuffs

0 comments
Currently immigration is something quite interesting to be studied, especially in the US with these long queues to get the green card. If you join a company in the US on a non-immigrant visa (like L-1 or H-1B), you usually start your green card process, either right away or after some time. To set the stage, let me explain better about these visas. L-1 implies that you must leave the country almost immediately if you leave the company. H-1B has a little bit more flexibility: you have one month to find another company that sponsors your visa or you will be out of legal status. Back to the green card, depending on the job requirements, on how your case is filed, it may take many many years to get it. And by many many years, I talk about 5-10 years, sometimes even more than that. Although theoretically possible to change jobs under certain circumstances, few do that because there is a chance the process is withdrawn and you lose your place in the line to get the green card. That means that you are stuck with one company, with one type of job (changing the job may jeopardize the whole process). And, even after you get it, you should stay with the company at least one year to avoid being potentially charged with green card fraud.

I never liked being stuck with one company. And, when living in another country, I never liked the idea of living in that country without being sure that I could stay there and your personal investment in the country won't be lost. For this reason, I never really thought of coming to the US, because of the hard work to get a green card (besides the compromise). And, in my case, I could work in Europe since I am a EU citizen, so that makes me reflect more about what to do.

For a big company, the point is not in getting the actually best and brightest minds (although all big companies say that all employees are the best and brightest!). Nevertheless, the point is not to hire genius, but relatively smart people and make the rules and decisions that benefit the average employee. And who would that be? The one that achieves or even exceeds what is expected based on his/her experience, and that stick with the company for a long time. These delays in the immigration process end up serving the best interest of big companies that are sponsoring the green card for the employees: in average, their immigrant employees will be around for a long time. It may not be used on purpose, but that is the fact and it benefits big companies. Who is brave enough to throw away many years of theirs lives, especially with a family that may be well settled in the country? And isn't it the best deal if you can hire an experienced foreigner paying less than what you would pay for an American with equivalent experience? The difference is only the relocation (which is one-time charge) and green card process (again, one-time charge). When outsourcing is not the best option, that is a great deal to keep big companies competitive in internal US market and also globally. These professionals (the average employee) get stuck over the time due to this immigration issues, sponsorships and related rules. But that is not all.

Other common policy to make people stay with the company: you offer deferred compensation over time. That can be in the form of bonus, stocks, or anything as long that means that the employee will only get it if he/she spends many years at the company. And, on a regular basis, based on contribution, you pay more and more of his/her compensation in this way. Who will leave the company and leave that much money on the table? These are known as golden cuffs.

Third, you create a competitive scheme that only the very best get compensated. That is great for the company, but that has different effects on the employees that end up being blind by immigration, deferred compensation, and this competition. These employees become more focused on whatever they need to do, losing track of skills that are generally applicable to other companies, and more and more skilled on whatever is specific to their employer. And, although I don't know if on purpose or not, but I see that people lose track of what is outside the company and their own view of the company is based on what they learn from the company material (what may be influenced by the company ideology). Back to the market, not knowing what is going on in the market is not too bad if your company follows market standards. But that is not often the case and some particular experiences are very specific and not much valued elsewhere. A professional who leaves such a company, being valued by his/her specific and narrowed knowledge with a high salary, may only get a job that pays much less that what he/she makes. Who would do that?

Fourth, you create an environment where people feel good about themselves because they work for that company. More ideology work is necessary here, but it is not too hard. One can offer entertainment and other sorts of offers that seduce the employee family as well. And associate a good image of the company, so nobody will feel bad about being immoral or unethical to work for such an employer. Any bad press must be worked on and reverted, at least internally.

In this environment, what happens is that the least important thing is if you really love what you are doing. And unfortunately the rest does not pay off if you pursue to do what you love and what you believe in. From my experience since university, though, the majority of people does not care much about that. After all, if all jobs are the same, why not to be with those that offers the points outlined before? At least there is some advantage to be at the big company.

That is sad, very sad. Especially if you care about what you do and/or you are an outlier. [And not to mention how that compare to open source software, but that is a topic for another post.]

Java covariant return types

0 comments
In my attempt to try to catch up with more recent features in Java and Linux, I found out that a feature introduced in Java 5 that I was not aware of is covariant return types, what is neat. You can override a method and change the return type, what was impossible before Java 5, as long the returned type is a subclass of the return type of the superclass method.

For example,
class SuperClass {
SuperClass getX() {
return new SuperClass();
}
}
class SubClass extends SuperClass {
SubClass getX() {
return new SubClass();
}


There is an interesting page here about it.

Friday, July 18, 2008

Stronger schools in the US

0 comments
Very good post by my friend Tiago. See the video below:



I think most of people that left their countries realized that this is a serious issue. But when you come from a developing country, that is not news. What surprises me above is to see that rich countries are starting to worry about that. And I am glad that countries like US do that ahead of time, before it is too late for them.

On a related note, today I a sticker on a car window saying something like that: "Send our children to universities, not to war". It is a good start when this kind of mindset starts becoming more common around here.

Wednesday, July 16, 2008

Greg Kroah Hartman on the Linux Kernel

1 comments


It's an interesting video about the Linux kernel. What always amazes is how it attracts contributors that would not happen if it were not open source and were that famous. Like Greg mentions people doing janitorial work or submitting even spelling patches. Although I don't know about the dynamics of the Windows team, it is hard to conceive that there are developers like that contributing to the Windows kernel.

Sunday, July 13, 2008

Fixed vs Growth Mind-set

0 comments
A friend sent me this interesting NY Times article: If You’re Open to Growth, You Tend to Grow. It starts with one question: "WHY do some people reach their creative potential in business while other equally talented peers don’t?" and shows how the best and the brightest sometimes have a fixed mind-set that prevent them to realize their potential. Looking out for the chances to grow and also learn from past mistakes, what is called a growth mind-set, may make the whole difference in terms of professional (and may I add personal) growth. Recommended reading.

Saturday, July 05, 2008

Universidade Brasileira

0 comments
Trechos do blog do Reinaldo Azevedo sobre universidades que achei bastante interessantes.

Com exceções, claro, como sempre, a universidade brasileira é um hospício de iletrados.

A academia, no Brasil, é um dos últimos redutos do comunismo no mundo. Há mais comunistas nas universidades estaduais e federais do Brasil do que em Pequim.

-- Reinaldo Azevedo

Wednesday, July 02, 2008

Brazil: Skilled Workers Wanted

2 comments
Read this NYT article about the need of skilled workers in Brazil. Being that a global demand, how to compete with other countries that offer more attractive compensation packages to top talents?