Some programmers believe that constants are the source of all goodness, because it means in the future that everything will be malliable. Particularly programmers paid by the hour. This is a mistake. Readibility suffers if constants are abused. I am reading some code today which exemplifies this. Continue reading
Tag Archives: Java
Don’t Baby Your Builds
In a conversation this week, one developer insisted that a special build machine should be built to assure that the build is always comes out the same. My response: if your project is building differently on different machines, then you have a much deeper problem. Continue reading
HttpServletRequest Path Decoding
The documentation on HttpServletRequest is very poor, and this fills in a critical set of facts that you need to know to write a TomCat application. Continue reading
Don’t Fear the Lowly Static Method
When people first learn object oriented programming (is there any other way) they seem to want to abandon all non-member methods (such as static methods) as being anti-object-oriented. This is foolish. There are times for objects, and times for static methods. Continue reading
Never Use StringTokenizer
You should Never Use StringTokenizer. That is a strong statement. It is a bit of an exaggeration. But in my experience, every case where StringTokenizer has been used that I have seen, has been an abuse of the original concept, and ended up in larger, more complex, and harder to maintain code. Continue reading
Public or Private Member Variables?
When is it OK to make member variables public? Continue reading
Method Exception Signature
In short, all interface methods, if they throw anything, should be declared to throw ‘java.lang.Exception’ and never a specialized exception class. Find this surprising? then please read on. The original goal to allow methods to declare the type of exceptions they might throw was a valiant attempt to clarify program behavior, but unfortunately it was misguided, does not work, and if used incorrectly can turn into a maintenance nightmare. Continue reading
File Path Manipulation
Three guidelines that make sense when handling files and paths.
- Never Use Backslash in File Paths
- Don’t use File.pathSeparator
- Converting slashes from the user
Continue reading
#27 Don’t Declare Variables at the Top
Somewhere long ago you attended a course that said that all variables should be declared at the top of the method. Modern languages allow you to declare the variable at the point in the code that it is initialized and this is a significant advantage. However, the outdated idea of declaring all variables at the top of the method persists. This post explains why this is a bad idea. Continue reading
#25 Never Convert Exception to String before Display Time
Proper handling of exceptions means that you keep it as an Exception object through all processes, particularly wrapping with another exception. A common error I see programmers doing is to convert the Exception to a String and use that as part of a new Exception for rethrowing. Don’t do this. Continue reading