Tuesday, June 29, 2010

Quiet down the frustrating Open Space Office noises

I am and always will be the enemy of the "lets have an Open Space office" idea. From multiple articles, blog posts and research I know that Open Space makes us, software developers, sick. In the worst case, we have to share the Open Space office with guys from marketing, management, etc. and this makes us even more sick! I guess that to some guys it's simply not clear that developers need to work in peace if they are to build a good quality software. What talent do you need to have to concentrate on design of you component or some algorithm when 15 of your 50 neighbours run around, speak on the phone or simply talk with each other? If you are able to focus on your work in such an environment then you are either deaf or you have some supernatural skills of shuting down your ears while working. Most project managers can't understand that developers are humans too and can get frustrated from time to time. The fact that people are half effective at work does not seem to be a problem for the management as well. This results in developers changing their jobs... or simply geting crazy... but who cares anyway? The office must be cheap! (Btw. in reality it isn't, but this is differnt subject and probably even harder for the managers to understand.) Like Scott Ambler once said "Management people are insane!" ... and I agree completely.

Now, why do I write about it? Well, as you may have guessed, I acctualy work in an Open Space environment. However, instead of chaning my job (which I probably will do sooner or later) I decided to find some other solution to this "unfriendly development environment" problem.


The Head Phones with Noise Reduction system!

Short story

The Noise Reducing head phones were wandering around my mind for many years before I actually got them. I saw them for the first time when I was flying to US for my high school abroad year (quite a while ago). A small guy wearing the Bose phones was siting in front of me. I remember him reading his book. He looked relaxed and seemed to enjoy the music among all this airplane noise. After few weeks I decided to find out something about his phones on the Internet. (They really must have seemed special to me.) When I saw the description and the price, I understood that they are state-of-the-art technology which I can not afford at the moment.

The head phones reapeard in my life for the second time when my girlfriend joined the team working in a large Open Space office. She complained about the noise, was frustrated, couldn't concentrate on her work, (paste some other usual stuff here if you like,) etc. Frustration is not helping to build a good relationship so we sat down together and discussed about it... and
... finally... "do you think the noise reducing headphone could help?", "why don't we try it?"

The effect

You would be amazed how much noise this little toy is able to reduce. Just put them on your head, turn them on and wuala, the usual noises are reduced by 70-80% (or even more). Turn some music on at the minimal loudness level and you won't be able to hear anything from outside! Its simply amazing!

The headphones worked like a cure for the Open Space sickness. After few days there was no frustration anymore, no concentration problems as well. Everyone in the office wanted to check them out and everyone who tried them bought them after some time!

The only wonder was that the management guys at our corporation who actually were aware of the problem and have seen their employees solve it on their own, did not agree to sponsor this noise reducing head phones to them. The clear efficency gain per person, the low ammount of frustration, etc. were not good enough arguments. What can I say? Stupid.

Models

I don't want to recomment any particular product here. There are many on the market so you can choose whichever you want. They all work very good. My personal pick was Bose QuietComfort 15. My girlfriend has Bose QuietComfort 3 model and is also very satisfied with its performance.

Thursday, March 11, 2010

News - why always negative? why always dummy? It's boring!!!

Introduction

Since a very long time I am totally disgusted by the information broadcast by the public/non-public TV (or newspaper) news. Most of it concentrates on a very negative issues and I think it has a bad influence on people. I feel it has a bad influence on me. That's why I would like to share my opinion concerning this subject with you. Also, I want to share an idea on how this problem could be solved.

Common subjects that I see in the Internet news (and simply scroll over them) go like "A politician X said that politician Y is an idiot", "5 people died in a car accident .... bla bla..", "plain crashed.... somewhere near a country I never heard about" . Some of that news are real tragedies that we really need to be familiar with (so that they never happen again). On the other hand some of them are of really minor importance or even just a total bullshit.

Today I asked myself, why do people need to be informed almost only about this bad and dummy stuff? I don't like to read only about bad things all the time and would really appreciate something positive. Bad news make me feel sad, confused, unhappy ... just bad feelings there. Is there any particular reason why media do this? Why can't they simply balance positive with negative? Do all people simply like to read about bad stuff? If yes (which I don't believe), then why am I so different?

The problem with Media

The problem is that media see (btw. maybe that's what they want) a group of people as a single consumer. They do not filter their news and present them in the same way to all of us. It does not matter if you are a student, a cook or a Nobel price winner. You will all get to read the same news everybody does. This is a bad approach and I think here is where the problem appears. We all are different! The information presented to us must be personalized, otherwise it may be totally irrelevant and may affect our personality by pushing it out of its balance. This stuff is serious! Irrelevant information may affect our lives quite seriously. How? Keep reading.

Unique personalities

You see, every single one of us has a unique personality, different needs, desires, expectations, etc. What is interesting to one does not necessarily has to be interesting to the other. Of course, there are some behaviors which are more or less common to all of us. As an example, we all share the desire of staying up to date with the stuff that happens on our planet. The problem is that we are not able to consume all the information that is available to us. It is simply too much data out there and we are only able to process a small fraction of it. Since we consume the data through the process of reading, listening or through the vision, if we concentrate on unimportant data, we loose the time to get familiar with the important one. Therefore we would really appreciate if the information would be filtered according to our criteria an then presented to us so that we don't waste the time to do it ourselves.

Staying in balance with yourself

I stated before that irrelevant information may affect our lives quite seriously. Here's why I think so.

Lets imagine a simple guy who works all day long for some big company which pays him junk money for his hard job. When he comes back home and reads the news (the unfiltered, bad and dummy information) he probably feels happy! Yes, happy!!! Happy that he has a job, that he is alive, that he has a wife and kids and that they are alive and healthy. The news he just read force his brain to think about stuff he would never think otherwise. Mentally he needs to keep the "good" and the "bad" stuff in his life in balance, otherwise he would go crazy. Bad news he just read magnify the value of the stuff in his life that was not so bad to the levels where it can be accepted as good. The guy is happy with his bullshit salary, crappy job position, wife and kids he does not actually know that well. He's happy because he thinks, hey, there are people on this planet who don't even have what I do! That's something to be proud of. What I have is enough and makes me happy. His brain will stay in this balance until it receives the next portion of the some sort of data (e.g. a portion of "positive" news).

Crazy, but I can imagine that this is the main reason why people actually like to read this kind of stuff. The message "your life does not suck that much" seems to be very attractive to many of us. It is easier to balance yourself in the negative direction (that is to "make to bad look good"). The other case may require some extra effort (that is to actually "have the good"). People are lazy, we don't like extra effort.



Hmmm, and what would the guy think if he didn't read the news at all (I mean totally at all)? Yeah.. in many cases (not all of course) by seeing most of his colleges or neighbors having better live then he does he would think "Shit! Something is wrong here, I suck, those guys live better then I do, what can I do to become like they are.. to improve the quality of my life? They did it so I know I also can do it!". It would seem negative to the guy but in a sense it would also motivate him to do more (which on the other hand is extremely positive). As I said, the first feeling is negative because having to balance in the positive direction requires some extra work (like e.g. to learn smth, look for a new job, talk to the boss, etc.).

NOTE: The theoretical way of thinking in the above paragraph applies to members of non-communistic or post-communistic counties only. In such countries a guy would probably think more something like this: "What can I do to make the life of my neighbors suck as much as my life does". In this situation, the guy does not want to improve his qualities to reach his psychological balance ("have the good") but rather causes his neighbors (which were the actual cause of putting him in psychological imbalance) to degrade to his level. This also puts the guy in the desired, balanced position. The side effect is that the neighbors are then out of the balance (no longer "have the good"), but who cares anyway :-).

This was a very theoretical example of a single person being affected by the news. The problem with the "your life could suck more" message is that it affects all of the important people who surround us like a virus. Family members who could actually be good at motivating us to do more, do exactly the opposite, they believe in "the message" and force you to do the same. They don't believe in you, which makes you do the same too. Very negative stuff.

This is why I think that news have to be personalized. They may cause a lot of harm to people who do not filter them by themselves. A potentially smart and creative people can be wasted by the inappropriate information presented to them in the news. The solution to the "family virus" problem may be much harder to find.

My feelings about the news

Coming back to the news subject. When I see such a negative news, they generate only bad feelings in me! Only bad!! Why? I don't like the "your life does not suck so much" message at all because I differ extremely from the "common" consumer image. Most of you probably also do. This kind of news suck to all highly motivated people.
I would rather see the news saying "The cooperated work of Politician X and politician Y lead to improvement of the ... bla bla bla", "The genius student of our [some university name] invented a .... " or "Our local companies gain respect on the international market ...". Of course our world is not perfect. There is some bad stuff we need to be informed about (wars, serious accidents, ecological catastrophes, etc.) but I would be happy to see it mixed with some positive news simply to keep them in a healthy balance. I am creative guy and want to stay that way.

To all unhappy news consumers

To all of you who feel like they want to puke when they see the news. I guess, you're bettor of not reading the news at all. Instead try to talk to your friends, buy yourself magazines containing information that is really interesting to you. Also, throw your TV and Radio out of the window and see what happens in your live after the first month without it. You may be surprised.

To the media. How to make the news personalized?

Well, the idea is simple. Make your web app learn about the person clicking news links. Get to know this person's personality. In a simple scenario, simply mark your news as "positive" or "negative" ("optimistic" or "pessimistic") and count the clicks (yes, just like Google does). If the guy is more interested in positive news, show him more of the positive ones. If he likes to read about political affairs, mark that and show him more news about it. People will decide which news help them stay in their psychological balance and you will filter the news appropriately for them. It's that simple! Do it!

Monday, February 8, 2010

Better email validation with Tapestry

Recently I implemented a small form for creating user accounts with Tapestry. I used all the standard Validators available hoping that they will successfully pass the manual tests. Well, some of them did :-) except from one: The 'Email' Validator.

If you look at the sources of Tapestry (5.1.0.5) email validator, you may spot the problem.

//...
private static final String ATOM = "[^\\x00-\\x1F^\\(^\\)^\\<^\\>^\\@^\\,^\\;^\\:^\\\\^\\\"^\\.^\\[^\\]^\\s]";

private static final String DOMAIN = "(" + ATOM + "+(\\." + ATOM + "+)*";

private static final String IP_DOMAIN = "\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\]";

private static final Pattern PATTERN = Pattern
.compile("^" + ATOM + "+(\\." + ATOM + "+)*@" + DOMAIN + "|" + IP_DOMAIN + ")$", Pattern.CASE_INSENSITIVE);

//...

public void validate(Field field, Void constraintValue, MessageFormatter formatter, String value)
throws ValidationException
{
if (!PATTERN.matcher(value).matches()) throw new ValidationException(buildMessage(formatter, field));
}
//...


Can you see it?

What about the user "dajdajda" having account at "dhadadhahjad.edhadja.dads"? What about a Polish guy trying "adaś@ćma.pl" or German one checking out "thomas.müller@öäüß.de"? Are these really valid email addresses? Do you want to accept them? I would rather reject them right at the beginning.

To me full SMTP validation is a little overkill (because of performance, complexity and multiple additional problems that make your life complicated). However a hybrid of regex checks and DNS validation seems to be the acceptable solution.

I have created my custom Email Validator based on the simple DNS check code samples from http://www.rgagnon.com/javadetails/java-0452.html.
Also, for regex validation I used the org.apache.commons.validator.EmailValidator which in my opinion offers a better regex pattern than one defined in Tapestry 5.1.0.5 (see code above).

If you agree with me, then please feel free to use my code shown below (free of charge ;-)). You can create your DNSEmailValidator in any package you want, then contribute it in you AppModule.java and simply use it within your @Validate or <t:.. validate="dnsEmail"/> statements.


