Entries Tagged 'programming' ↓

fun with microsoft installers

Now this is a really nice one from microsoft. To reproduce:

  1. get linux on a ext2 or 3 partition.
  2. get the ext2/3 windows driver
  3. load your partition into any letter, I used Z and X
  4. download visual studio 2008. (don’t worry you don’t need to install it it will crash before the big download) I used the C3 one.
  5. run said installer, and you get a neat error.

Now my question is, why on earth are they unpacking in other letter other than c:? Even better why they don’t do a check instead of taking the last letter available?? nice way to go really, go microsoft!

I’m reading a book, and it seems like deja vu

First of all please no “2005 call he wants his revelation back” jokes.

Honestly I didn’t put a lot of attention to this the first time it came around. I just though, it was a bunch of buzz… but it turned out to be a huge success, and even though I still don’t like the toolkit, because it’s way too narrow. (which now I understand why) I have to totally agree with the philosophy. Most of the stuff that is said in this book I have either said, think or didn’t had the words to articulate my thoughts. But I knew it right after reading the “essay” (books is split into “essays” instead of chapters).

It will take you at most 2hrs to read it entirely (if you where like me), maybe a week or more if you haven’t even think of it’s core ideas. and some will probably never understand it. This is how companies should work, this is how software should be build, and this is how I plan to run my company. Anyway without anything else to say please enjoy this little gem of modern software development, Getting Real by 37 signals.

java certification

This post had sometime on the “drafts” everything but the last part was written several months ago.

Today someone ask me why aren’t you finish with the java certification, my answer was something like “well you know because ehhh yea”, but in reality I knew exactly why. I have lost faith on the language, java no longer excites me, sure is useful to have the compiler bark at you for every little detail. But they have added so much crap on top of it that programming Java is no longer fun.

The first place where I think Java stop being fun, was when you totally needed an IDE to write anything useful, and of course when everyone was using eclipse. Don’t get me wrong eclipse is very nice, it even won me over from netbeans, but what I don’t like about it is when someone has no clue of what’s going on because they have delegated all knowledge of it to the IDE, one particular case version control, you will be impress of how many people don’t know how to work with CVS and/or SVN, just because the smart-asses at eclipse decided to do things “a little different”.

The second place which is actually in order of how I found out and now how much they suck, is J2EE.  Interesting enough the problemwith J2EE is not sun but everyone else. Starting with the application server, why on earth you need a program to run a program unless it’s running several programs? Then the zillion frameworks and crap on top of http + html it’s just ridiculous.

Now that said I finally got my act together and went to take the exam, considering the fact that I barely study for it, that I had about 10 days of party and that the thing asked a lot about “the name of the methods that does foo” I got a not so decent score but I pass. So yes my friends you got a new SJCP in the group (yay!) Now lets keep on bashing on how cobolist it’s starting to be and how big huge and monstrous systems are not the way the computer world should be heading too.

google apis, they just make you think why not?

The other day I sat down and watch a lot of Google developer day videos, here are the ones that catch my atention the most.

update: for some reason not all videos are loading. Here are the links
google maps
googlegears
data API
geoweb

google maps
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

googlegears
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

data API
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

geoweb
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

MPX multitouch driver for X server

This is something very cool, someone named Peter has been working on a driver for X to support multi touch, some of you may be saying 2006 call it want’s it’s really cool multitouch screen back, but let me tell you why this is different.

We don’t need gesture support in X. Gestures depend a lot on the context. A gesture in one context can mean something different in a different context. And the only thing that knows the context is the application. This is very similar to a button press. Pressing a mouse button can mean a zillion different things, depending where and when it happens. That’s why all X does is relay the button press to a client application, which then does the right thing.

Which in short means the X server will just send an event to the client, remember that in X terms the client is the Desktop Environment (gnome,kde,enlightenment) or the window manager (fluxbox,w3m, etc.).

To your multi-touch driver all this doesn’t matter. It sends blob events, the server takes care of the rest. You’re guaranteed to be able to interact with any X application. X doesn’t care about the hardware. You can use your DiamondTouch, your FTIR table or - if you can afford one - your MS Surface table.

which means that ANY application can work with multi-touch, in fact ones GTK gets support for BlobEvents all your program has to do is support one more event and process it.

Even better you can use the mouse and keyboard and multitouch all together as MPX is just another driver!

Full article here which is the cool part which is the reason why I’m not liking the video from here, so go read the artcle and watch it in action.

This is like xgl for multi touch displays!!

never run @rm -rf $(PREFIX)/bin/deluge

