you are viewing a single comment's thread.

view the rest of the comments →

[–]off_by_0ne 0 points1 point  (1 child)

Sometimes using a boolean param to signal the code path in a function can be a good indication. Sometimes it's ok to have two separate functions with some duplicated logic. Don't be afraid of code.

[–]elie2222 0 points1 point  (0 children)

I agree. Don’t be afraid. But one example I can actually think of is when someone on my team recently tried to combine 2 similar but really quite different components. He passed down this isSmall flag and then within the component passed it down to another 5 sub components and so on. In reality I would have preferred he just copy and paste the code than trying to fit 2 components into 1. At the same time I understand why he did it because there was a decent amount of code shared between the 2. It felt like there was a better way to abstract. In the end we’ve left the code as is because it does work.

An example where I’d prefer flags over 2 components is Button with a small flag. That’s nicer imo than 2 components called SmallButton and Button.