Skip to main content
7 events
when toggle format what by license comment
Jan 10, 2018 at 14:06 comment added Steve @GrahamLee, I think Fowler's argument is quite subtle and really rests on judgment. I wouldn't use a bool isPremium flag in his example, but I would use an enum (BookingType bookingType) to parameterise the same method, unless the logic for each booking was quite different. The "tangled logic" that Fowler refers to is often desirable if one wants to be able to see what the difference is between the two modes. And if they are radically different, I would expose the parameterised method externally, and implement the separate methods internally.
Jan 10, 2018 at 14:00 comment added Graham Lee @17of26 as a concrete counterexample (to show that "it depends" rather than that one is preferable to the other), in Apple's AppKit there is a -[NSView setNeedsDisplay:] method where you pass YES if a view should redraw and NO if it should not. You almost never need to tell it not to, so UIKit just has -[UIView setNeedsDisplay] with no parameter. It doesn't have the corresponding -setDoesNotNeedDisplay method.
Jan 10, 2018 at 13:59 comment added anon Looking at it from a similar lens: If you need to hardcode what the value will be, that's easy with either. However, if you need to set it to, say, user input, if you can just pass the value directly in, that saves a step.
Jan 10, 2018 at 13:53 comment added 17 of 26 In my experience, setSwitch(value) almost always results in less overall code than setOn/setOff precisely because of the if/else code quoted in your answer. I tend to curse developers who give me an API of setOn/setOff rather than setSwitch(value).
Jan 10, 2018 at 11:30 history edited Bart van Ingen Schenau CC BY-SA 3.0
make the code block part of the quote
Jan 10, 2018 at 10:01 review First posts
Jan 10, 2018 at 15:40
Jan 10, 2018 at 9:56 history answered Graham Lee CC BY-SA 3.0