Take the 2-minute tour ×

Should a programmer be able to perform all operations programmatically on a object that a user could do?

By way of example, I'm working with a list selection object. To populate the list List.AddItem(itemData) is repeatedly called until it is built. A user can then:

  • View the entire list
  • Select a single item from the list

However there is no programmatic way to list all of the items. Nor is there an easy way to set an item as selected. You can if you keep track of what was added to the list and call List.SelectItem(itemData). This means you'd have to maintain an independent list of the items separate from the object, which could cause it's own problem (This bit of ugliness isn't necessary to the question, but part of the motivation).

In general if a user can get information about an object or perform an action on an object should this same functionality be available to the programmer and not hidden? I suspect the answer is "yes" but recognized I may be overgeneralizing from this one case that I'm unhappy with.

share|improve this question

closed as not a real question by gnat, Glenn Nelson, unholysampler, GlenH7, Michael K Feb 7 '13 at 19:10


This question is really vague. I would say yes but it's not altogether clear what you mean. Are you asking if the code should always model the UI? –  Jimmy Hoffa Feb 7 '13 at 16:29
I think it depends on where you're using this, web or desktop, but itemData could have information on whether it's selected. In the case of a web app you could have an array of selected ids that you could use to match with the ids from the original list. When you post back a select list all you get is the values, not the original list object of course. –  The Muffin Man Feb 7 '13 at 16:33
I have voted to close, but I think you potentially have a really good question in here. Please edit and revise your question so we can understand what you're really asking. If your question ends up closed, you can flag it for moderator attention after the edit and then request a re-open. Chat and Meta are available to help discuss how to make this question more constructive. –  GlenH7 Feb 7 '13 at 18:56
Why on earth would a programmer not have access to part of the model? He's the guy coding it! –  Michael K Feb 7 '13 at 19:10
@GlenH7 I'm trying to ask a philosophical question about practice. For instance information hiding is a good practice. I'm asking something like "Is it ever good practice to hide functionality that a user has access to." –  Rob Mosher Feb 7 '13 at 20:30
show 2 more comments

1 Answer

What you're asking is really "Should the programmer have access to the applications state?". I would argue yes. The situation you're describing lacks a clear separation between the model and view of your application. Specifically the state of the model seems to be wrapped up in view code.

With better separation of concerns you would have a model that held a list object, and a view that then reflected that list. You could then manipulate the list as you chose.

So to answer your original question, I would say YES the programmer should be able to do anything the user could do, because the full state of the application should be held in the model where the programmer has access. The user should simply be interacting with a view that exposes ways to interact with the model to which a developer has full access.

share|improve this answer
add comment
