Tuesday, February 1, 2011

K Code Parser (story 5)

Where's story 4? Well, it's coming. Probably in an episode named 'the missing story'. Who knows? :) Half the story is written in mercurial commits, the other half will be written later.

So today, about a new cool thing. Not that new, in fact, but pretty new to me.

I was always baffled by the need to iterate through collections. I always loved the idea of foreach statements, and this morning I found the 'foreach' of Java. It's 'for', and it looks like this:

 for (String s: myArrayList)
  doSomething (s);
compare this with:
 int i;
 for (i=0; i< myArrayList.size(); i++)
  doSomething (myArrayList.get(i));
While the difference might not be too big, it definitely feels big to me. Because, for example, every time you do a get(i) you might get something that's checked for bounds, maybe not O(1) complexity (if you change the data structure for myArrayList without notice) etc. And the point is that all you want to do is do something for every element of your collection. No need to extract data from an iterator (as you get data directly from the source, from a hidden iterator that probably is more optimal than anything externalized) - and it feels a lot better than the indexed code.

So I like this feature very much, thank you; I wonder, however, how readable I will find this at 3AM in the morning. I'll have to set my clock and wake myself at that hour, just to have a look at that piece of code.

Friday, January 28, 2011

K Code Parser (story 3)

Delivering code that you can't compile.

It's Java, therefore it's possible. How, you ask me? Simple. Watch this simple error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method setVar(String, int) from the type VariableStorage is not visible

Yes, this is precisely what it means. Unresolved compilation problem. This means that the code shouldn't have compiled in the first place; but heck, people can deliver it anyway.

I don't know if I should call this silly or not. I am just thinking about that corner case that happens once in a million years (let's say, when you fix your clock for the daylight savings time). What can I say, tester's hell.

Tuesday, January 25, 2011

K Code Parser (story 2)

So the first day passed, and it was kind of lazy. Actually, after hitting that SVN frustration I stopped doing that and started doing other things. Unrelated to the project. But this morning was a bit more productive, and I managed to implement the first part of Mr. Crenshaw's tutorial. In Java. As I said, the code can be found on the mercurial repository from Google Code.

One nice touch. Eclipse is really cool when it wants to be (it proves to be really helpful when it wants, and writes tones of stuff that I don't want to for me). Second: Java + Exceptions. I truly hate exceptions, but they seem to suit this type of implementation (that I'm trying to do). So I will roll with exception. It's a nice way to abort something, and they can be helpful too.

One thing I hate about Java. Why the heck did they name the bool 'boolean'. It's toooooooooooooooooooooooooooo daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaamn looooooooooooooong. And I always write bool. So eclipse, unhelpful in this case, doesn't try to correct me by writing stuff for me. So long with the helpfulness of Eclipse :(

Now onwards to the second page of the tutorial.

Monday, January 24, 2011

K Code Parser (story 1) (continued)

So what the heck should this error mean?

 Missing requirement: SVNKit 1.2.2 Implementation (Optional) 2.2.2.I20101203-1700 (org.polarion.eclipse.team.svn.connector.svnkit15.feature.group 2.2.2.I20101203-1700) requires 'org.eclipse.team.svn.feature.group [0.7.9.I20101001-1700,1.0.0)' but it could not be found

[Retorts taken out. Really, really upset dude at keyboard]

Mental note. For the fun of the game, add "error 0.7.9.I20101001-1700,1.0.0 detected" message in my project.

So I cannot use SVN from Eclipse. In case you were wondering if it works, it doesn't, no matter what the official docs say.

PS: I know it's a 64 bit issue. I don't care. Why should I, the user, care? It's an IDE, it doesn't work, the feature is disqualified. Now if I could only change my code.google.com source versioning to mercurial :( *sigh*

K Code Parser (story 1)

I'm gonna update the blog about the advance in my project in stories. I don't know how many stories I will have, nor will I bother to name them (unless they are tremendously interesting, like this one is not).

So first story is how difficult is to have SVN on eclipse, and make it work. It's not that I cannot find my way without Eclipse. It's that I want to learn how to use the damned thing from Eclipse - after all, it IS an Integrated Development Environment.

So we want to install some plugin for SVN. Easy. We go in Help->Install new software (always loved to do that) and we search for SVN. Wait for about 1 minute before deciding not to use the task manager to close eclipse, select first Subversive SVN connectors. Amaze yourself with the fact that it doesn't work. Try again, selecting from the window stuff that might work. Try again, again and once again. When you have a 'Next button' on the second page (no errors, then) press it. Don't think twice. Don't mind what's installing. I don't know, and you don't know. Eclipse knows. Restart Eclipse. Notice that it doesn't work. Try again. Don't succeede. Write an angry post on how it's friggin' incredible this piece of sh**.

Then relax, and try again

File->New Project

Ok, so it's that time of the year. It's 7:27 in that crazy wintery Monday morning that you know you ain't going to work. You are bored, and you feel like doing something useless.

And you remember that some time ago you have bookmarked a 300 hundred pages tutorial. It's about parsing code. And dumping assembly code. Which sounds like fun.

So five minutes later you finish writing the blog post in which you announce the URL of your new project, you're committed to writing it in Java although it's the silliest thing to do in Java and then you open your Eclipse.

So here it is, guys... http://code.google.com/p/k-code-parser/source/checkout . Don't rush, there's nothing there yet.

But there will be :)