Refactor this if statement without an additional method
Sorry folks. I'm a bit codeblind atm. What's the neatest way to do the below without another Method (which would contain the repeated code). This feels like a code smell atm:
19 Replies
the only thing i can think of right now -- not tested at all
i was about to do the exact same thing ^
ah dammit, sorry folks, forgot to add the
cell
initiator. Updated OP. Think that kyboshes Clement's
Yep - thought of something similar, but wanted to avoid the nested ifthere's more stuff that you could do, maybe, i don't think i would make code more difficult to understand than that
The original could be better, but at least is readable and is clear on what it's doing
There's this, but it still looks smelly:
exactly
if you make an extension you could ortographically avoid the if, like
cell?.RemoveSpaceControlChildren()
; or something
but at that point i would probably rethink the whole thing instead of doing thatYeah. Problem is, it's someone else's code - working on a github fork bug shoot
Don't really know the etiquette for that
then, you know, "keep it stupid simple"
Think I'll stick with my second version - less repetative
From my perspective the second version is harder to read
hmm - which is conventionally the bigger sin? More repetition or less readable?
I think the truth is somewhere between
😆
Well, I'll post it with the alt version and see what the devs think
:Ok:
i feel like this
SpaceControl!.Root.Children!.Remove(cell);
shouldn't go 4 levels deep to do his thing
that's why to me it looks like it could have its own class with a specific method to do thisyeah - that's the original dev's code
This is one way I find myself doing a lot: