Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

Monday, 2 June 2008

Why return isn't evil?

We know that GOTO is the root of all evil (OK, GOTO and premature optimization). However, why return is different? For instance, if you write in Java...

boolean equals(Object o) {

if (!o instanceof MyClass.class)
return false;
....
}

it is salt, and spice and everything nice, even though it is unstructured. Not only is it OK, it is recommended.
I think I have an idea. In this case you are not breaking the structure of the code. You are just shortcutting a huge else; it is the short for of "else do the rest of the stuff, clear local variables and return a value". However, this doesn't apply for continue of break; In both cases they are unstructed and mean: "continue with an unnamed block of code, but leave variables as they are", which is exactly what GOTO does.

Update Jun 4, 4:04: A colleague reminded me the amazing number of WTFs that can be produced just with returns. I have seen them and they can be as ugly as GOTOs; I mainly meant those clear returns that are nested only one or two levels deep.

Add to Technorati Favorites

Saturday, 29 March 2008

Travelling salesman with N processors

XKCD applies one more... I have to say that in this case the problem is slightly changed, since it is no longer the travelling salesman, but N customers going to the distribution office, but heck, the joke is still good.

Add to Technorati Favorites

Monday, 24 March 2008

How to update Netgear WPN824

In this post I just want to single out a something from my previous post... If you have a Netgear WPN824, the auto-update feature doesn't work. You have to download the firmware image from the website and apply it.
Of course, applying a firmware upgrade is not for the faint of heart. It is one of those cases when reading the manual and following precautions is useful. You have to do it with the device firmly connected to the wall, in a sunny day, without cats, dogs or children around, praying to your favorite deity (in my case, Steve Jobs) that everything goes well.
In a related note, it reminds me of something I learned in my previous jobs. Electric companies don't apply patches to their EMS or other important systems in rainy or windy days, just in case there is a power failure.

Add to Technorati Favorites

The state of plug and play

Today I finally managed to configure my VOIP adapter, a Grandstream Handytone 286. Mind you, it was not easy, to say the least. And that's considering I am a graduate software engineer with 7 years of professional experience; the only way you have a chance is if you fully understand XKCD.
The first strange issue was that my router, a Netgear WPN824, crashed when I plugged the VOIP adapter into it. My first idea was to check if it had the latest firmware; the update system said so, and I went on. Since I had some problems with some VOIP providers and my softphone, and some reports on the Internet said that the firewall could crash the router, I tried to set the adapter in the DMZ. Since my router could only take one server in the DMZ, I had to disable DHCP and manually setup the address, which involved typing the MAC address in the router configuration. As that didn't work -I guess I would have needed to force the expiration of the DHCP address in the adapter- I had to set it statically in the adapter too.
It was really fun to find that the problem was still there: the bloody adapter still crashed the bloody router. I still had a couple of tricks left. I tried disable UPnP, which I read it also caused problems, but to no avail. I was thinking of setting up some port triggering, but I thought that if setting the adapter in the DMZ didn't work, port triggering would be quite useless too.
Going around the router documentation I come across some firmware downloads. I see the versions available and with the corner of the eye I see something strange: the latest version number seems to be different than the one I saw in my router. Fiddling a bit I check and, indeed, I had an old firmware version. All I had to do is a firmware upgrade.
For those of you who have never done it, firmware upgrades is something that really makes a person nervous. If something goes wrong you turn a piece of hardware into a nice decorative ornament; there is no undo, no turning back, it is the point of no return, you cross the Rubicon, you burn the bridges, etc.
Fortunately, the firmware upgrade worked OK and the router no longer crashed. So all I had to configure was the SIP address, the STUN server, the works. That was pretty simple in comparison.
In case you didn't notice the irony of plug and play, I included 11 very technical terms just to configure a bloody VOIP adapter, which took me 2 hours and lots of guesswork to make it work


Add to Technorati Favorites

Saturday, 15 March 2008

Bubblesort with N processors cannot still be reduced from O(n)

So, continuing with the previous post, let's assume we can make N comparisons simultaneously. Bubblesort won't still improve the speed from O(n); in the pathological case, where we have MAX, x, x2, x3, ..., x(N-1). Only one comparison per cycle will return that a swap has to be executed. so, we still have to do N-1 swaps.
Now, how we use all this comparisons? Well, a simple algorithm will be to make N/2 comparisons per cycle, comparing all elements xE with xE+1 (where E is all the even numbers). In the next cycle, we compare xE-1 with xE. Why not do both at the same time? It is very simple: we might have a problem that both return true, and we must execute both swaps; which is the equivalent of swapping xE-1 with xE+1. But how do we know that? We must compare the results of the comparisons, and we still have the problem of how xE+2 may compare with xE+1.

