Question: 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.

Answer: 
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 work
* set the view as active, and visible
* set the other 2 views as inactive and invisible

It has multiple advantages about a raw call to `setVisibility`:

* friendly: calling it unnecessarily does not create a performance issue
* defensive: 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.0f`
* resilient: the next guy cannot accidentally forget one of the views
* adaptable: 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 updated

Ideally, to help enforce the invariant, no other function should be able to mess up with this setting...
In this particular case, @Mattieu M. has the right solution.

In the more general case, where there is no similar transform, you have to ask yourself: Is there *any* chance a future programmer might mess this up?

The answer is usually yes. Which means, yes, you should add the call. Maybe some future version of the framework starts with all views OFF instead of ON.