//...

import java.util.Hashtable;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

import org.apache.commons.validator.EmailValidator;
import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.validator.AbstractValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DNSEmailValidator extends AbstractValidator<Void, String> {
private final static Logger _logger = LoggerFactory
.getLogger(DNSEmailValidator.class);

public DNSEmailValidator() {
super(null, String.class, "invalid-email");
}

public void validate(Field field, Void constraintValue,
MessageFormatter formatter, String value)
throws ValidationException {

// validate the syntax
final EmailValidator validator = EmailValidator.getInstance();
if (!validator.isValid(value))
throw new ValidationException(buildMessage(formatter, field));

// validate the DNS
final String[] tokens = value.split("@");
try {
int servers = doLookup(tokens[1]);
_logger.info(tokens[1] + " has " + servers + " mail servers.");
} catch (NamingException e) {
throw new ValidationException(buildMessage(formatter, field));
}
}

private String buildMessage(MessageFormatter formatter, Field field) {
return formatter.format(field.getLabel());
}

public void render(Field field, Void constraintValue,
MessageFormatter formatter, MarkupWriter writer,
FormSupport formSupport) {
formSupport.addValidation(field, "dnsEmail", buildMessage(formatter,
field), null);
}

static int doLookup(String hostName) throws NamingException {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes(hostName, new String[] { "MX" });
Attribute attr = attrs.get("MX");
if (attr == null)
return (0);
return (attr.size());
}
}