Add to Technorati Favorites

Thursday, 6 March 2008

Bubblesorting with N processors (where N is REALLY large)

I was reading this article in Slashdot, and after this comment an interesting question came to my mind: what may happen if you have a massively overpowered computer for solving a problem. By "massively" I mean that for an O(n) or O(n .log n) you have C.n or C.n.log n processors and equivalently ingent amounts of memory considering parallel memory access (usually memory is not a problem, since even if you solve problems with 1.000.000 integers, that doesn't make a dent in present computers).
So I will try to think how to implement some of this algorithms... if I have too much time (I won't) I will check if I can simulate them. Unfortunately, normal multithreading may not work optimally, since to have some real simulation I would need a per-instruction round-robin, so I don't think that will be possible.
Of course, I am not original. This is the same concept as the Chinese Lottery Cryptanalisis attack (there is even an RFC about it)

Add to Technorati Favorites

Wednesday, 30 January 2008

You are old when you are a part of a museum...

Last few months I've been to a couple of “Living History” museums. What I mean by “Living History”? These were historic museums, but some parts are so recent that actually people who lived through that age are teachers themselves. Last weekend I went to the California State Railroad Museum in Sacramento. It was really interesting, especially where they showed a Railway Post Office; in this car mail was sorted while the train was riding, so letters could be delivered as soon as the train arrived to the destination! The guy who explained all this, now in his seventies, was actually a clerk, so he explained how he did his job. Actually, since the last wagon was retired in 1977, I was alive when this kind of cars existed!
In addition, 6 months ago, I went to the Computer History Museum in Mountain View. They have a restoration project for a PDP 1, and the teacher has actually worked with the computer when he was at university. He told the story how they found the data for a music program, but not the program itself. Amazingly this guy had written the original program, so he reconstructed it from the data! As if that wasn't enough, one of the first Google servers was on display... if you thought turning forty was a crisis, being a part of a museum is way worse!
I can imagine in thirty years being a teacher in a museum explaining the history of the Internet.
I: “So, when I was young, we communicated our computers with modems over a phone line... (young girl raising her hand) Yes, darling?”
Young girl: “What is a phone lane?”
I: “A phone is what we used to talk before we had iBlackBerry's, but the difference is that it was connected to the wall.”
Young girl: “My daddy connects my iBlackie to the wall one night a month, and it is terrible, I cannot use it at that time”
I: “Well, actually, phones had to be connected to the wall to be used....”
Young girl: “But how did you carry it to the playground, to school?”
I: “We didn't” (young girl looks perplexed, not understanding the concept of being out of touch)
Young boy: “How fast were these “phones”? How many Gbps?”
I: “My first modem was 2400 bps”
Young boy: “Ohh, 2400 Gbps is quite good”
I: “No, no, sorry for not being clear: I meant bps. That's like 1 billionth of a Gbps” (the boy refrains from asking me how we hunted mammoths)

Add to Technorati Favorites

Sunday, 7 October 2007

Generics/template: giving peace of mind to the anal-retentive

I admit it: I am obsessive. So I am a bit conflicted about Object Oriented Programming. To be true to the concept, objects themselves should define whether they accept a message or not; type checking should not be allowed, since it should be impossible to realize beforehand whether a message (a function call in other paradigms) is valid or not until it is passed to the object. However, not adhering to theory has lots of advantages. On one hand, static typing allows you to detect errors at compilation time, errors that wouldn't be detected until the function is executed; that is certainly a huge advantage, especially since not many people are comfortable with mutable code. In addition, if a call is not polymorphic, it has better performance (this advantage is quite minor, since the performance improvement is very minor).
Java and C++ were strong typed, and life was easy and nice to your average control freak. However, there was a thing in Java (up to 5.0) that bothered me a a bit. You could only add “Object”'s and get “Object”'s from Collections, so to get syntactic errors if you added the wrong type to a collection you had to either to do a very strange casting when adding to the collection (every time casting to the desired class and then letting the implicit casting to “Object” work, without forgetting once about the casting) or you had to subclass the desired Collection instance (which was safer, but you made a bigger mess by adding unnecessary classes). Fortunately, by using Generics (or templates in C++) you can don't have to do anything for type checking the input, you can specify what objects should be contained in a Collection when you must pass a parameter and you don't have to cast the get function, all through a simple syntactic trick (unfortunately, not everything is just a syntactic trick away)

Add to Technorati Favorites

Saturday, 6 October 2007

Why I hate Java enums

Enums are nice: they are static instantiation of objects where some absolute order is introduced between the elements. However, in Java, they have made the instantiation of enums and type declaration go together. You cannot make enums of objects that you have declared previously.
From the implementation point of view the reason is obvious. If an element is a member of an enum and it has a base class, suddenly that object has multiple inheritance, a big NO-NO in Java. On the other hand, if an enum doesn't inherit from any other class the object of class T can inherit from Enum, so it is just a simple syntactical trick to make the enum. The problem is that it is worthless. If you want to create objects of that class, apart from the enumeration, you can't.
Implementing it the other way would have been harder; the element would have had to handle methods with the same name, common ancestors, etc., all the nice stuff that make C++ inheritance syntax a huge mess, and really difficult to implement. But then enums would have been useful instead of a quick gimmick for rookies; right now enums are only useful for a simple lists of Strings.
PS: I am not the only Java-enum-hater

Add to Technorati Favorites

Thursday, 13 September 2007

Working at Google VI: It's the people, stupid!

It is great to work with great people; isn't it? Then it it follows that it is amazing working with amazing people...
In Google everybody is great; they are amazing and friendly. Actually, you can see that in the hiring web page: "world class programming skills", "Are passionate about their work and are great colleagues". And it is important that it is not strong programming skills: they are "world class" programming skills. "Passionate about", not "self-motivated". "Great colleagues"; maybe you have seen "team players" in other companies, but "great colleagues", who can support each other, who can undermine their management, that's outright subversive.
If you read closely the two last posts, you might always find some comment about the people. Your colleagues are another advantage of working at Google. You will always learn something AND have fun. And they are not petulant or trying to show off... they are so good that they don't need that. Actually, every single person in Google I've met is friendly, nice and very simple... So simple that they might trick you in judging the book by the cover. But inside you will always find Kafka, T.S. Elliot and Borges together, in the best ensemble you can think of.


Add to Technorati Favorites

Wednesday, 12 September 2007

Working at Google V: Evilness is in the eye of the beholder

I guess this title could be used for some deep thoughts about serious issues like the Iraq War, terrorism or such.
Instead, I will post about how Google gains some good Karma (or loses it, from my point of view): the Gym. As you have read in my previous post, the food is great, abundant, etc. (most probably you knew about that, but I was running out of subjects). However, something has to be done in order to battle the weight gain. And the Gym is the best way to do it. I guess in the grand scheme of life, it is a good thing. However, due to my personal preferences, I'd rather consider that evil. In addition, what else could be said about a place with sweaty engineers exercising (I shriver just at the thought)? They might be computer whizzes all of them, great fun, but none will be featured in Playboy (another awful image, engineers in Playboy, I won't be able to sleep tonight).
On other news, Google has another method of fighting weight gain: the conference bike. Since everybody knows that meeting are a waste of time, at least you can exercise (if something important were to be said, there will be an e-mail later anyway).
PS: no link to Playboy in order to avoid angry parents whose kids have read by blog and found about Playboy.
PS2: that's a Gedankenexperiment! Thinking that somebody with a computer doesn't know about Playboy


Add to Technorati Favorites

Working at Google IV: The free food

Yes, there is free food; yes, it is amazingly good. Last wednesday, for instance, I had oysters. Unless you've been to a school in the Swiss alps, I guess no other canteen will serve oysters. And of course, you put on weight. It is so common that it even has a name: Google 15 (the imperial impaired say the Google 5, since the Google 6.80388555 don't have such a hit, or the Google Stone, those who are really into measures).
But this being Google, it is part of the world's information, and has to be organized (and Googlers really like to code). The result: The Google 15 Weight Tracker. I rest my case.

