[progress Communities] [progress Openedge Abl] Forum Post: Re: To Return Or To Not Return?

  • Thread starter Thread starter Peter Judge
  • Start date Start date
Status
Not open for further replies.
P

Peter Judge

Guest
I agree 100% that for (internal) procedures, RETURN is optional. But I cannot stress strongly enough that it MUST be mandatory for methods and functions. (the compiler doesn’t require it). I have been bitten hard by the code below. Note that the HandleGet has no RETURN statement. The code compiles and runs. What do you think happens? Runtime error raised Method returns 0 / zero Method returns ? / unknown value The answer is 3. Which is NOT what I thought, since integer default values are 0. The moral here is that a clear RETURN statement makes it unambiguous what the value is. method protected integer HandleGet( input poRequest as IWebRequest): end method . method public integer HandleRequest( ): define variable webRequest as IWebRequest no-undo . define variable httpStatus as integer no-undo . assign webRequest = new WebRequest() httpStatus = integer (StatusCodeEnum: None ). /* Check http method and dispatch to corresponding handler */ case MethodEnum:GetEnum(webRequest: Method ): when MethodEnum: GET then assign httpStatus = HandleGet(webRequest). otherwise assign httpStatus = HandleNotImplemented(webRequest). end case . // Assume no malice here, just now knowing/forgetting to RETURN . if httpStatus eq ? then

Continue reading...
 
Status
Not open for further replies.
Back
Top