Sometimes I hate Java

Java is a nice language. It got a lot of ways to do efficient OOP, a garbage collector, a wide library of functions, and a really big community. Coming from C/C++, starting Java wasn't very hard for me. I still prefer my beloved C/C++, especially because of the precise memory management. But as almost everyone says, each problem has his solution, and Java is a good tool to have. But sometimes, like those last days, I hate Java. Maybe it's because I'm not as good in Java as I am in C/C++. Maybe it's because I am in the very special cases where Java sucks. Maybe I'm just going the wrong way. But I think it's more about the flaws of Java (and I'll be happy if you prove me wrong).

Templates, templates everywhere

The first thing and most annoying for me is the template. It seems it's not that common in Java to use (or for me, abuse) of templated class/method. I know it's not always the best solution, sometimes complexifying the code even for the JVM/compilator, and I try to avoid using template in those cases. For example, I'm currently trying to make the most generic DAO service possible in a GWT application I'm working on. The goal is to put the logic and genericity in a framework, helping us manage database access very easily and properly. The logic is described in this image :

DAO service logic

And when I say that I like templates, the DAO interface looks like that :

public interface Dao<T extends Model<V>, V> /* Our Model items can be used with String ID (UUID) or Long ID */
{
    public T put(T object);
    public T get(V idObject);
    public List<T> getList(Map<String, Object> filterMap, int start, int length);
    public <W extends Dto> List<W> getList(Class<W> dtoClass, Map<String, Object> filterMap, int start, int length);
    public T delete(T object);
}

And as you can see, I created a generic method to return a DTO list too. Described like that, it seems pretty, with maybe a little too much templates for those who are not familiar with them. But where I really don't like it, and mostly because of Java, in my opinion, is in my DaoFactory. The way I manage to get the right DAO seems pretty dirty to me :

Class<?> daoCls = Class.forName(DAO_PACKAGE + "." + className + "Dao");
Method method = daoCls.getMethod("getInstance");
Dao<T, V> obj = (Dao<T, V>) method.invoke(null);

And it's even dirtier with the DTO :

Class<T> dtoClass = (Class<T>) Class.forName(dtoClassName);
Class<?> modelClass = dtoClass.newInstance().getModelClass();
Dao<V, W> dao = getDaoObject(modelClass.getName()); /* Same method as the previous one */

I know there must be a prettier way. But I didn't found it. And one of the biggest problem was the way I got the model class from my DTO. My DTO is templated with the model class it represents, but guess what : Java cannot return the templated class.

SERIOUSLY ? This is one of the stupidest thing ever. Say you have two model class : ObjectA and ObjectB, and a DTO for ObjectA called DtoA. DtoA is implementing Dto<A>, an interface for all the DTOs. So if I pass an ObjectB to the DtoA, I got a runtime error. But this same runtime cannot tell me what type of object DtoA is excpecting ? Why ? Is there a reason ? I add to add a method called getModelClass() than can return ONLY a Class<ObjectA> in this case. And as I need this method to be in the interface (well, at this time it became an abstract class more than an interface, obviously), I can't even have it in static, because you can't override a static method (seems logic to me). So yeah, a non static method returning a constant value because Java sucks. (At least on this point)

Dating time

Another horrible thing in Java, the dates. I think this is mostly because of the retro-compatibility with older programs, but why did they do that in the first place ? The logic way would be to have a Date class, that you can construct from a timestamp, a string, another Date object, or with the classic parameters (year, month, day, hour, minute, second). And if you want to add two days, you just call the method add(DateType.DAY, 2). For a difference between two Date just a method called for example diff (because yeah, another bad point about Java is that you can't overried the operator, but I won't get into that, I already miss my C++ too much). But no, that would be too simple, too clean, too easy. In Java, you need at least two class to do that. Date and Calendar. And it's worth mentionning that you need other classes to parse string date (like GWT's DateTimeFormat, or SimpleDateFormat for examples). And combining these classes, the next code sample shows how to start from a string date to end with a Date object with 2 added days :

String target = "Thu Sep 28 20:29:30 JST 2000";
DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy");
Date parsedDate =  df.parse(target);
Calendar cal = Calendar.getInstance();
cal.setTime(parsedDate)
cal.add(Calendar.DAY, 2);
Date result = cal.getTime();

Yeah, that's a lot of code just to do that.

And because the wide choice of standard libraries is supposed to be one of the best side of Java, those sort of things can really make me hate Java.


