re: Compact or Verbose Codestyle? VIEW POST


There are two completely independent idioms that make the 2nd example more verbose:

  1. The use of if instead of boolean operators for conditions. I tend to use if as the default and sometimes refactor when I think that the code is more readable when using a boolean operator. I also know some people who always use if and consider the other variant as a misuse of boolean operators.

  2. The use of intermediate constants for function returns instead of function chaining. This can be useful for two reasons: You can use meaningful names for these constants that provide additional information about what is happening and thus make the code more readable. In this example, I would say that the names jsonStr and especially dataObj do not provide much useful information. Another reason not to chain function calls is to make debugging easier.

I personally have a certain bias towards compactness and like the 1st example slightly more. In real code, the optimum is probably somewhere in between.

code of conduct - report abuse