Sunday, January 31, 2010

PyCamp впечатления

Вчера посетил конференцию по Python, PyCamp в Киеве.
Очень классная организация, приятно удивили наличие транслироваляции онлайн видео и twitter канал.

Среди участинков, были разработчики не только из Киева, а и из Питера, Омска, Запорожья.
Меня очень впечатлили доклады по базам данных: Redis и App Engine store. Redis - революционная inmemory key-value DB, и как заявлено докладчиком, по производительности обгоняющая даже memcached. App Engine store - одно из 2х хранилищ Google App Engine (2-e memcached). Стоит задуматься лишний раз, нужна ли реляционная модель?

Также очень понравились доклады про декораторы в Python (провел аналогию с AOP в Java), Расширение и встраивание Python и WebSockets в Twisted. Просто влюбился в новую среду разработки для Python - PyCharm от JetBrains. Количество фич просто поражает: поддержка рефакторинга, TDD, autocompletion - на выстоте, что весьма круто для динамически типизированного языка. Всегда хотел попробовать IntelliJ IDEA в Java, но все не находил времени, и вот теперь представится возможность. До этого использовал IDLE в ubuntu ну и emacs, где кроме подсветки и базовой подсказки ничего нет.

Несмотря на то, что мои знания синтаксиса и библиотек Python на начальном уровне, большинство презентацию были для меня понятны. Хотелось бы чуть больше live demo, по каждой из тем. Демонстрация "живого" чата, реализующего протокол websockets и PyCharm просто завели зал.

Для себя хотелось бы попробовать поиграться с Django ну и конечно же посмотреть сетевую библиотекуtwisted. Познакомился со многими новыми технологиями, про которые раньше слышал только мельком. Также был приятно удивлен, узнав про такие проекты как CloudMade и wishes.in.ua. Побольше бы таких мероприятий в сообществе киевских разработчиков.

Ну и конечно же огромное спасибо организаторам и докладчикам.

Monday, January 18, 2010

huge constructors

Some weeks ago working with tons legacy code I've found such an ugly classes (all names are changes):


public class Monster {

private static final String code;
private static final String userId;
private static final double weight;
private static final int money;
private static final String name;
private static final double height;
private static final Date birth;
private static final Date death;
private static final String type;
// extra 30 params

}

//construction:
public Monster(String code, String userId, double weight, int money, String name,
double height, Date birth, Date death, String type /* ... */){
// ... fields assignment
}


Passing values to such constructor and guessing is a hell:

Monster mon = new Monster("XY1", "user555", 19.5, 2345, "weird_name",
232, someDate, anotherDate, "animalType", /* ... */);

It is extremely hard to support such code, especially when you want to pass 28th parameter, getting lost in order and types. A good question is why do we need such a huge class, but that's another story (legacy code is legacy code).
A good solution is to use builder pattern, introduced by Joshua Bloch and mentioned in Design Pattern GoF book.

Thursday, December 10, 2009

J. Spolsky and developers test, Q11

Today during the lunch discussion I refered to one IT guru which motivated me as a developer on early stage of my career:
His name is Joel Spolsky, Microsoft product manager in the past, currently CEO of Fog Creek Software and creator on amazing developers resource stackoverflow.com.

As for me one of his major contribution into dev community is Joel's developers test.
Being a student and working on my first project, I was inpired by Joel's ideas and promoted them to my project manager. He replied: "Just try make it 12 point". So I launched continuous integration server (Cruise Controll), atached build script with unit tests, and set up 2nd screen on my table to bootstrap my productivity. Everyone in my team was happy, and it was preety strong motivation for us.

I want to touch Q 11(For me it's the most burning) which is about an interview:
"Do new candidates write code during their interview?". I absolutely agree with Mr. Spolsy on this point and there is no point to hire developer if you don't know how good he is in his primary reponsibility - writing code. And here is the main complication:


  • most companies interviews candidate for the technical background only for one hour or so
    and they do not have time for writing the code.

  • it's hard to find simple coding problem. What is good for 10 min quiz: reverting strings or writing simple web app?

  • it doesn't work for the Ukrainian market. Unfortunately most of developers in Ukraine (I'm not an exception ) do not write a lot of 'real' code. Typicaly they do integration, bug fixing, configuration, etc. So such simple coding problems like naive traversing trees, sorting, searching, filtering, even simple money calculations make a lot of surprise.

Object.wait() and spurious wakeup

Few month ago I was asked an interesting java question on interview.
The question was something like:
"Why we need to wrap Object.wait() call in while cycle?"

The answer you could find in Joshua Bloch book "Effective Java" 2nd edition, Item 69.
Always use the wait loop idiom to invoke the wait method; never invoke it outside of a loop

One of the reason, stated by Joshua is that:
The waiting thread could(rarely) wake up in the absence of a notify. This is known as a spurious wakeup [Posix 11.4.3.6.1; JavaSE6].

Browsing javadoc I noticed, that this issue was added to javadoc since 1.5 version:

Another reasons to use wait inside the loop are described in J. Block book or API, mentioned above


synchronized (obj) {
while ()
obj.wait(timeout);
... // Perform action appropriate to condition
}

Monday, September 21, 2009

Detecting deadlocks in java



Recently I faced the problem of deadlocks detection in java.
From my experience I used jconsole to connect to application server/container jvm and to print stack trace and to find waiting thread and method. Unfortunately sometimes occurs the situations when your jvm is started without JMX extension, necessary for jconsole. Imagine the situation when your live jvm instance is frozen and you think that deadlock is the reason. Since JMX is not started you can use jstack, nice utility from jdk tools. You need to find out a pid of jvm:

#jstack your_app_pid

The output will be like:



If you have access to shell with jvm another alternative is to press and stack trace will be printed in the shell. But be careful, if your jvm was started with -Xrs (reduce signal usage) process will be stopped.
In case you run your jvm on solaris you can use dtrace to find deadlock. Your java should be started with
-XX:+ExtendedDTraceProbes option.

Wednesday, January 14, 2009

Bugs are not bucks, sometimes it is hard to catch them

Twenty minutes ago I was building an application with maven on my linux virtual machine image and I've cached quite strange exception:
java.io.IOException: read only file system, however mount -l gives all FS mounted correctly, manualy I could create regular file and directory in any location and all files were with rw permission for current user. I've experienced the similar bug 2 moth ago, but nobody could reproduce it again (rebooting and remounting gave nothing).
After reboot maven build went OK, and the bug magically disappeared.

Such king of bugs are are united in special category as unusual software bugs. Seems that my bug is Mandelbug, the bug which behavior is so complex, that it seems like chaotic.
Other kind of such bugs are Heisenbug, Bohrbug, Schroedinbug etc and their can bring a real frustration to sofware developers and QA.

Have you experienced such kind of bugs?

Tuesday, December 30, 2008

Engineering is ...

Engineering isn't about perfect solutions; it's about doing the best you can with limited resources.

Randy Pausch, Computer Science Professor,
Carnegie Mellon

I found this amazing words in the "The last lecture" book. This book is not about software engineering, it's about life. Every day for the last week I wake up with this concept. Sometimes there are moments when you need to stop and ask yourself a couple of questions like "Are you going the right way? Is this solution optimal? Does you code looks fine? Are you the best in your field?".
Your team, knowledge, languages&tools, PCs, power, CPU, memory and even your salary - everything is limited. However, the most limited resource is time. Doing the best in a finite time - that is an engineering. What kind of application to create, what language or framework to study, what OS&tools& to use - that is the most challenging problems in my career of software engineer.