Contribution code:


//...
public static void contributeFieldValidatorSource(
MappedConfiguration<String, Validator<Void, String>>> configuration) {
configuration.add("dnsEmail", new DNSEmailValidator());
}
//...


Of course, this DNSMailValidator does not make sure that the mail account really exists. It proves that there are mail servers available at the given domain name. Checking the existence of mail account may take a little longer and sometimes fail (e.g. when greylisting is enabled). The cool thing is that Tapestry allows you to create any Validator you want, so you may implement both and use the one that satisfies current requirements of your project.

Wednesday, February 3, 2010

After interview

Yesterday I had a job interview for a Software Engineering (at least I thought so) position at one of the departments of my current company.

I am an interview newbie (who did like 5-6 of them in his life) but I think that's enough to notice the difference between a good and poorly prepared one.

Well, since the company I work for was never (and probably will never be) particularly good at interviewing software engineers, I kind of expected only pointless and stupid questions to be asked.

The fact that I usually like to read a lot on "what's the difference between a good and bad software professional", "how to filter people when you recruit them", etc. only made it only worse.

I think that the guy asking the questions didn't really know what he would like to hear and know about me. How would you answer a question going something like this:
"How much time do you think you would need to get up to speed with our project?". Well, it sounds like an important question, doesn't it? ... no doubts about it... but how the hell am I supposed to answer it if I know very little about the project, it's size, the code and documentation quality, the people (e.g. if they are helpful or not). I couldn't say that loud but I got really pissed off and thought ("This is the question you should ask yourself after getting to know me a little bit better!! That's why I am on the f.... interview, isn't it?"). Some people would probably give him an answer "As fast as it's possible", and I bet that this would satisfy that guy (who I bet loves "standard answers"). The problem is that I am a creative engineer and do not like routine too much. When interviewed I like to THINK.

