Stand still and watch the patterns, which by pure chance have been generated: Stains on the wall, or the ashes in a fireplace or the clouds in the sky, or the gravel on the beach, or other things. If you look at them carefully you might discover miraculous inventions. (Leonardo da Vinci)
 

5 Principles to improve your Code Quality

March 18th, 2009 Development| No Comments »

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?


Questions I ask during Job Interviews

March 3rd, 2009 Recruiting| 3 Comments »

In my current job I am responsible to interview new candidates for the developer team. Since this is the first time that I am sitting at this side of the table I had to develop my own system of questions that would lead to the informations I need to decide whether someone is suitable for the team or not.

I want to share those questions:

1. Methodology

  • What is agile software development? Do you know or have any experiences with the agile principles? What is your opinion about agile team and organizations.
  • What is code refactoring? What is it used for? Do you have some best practices how you refactor your code?
  • The topic is debugging: How do you handle bugs?
  • What is Test-Driven-Development? What is your opinion about TDD? What would you say if I tell you that I do not like TDD at all.
  • Do you know design patterns? Did you use them already? What is your favorite one? How do you learn design patterns?
  • What is AJAX? How does AJAX work? What is the difference between AJAX and Web2.0?
  • Can you handle the words cohesion and seperation of concern?

2. Thinking

  • I tell you to learn a new programming language, say Ruby. How do you organize the learning? What will you do first?
  • What would you do if I give you 5 million Euro to launch a start up?
  • What is the most important thing you want to do within the next two years?
  • What is my company, the company you want to work for, doing? How do you figure the underlying technology we’re uisng to do exactly this?
  • Which 5 books did you read last?

3. Common chat questions

  • Do you like google? What do you like about it?
  • What are current innovations in the java ecosystem?
  • It is your task to design a database which holds personal data about some million people. What is the significance of data privacy protection?
  • How did the internet change techologically during the last 5 years? How does the future look like?

4. Java Questions

  • What stands transient for?
  • What are annotations? What are they used for? What is your opinion about using annotations?
  • What are the principles of programming servlets?
  • What is the session scope? Are there other scopes? What are they used to?
  • Tell me about the life cycle of a standard java application and a servlet.
  • Is it possible to use Multithreading in Servlets? Should you?
  • What is the differnce between a stack and a queue?
  • What are the technical principles o a hash map?
  • What are Generics? How do you use them? What is your opionion about generics?
  • Describe the deployment of a Java Application.
  • What is JDBC? What is Hibernate? When do you use them?
  • Why is the main method static?
  • Which impacts does the final modifier have on object references?
  • How do you let the JVM execute some code right before the main method is invoked?
  • What is reflection, what is introspection?
  • What is the basic idea of a java bean?
  • How do you optimize the performance of a loop?
  • What is the difference of a servlet and an applett? What does they have in common?
  • How do you forward a http request from a servlet to a JSP? Which pattern can you realize by doing this?
  • What are the priciple of RMI?
  • How do you integrate some native C-code to a Java Class?
  • What is JUnit and how do you use it?
  • Is it possible to realize a Callback mechanism in JAVA?

5. PHP questions

  • Tell me about arrays in PHP? What are the principles? What do you not like about arrays in php?
  • Can you name some array sorting functions in PHP?
  • How do you write multiple variables using echo? What is the fastest way doing that?
  • What dou think, is PHP object oriented? Why?
  • What is the difference between “1″ and “True”?
  • How do you write to the end of a file?
  • How do you define constants in PHP classes?
  • Is it possible to overload methods in PHP?
  • How do you use callback functions in PHP?
  • What additional features do you think should a future version of PHP provide?
  • What is Zend?
  • What is Pear?
  • What about type safety in PHP? Any opinions?

6. Logic

  • Connect all dots using just 4 lines:
  • There is a town with two hospitals. One is very big, the other is quite small. On one day the newspaper says: 3 boys and 9 girls were born yesterday. What do you think: Which hospital is more likely to have such rates?

7. Opbject Oriented Principles

  • What is the difference between an abstract class and an interface? When do you use the one or the other? What impacts does each have?
  • What do you understand by encapsulation?
  • What is polymorphism? Can you give me an example?
  • What are alternatives to object oriented languages? When do you use them?
  • What happens when you instantiate an object?