Tag Archives: java

Type safety

Consider the method findByDate that executes a query to find something by the year and month. One way of implementing this method in Java can be with two parameters year & month, both of type int. But this has some problems with passing valid arguments to methods and statically type checking.

public function findByDate(int year, int month) {
  // do stuff
}

Continue reading Type safety

Websockets in Java EE

With the JSR-356 spec websockets can be easily created and run within a Java EE container. I am using TomEE as a very lightweight and easy to install and deploy container but every Java EE 7 container should work, thanks to the EE specs.

I’m showing some easy to understand example of the Java POJO and some Javascript example code, together with some explanation about what is does and how it should work.
Continue reading Websockets in Java EE

OpenCL in Java

My first experiment with OpenCL was in XCode on Mac and I was wondering if there is also support for Java. My C/C++ skills are not what they used to be and I feel more comfortable with Java. Luckily there is a binding for Java which is called Javacl and I have tried to make the shortest working example to learn how OpenCL is working and how the library must be used. I’m sharing this example because I found that there are not many simple short examples.

At the end of the post you find the complete sourcecode I’ve used and I will describe the code in a few blocks to make clear what it does and why. You should be familiar with some of the OpenCL terminology, this helps in understanding the code.

Continue reading OpenCL in Java

The problem with dynamic languages and large projects

Abstract: In large projects it is important to find unused and old code and remove those pieces of code. With dynamic languages this is virtually impossible. It is important to clean and refactor unused parts of a system because this can become a security risk. Also a lot of “noise” is added to the system that makes it more difficult to understand the system.

While working on a large project I have the need to find pieces of code that are no longer in use. With a dynamic language and specific PHP this is virtually impossible and below I will give an explanation why that is. Continue reading The problem with dynamic languages and large projects

Is PHP suffering from a handicap of a head start?

In dutch we have a nice expression (“Wet van de remmende voorsprong”) and translated in English it is something like The Law of the handicap of a head start. A company or a product can be very innovative but after a initial success it can be too slow to react on changes and then become outdated.

In my opinion PHP is suffering from this particular problem. PHP has made a real fast start and has an made it to a great deal of the websites of today. But now it is suffering from a burden of legacy and innovation is going really slow. To name a few:

  • With the release of PHP 5.3 we finally got namespaces, Java has it by design for a decade or so.
  • Annotations are used in a “poor mans version”, in comments instead of native in the language.
  • Dynamic typing, this is not really a PHP issue but it can work out very dangerous with SQL injections that are possible “by design”. A GET query parameter is not checked anyhow. All checking should be done by the programmer instead default in the language.
  • Refactoring, with the dynamic typing comes another problem that refactoring is almost impossible in large projects. We changing a function signature you must manually search for all references and change them. The only way to find out you forgot one is at runtime. The compiler will not complain.
  • Exception handling is not always used. Some newer classes are using exception throwing when something is going wrong. But a lot of older functions are not using exceptions but still generate a plain old E_ERROR or similar. This way it is impossible to catch some errors and react on it. And then people start using the @ sign.. with all consequences.

I think PHP should react on these legacy problems by supporting optional typing (like Scala does), so a programmer can make a choice and old legacy software will keep running and professional programmers can use static typing. And maybe drop all the old procedural functions or refactor them to support exceptions were possible. This way PHP can become better in my opinion. Because Java becomes very tempting for me 🙂