I usually have nothing against dummy questions like "Describe Visitor Pattern" or "What's the difference between heap and stack?". They prove that I read books from time to time, or that I happened to work on a project where people actually used design patterns. On the other hand I do not favor this kind of "checks" because they do not prove if I am a "THINKING PERSON". I may be an idiot who knows patterns by heart but has no idea how to solve complex problems with or without them. Software Engineering is more like art. There is many ways to build software, nice and less elegant ones (but still correct). We can not say that the "Gang of four" defined the best ever solutions to design and implement applications. Patterns help to solve common problems and establish communication layer between developers who know what they are. However, they do not always solve our custom problems in the best possible way (there is no such thing like "the best way" anyway). That's why I would test people not on their knowledge but rather their ability of CREATIVE THINKING.

We will see if I get the job :-) The project is very interesting but one of the interviewers did a really good job in demotivating me.

At the end he also said something about my experience. That he does not like the fact that I did Java development for almost all my professional career (he would be really happy if it was C++ instead). I mean... honestly, he could hold it for himself because I personally, do not regret this fact AT ALL!! Language is just a tool, and as long as people do not get that it is JUST A TOOL, they will not be able to hire the real passionate software developers.

I think I suck, but my interviewer sucks much, much more! (and get's paid much, much better).

The guy did one good thing though. He motivated me to spend even more time on my own project. I can't wait to finally launch it. It would better be a success!

Tuesday, February 2, 2010

Want to learn C++ for free?

I found a very nice and free C++ tutorial (which kind of looks like a huge electronic book to me).

I find the section 7.9 — The stack and the heap particularly well written. The author uses simple analogies (e.g. the plate and the mailbox analogy) to explain how the stack and heap works. I always liked this kind of approach when learning new stuff. Unfortunately not many book authors use them in their works. Too bad!

1:0 for the free electronic book.

Monday, February 1, 2010

Can call myself a C++ programmer now!

Yeah, I've finally finished the "C++ from the ground up" book today (including the last appendix).

The author himself calls everyone who managed to go through all the chapters of the book a C++ programmer. I guess he is right. I totally feel like I am able to not only understand but also code some pretty advanced apps in this language. Of course, advanced does not mean perfect and bug free in this case. Every newbie has to start with some shitty code to become a master. The important point is to write the junk code at home and not contribute it to latest version of the application produced together with your colleges at work.

The book is really awesome and I highly recommend it to everyone willing to learn Standard C++.

The dark side of the book was that it did not cover some of the subjects commonly seen in the professionally written C++ applications. The author suggests his other book (isn't it funny? "... to know more about XXX refer to MY other book ...") to learn about e.g. "function objects" or some advanced STL data types and algorithms. Also, the author does not give any hints about how the C++ app should be structured (the ".h" files, dir structure of a project, dll's (or so's), etc.) which I think is a pity. I would expect at least a small, mini chapter covering this topic. I guess the book is good if you are willing to learn a new language (and only the language), but not the way to use it efficiently when building a large application.

Well, I am happy that I've read this book and will probably come back to it from time to time to refresh my knowledge on some certain language specific subjects.

Hmm... and maybe I will buy Herbert's second book "C++ The Complete Reference" to make sure I did not miss anything important. The templates, I definitely need to refresh my knowledge on templates right now! :-)