Notes of a (Java) developer

Software developers Programmers

Decoding simple JDT signatures

Software developer Programmer

The JDT sometimes returns simplified type signatures, for example the IMethod#getParameterTypes() method can return values such as QString instead of java.lang.String.

To decode such values, the org.eclipse.jdt.core.Signature class provides utility functions. Signature#getSignatureSimpleName(String) transforms QString into the simple name, i.e. String.

To get the full name, the containing type allows to resolve the simple name. IType#resolveType(String) transforms this simple name using the imports of the containing type. The result is an array with two dimensions. The first one is for the case where there are multiple answers possible. The second one separates the name of the package and the simple name.

The following code returns the first full name of a method return type:

	String name = method.getReturnType();
	String simpleName = Signature.getSignatureSimpleName(name);
	IType type = method.getDeclaringType();
	String[][] allResults = type.resolveType(simpleName);
	String fullName = null;
	if(allResults != null) {
		String[] nameParts = allResults[0];
		if(nameParts != null) {
			fullName = new String();
			for(int i=0 ; i < nameParts.length ; i++) {
				if(fullName.length() > 0) {
					fullName += '.';
				}
				if(nameParts[i] != null) {
					fullName += nameParts[i];
				}
			}
		}
	}
	return name;

An exchange on stackoverflow details the code for parameters types full names.

Web components and the Polymer project

Software developer Programmer

At Google I/O 2014, Polymer was introduced in deep by Eric Bidelman. Polymer is a very interesting move by Google</meta> </meta> promoting in some way a W3C work: Web components. I try to sum up here all I learned from the Polymer tutorial.

What is the relationship between Web components (as a W3C recommendation) and the Polymer project (as lead by Google) ? In a few words, Polymer bridges the gap between the work pending in the frame of the recommendation working group and the features implemented by browsers. This is done via a simple Javascript, platform.js. The Polymer project also provides a set of initial web components to simplify the development of web-component-based applications.

Web components are custom HTML tags. How is the behavior and rendering of such elements defined ?

The components definition relies by convenience on another W3C recommendation, HTML imports. Introduced as a new link type (import) the principle is simple. This allows to include an external resource into an HTML resource. The practice for Web components is to use an included resource defining the behavior of each custom element in order to allow reuse of that definition. Web components could of course be defined without imports but this would be of limited interest. A singularity about HTML imports is detailed in a blog post by defining multiple imports using a same library (e.g. jQuery) can be challenging to load for browsers. Strategies have to be found to reduce loadings.

One important point is in the naming of custom element. As explained in that article by each name should contain a dash in order to avoid conflicts with standard HTML elements (which are still important because needed in the definition of custom elements).

In the introduction, Bidelman</meta> states that every framework is compatible with DOM . Indeed, as a result of the document structure simplification induced by Web components, this is a huge change in the way information is provided on the Web. This won't change so much for end users in the first place.

On a software engineering point of view, the step could be a real revolution: information provided by the Web server could have a same structure for a Web browser and for any software client. HTML would really look like an XML document, except for the head imports.

What will make the real success of Web components is the behavior of software giants. And with Polymer, Google seems to be seriously involved. Could it be a serious move to use Web standards in replacement of any Android API challenged by the Oracle lawsuit ? Perhaps the end of the mobile native / Web apps dichotomy ? Is it a dream ? Still a long way to go for involved engineers, but so many promises...

Edit (2014-12-26): the platform.js script has become webcomponents.js.

WEB WEB COMPONENTS W3C POLYMER GOOGLE

Apple SSL case: code quality

Software developer Programmer

The point is clearly about programming practice. In February 2014, Apple faced an SSL bug. This was a very simple code mistake due to conditional sequences.

Because of the conditional aspect, we easily focus on curly braces. Two comments suggested the solution to such a problem could be about test cases (both articles provide simple code extracts of the guilty section):

  • Apple's SSL/TLS bug by
  • Reflections on Curly Braces by </li> </ul>

    For sure, testing is an important point in code quality. In an ideal world there would be a test case for any code piece. For sure, there are excellent other tools. I previously wrote about design by contract. Coding a verified program, checking 's axioms is also an important topic. When it comes to software quality, I won't say any practice is inappropriate.

    Stop dreaming about a world with perfect programs. Let the code verification/prove apart and come back to the code. Adam Langley also suggests code reviews are important. Curly braces ? Perhaps the point isn't central. What matter is a readable code. Some interesting code conventions exist, especially in large organizations such as Google (the naming section is especially interesting). But is respecting rules enough ? Many programmers write endless code sequences. What could be the solution ?

    We, French people, tend to be very verbose in our texts. At school, we are taught to be concise. We do not succeed in any case. How would it be possible in code ? Think about Twitter 140 characters. Just consider what a French journalist could write in 2011. Nowadays, very few journalists still criticize the system. Conciseness can be very precious.

    When it comes to quality control, human verifications are weak. I think the twitter limitation is an interesting idea. In writing programs, we have the advantage of compilation to induce strict checking. Why don't compilers warn when a function exceeds 100 lines (or any number that suits you, to be honest the guilty section is only 80 lines long) ? At first glance, this is not the exact topic because this would not have prevented programmers from coding that bug. In broader sight, I tend to think the solution to that kind of problem is in static checking . It won't be possible to automatically test any piece of written code, or even review it properly.

History of computing: information processing and transactions

Software developer Programmer

"Computer science is no more about computers than astronomy is about telescopes" said Edsger Dijkstra.

I have always been interested in the two sides of computing:

  • Calculus
  • Information processing

In the early ages of computing, we tend to focus on the first machines and their calculus properties. inventions are famous.

But in the early 19th century, the pioneer was also interested in information processing and transactions. Reading an article I discovered he described the processes involving bank transactions in one of his works: On the Economy of Machinery and Manufactures.

Point of view: MVC frameworks

Software developer Programmer

After some (bad) experiences, I am quite sceptical about MVC frameworks. The hall of fame has accepted a few names: Struts, Play, Wicket... And then ?

Each period has its champion. Struts, as one of the elders, had a long period. So many developers had to use it. But what about software maintenance and evolutions ? Software dependencies between the model, the view and the controller can make moves very challenging. Struts 1 upgrade to version 2 ? What about moving to another technology ?

Quite a nightmare, it is sometimes easier to rewrite completely the application. In my point of view, long term solutions rely directly on the Java platform. The classic Servlet / JSP tandem is not an MVC implementation but is plain and simple and evolutions are easy. I understand JSF enthusiasts. The solution is modern and interesting on a productivity point of view. I have a personal problem with JSF (and others share my opinion) : JSF and JSP are bad companions. What a shame for two specifications...

While the RESTful architectural style is trendy, the idea of integrating JAX-RS and JSPs is interesting (part of Jersey). Hope it will be part of the core specification someday.

Edit (2014-08-21) : the JAX-RS / MVC integration was part of the JSR 339 initial request but was dismissed in the final specification. A recent message on the specification list let me have some hope...