I have three views in my program (iOS app). Only one of them is ever active at the same time so I set the visibility off for two of them and switch visibility as the user presses buttons. The views are initialized as visible so I set the visibility off in code before the main view shows.  I can do  [view1 setAlpha:0.0f];[view2 setAlpha:0.0f];for two of the views, but now the third one (the one that should be visible at the start of the app) is not addressed. I put a  [view3 setAlpha:1.0f];after the first two, because I think it keeps it clear that there are in fact three views, not two as one might think when seeing the code. How do other programmers do this? Is it purely preference or are there some conventions?  If the call is very heavy, it's obviously better to not call it when that isn't necessary, but I was wondering about small things like my example.
Is it better to call a function that doesn't have an effect at that point, IF it improves code clarity?
coding style;clean code
You have an invariant:Only a single view (out of 3) is ever active (and visible).Then, I suggest that you provide a function to switch the activity and visibility of ALL views at once:[setActiveView viewID:2]This function will:check if the view is already active, avoiding unnecessary workset the view as active, and visibleset the other 2 views as inactive and invisibleIt has multiple advantages about a raw call to setVisibility:friendly: calling it unnecessarily does not create a performance issuedefensive: its single parameter is much harder to botch, whereas for setVisibility it's harder to remember that the range of values is 0.0f - 1.0f and that only one must be set to 1.0fresilient: the next guy cannot accidentally forget one of the viewsadaptable: adding/removing a view does not require scrutinizing all the application code to find where the switches are, a single function (this one) need be updatedIdeally, to help enforce the invariant, no other function should be able to mess up with this setting...