Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions: "State" versus "Status" [closed]

Quick question: I'd like to hear your thoughts on when to use "State" versus "Status" when naming both fields such as "Foo.currentState" vs "Foo.status" and types, like "enum FooState" vs "enum FooStatus". Is there a convention discussed out there? Should we only use one? If so which one, and if not, how should we choose?

like image 885
Sophistifunk Avatar asked Jul 22 '09 02:07

Sophistifunk


People also ask

What is difference between state and status?

Status is the precision of describing the situation while state is a general description.

How do you define a naming convention?

A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.

What is the naming convention for variables in Python?

Rules for Python variables: A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

How do you name a service program?

There is no "special" convention for naming service classes. They are classes so they should be a noun(s) in singular form in CamelCase: Customer , Company , Employee , UserService , WrapperManager , FileStream , etc.


8 Answers

IMO:

status == how are you? [good/bad]

state == what are you doing? [resting/working]

like image 196
spemble Avatar answered Oct 14 '22 21:10

spemble


It depends on the context

State generally refers to the entire state of an entity - all its values and relationships at a particular point in time (usually, current)

Status is more of a time-point, say, where something is at in a process or workflow - is it dirty (therefore requiring saving), is it complete, is it pending input, etc

I hope that helps you in your decision.

like image 28
Luke Schafer Avatar answered Oct 14 '22 19:10

Luke Schafer


Typically I will use State to mean the current condition of an object or the system as a whole. I use status to represent the outcome of some action. For example, the state of an object may be saved/unsaved, valid/invalid. The status (outcome) of a method is successful/unsuccessful/error. I think this jibes pretty well with the definition of status as "state or condition with respect to circumstances," the circumstances in this case being the application of an action/method.

like image 37
tvanfosson Avatar answered Oct 14 '22 21:10

tvanfosson


Another (entirely pragmatic) reason to prefer state over status is that the plural is straightforward:

  • state -> states
  • status -> statuses

And believe me, you will sooner or later have a list or array or whatever of states in your code and will have to name the variable.

like image 20
robinst Avatar answered Oct 14 '22 20:10

robinst


I think many people use "Status" to represent the state of an object if for no other reason than "State" refers to a political division of the United States.

like image 27
Dave Markle Avatar answered Oct 14 '22 19:10

Dave Markle


I think you could add another perspective to the equation, namely 'sender-requester'.

From a senders perspective, I'd communicate my state with anyone willing to listen. While from a requesters perspective, I'd be asking for someone's status.

The above could also be interpreted from an uncertainty point of view:

  • Defined = state
  • Undefined = status

What's your status? I'm in a relaxed state.

I'm pretty sure this is just one interpretation, which may not apply to your particular situation.

like image 28
Michel Verkaik Avatar answered Oct 14 '22 21:10

Michel Verkaik


A quick dictionary check reveals that status is a synonym for state, but has an additional interpretation of a position relative to that of others.

So I would use state for a set of states that don't have any implicit ordering or position relative to one another, and status for those that do (perhaps off-standby-on ?). But it's a fine distinction.

like image 44
Brian Agnew Avatar answered Oct 14 '22 21:10

Brian Agnew


A lot of the entities I deal with (accounts, customers) may have a State (TX, VA, etc.) and a Status (Active, Closed, etc.)

So the point about the term being misleading is possible. We have a standardized database naming convention (not my personal choice) where a state is named ST_CD and a status would be ACCT_STAT_CD.

With an enum in an OO milieux, this issue is not as important, since if you have strict type safety, the compiler will ensure that no one attempts to do this:

theCustomer.State = Customer.Status.Active;

If you are in a dynamic environment, I would be more worried!

If you are dealing with a domain where state machines or other state information and that terminology is predominant, then I would think State is perfectly fine.

like image 29
Cade Roux Avatar answered Oct 14 '22 19:10

Cade Roux