As I said, sometimes I hate Java. And when I use the word sometimes, it means that most of the time it's a language I enjoy. Not my favorite, but a very good tool. And I really hope someone prove me wrong on what I said, but for now, this is what I think.

Tagged , , ,

I like Gnome Shell

Since the Gnome Shell (also known as Gnome 3) launch, every now and then there is an article, a blog post, or a Linus Torvalds thoughts saying that Shell is horrible, that it's useless, that it's bad. I think that most of the people saying that are just resistant to change. Of course, there is also the point that Gnome didn't respect his philosophy (incremental improvements, as read on The Register), but that's another debate.

I never was a big Gnome fan. Yeah it did the work. Yeah it was light enough. But I always chose KDE, or a very lightweight desktop, or a very customizable desktop, but never Gnome. And since KDE started to become more and more heavy, I was searching for a new desktop. And BAM, Gnome Shell arrived.

The extensions

In my start-up, we love Shell. Seriously. Some of us use the out-of-the-box experience, but most of us use one of his big strength : his plugin system. Sure, out of the box there is some missing functionality, but it's still interesting, and I had clearly a better first impression with Shell than with Canonical's Unity. But there is already a lot of plugins, and since it's javascript, there will be a whole lot of others.

gTile screenshot For example, one of the best is gTile. With it, you can organize your windows on screen very easily. You want to have 1/3 of the screen used by Chrome, and the other 2/3 with an equal split of four terminal ? Easy. And it's only one extension. I also like the multi-screen capable dock, the removable drive menu, and a lot more.

Ok, I agree, there is some of them that must have been inside Shell from the beginning, like the removable drive menu. But isn't it great to be able to fix your desktop so easily ? Sure, there is other desktop that have a plugins system, like Mint's Cinnamon, but nothing I tested was as stable as Shell. Nor has a community as big as the Gnome's community.

Good ergonomics

There is more. I have a lot of experience with Windows 7, because I'm a gamer, and my last company was forcing us to use Windows, for security reason (yeah, never understood either). And regardless of your a priori against Microsoft or Windows, it's undeniable that 7 was a big leap forward in ergonomics : Moving a window on a side border resize it to take half the screen To open a program, just type the windows key and enter the name of the program (or just the first letters in most case) And some more. And you know what ? Shell does it too. And faster. And customizable (like the default search when nothing is found after typing the windows key, actually is calling wikipedia, and you can change that). So now, when I want to open gedit, for example, I just type "Super key > ged > enter". If I want to talk to my co-worker on gtalk, "Super key > his name > enter", and the contact window open (yeah, I need to found or create a plugin to be able to open the chat window directly).

And as I talk about chatting, the social integration is pretty cool. If you don't want to use it, don't. There won't be a popup from time to time asking you to connect an account or anything. As we are pretty close to Google in my company, it's really helpful to be able to see if I missed a chat message just via Shell.

The dark side

But of course, as a new project, Shell isn't finish. And it misses some features that I couldn't fix via existing plugins. As I said, if we were able to directly open a chat from the super search menu, it would be awesome. It would be good too to have the Google Apps fully integrated, with e-mail, calendar & all. Or at least an integration without Thunderbird. I mean there is a lot of protocol to share calendars or e-mail, if they were built in Shell, it would be very useful.

And finally, the darkest side of all : the keyboard use.

Shell in itself is pretty good :

  • You have the super key to open the explode view and access the awesome search
  • You can switch workspace with Ctrl+Alt+Up/Down
  • There is of course the Alt+Tab switch window
  • Ctrl+Alt+T open a terminal
  • You can access your shell notification (Super + M)

The only missing point in here is the selection of a window while in explode mode. Maybe there is a way, but I haven't found it yet.

However, the shell extensions are mostly not usable by keyboard. That's a shame, and though it's not entirely up to the Gnome Team, they must do something to ensure that most of the extension's developer make the extra effort of making it usable via shortcut. For example, gTile would be even more awesome if I could use it with my keyboard.

