RSS

Category Archives: Coding

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

Advertisements
 
Leave a comment

Posted by on May 11, 2019 in Coding, Example Code, practice

 

Tags: , , ,

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 technique to improve the readability is to name the variable in java to match the key in JSON.   Simple concept, easy to do, I sometimes wonder why it is not obvious to all. Read the rest of this entry »

 
Leave a comment

Posted by on May 7, 2019 in Coding, Example Code

 

Tags: , , ,

Keep Things the “Same”

This general design principle does not mean to never change anything, but to consciously create a paradigm where the same things have the same names and are accessed in the same way as much as possible. Read the rest of this entry »

 
Leave a comment

Posted by on January 24, 2019 in Coding, Design

 

Tags: , , ,

Ultimate Java Exception Class

This is the third in a series about translatable exceptions (see Translatable Error Messages).  This post is about the class JSONException which contains the required features. Read the rest of this entry »

 
Leave a comment

Posted by on January 9, 2019 in Coding, Design, Uncategorized

 

Tags: , , ,

Exception Receiving

When you make a web service call, you want to report the problem to the user save as you do for any other part of the program, and that is through an exception object.  This post talks about converting the JSON received back into an exception object so that it can be reported properly.  This is the fourth post in a series about translatable errors for REST web services. Read the rest of this entry »

 
1 Comment

Posted by on January 8, 2019 in Coding, Design

 

Tags: , , ,

Variable Arguments for Messages

We need to construct an object which has a template and a set of parameter data values.  Java offers a couple of ways to do this, and this post shows how the variable parameter mechanism works easily and conveniently for this purpose. Read the rest of this entry »

 
1 Comment

Posted by on January 7, 2019 in Coding, Design, Uncategorized

 

Tags: , , ,

JSON Translatable Error Messages

Second in a series on translatable exceptions, this discusses how an error message should be returned as JSON from a web-service API so that it the calling program can display the error in the right language for the user. Read the rest of this entry »

 
2 Comments

Posted by on January 6, 2019 in Coding, Design, Uncategorized

 

Tags: , , ,