There are time when being ovidient bytes you in the ass.

For example the shell and rm, yes you know where I’m going. It turns out that the following command inside a makefile @rm -rf $(PREFIX)/bin/deluge does something really extrange. And yes it’s all my fault because I force it twice.

For some reason the r flag went to $(PREFIX)/bin and deleted everything, which I’m stil confused as to why.

ohh yes and $(PREFIX) was set to /usr, lovely isn’t it?

any ideas of how can I restore those files? I assume if I get the basic binaries for installing .deb it will show me the broken packages (read: all packages) then I could reinstall them all?

update:  So I got a liveCD and reinstalled my / keeping intact the home, this is one of the things I love about unix, even my windows positions where intact all I had to do was use the same username.

with: the lazy programmer CLI tool.

The other day Ricardo came up with an idea which I found great, so we went and implement it. Since then it has grown a nice set of features and I think it’s ready to test the world (well it was a week ago but I haven’t had the time to make the post).

In general the idea is to reduce the ammount of typing you do in the CLI.

I wrote a nice “extensive” readme file, which also showed me the very cool mime type “text/x-trac-wiki” so the link before is directly into SVN with trac wiki syntax formatting, sweet!

Since it’s a one file program there is no need for a installer, so just download it from here. If you are lazy enough the Makefile has a install target, and in case you where wondering the build.xml is just a sample. Although I could make it install the python code just for fun (evil laugh).

Last but not least I finally got my trac up (I’ll add another post for that) but if you find a bug please submit the patch here

Enjoy!

ClockTicker.py vs ClockTicket.java

Some people think that when scripting language abocates say “less code” is because they are lazy and that they are sacrificing performance over code. This article plans to counterpoint that with a small python/java program.

A little background first. We are working on a little project in which the server is written in python and we’ll have several clients (including one J2ME), also one of the people involve knows nothing about python. Anyway one of the proposals for server-client interaction is having the client pull every X seconds for updates. So I through of an algorithm for making this a bit more intelligent than just setting X to some value. The algorithm itself is very simple. it keeps track of the last Y plays, actually of the time they took, and then using a simple average calculation it will try to guess the next poll time. So basically if it’s a fast game (each player will play their turn fast) then the updates will be more frequent. it will also have a min poll time so clients won’t update way too often, and of course the server will have a timeout but that’s outside of the scope.

Below implementations written in python and java.

warning: sorry for the small code I’m still looking for a decent code highlighter for wordpress.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

public class ClockTicker
{
    private ArrayList data;
    private final int MIN;
    private final int SIZE;
    public ClockTicker()
    {
        //this(10,20)
        this.SIZE=20;
        this.MIN=10;
        data = new ArrayList(this.SIZE);
    }
    public ClockTicker(int min, int size)
    {
        this.MIN=min;
        this.SIZE=size;
        data = new ArrayList(size);
    }
    //not going to waste my time on the other 2 constructors
    public void add(Float item)
    {
        if (data.size() == this.SIZE)
            data.remove(data.size()-1);
        data.add(0,item);
    }
    public float next()
    {
        float sum = 0;
        Iterator i = data.iterator();
        while(i.hasNext())
            sum+=(Float)i.next();
        float ave = sum/data.size();
        return Math.min(MIN,ave);
    }

    public int len()
    {
        return data.size();
    }

    public static void main(String args[])
    {
    ClockTicker clock = new ClockTicker();
    Random random = new Random();//or could have used (float)Math.random(), this seems less ugly
    for (int i = 0;i<50;i++)
        {
        float value = random.nextFloat();
        clock.add(value);
        System.out.printf(”%s,%s,%sn”,value,clock.next(),clock.len());
        }
    }
}
class ClockTicker():
    def __init__(self,MIN=10,SIZE=20):
        self.data=[]
        self.MIN=MIN
        self.SIZE=SIZE
    def add(self,item):
        if len(self.data) == self.SIZE:
            self.data.pop()
        self.data.insert(0,item)
    def next(self):
        return min(self.MIN,sum(self.data)/len(self.data))

import random

clock=ClockTicker()
for i in range(50):
    value=random.random()
    clock.add(value)
    print value,clock.next(),len(clock.data)