Next installment: how we battle the bad karma (Gaining weight is evil)

Add to Technorati Favorites

Monday, 10 September 2007

Working at Google III

Mariana Riva wrote a link in her blog about my posts on working in Google, and I have realized I didn't write anything about that in a long time.
The first thing that I found interesting were the interviews. I won't go into details; needless to say, they are gruesome. But I had fun, since my interviewers were really smart guys. Of course, even I know that my concept of fun is a bit weird, in the same way that a SM concept of pleasure is kinda strange.
I remember I once had fun sitting for my Data Structures exam. There was a problem that required a mathematical proof about data structures; it had been an exercise left to the during the classes but it was so esoteric that we skipped it, considering it useless.
It was a written exam, but the professor asked oral questions afterwards; therefore, we had as much time as we needed. Since it was a challenge and I had time, I set myself to solve the problem. I started the exam at 8 a.m., finished at 2 p.m., had great fun in between (and got an A+!).
If you are this kind of person, you will excel at Google (and certainly pass the interviews; most probably, you have even solved the famous billboard). If you are not working in Google already, I certainly encourage you to submit your resume.

More to come in my next entry...

Add to Technorati Favorites

Saturday, 8 September 2007

Thursday, 6 September 2007

What's good about working in Google...

The people.
Yes, the people.
They are absolutely f...ing brilliant. Last week, one of my co-workers discussed about a site he created, a slang dictionary. Today, I look for a word and his dictionary is the second entry, just after Wikipedia!
I guess I'll start looking for my colleagues in the list of Fields Medals, just in case.
Disclaimer: The fact that I work there is certainly the result of a bet, most probably something akin to Trading Places

