Category Archives: Example Code

BibTeX: What Authors Need To Know

Books and article with cite other references.  LaTeX will format the references (bibliography) section quite well and quite automatically as long as it is given a BibTeX file to read the information from.   If you have a list of references … Continue reading

Posted in Example Code, LaTeX | Tagged , , , | Leave a comment

Good Error Messages Can Be Easy

Here is an error message I encountered one day.  It is frustrating, because obviously the code was checking something, but it is frustrating because you get no real clues what the problem really was, and a simple change would make … Continue reading

Posted in Coding, Example Code, Poor Error Msg | Tagged , , , , , | Leave a comment

Return Null or Exception?

I am writing a getter function, and the requested object can not be found.  Do I return null?   Or do I throw an exception?  The answer is “it depends.”  Sometimes both options are needed, but how to decide?

Posted in Coding, Example Code, practice | Tagged , , , | Leave a comment

Variable Names & Key Values

Constructing JSON in Java can be a bother.  The most standard JSON library requires objects to be created, and then called to put the members on there.  So much easier in JavaScript, but it is not Java script.  Still, one … Continue reading

Posted in Coding, Example Code | Tagged , , , | Leave a comment

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 … Continue reading

Posted in Coding, Example Code, practice | Tagged , , , , | Leave a comment

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.

Posted in Coding, Example Code | Tagged , | Leave a comment

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 … Continue reading

Posted in Coding, Example Code, Poor Error Msg | Tagged , , , | 2 Comments

#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 … Continue reading

Posted in Coding, Example Code | Tagged , , , | Leave a comment

#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 … Continue reading

Posted in Coding, Example Code | Tagged , , , | Leave a comment

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 … Continue reading

Posted in Example Code | Tagged , , | 5 Comments