python total of 19 lines, and just 11 for the ClockTicker
java total of 55 lines and 39 for the ClockTicket class, but lets be fair I use the { in a new line (hi k&r fanatics) those don’t count. so it’s -1 line for each method and class. that leaves us with.
java K&R total of 47 lines and 33 for ClockTicket.

That means the python code is close 66% shorter then the java counterpart. One thing I should point out is that I wrote the python code first and the java one is a port but if you look at the java code, it follows java conventions and IMO it’s a fair competitor.

1. lossy data types, this is probably the most important one when I was writing the java code for some reason I wrote public void add(int item) and I didn’t notice that until the ave calculation in which the result was a float, which made me saw my mistake that I actually needed a bigger number to store time deltas, even worst I forgot that the time measured since epoch was stored in a long not a float. Anyway the python code works with int,floats,doubles,probably even strings. In the java counterpart I’ll probably have to write one class for each different datatype or just handle them in the same class with method overloading.

2. default parameters: the python’s init method
def __init__(self,MIN=10,SIZE=20)
is equivalent in java to
public ClockTicker()
public ClockTicker(int min, int size)
public ClockTicker(int size)
public ClockTicker(int min)

lets leave the fact that the last two won’t compile and think of all the boilerplate code that needs to be written just to have different ways to create a constructor. in java it can be minimized with calls to this() but that is at least 3 lines of code per constructor and a couple of curses from whoever is following that code. So we are looking at at least 10 more lines to achieve the same functionality.

3. named parameters: Back to the last two constructors issue. In java it will have to either be an ugly hack inside the two constructor parameter that if you call it as ClockTicker(null,size) min will be set to default. Or an even uglier one like ClockTicker(int minOrSize) and it will guess what you are passing in. But what most sane java programmers will do is something like ClockTicker c= new ClockTicker(); c.setMin(); or c.setSize(); which means adding even more lines of code and lets not get into the issue of fixing setSize so it won’t eat already present data. in python you just do what you need ClockTicker(MIN=100) or ClockTicker(SIZE=10) and done.

4. lists,dicts,etc as native data types and not API:
This is not really a feature that will directly make the size of the code smaller, but the fact that they are fundamental data types makes the developers of the std. api use them more often. Therefore functions like sum,min and len are prepared to handle Collections of data while in the Java counterpart they need to be hand coded outside of the std. api. Which is what is happening in the next method.

5. the fake access control (public,private,etc.)
One of the first things a good java programmer learns is to make class variables private and provide methods to access them,
• this is because setters should make sure the Object don’t gets corrupted.
• changes in the internals of a class will not affect client code.
• provide a clean API
• provide security of the object

Now in practice most setters don’t check anything, noone changes the name of a variable inside the class and if they do they normally do not keep the old setter/getter pointing to the new variable, until they compile everything crashes and they go back either in the name change or readd the old setter/getter pointing at the new name. About the clean API lets suggest an alternative lets say all “private” methods start with a symbol and and by convention (something the java crowd loves) lets say that symbol is _ . So in the event that you call a method that starts with _ it will crash with an access error? hell no if you really need my private method by all means use it, now don’t come crying to me when I break your code because I changed my private stuff, fair enough right? now think of all the setters and getter that are out there. All those millions of lame, useless lines of code, waiting to be strip out of existence to make tarballs,binaries, ISOs, backups, internet transfers and compile times smaller. ohh and about security just use reflection like this or this

6. primitives issue, this is more a language flaw in java than a real advantage in LOC. We have to admit that with autoboxing it makes code smaller, although official documentation states autoboxing is slow. Therefore this is not the optimal solution to fix the headaches of working with collections and primitives

7. And just to mess around with some people, time(1) says this

for the python code
real 0m0.083s
user 0m0.040s
sys 0m0.008s

and for the java code
real 0m0.117s
user 0m0.068s
sys 0m0.012s

so in this particular case python is faster, and just in case you where wondering neither program is optimized. They where both written for readability since after all the idea of this was to show a way the polling could be implemented.

Overall the python code is more readable, has more functionality, has less LOC and is faster

A great vi/vim article.

A very nice article on vi/vim

The editing commands he shows are great. I guess what we need is more resources like this. Most vi/vim manuals out there focus on showing what each feature is and what it can do they are well … boring. With this article half way thru it I was writing the things in my vim and being impress for example I had no idea such thing as ]] existed and I knew about ‘c’ also about ‘%’ but “c%” is just amazing!

The first postmodern programming language

I just read this great article about postmodernist, well actually about perl. In fact it’s about a lot of things, which is why the article itself is postmodern

On a side note I love this quote: ” I have to be honest here. I’m with Linus–I personally want to take over the world. I want to take over the world because I’m an egomaniac. A nice sort of egomaniac, an egomaniac moderated by belief in the value of humility, but an egomaniac nonetheless.”

enjoy the reading.