RSS

Category Archives: Example Code

Brainless Getters & Setters are a Waste

Someone long ago set a pattern that all members should have a getter and setter method.  Some are persuaded that this is OO and this is encapsulation, so a lot of inexperienced programmers do this by default.  But this is a problem. Read the rest of this entry »

 
Leave a comment

Posted by on March 7, 2016 in Coding, Example Code, practice

 

Tags: , , , ,

Proper Stream Patterns

Java has streams for bytes, and streams for chars.  Learn to use them correctly.  It can be daunting at first, but if you just learn a few basic patterns, it all works well. Read the rest of this entry »

 
Leave a comment

Posted by on January 7, 2014 in Coding, Example Code

 

Tags: ,

Error Message should be clear, plain, and direct

This post is about a real error message I received and puzzled through.  Luckily, because I was working with open source code, I was able to see a copy of the source, and only then did I understand what the message meant.  An error message should not require you to know and understand the source, in order to understand the message, and I think this is the root of the mistake that many programmers make. Read the rest of this entry »

 
1 Comment

Posted by on August 24, 2013 in Coding, Example Code, Poor Error Msg

 

Tags: , , ,

#33 Eliminate Exceptional Cases before the Main Logic

When writing code, you naturally want the code to be readable so it can be maintained easily.  Generally, you try to reduce the cognitive load, and one recommendation is to handle exception cases that might occur up front, in a small, localized block of code, before falling through to the main block of logic. Read the rest of this entry »

 
Leave a comment

Posted by on December 31, 2012 in Coding, Example Code

 

Tags: , , ,

#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. Read the rest of this entry »

 
Leave a comment

Posted by on April 14, 2012 in Coding, Example Code

 

Tags: , , ,

Working Around Java’s SSL Limitations

The Java run-time environment (JVM) is able to support connections to other servers using SSL, but it has this very inconvenient behavior of refusing to connect to self-signed servers.  A self signed server has the public key necessary to ensure private communications, but does not have a certificate that proves who it is.  In the default mode of operation, when connecting to such a server, Java SSL subsystem with throw an exception and prevent all communications.  But there are good reasons why a service that you want to communicate with privately may not have a certificate, and this post tells you how to accomplish this. Read the rest of this entry »

 
5 Comments

Posted by on October 16, 2011 in Example Code

 

Tags: , ,