Add to Technorati Favorites

Sunday, 2 September 2007

You are old...

...when the stuff you used at university is already in museums (not to mention half of your childhood).


PS: This is the museum link.
Add to Technorati Favorites

Solving the turnover problem

In a company that I've worked there was a huge turnover (around 60% per year). This is a huge problem, as you can imagine. So, in order to improve this situation this company decided to avoid having pictures in their passes (used to open the doors), so when an employee left the company they just removed the label with the name from the pass and gave it to a new employee, with his own personal $0.01 label.

Maybe this offers some insight why there was such a high turnover?


Add to Technorati Favorites

Thursday, 30 August 2007

Google Analytics is fantastic

Do you have a website? A blog? Some presence in the web? Then you must use Google Analytics. The wealth of information is awesome, and it is really well displayed, as pie-charts, graphs and maps. For instance, the two main countries where this blog is read are Argentina and the US (especially since I am now in the US :-) ), and that is displayed in a map, so it is really easy to see, but if I hover over the map, I can get the precise number and if I click I can see where in the US my visitors are coming from.

Disclosure: I am currently employed by Google; however I have found the product great on its own, so my recommendation has nothing to do with that. In addition, my views and opinions are solely my own, and are not endorsed by my employer.

Add to Technorati Favorites

Wednesday, 29 August 2007

Let your f...ing people work

Once again I will show why it is great for work for Google (and therefore, everybody wants to work for Google, even the people who literally invented the internet)
The big secret is...
We are allowed to work; there are no obstacles between us and our job.
Since I am currently in the US, I have to use an adapter to plug my computer to the power grid. No biggie, except that the adapter is so large that I cannot have anything plugged in the socket where I plug my computer. Therefore I asked for a power source with the correct plug and it was provided. I didn't need any authorization, explanation or anything. Now my colleagues don't risk that I'll unplug their computers; it is just great that I am allowed to work!

Again, this is my sole opinion and doesn't reflect the opinion of my employer.

Add to Technorati Favorites

Tuesday, 28 August 2007

Sparing a buck by spending more on programmers

It is a well known fact that turnover among Software Developers is high, since they usually want higher salaries than the company can afford. So it is just reasonable to save money by letting them go and hiring new ones, instead of trying to retain them. It's just the way things are.
Except it isn't. For those of you who have read my thesis, I will just copy a small part, so don't bother to go on. Imagine you have to replace a developer. Yo have to train him/her for 6 months, in order to have him up to speed (my estimate is quite optimistic, isn't it? So you already have 3 monthly wages lost. In addition, hiring a person through an agency or through internal processes normally costs about 2 months worth of his salary. So you have already lost 5 months as a sunken cost. If you have just a 66% turnover (quite low, I might say), every person stays around 1.5 years, so 5 months is about a 30% of the amount you'll pay this person during his career in the company. If you could double his stay, that would be only a 15% of his earnings with you; I think that paying 15% above market conditions is a good way of keeping your people for a really long time. By doing this you improve quality by having better trained people, with a longer-term mindset, who are more loyal to the company. For the exact cost of 0.
Of course, Timothy Lister and Tom DeMarco said this and nobody listened to them. Also Joel Spolsky repeats this every now and then, but who cares. Only bad companies as Microsoft and Google.

Disclosure: As of the date of publication of this article I am employed by Google. However, the content of this article reflects only my opinions and beliefs, and is in no way sponsored by my employer.


Add to Technorati Favorites