• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this a good coding practice?

 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is one of the code piece, where the method has a series of steps to be performed.
The successful execution of the first step is a prerequisite for proceeding with the second step. If there is a failure in step 1, the control should reach the end of the method and continue further.The steps continue this way. The reason for the failure of a step is to be noted in 'valueForReport'. With this in mind, I have used 'success' as a marker for proceeding through all the steps.
Please tell if this way of coding is right/advisable/ideal. If not, how should this situation be handled. I face this kind of situation in my regular work too and hence your suggestion will be very useful.
Thanks in advance,
Rajesh
 
Marcel de Jong
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would write that piece of code like this:

Where the method findFlightUtil(criteria, modelName) throws a DataNotFoundException, or another user defined exception.
In this way you don't need you success variable and in my option its more readable.
Regards,
Marcel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic