Review main Abandoned

71188[TASK] Return early in switch statements

Simon Schaufelberger CR 0 V 0 Hard +165 −287 updated 11/03/21, 16:06

Commit message

Reduce lines of code and return early in switch statements
and optimize some other return values

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 14

Review log 810

  1. Simon Schaufelberger uploaded patch set 1 09/22/21, 16:20

  2. core-ci voted on patch set 1 V -1 09/22/21, 16:35 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/17057

  3. Simon Schaufelberger uploaded patch set 2 09/22/21, 16:45

  4. core-ci voted on patch set 2 V +1 09/22/21, 17:14 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/17062

  5. Oliver Klee commented on patch set 2 09/24/21, 09:05

    I strongly recommend not doing this. The reason is (that I think) that early returns in the middle of a function make it harder for the reader to get an overview of what a method returns. This is a lot easier if a method only returns at the end and (for guard clauses that check error cases, null cases etc.) at the very beginning.
  6. Oliver Klee commented on patch set 2 09/24/21, 09:06

    This is a good starter concerning guard clauses: https://dev.to/codebryo/the-power-of-guard-clauses-5d3h
  7. Simon Schaufelberger commented on patch set 2 09/24/21, 12:00

    Reply

    I like the early returns and by the way, the core uses them a lot in other places as well(!) because you know that there is no more code executed after that and you are sure that this is the final return value (no more hooks for example)
  8. Oliver Klee commented on patch set 2 09/24/21, 12:50

    Reply

    I know that the core uses a lot of early returns. And I still think that they (with the exception of guard clauses) are detrimental to code readability and maintainability. I'd like to move this discussion away from what we like (i.e., the feelings), and instead move it to what helps code readability and maintainability
  9. Christian Kuhn commented on patch set 2 11/03/21, 16:06

    Hey. I'll abandon this patch and I hope it's fine: It mixes multiple topics into one patch, and it's kinda hard to find consensus on all of them. I guess we could argue on each details for a long time and there's a lot of personal taste involved. Imho, *if* we want to go ahead here, it would be helpful to reach consensus up front *and* come up with a rule for instance using phpstan to fix it once and for all *and* ensure to keep that state. These kind of things are patches one would want to do exactly once and then never think about again but auto-maintain it with a cgl fixer.

    QueryView.php:849 Unresolved

    I'd argue coders are used to switch & break combinations and actively look for it.

    LocalDriver.php:735 Unresolved

    These are actually useful at times and I tend to keep them (why not?): It helps adding a break point just before the return.
  10. Christian Kuhn abandoned the change 11/03/21, 16:06