Imagine : Your working on a website in Vim, you want to have your Vim window side by side with your terminal used to build/deploy the site, and also a Chrome window to test it (I'm not an expert of using a browser via keyboard, but it must exists), and from your keyboard you make your window organization, without any script like on other linux desktop, just by calling the extension via a shortcut and then making your configuration with it's graphical interface, but again using only keyboard. That would be awesome.


Despite those little youth error, I really like Gnome Shell. I'm gonna use it a lot more, and watching his evolution, but clearly, as a developer, I'm clearly winning productivity, especially on such a small resolution.

Tagged , ,

Debian Squeeze on Intel H77 motherboard

This week-end, I built my own home server. I don't care if it's a big tower, but I wanted something silent, energy efficien, with a capacity of at least 5 hard drives, and capable of decoding 1080p videos. Yeah I know, a server shoudln't be used for multimedia, just for storage, but it was cheaper to do that instead of buying a video receiver apart.

For the size, I found a good compromize between silence, quality and size, the Fractal Design Define Mini. It's classy, well built, relatively cheap, and it looks good in my living room, perfectly integrated with my TV stand (almost the same height). And when I said silence, I mean I can't hear it unless I put my head right on it. My fridge and my house ventilation are way louder, and even them, I almost can't hear them.

And for the 1080p decodin, I chose the combination of the mother board ASRock H77 Pro4-M and the Pentium G860. And with the integrated graphics of the processor, I was all set (minus RAM & co of course).

So I built it, pretty easily, thanks to the built quality of Fractal, and installed OpenMediaVault. I used the HDMI port during the installation, and after that, put the server beside my TV stand, and started configuring it. All seems to worked perfectly, except for the video drivers and the sound. Too bad for a media center right ?

The video card

The HDMI port worked out of the box, but the video drivers weren't working. The display was at the lowest resolution in the terminal mode, or with a X server (I installed LXDE to test the drivers), and there was no graphic acceleration, ie there was no OpenGL available. It seems that the integrated graphic cards is too recent for the 2.6 kernel used by Debian Squeeze. Maybe there is some workarounds to stay with this kernel, but after some googling, the answer mostly given to this problem was to upgrade the kernel. I did it using the Squeeze backports :

$ echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/debian-backports.list
$ sudo apt-get update
$ sudo apt-get install linux-image-3.2.0-0.bpo.3-amd64

After that, reboot, select the new kernel in the Grub list, and ta-da ! Your on a 3.2 kernel. There was some warnings about some firmware during the package installation, but it seems it isn't important because all is working (for me at least). But that's not all. Now that we are in 3.2, we still have some package to install for the video cards to fully work. I struggled a little at this point, in fact I spent most of my time trying to solve that problem. But thanks to T_Send on StackOverflow, I solved it using the Debian Wheezy repo :

$ echo "deb http://ftp.pl.debian.org/debian/ testing main contrib non-free" > /etc/apt/sources.list.d/debian-testing.list
$ apt-get update
$ apt-get install --reinstall -t testing libdrm2 libdrm-intel1 xserver-xorg-video-intel xserver-xorg-core libgl1-mesa-glx libgl1-mesa-dri mesa-utils

dpkg-reconfigure xserver-xorg

And this time, we did it ! OpenGL works, and you can use the rightful resolution when using the server directly.

The sound

The second problem was the sound. No sound card were found out of the box. But by using the 3.2 kernel, we almost entirely solved that problem. But there is still a problem : the sound doesn't come out via the HDMI port. Again, too bad for a media center. But thanks to the famous Alsa, it's not that hard. Before starting, let me say that the following configuration will set the HDMI port as the default sound output. If you want to be able to switch automatically when pluging/unpluging a HDMI cable, there is a lot of information about that on the net, and it will be based on the information gathered by the above operations.

First, we need to install the alsa tools

$ sudo apt-get install alsa-base alsa-tools

Second, we need to find the HDMI output

Please keep in mind that your results may differ.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

From this results, we're going to test all the cards and devices. Speakers (via TV, screen or anything) must be connected to the HDMI port you want to use at this time.

$ alsamixer -c 0 # 0 because my HDMO port is on the card 0
# In alsamixer, unmute all your channel and set raise all the volume to max, except the microphones. Use Esc to exit.
$ aplay -D plughw:0,3 /usr/share/sounds/alsa/Noise.wav # Card 0, device 3
$ aplay -D plughw:0,7 /usr/share/sounds/alsa/Noise.wav # Card 0, device 7
$ aplay -D plughw:0,8 /usr/share/sounds/alsa/Noise.wav # Card 0, device 8

For one of the device, you'll hear a "shhhhhhh" through your speakers. From there, you now what card/device is your HDMI port.

Finally, we set the device as default audio output

For this step, just use your favorite text editor to edit/create the /etc/asound.conf file :

pcm.!default {
    type plug
    slave {
        pcm "hw:0,8" # My HDMI device is on card 0, device 8
    }
}

And there you are, video and sound working on your server ! Now you can install VLC and play your audio/video files, or make a real media center and install XBMC.

Tagged , ,

Test md

Markdown format test file, written by Greg Schueler, greg@vario.us.

Quick Markdown Syntax Guide

This guide shows you how to use Markdown instead of HTML when writing posts or comments.

Markdown is way easier to use than HTML. (But you can still use HTML at the same time if you really want to and you know how.)

Just write in the comment box the same way it's shown in this file, it's really that simple.

(See bottom for more info about Markdown itself.)

Links

For a URL or email, just write it like this:

http://someurl

somebbob@example.com

To use text for the link, write it like this.

You can add a title (which shows up under the cursor), like this.

Reference Links

You can also put the link URL below the current paragraph like this.

Here the text "link URL" gets linked to "http://url", and the lines showing "1: http://url" won't show anything.

Or you can use a shortcut reference, which links the text "shortcut" to the link named "shortcut" on the next paragraph.

Text

Use * or _ to emphasize things:

this is in italic and so is this

this is in bold and so is this

this is bold and italic and so is this

Just write paragraphs like in a text file and they will display how you would expect. A blank line separates paragraphs.

So this is a new paragraph. But any text on adjacent lines will all end up in the same paragraph.

Blockquotes

Use the > character in front of a line, just like in email. Use it if you're quoting a person, a song or whatever.

You can use italic or lists inside them also. And just like with other paragraphs, all of these lines are still part of the blockquote, even without the > character in front.

To end the blockquote, just put a blank line before the following paragraph.

Preformatted Text

If you want some text to show up exactly as you write it, without Markdown doing anything to it, just indent every line by at least 4 spaces (or 1 tab).

This line won't *have any markdown* formatting applied.
I can even write <b>HTML</b> and it will show up as text.
This is great for showing program source code, or HTML or even Markdown.
<b>this won't show up as HTML</b> but exactly <i>as you see it in
this text file</i>.

(In a normal paragraph, this will show up in bold just like normal HTML.)

Remember, you have to indent by at least 4 spaces to do it. This paragraph won't be preformatted.

And if you use [reference][] links, make sure the links are indented by fewer than 4 spaces.

[reference]: http://example.com/blah

(woops, that link didn't work, see? It just got displayed as preformatted text.)

As a shortcut you can use backquotes to do the same thing while inside a normal pargraph. This won't be *italic* or **bold** at all.

Lists

  • an asterisk starts an unordered list
  • and this is another item in the list
  • or you can also use the + character
  • or the - character

To start an ordered list, write this:

  1. this starts a list with numbers
  2. this will show as number "2"
  3. this will show as number "3."
  4. any number, +, -, or * will keep the list going.
    • just indent by 4 spaces (or tab) to make a sub-list
      1. keep indenting for more sub lists
    • here i'm back to the second level

Headers

This is a huge header

this is a smaller header

Just put 1 or more dashes or equals signs (--- or ===) below the title.

You might use the huge header at the very top of your text for a title or something (except weblog posts usually already have a title), and use the smaller header for subtitles or sections.

Horizontal Rule

just put three or more *'s or -'s on a line:


or you can use single spaces between then, like this:


or


Make sure you have a blank line above the dashes, though, or else:

you will get a header

Images

To include an image, just put a "!" in front of a text link:

alternate text

The "alternate text" will show up if the browser can't load the image.

You can also use a title if you want, like this:

tiny arrow

Escapes

What if you want to just show asterisks, not italics?

  • this shows up in italics: a happy day
  • this shows the asterisks: *a happy day*

The backslashes will disappear and leave the asterisks.

You can do the same with any of the characters that have a special meaning for Markdown.

More Headers

More ways of doing headers:

this is a huge header

this is a smaller header

this is even smaller

more small

even smaller
smallest still: <h6> header

You can use up to 6 # characters at the beginning of the line.
(You can optionally put them on the end, too, and they will disappear.)

HTML crap

Don't worry about special HTML characters. I can write an ampersand & a less-than sign, and they show up as I intend them to: 3 < 4.

(You can still write &amp; (& character) and &lt; (<) or &gt; (>) if you want. or ignore what I just said.)

About

This text file shows you how to use Markdown instead of crappy HTML when writing posts or comments.

Markdown is an easier way of making HTML pages from text, rather than having to know HTML.

Thanks

Thanks to John Gruber and Aaron Swartz for creating Markdown.

Fin

No rights reserved, do with this what you like.

PS : Some new tests

Python :

for i in range(0, 5):
    print i

Java :

for(int i : Arrays.asList(1, 2, 3, 4, 5))
{
    System.out.println("" + i);
}

Some inline code, looks great.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

A quote inside a quote.

Yep.

Key Ctrl Ctrl-Shifted Notes
[ Subset of, Not subset of
] Superset of, Not superset of
Left
Right
Up/Down
Tagged , ,

Hello world

What an original title for a first post. But like a first test in a new language, it's always a good way to start. And you have to start somewhere...

It's been a long time since my last blog. One of the top reason I stopped was WordPress. WordPress is amazing. You can do almost anything with it. But because of that, it's too much when you just want to blog. My server (the one you're reading from now) had a hard time to support the charge even with the very small audience I had (hundred readers a day). I want to keep this hosting plan because it's really cheap (around 25€ a year, hosting and domain name included), and I don't really need more. I know that a lot has changed in the last years. You can now host your static site on GitHub, or even have some not totally static site on Google AppEngine or Heroku. Maybe even with Amazon, I don't really know their product. But I'm happy with my 25 gigas plan at OVH (a French hosting provider), and don't want to change.

I'm unhappy with WordPress, but I want to blog. So I started searching through the web for different solution, and I rapidly came to a solution : I want to blog using a static site generator. There is a lot out there, and it's not that simple to find the right one. It took me almost a month to choose, but I'm finally happy with my solution.

Jekyll

First, as I already use GitHub, I tried Jekyll. It's a really well built static site generator, relatively easy to configure, and with lot of examples and documentation on the web. It's coded in Ruby, and of course, open source.

I played with it almost a week, trying to make a design that pleased me. I started to being stuck when I wanted to play with categories and tags. It's not like I need it, and to improve it you need to add some plugins, or hack Jekyll yourself.

At this point, I started searching something else. Jekyll is a good start, and I would have happily get back to it if I didn't find something else. But for now, I don't want to learn Ruby, and relying only on the available plugins can cause some troubles.

Hyde

Since I found Jekyll very interesting and promising, the next "toy" I tried was his Python port (at least, originally), Hyde. But because the site (first link on Google) isn't explicit enough, I started using a very old version, the 0.5.3. Yes, if I had read the README more carefully I would have seen the newer version. And yes, just by checking the age of the last commits (3 years ago) I also could have seen that's an abandoned project. But still, I didn't see it at the beginning.

I first played with it to create the site of my startup (LumApps), on-line soon as I wrote this lines. Then I tried to port my Jekyll site to Hyde. I did it so fast, I was impressed by the ease of it. But then, I started to be stuck again with the categories and tags. And although Jekyll has a lots of examples and documentation, there is a lot less for Hyde. And after some times of search, of hack and everything, I found the newer version of Hyde, the 0.8.5a14.

I switched my blog to this newer Hyde, and oh boy, it was way more difficult to do it than it was to switch from Jekyll and Hyde 0.5.3 :

  • The newer Hyde uses Jinja2 instead of Django
  • The configuration system is totally different
  • There is almost no examples
  • The documentation is a pain in the ass : hard to find, missing a lot of points, etc... The README tells it better than me, it's a work in progress
  • Even when you found examples, it may not work (I'm not entirely sure why)

After 4 days of hard work on this newer version, I decided to leave Hyde. The first goal of using a static site generator was to make my life easier... I already did too much work to just have a basic blog, I can't even imagine the work I'll have to put to had some advanced feature.

Octopress

After the Hyde failure, I searched for static site generator made for blogging. Octopress rapidly came out of my Google search. It's an overlay of Jekyll, configuring it with plugins and theming. I tried it very briefly. On of the first thoughts I had was "Ok, it's really cool, but it's like WordPress, too much." And by playing with it, I kept thinking that over and over. And it's still in Ruby.

Pelican

Then, by searching again, I found pelican. In Python, made by a French developer (cocorico !), simple, easy to install, easy to use, multiple theme already given. Sounds like a winner. And there is some good theme, like the one by tBunnyMan, pelican-chunk.

By the end of the night, I got my blog up, with everything that I wanted. Or almost. First I used my modified version of tBunnyMan's theme (wider, with the categories regroup in one menu item, and some other stuff), but that didn't pleased me enough. So I created the current theme the next week end, very easy to make (just a few hours, but yeah, almost all the design choices were already made during all my play-around). You can see the result on my Test page.

There is still some things to do though :

  • Sitemap
  • Robot.xml
  • Fix border "bug" on archives.html
  • Set markdown date with more precise data than just YYYY-MM-DD
  • Responsive design (for the moment, sorry for the mobile reader, especially those using Apple devices)
  • Put all in github
Tagged