Coding Horror – C code in disguise of Java

There is huge demand for software developers in the market but there are not enough candidates which fits the requirement of company. Thus, on and off there would be some developers who has coding issue, were hired. Today I would share some bizarre code I have seen in workplace.

Let’s start with conclusion, “He/She is a C developer instead of a Java developer. He/She is writing C code while pretending it is Java.”

The case is this: we need to generate several reports with data from database. Let’ say there are 10 reports. Here is some strange code I’ve seen, it is not the real code, I have change it and omitted some detail which is related to company’s business:

private final static String[][] titles = { {“Column A1”, “Column B1”}, {“Column A2”, “Column B2”}, {“Column A3”, “Column B3”} ,{“Column A4”, “Column B4”}, {“Column A5”, “Column B5”}, {“Column A6”, “Column B6”}, {“Column A7”, “Column B7”}, {“Column A8”, “Column B8”}, {“Column A9”, “Column B9”}, {“Column A10”, “Column B10”}};

Who use two-dimensional array for String? In this case, the column headers for each reports are not related to each other so they should not be in an array. An array is used for data which has order relationship, of the same type. This developer just use two-dimensional array for convenience. Also, there configuration stuff should be put in a configuration file so that later when we change the column header, we don’t have to compile the code again.

BufferedWriter[] bfwList = prepareBufferedWriter();

Come one, what is this? Same argument as above.


genReport1(bwList[0], dao);
genReport2(bwList[1], dao);

genReport10(bwList[9], dao);

This part is where the real work happens. It’s pain to see he/she passed a BufferedWriter to a method. It’s illogical and not necessary. To be honest, I won’t declare a BufferedWriter outside of the method. I would prefer this:

public void genReport( String filename );

The BufferedWriter I would create INSIDE the method with the provided filename ( with actual file path ). I don’t pass a DAO ( data access object ) around. The DAO should be a class member of the service class in which this method belongs to so that it already has access to the DAO.

In conclusion, it is not object oriented programming, it is a C procedural programming disguised in Java.


Leave a Reply

Your email address will not be published. Required fields are marked *