Codovation
Agile Development, Leadership and Innovation
9 Steps to integrate a remote HornetQ with Glassfish 3.1
I recently found myself browsing and searching the web for long hours just for finding an answer for an apparently simple configuration issue: How to configure Glassfish 3.1 to receive messages from and send messages to a standalone / remote instance of the HornetQ Messaging Platform. I didn’t find any tutorial, how-to, or any other useful resource that gave me the answers I needed. Everything was about how to embed an instance in Glassfish (running HornetQ within the Applicationserver) or how to configure JBoss + HornetQ. But nothing up to date about Glassfish as a client for a HornetQ standalone server…
At the end I scanned loads of different sources, modified what I found and tried all options since I found myself – some hours after midnight – sending and receiving simple Messages in Glassfish using a standalone HornetQ. Since there is no effective description about this simple task (at least nothing I found) – and I know that finding out by oneself is quite time consuming – I share the steps I went through to configure my situation.
Maybe you know better ways or have answers to my questions I will put at the end of this article. I really would appreciate any comments or hints….
Step 1: Adding libraries to your Glassfish installation.
After you installed Glassfish and HornetQ on your system(s), you need to copy a group of libraries to the lib folder of your Glassfish installation:
- hornetq-core-client-2.2.7.Final.jar (Download)
- hornetq-jms-client-2.2.7.Final.jar (Download)
- hornetq-logging-2.2.7.Final.jar (Download)
- netty-3.2.5.Final.jar (Download)
Don’t forget to restart your server afterwards.
Step 2: Deploy the HornetQ Resource Adapter as an application in Glassfish
First locate the file hornetq-ra.rar in the lib directory of your HornetQ installation. This file can be deployed in Glassfish directly using the Admin-Console (usually http://{glassfish-host}:4848). Open the Applications View and choose Deploy as the option. Now you can upload the file to deploy it as a connector application. The application should be listed in the Application View afterwards.
Step 3: Edit the Resource Adapter Configuration (ra.xml)
In order to communicate with a remote or standalone instance of HornetQ you need to modify the ra.xml in the directory of the delpoyed application:
{GLASSFISH_HOME}/domains/{domain_name}/applications/hornetq-ra/META-INF/ra.xml
You need to do several modifications:
First of all change the ConnectorClassName config property. By default this is is set to InVMConnectorFactory which just means that the client connects to an embedded HornetQ (running in the same virtual machine.
<config-property> <description> The transport type.... </description> <config-property-name>ConnectorClassName</config-property-name> <config-property-type>java.lang.String</config-property-type> <config-property-value> org.hornetq.core.remoting.impl.netty.NettyConnectorFactory </config-property-value> </config-property>
The second modification regards the ConnectionParameter config property. Make sure to set the right host name or IP and the right port. Note that these parameters are set as a semicolon separated list of properties.
<config-property> <description>The transport configuration.</description> <config-property-name>ConnectionParameters</config-property-name> <config-property-type>java.lang.String</config-property-type> <!-- Put your values here... --> <config-property-value>host=127.0.0.1;port=5445</config-property-value> </config-property>
If – and that should be the case – your Message Server is configured using a username and password for accessing a queue you also should set these credentials within the ra.xml file:
<config-property> <description>The user name used to login to the JMS server</description> <config-property-name>UserName</config-property-name> <config-property-type>java.lang.String</config-property-type> <config-property-value>test</config-property-value> </config-property> <config-property> <description>The password used to login to the JMS server</description> <config-property-name>Password</config-property-name> <config-property-type>java.lang.String</config-property-type> <config-property-value>test</config-property-value> </config-property>
Now restart your Glassfish. The deployed resource adapter should use the modified settings now.
Step 4: Create a managed thread pool
The next steps are quite easy. Just open your shell and move to {GLASSFISH_HOME}/bin/. Note that you might be logged in as root or use sodu for the following commands.
To create a managed thread pool type into your shell:
Choose the name (hrntq-ra-thread-pool) carefully because you will need it to connect several resources to each other.
Step 5: Create the managed resource adapter config
Next, create the managed resource adapter config. I am not sure how this differs from the ra.xml described earlier. But for me it doesn’t work to have just one of both configs…
--threadpoolid hrntq-ra-thread-pool --property "ConnectorClassName=org.hornetq.core.remoting.impl.
netty.NettyConnectorFactory:ConnectionParameters=host\\=127.0.0.1;
port\\=5445:UserName=test:Password=test" hornetq-ra
Whatsoever … You have to set the same properties as in ra.xml: The ConnectorClassName, the ConnectionParameters and the UserName and Password. With the threadpoolid option set to the name you used in Step 4 you tell this config that it should use your custom thread pool. Again, this Resource also needs to get a proper name.
Step 6: Create the Connector Pool
Now we create a ConnectorPool configured to use the HornetQ Resource Adapter. This provides the basis for creating multiple connection resources that can be injected into your managed JEE application.
javax.jms.Queue:UserName=test:Password=test --transactionsupport XATransaction hornetq-ra-connection-pool
Step 7: Create the Connector Resource
This one can be injected into your application using the @Resource annotation – see Step 8 for an example.
Step 8: Create an EJB that sends Messages to the Queue
Finally I will give you an really simple example of how to use the configured Connection Resource within your managed JEE item. As mentioned before you just have to use the @Resource annotation and the name to link to the resource you configured in Step 6. I did not find out how to wrap a HornetQQueue into a configured and managed module. That’s why I instantiate it directly in the code below. But I’m sure that there must be ways to give the responsibility for this to the Appserver. However – the way showed here works!
/**
* Example EJB that connects to a HornetQQue named "testqueue"
* to send a TextMessage with a given String value.
*/
@Stateless
class SimpleMsgSender {
@Resource(mappedName="hornetq-ra")
private QueueConnectionFactory qcf;
public void send(String message) {
QueueConnection queueCon = null;
try {
queueCon = this.qcf.createQueueConnection("test","test");
QueueSession queueSession = queueCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = new HornetQQueue("Requests");
QueueSender sender = queueSession.createSender(queue);
Message msg = queueSession.createTextMessage(message);
sender.send(msg);
} finally {
if (queueCon != null) {
queueCon.close();
}
}
}
}
Step 9: Create a MDB (MessageDrivenBean) to Receive Messages from the Queue
Sending messages is just one side of the medal. Receiving messages could be also done using managed resource as in Step 8. But then it’s the responsibility of the application to poll the queue. In JEE we have a way to describe a receiving component as a listener to a specific JMS queue. This is called a MessageDrivenBean. The problem here: You cannot use the configured resources described above. I didn’t find any way to connect these resources to a MessageDrivenBean. However, you can use the sun-ejb.xml in the applications META-INF direcotry to configure the MDB to connect to the remote HornetQ server…
<enterprise-beans> <ejb> <ejb-name>simpleReceiver</ejb-name> <jndi-name>simpleReceiver</jndi-name> <mdb-resource-adapter> <resource-adapter-mid>hornetq-ra</resource-adapter-mid> <activation-config> <activation-config-property> <activation-config-property-name> destinationType </activation-config-property-name> <activation-config-property-value> javax.jms.Queue </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> destination </activation-config-property-name> <activation-config-property-value> /queue/Requests </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> ConnectorClassName </activation-config-property-name> <activation-config-property-value> org.hornetq.core.remoting.impl.netty.NettyConnectorFactory </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> ConnectionParameters </activation-config-property-name> <activation-config-property-value> host=127.0.0.1;port=5445 </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> User </activation-config-property-name> <activation-config-property-value> test </activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name> Password </activation-config-property-name> <activation-config-property-value> test </activation-config-property-value> </activation-config-property> </activation-config> </mdb-resource-adapter> </ejb> ... </enterprise-beans>
With this configuration you can implement a lightweight MessageListener which will connect to the HornetQ just by using the @MessageDriven annotation and the mappedName attribute to link it to the XML configuration.
/**
* Example MessageDrivenBean that receives TextMessages
* and logs them.
*/
@MessageDriven(mappedName="simpleReceiver")
public class SimpleMessageReceiver implements MessageListener {
private static Logger logger = Logger.getLogger(SimpleMessageReceiver.class);
public void onMessage(Message message) {
TextMessage m = (TextMessage) message;
try {
String body = m.getText();
logger.info(body);
} catch (JMSException exc) {
logger.warning("Some Error in receiving JMS Message: " exc.getMessage());
}
}
}
As you see, it’s quite simple to configure a Glassfish to make your application a HornetQ client. But still, there are still open questions and some need for optimization. I am sure that I am not the only one out there who would appreciate any help from you, if you have any experience with this topic
As said in my introduction, I will start the discussion by giving my questions:
- How can I configure a managed queue resource to be linked to a HornetQQueue using the Resource Adapter?
- How can I use the config resource in a MessageDrivenBean?
- Are there any other pitfalls to consider when using HornetQ within a Glassfish App?
Cheers!
3 books every (not just junior) development manager should read before diving into practice
Often, especially when small companies grow, good developers get promoted into leadership or management positions: Scrum Master, Development Team Lead, Development Director, or even CTO. Back in 2007 I was in the same situation – barely graduated from university and all of a sudden assigned to manage and organize a development team of 8. Yes, and I must admit that I didn’t have any clue about what it really means to manage and lead a growing development team in a permanently changing organisation… I was a software developer with interests in agile methodologies and fairly high standards for myself and others, but I still was a software developer and had never learned about the responsibilities, pitfalls and mindset you need to know to succeed in a leadership position.
I learned a lot since that time and thankfully I had a great boss who was and still is a patient coach and mentor for me. I read loads of different books, joined leadership seminars and talked to dozens of other development managers, consultants and senior developers. All this learning effort and the chance of gaining management experience within a growing and healthy company combined with the strong support from top management formed a quite effective stage for my leadership take off.
However, in the beginning I surely made lots of failures and the company had to invest in myself by accepting imperfections an experienced and highly skilled manager probably wouldn’t have had. I lately read three different books: Peopleware, Management 3.0, and Growing Software. These books are great material to study for becoming an effective development manager in an agile and more and more chaotic world. I strongly would recommend these books to every management aspirant – not just in the area of software development. Back in 2007 I would have been really happy to know about these books…
I want to share this great and powerful introductions to development management with you:
1. Peopleware: Productive Projects and Teams

A real classic! In Peopleware, first published in 1987, Tom DeMarco describes what most post-conventional leadership theories and the whole agile community put onto company agendas today: Projects are all about people and the intrinsic motivational energy amplified in great team work! Projects succeed when you have yelled teams and they will fail with poor performers and lone warriors.
It’s an easy and short read but contains much more value then lots of todays books double the size of Peopleware. It’s structured into 5 parts all of which consist of several essay like texts with lots of practical hands-on suggestions described in a very funny way:
Managing the Human Resource
Almost all project failures are due to problems based on the working people, yet managers spend most of their time on technological issues because those are the issues they were trained to handle. But especially in the area of software development managers have to understand the nature of the human beeings, their working habits, motivation, and the factor of creativity. DeMarco suggests to give more room for errors, to respect and value both individual und team contributions without only focussing on technological yardsticks but also on sociological ones. One important aspect which is underlined is the use of the brain in the office. Lots of companies today and at that time focus too much on producing code. They forget about the creative thinking process before the implementation which is maybe even worth much more. Another important fact that has to be considered in development projects is that quality should equal productivity. And this is mostly about the people building the software. Nothing is more demotivating for software engineers then a management which prioritizes code / feature quantity over quality. A last finding of DeMarco regarding the Human Ressource factor is that project estimations should be done by the engineers themselfs and not the manager or some third party stakeholder. This is quite common today in agile companies that adopted planning or estimation poker.
The office environment
Investing in customized workplaces that enhance the productivity of intellectual and creative workers is one of the most important but least understood nuances of engineering management. Effective workplaces should allow privacy and calm focussed work as well as creative group sessions and discussions. It must be possible to support an enironment where it’s possible to concentrate and think while working (aka flow). In open office spaces with noisy telephones and moving colleagues this is definately not possible. When it comes to the measurement of productivity DeMarco points out that the gut feeling backed by some raw data is enough. There is no such thing as real productivity measurement in software development.
The Right people
Don’t let yourself influence by appearences to bring in talented people. It is important to support people in beeing themselves without playing any role: Thats the way you get the most out of your people. You should put as much effort in the hiring process as possible… The same counts for the process of developing people and their talents and create a sense of performance with a carreer path.
Growing productive teams
Real work gets done so much faster and better in great teams that effort should be put into setting an effective stage for them and help them grow together. Don’t try to standardize the behaviour and manner in which a team operates. Strinving for professional behaviour is just a sign of a insecure and immature management: The effectivity of teams is much more important. People have a natural tendency to learn to work well with each other if they have the same goals. We must try not to impede this phenomenon and instead make full use of jelled teams. “Teamicide” is supported by defensive management, bureaucracy, physical separation, fragmentation of peoples time, quality reductions, phony deadlines and clique control. It is not enough to avoid or reduce these habits… You as the manager have to support your team to find as much situations to succeed together as possible. Trust your team and every single team member! That’s the only way to succeed. The best bosses do what they are best at and leave what their workers are better at to them. Build an environment with these feautures: Cult of quality, lots of satisfying closure, sense of eliteness, support for heterogenity, preserve successful teams, provide strategical but no tactical direction. The elements that facilitate team formation and jelling may be counter intuitive, but if a manager is brave enough to provide the above mentioned environment, the team will reward him with success as they try to protect the enjoyable environment.
It’s supposed to be fun to work here
There is a need to constantly breathe life back into our work. We spend way too much of our lives working to find it a drag. Good managers try their best to sense who needs direction and who doesn’t, and provides direction for the former while only removing barriers for the latter. Don’t be discouraged that you are the only one trying to change something silly in your work environment. If it is obvious enough, you may be able to easily get your co-workers to join in your efforts.
2. Management 3.0

This master piece book from Jurgen Appelo just was released in the spring of 2011. I really enjoyed the read and I was quite glad that I finally found a book that takes management and leadership in an agile world into account. There are is way too much material about agile methodologies out there that don’t even mention the role of leadership in SCRUM, XP, KANBAN etc. Somehow you could get the impression that leadership and management isn’t needed anymore: The Scrum Master and the self-directed (sorry: self organized) team will handle it themselves. Wrong!!! And Jurgen Appelos book descibes the new role of management in a comprehensive and both theoretical and practical way. The book is organized in 6 themes and a introductorial part about chaos and systems theory and the description of the body of knowledge of software development.
Energize people
People are the most important parts of an organization and managers must do all they can to keep people active, motivated, and creative. Beware of the difference between making and keeping people active, motivated and creative! It’s the managers responsibility to support the information-innovation system: Spread information, support people to think and collaborate with each other to make innovation happen. Therefore managers have to understand the basic intrinsic desires of people by setting up regular one-on-ones, asking questions about the health of the organization, and supporting an open feedback culture.
Empower Teams
Teams can self-organize and this requires the right touch of empowerment, authorization, and trust. Managers have to understand that they should have a gardener mindset: Growing a team instead of building it! The right amount of clarity (about responsibilities and key decision areas) is critical for letting a group of grow into a self organized team.
Align Constraints
Self-Organization can lead to anything! It’s the manager who should protect the boundaries of a team by supporting people and resources and give people a clear purpose and defined goals. The manager should manage higher goals without using targets and extrinsic motivation. Instead he or she should build trust to accept common rules, increase the understanding of current situations, increase the social belonging accross the team, and address the need to improve oneself.
Develop Competence
It’s essential to understand that teams cannot achieve their goals if team members are not capable enough. It’s a critcial management task to develop the competence of each team member.
Grow Structure
Since most teams operate in the context of complex organizations it is important to consider structures that enhance communication and collaboration. This should be done by making peoples jobs dynamic and change work structures into a network like organization.
Improve Everything
To avoid failure and minimize team erosion as long as possible it’s important continously improve everything: people, teams and organizations by setting up regular learning and correction possibilities (e.g. retrospectives, kaizen, kaikaku). This should become the cultural baseline of the whole organization.
3. Growing Software

This 2009 publication of Louis Testa is unlike Peopleware and Management 3.0 not just about the management of humans and teams but also about the system and software development process. It is packed with useful hands on practices and strategies for almost everything that a typical manager encounters-from personnel decisions and relations with other departments to project estimates and software release strategies. This one is structured in 5 different parts from team management to the planning of the technological future.
Development Team
The book starts with a brief description of how to start your job. It doesn’t matter if you got promoted or changed to a new company – the introduced strategies of how to get on touch with the team, its issues and working habits are quite useful for both cases. The rest of this first part reads like a short summary about communication, team forming, hiring and development processes and effective working environments.
Product And Technology
This one starts with a description of how engineering and marketing teams should collaborate to define and conceptualize the product. It’s about different types of pre-releases, real world tests of products, the process of driving releases and how to kill projects. Testa continous by describing how to decide and use tools and methods for the engineering process. The assessement, documentation and orchestration of technologies forms the end of this section.
Outside Of Engineering
In this section Testa gives you guidelines for working with other parts of the company, the CEO and the customer. This is about the representation of your team in an outside world and the effective first hand understanding of the needs and requirements for the products you gonna build.
Making Work Flow: Projects, Process, And Quality
The project management section with hands-on strategies for how to plan, drive, track and exectute projects and processes. It’s completed by a brief description of the responsibilities and processes of a QA team within your oganization.
Planning The Future
The last section of Growing Software deals with the process of creating visions and making roadmap strategies to reach these visions.
8 Steps of good decisions
Eine der wichtigsten aber in vielen Fällen vernachlässigte Aufgabe von Führungskräften ist es Entscheidungen zu treffen. Im Recruiting, in der Einführung bestimmter Management Methoden, Businessprozesse oder Softwaresysteme, in der Budgetverteilung oder aber bei ganz alltäglichen Entscheidungen … immer wieder geht es darum eine Veränderung herbeizuführen deren Implikationen gut durchdacht werden sollten.
Fredmund Malik beschreibt in seinem Buch “Führen, Leisten, Leben” einen sehr einfachen aber umso durchdachteren Prozess, den jede gute Entscheidung durchlaufen sollte. Im grunde basiert dieser Prozess auf 8 aufeinanderfolgende Schritte, von denen allerdings keiner ausgelassen werden sollte, auch nicht bei scheinbar sehr einfachen Entscheidungen oder Nebensächlichkeiten:
- Präzise Bestimmung des Problems
- Spezifikation der Anforderungen, die die Entscheidung erfüllen muss
- Herausarbeiten aller Alternativen
- Analyse der Risiken und Implikationen jeder Alternative
- Festlegung der Grenzbedingungen
- Entschluss selbst
- Einbau der Realisierung in die Entscheidung
- Etablieren von Feedback, Follow-Up und Follow-Through
Ich möchte kurz auf die einzelnen Schritte eingehen.
1. Präzise Bestimmung des Problems
Es ist wichtig sich bei der Problembestimmung nicht mit Symptomen oder Meinungen zufrieden zu geben. Es geht darum die wahren Ursachen und Tatsachen aufzudecken die eine Entscheidung erfordern. Man sollte sich die wichtige Frage stellen: Worum geht es hier wirklich? Bei der Beantwortung muss man sich Zeit lassen um die Antwort nicht zu schnell und leichtfertig zu geben. Der Grund: Von einem falsch verstandenem Problem kann man nie (oder nur zufällig) zu einer richtigen und nachhaltigen Entscheidung gelangen.
2. Spezifikation der Anforderungen
Hier geht es um die vollständige und präzise Herausarbeitung der Anforderungen und Kriterien denen die zu treffende Entscheidung entsprechen muss. Es ist wichtig die folgende Frage zu beantworten: Worum geht es hier wirklich? Und nicht etwa: Was ist am einfachsten, was am angehmsten, leichtesten oder für mich am besten? Dabei ist geht es aber nicht um den Maximalzustand sondern um den Minimalen Idealzustand. Zwei Prinzipien stecken darin: 1. Die Anforderungen müssen das Minimum beschreiben. Alles was darüber hinaus gilt ist zwar willkommen aber nicht unbedingt benötigt. Und 2. Es geht um den Idealzustand. Kompromisse sollten aussen vor gelassen werden. Man kommt noch früh genug zu Kompromissen.
3. Suche nach Alternativen
Bei der Suche nach Alternativen sollte man zwei gängige Fehler vermeiden:
- Mit den ersten, einleuchtenden Alternativen zufrieden geben. Wirksame Leader wissen, dass es immer noch mehr Alternativen gibt und zwingen sich und ihr Mitarbeiter dazu sich nicht sofort zufrieden zu geben, sondern immer weiter zu suchen und den gesamten Horizont zu betrachten.
- Die Null Variante, den Status Quo ausschließen. Der heutige Stand ist zwar nicht der beste (deshalb will man ja eine Entscheidung fällen) sollte aber niemals aus dem Optionenraum ausgeschlossen werden.
4. Durchdenken der Risiken und Implikationen jeder Alternative
Dies ist der arbeitsintensivste Schritt. Zunächst gilt es ein Framework zu modellieren bzw. auszuwählen und anschließend umfassend und genau mit objektiven Inhalten zu füllen.
5. Festlegung von Grenzbedingungen
Nachdem man die Informationen zu den einzelnen Alternativen gesammelt und eingeordnet hat gilt es die Integrationsfläche – die Prozesse, Abteilungen, Systeme, Strukturen, Personen etc. – zu analysieren und nach Grenzbedingungen und Ausschlußkriterien zu suchen.
6. Der Entschluss selbst
Man kann nur zu einem Entschluss gelangen, wenn man die ersten 5 Schritte durchlaufen hat. Man muss sich sicher sein, dass weitere Analysen und Studien nicht bringen. Aber: Trotz aller gesammelten Informationen ist es auch ratsam auch auf einen sehr günstigen Berater zu hören: Seine eigene innere Stimme.
7. Realisierung der Entscheidung
Laut Malik ist es 10 Mal schwieriger eine Entscheidung zu realisieren, als den Entschluss zu fassen. Aber: Man kann erst von einem Entschluss sprechen, wenn es sichtbare Ergebnisse gibt. Ohne Ergebnisse hat man lediglich gute Absichten – aber nicht mehr. Deshalb gilt: Die Maßnahmen, die für die Realisierung wichtig sind, sollten festgelegt und aufgeschrieben werden. Aber das Aufschreiben allein reicht nicht. Für jede Maßnahme muss eine Person die Verantwortung tragen, und für die Umsetzung muss es Termine und Deadlines geben. Denn: Am Ende des Tages werden Entschlüsse durch den Terminbezogenen Vollzug von Maßnahmen durch Personen realisiert.
8. Etablierung von Feedback, Follow-Up und Follow-Through
Wenn eine Entscheidung getroffen wurde muss die Person / müssen die Personen, die Owner der Entscheidung sind der Realisierung nachgehen. Personen, die an der Realisierung arbeiten müssen regelmäßiges Feedback über den Gesamtstatus, die Anforderungen, Ergebnisse und Erfahrungen anderer Maßnahmen erhalten. Die Finalisierung bzw. die Erreichung von Ergebnissen muss kontrolliert werden ohne dabei die Verantwortlichkeit der Umsetzer zu unterwandern. Es geht um Koordination, Information und weitere Entscheidungen sobald sich in der Umsetzung Probleme zeigen.
5 Principles to improve your Code Quality
Since I write software I am conviced that this is not just a kind of a technical handicraft but also an act of high creativity – say art! Since I work with different people to produce software code in a team I wonder how different working styles, the different personal and professional backgrounds, and the chaos of … uhmmm … artistic individualism can lead to high quality. To often there is chaos in the code as well, even if individual modules seem to be almost perfect. I want to name 5 fundamental priciples every programmer should follow to prepare the ground of high quality software because upon this ground there is enough space to use his / her own coding and working style as a valuable part of the whole.
1. Simplicity and Elegance!
Simplicity is not always elegance and elegance is not always simple. But in coding there are some strong links between both. In my eyes simplicity means that the complexity of a system must be adequate and comprehensible. Every part of a system should add something distinct and valuable to the whole. The parts are associated together by similarity or domain and don’t hide any nasty surprises. Achieving this is not easy. Simplicity is not easy – it’s hard work of understanding what the code is for and how several parts can be abstracted and substituted. The coder have to recognize patterns within the code and between several projects to identify modules that can be added to common libraries… and so on. A good use of interfaces underlines the simplicity – the coder reduces the complexity of system parts for other parts or other developers that use a system.
And there is a state of simplicity that is somehow elegant or aesthetic. It takes time to really understand that.
2. Give it a proper Name!
When you really know the “thing, be it a class, an objet reference, a variable or a function, there shouldn’t be any hassles in finding a proper name. Names can help you to think about the concepts and functionalties you write or use while developing and they should help you to understand the code while reading it.
3. “Make it readable” equals “make it understandable”!
Your audience is not just the compiler and yourself. It’s other programmers, your team mates, possibly your client or your successor (when you decide to leave). And it’s part of your job to write code for their benefits. There are three simple words that summarize what to do: The three C’s – Consistent, Conventional, Concise!
- Consistent
Develop your own style and use it throughout your code parts and projects. If you are coding for a company adopt the “house style” and use that instead of your own. It’s somehow stupid that there are so many fights about how to set brackets, how to intend code, how to insert comments or even how to sort the member of classes. I say: Fight if you want to but stick to the result whenever you find one. - Conventional
Even if you have your own style let it be based on one of the industry standards (e.g. K&K Brace style, Extended Brace Style, Intended Brace Style …) - Concise
Know what you are doing and why. If someone asks you why you write it that way, know your arguments – Think about it! It’s important whenever there is a new team member who has to adopt your style and that is not easy if there are no good reasons to use it.
4. Be defensive!
Be careful while coding! Don’t code in a hurry! Think about what you are doing: It’s engineering and solely because it’s just writing some code to a computer it is still some kind of construction. And construction has to be safe; otherwise there is a high risk of a (system) collapse. Therefore a good software developer has always to be doubtfully about the correctness of some piece of code. He never should assume the context in which a function is called, he should not assume that a function never will nver produce an error and that nobody will try to access that function in ways it is not meant to be called. Some additional points to have in mind when coding the defensice way:
- use safe data structures
- check every return value (even if it’s just a standard function you used already for thousends of times)
- handle memory carefully
- initiate variables always when they are declared (or use the constructor of a class to initiate fields)
- check numeric limits
- add preconditions, postconditions and check vor invariants within functions
5. Selfdocumenting Code needs less documentation!
Edwin Schlossberg: “The skill of writing is to create a context in which other people can think” (found here) When you code always think about others that have to read and understand what you did later on. You only need to comment that fundamental parts (classes, funtions) and avoid extensive inner code comments when you choose meaningful names, avoid redundance, have clear data flows, strict separation of concern and very high cohesion.
Just think about a function call “int x = r12.s(3);” where you also could write “int innerSize = room12.getSize(Room.INNER_SIZE);” Got it?
2 Examples of how OpenSource could improve your overall dev-team performance
Developing special, complex, but independent functional subsystems can be done in two ways:
- Develop it by yourself
- using OpenSource Frameworks, APIs, and SDKs
Of course, this is dependent on the type of software you want to create, it is dependend on the domain, the company you’re working for, and the basic conditions you’re facing. However, my experience usually is: A developer team is confronted with a project, which is too large to accomplish. The common reasons: lack of man power, time, and knowledge. In some cases the team will completely reject the project, in other cases the team will recommend a lightweight version which only covers a subset of the requested features, and in a few cases the team will just begin to develop a solution on its own … flatlining due to those high requirements. In most cases, the easiest way to solve complex but well known problems with limited resources is to use OpenSource Frameworks or APIs. There are solutions for almost every task one could face in programming. Using these, the team can focus on the important things and put first things first. I want to show two examples of how a OpenSource producted helped me and my team to develop a solution which we couldn’t accomplish on our own with the given resources (Manpower, Time)
Example 1: Implementing a flexible, high performance Enterprise Database Search for an existing PHP/MySQL System.
The problem: The client had had a very large mySQL database which was very slow and unstructured: A composite of about 200 tables with up to 18 Million data sets and each table having50 fields and more. The tables were not normalized nor were the fields optimized using proper filed types and lengths. To perform search requests they added two hash values allowing users to find information very fast as long as they’re just looking for standard values. More sophisticated search requests, table analytics, and fuzzy searches are simply not usable: They need about 20 to 30 minutes to finish and paralyze the database server for other processes. This situation was not accaptable regarding the future of the overall system. A complete re-design of the database was not possible as the first step. Because money and manpower was limited. We had to find a neat solution which is cheap but powerful, which could be implemented seamlessly in the PHP based system and which can handle the complexity of the data itself.
The solution: Read queries shall be seperated from the master database. In the same breath fuzzy searches (e.g. phonetic) shall be enabled. Ideally those fuzzy read queries directly deliver results without disturbing the rest of the database. After several brainstormings, weeks of thinking and planning, the rejection of other sound but not usable alternatives, and a lot of coffee we discovered the solution:
Apache Solr. This is an enterprise search server based on lucene. We could achieve all objectives by appointing two developers three weeks to integrate Solr in our systems. Solr enables access to a structured, highly configurable fulltext index by using the standard HTT protocol. It was not our job to implement all those funky search algorithms and index strucures but to design a proper index scheme which meets both, the complexity of our data and the flexibility of the search queries we wanted to have. We decided to use Solr as a tier right above the database which just stores the index and the particular id of the result dataset but no data. Updates are solved by triggers within the mySQL database. Whenever something is updated or deleted in one of the db tables a trigger writes to a special update table. This table is read frequently by a batch job which transfers db updates to the index.
In the existing system we replaced all reading queries by an lightweight search API which encapsulates a two step retrieval: 1. Search query for Solr 2. Database query with the result set (of id’s). A Search query which needed round about 20 minutes to perform now needs not more then 0.1 seconds. We can create complex analysis and flexibly react on special search requests by our client which were rejected until now “by technical limitations”.
One of the moste important advantages Solr has is its independence. The system which was aimed to use the new search system was written in PHP. But there is no proper solution for PHP. But with Solr we just could use the standard HTTPClient to send requests to the Solr (which runs on tomcat).
Today we use the solr index for several databases and in three different environments: Integrated in PHP, directly in JAVA, and through XSLT as a HTML based web search form.
Example 2: Implementation of a text analysis system to extract and transport structured data out of unstructured text to a relational database.
The Problem: A client uses specific data to back up process critical decisions. This data is embedded in texts and thereby not automatically processable. The manual effort to structure the data of interest ist terribly expensive, but the implementation of a text information retrieval system which could automatize this task is just to expensive to develop by a team of 10 developers in terms of time and money. A simple, lightweight solution is almost impossible to imagine because of the high complexity of the data.
The solution: The university of Sheffield develops an OpenSource System which is perfect to use for solving the problem: GATE. This is a framework to read and process textual data. In addition to a basic processing framework GATE consists of a bunch of plugins covering several capabilities from different domains. The most important plugins are consolidated as ANNIE, which stands for A nearly new information extraction system). Basically GATE consists of Language Resources (LR) and Processing Resources (PR). The latter are orchastrated in pipelines and used to process language resources, e.g. documents or corpora. Processing in this context means that contents are annotated throughout the process. Our task especially required the use of two ANNIE processing resources: The JAPE-Transducer and the gazetteer. The Gazetteer uses several lookup tables to apply annotations for named entities. Therefore we built a bunch of general and domain specific tables: Firstnames, Lastnames, Cities, Zip-Codes, Streetnames, Legal Forms, Key Words, Toplevel domains etc. The JAPE-Transducer in turn uses annotations to identify patterns of higher level qualified information. Patterns are described in the JAPE language, which is based on regular expressions but applied on annotations and their features (properties).
The information identified by the JAPE Transducer is anlayzed, structured, normalized at the end of the process to prepare the transaction to the relational database. Our result: The system reads, processes and stores about 5000 documents in 20 minutes. By the addition of a compouter aided manual process for all documents with ambigious information we reached a rate of almost 100 % and a quality that is much higher then the former manual reading of the documents.
Passion for Technology: What is it all about?
I think that Passion is one of the vital skills a software developer should possess. Passion for technology, passion for solutions, passion for progress. Mike Peters has pointed at this tellingly precise in his blog aritcle “How to pick a GREAT Software Engineer“. He writes, that passionate developers are characterized by reading DZone or TecCrunch, testing new software, or writing code in their sparetime:
Love what you do and pass that love to everyone you deal with. Always be positive, energetic and make progress, no matter what. What do you do in your spare time? If you’re not writing code, installing a virtual machine, reading TechCrunch/Slashdot/DZone or testing out the latest version of Windows 7, you are not passionate about technology.
I completely aggree with that. Of course there are things much more important then technology (family, friends, health etc.) but I think that passion in this context just means that technology is not just a job but also a hobby, a hobby which serendipously became ones job. And as a hobby it affects the daily life, the character and thinking. Maybe I can express it that way: A triathlet, a football fan and a technologist (to use a name which expresses the passion more then the title software developer) are on beach holidays with their kids and spouses. The triathlet will go on a beach run as soon as his kids are playing in the water and his wife is relaxing in the sun. The football fan will inform himself about the results of his favorite team. And he will buy newspapers, search the internet, call friends at home or ask other tourists until he knows how the match ended. And so is the technologist. He will pleasurably read a book about an interesiting field of technology at the beach (my beach lecture last year in south africa was The Big Switch written by Nicholas Carr). Maybe he actually will have his laptop with him to check his RSS subsrictions in the evening as soon as his family fall asleep; and some will start eclipse to try a tutorial about the new framework or SDK. Those three guys have one thing in common: While doing their stuff they feel an inner satisfaction which is motivated completely intrinsic. Friends or their partners only have little understanding and will wonder how one can be that passionate about such an apparantly unimportant thing. But this question is not really important to the triathlet, the football fan an the technologist. Especially for the technologist its just a neat sideeffect that he can make a living with his hobby. To come back to the article I mentioned above: I think that its really important to be passionate about what you do when you work as a software developer or engineer. I made experiences that there are a lot of developers who understand their occupation as nothing more as a 9 to 5 job. In a lot of cases this will be enough. A lot of projects will succeed and they will implement some beautiful systems. But at the end of the day there is no fun and little innovative potential. They will mark time without making progress for theirselfs and on the team they are working in.


