From surial, 1 Week ago, written in Java.
  1.   // Note; input.getId() returns an int here;
  2.   // if invalid input was passed, as in, input that cannot be turned,
  3.   // this code would not even get called; an alternate path is chosen which
  4.   // aims to feedback to the creator of the input that they messed up.
  5.   // If it was a user, the UI shows an error dialog indicating the nature of
  6.   // their mistake (they put a non-number in a place where a number was the only thing that makes sense).
  7.   // If it was code, an exception with sufficient info to tell there is a bug,
  8.   // and makes it easy to find the line where the bug was written.
  9.  
  10.   // also, infecting your code with style crutches, such as putting a final on all fields, is bad...
  11.   // if you think changing params is bad style (debatable), config your iDE to warn on those lines.
  12.   // Don't make the code hard to read by adding keywords that convey absolutely no information everywhere.
  13.  
  14. public Output map(Input input)
  15. {
  16.  
  17.         return new Output(
  18.                 #...
  19.                 resolveId(input.getMyId()),
  20.                 #...
  21.         };
  22. }
  23.      
  24. private String resolveId(int id)
  25. {
  26.   ResponseDto dto = myMapper.resolveId(id);
  27.   // It's a bit odd that you go through a DTO for a single-string value here.
  28.   return dto == null ? null : dto.getString();
  29. }
captcha