Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • So tl;dr is: You recommend splitting into two functions because you won't have to change them when you add layers? If a layer4 is added, we may need to say "this.layer4.visibility = isHintOn", too, so I'm not sure I agree. If anything, that's a demerit against it, as now when a layer is added we have to edit two functions, not just one. Commented Jan 10, 2018 at 10:49
  • No I (weakly) recommend it for clarity (showHint vs setHintVisibility). I mentioned the new layer just because OP was worried about it. Also, we just need to add one new method: isLayer4Visible. showHint and hideHint just set the isHintVisible attribute to true/false and that doesn't change. Commented Jan 10, 2018 at 10:58
  • 1
    @doubleYou, you say longer code is not automatically less maintainable. I would say that code length is one of the main variables in maintainability and clarity, overtopped only by structural complexity. Any code that becomes longer and more structurally complex ought to deserve it, otherwise simple problems receive a more complex treatment in code than they deserve, and the codebase acquires thickets of unnecessary lines (the "too many levels of indirection" problem). Commented Jan 10, 2018 at 16:20
  • @Steve I completely agree that you can over-engineer things, i.e. make code longer without making it clearer - otoh, you can always make code shorter at the cost of clarity, so there's no 1:1 relationship here. Commented Jan 10, 2018 at 20:14
  • @Steve Think „code golf“ — taking such code and rewriting it in more lines does usually make it clearer. „Code golf“ is an extreme, but there are still many programmers out there who think cramming everything into one clever expression is ”elegant” and maybe even faster because compilers are not optimizing good enough. Commented Jan 11, 2018 at 16:58