Saturday, March 17, 2012

Blogger on mobile

Apparently google has a mobile app for Blogger. Just installed it on my Android phone and I'll give it a try.

Will report later in case I actually want to blog from my phone.

Friday, March 16, 2012

Java get class name from static method

Okay, so it seems that Java is a really bad language. Apparently, you can't get the class name from a static method. Why? debugging, of course. You want to be able to have


stuff like this in any of your applications. Unfortunately, you can't do it from a static method (since there is no this object on which you can call .class.getSimpleName() ).

People tried to find alternatives -- see here: http://stackoverflow.com/questions/936684/getting-the-class-name-from-a-static-method-in-java and http://stackoverflow.com/questions/1075935/using-current-class-in-java-static-method-declaration

Still looking for my solution.

Blogger Code Snippets

So, I was thinking about (re)starting work on this blog and sharing some interesting code. By default, Blogger does not have it. My searches took me here where I found out more. If you are too lazy to click on the link, here are the steps to show off code on your blog (direct source of inspiration the link above):



  1. Go to http://gist.github.com 
  2. Paste the code you want to post
  3. Copy the embed tag 
  4. Go back to blogger, and select "Edit Html" 
  5. Paste the embed tag into your post
This relies on GitHub still existing in a couple of years, when your grand-children will visit your blog to learn how to code with their mind (no hands!) in Java or any of the other 2134 (random number) languages supported by Gist.

One last rant (Java multiple inheritance)

and I'm off to sleep.


Java does not support multiple inheritance. I understand that there is a hard problem to solve from a compiler / language point of view -- namely, the diamond problem -- but totally ignoring this language feature because of some problems ... that I can't understand. But the Scala language has this implemented (and it is based on Java) and it has it using a simple rule: right-first depth-first search of extended 'traits'.


While the same result can be achieved with interfaces and multiple inheritance of interfaces, this has some draw-backs:

  • the fields are static and final in an interface
  • non-abstract methods avoid code duplication

Why it made sense for me: I have two characteristics for a class -- one which determines the communication layer of this component (Sockets or WebSockets) and one which determines the functionality provided by this component (let's say binary). In total, I would actually need all 4 possible combinations. But, in this case, the code for sending a message via a Socket (or a WebSocket) does not change, regardless of the functionality. Also, the functionality does not depend in any way on the communication layer. 



In this case, I would love to be able to inherit both classes that are useful for a certain combination and basically do nothing in the inherited class (see example). But it doesn't work :(


In terms of programming language, I have learned to love Scala  -- I took some Logic classes that involved writing Scala code and it seems like a perfect blend of a functional programming language and a hidden interface to Java (in case you really need it). Unfortunately, even if the language is so good, the tools are extremely bad (or were the last time I used them, I see here some updates) -- the Eclipse IDE was extremely slow and on every save it would recompile the file and the system would just jam completely for 5 seconds, totally non-responsive.


It just seems you can't have best of all worlds: OS-independent code, a good language and a good IDE (though I have to look into the other IDEs for Scala).

Eclipse verbosity

So, I was thinking... How verbose can Eclipse get? Well, apparently very. With this Java reflection statement above, all the rest of the code to handle the exceptions is automatically produced by Eclipse.

I wrote this because I use an abstract class (A) that two other classes (B and C) extend. I want to have a general method of calling the constructor of the classes B and C and passing an argument to it (maybe this wasn't the brightest of ideas, but that's what came up).

In the long run, I want to have small, readable code that is easy to understand. This seems to come somewhat in contradiction with the design principles of Java, but... we'll see how it pans out.

New Java project

So, I'm working on a Java project right now -- it's called SiSsi, part of my work at Jacobs and I will start sharing code snippets and interesting facts related to this, for further use by me / anyone else.

Tuesday, October 18, 2011

FP

First Post ... more coming soon

Oh, yes. The name? Look at your keyboard. Now back to the screen. If you ever played any first-person shooter, you will see that the initials represent the most used keys on the keyboard :)