77

Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist:

  • When a variable holds a value intended to indicate that something is in a certain state, the name of that variable more often than not contains the word "state", or an abbreviation thereof.

  • However, when the return value of a function serves to indicate some such state, we tend to call that value a "status code"; and when that value is stored in a variable, this variable is commonly named "status" or something similar.

In isolation that's all fine I guess, but when the aforementioned variables are actually one and the same, a choice needs to be made involving the perverted intricacies of English language (or human language in general).

What is the prevailing coding-standard or convention when it comes to disambiguating between the two? Or should one of those two always be avoided?

This english.stackexchange question is also relevant, I suppose.

6
  • 2
    Hence this attempt at crowdsourcing. This is very much not the place for opinion polling, though. Nov 24, 2013 at 2:20
  • Not on any Stack Exchange site; a forum perhaps? Nov 24, 2013 at 2:35
  • 1
  • 12
    The status of this question will soon be closed, but it will remain in an active state for sometime afterwards.
    – Reactgular
    Nov 24, 2013 at 14:23
  • 1
    I know the question is closed but I disagree with a reason. It's not an opinion, it seems to be universally understood whenever a concept of an FSM (final state machine) is being discussed. A machine can be in exactly one of a finite number of states at any given time. A status informs which state it is in. Assume a set of states for an object: a->b->c. A possible status of this object could for example include: "doesn't exist", "in state a", "in state b", "in transition between states a and b", "waiting for a condition to transition to state c", etc.
    – cprn
    Jul 25, 2018 at 16:21

3 Answers 3

80

I like this question. The following is from my head but I think it fits quite well.

  • status is used to describe an outcome of an operation (e.g. success/fail).

  • state is used to describe a stage in a process (e.g. pending/dispatched).


I also like this definition:

  • status is a final (resulting) state.

It is quite clear when applied to programming. Much less clear when you apply it to natural language. Let's take the examples from the english thread and see if it holds with the most upvoted answer.

"What is the current status of this project?" The answer should be "In testing."

Well, this might seem to contradict my definitions at a first look but we must realize the context. Probably some supervisor is asking his team about the project and how far they have reached. The point is that the supervisor is interested in the outcome up to now. The fact that there will be something after is just put away because it is not the point of the question.

"What is the current state of this project?" The answer should be "On hold for financial analysis."

So I think that this very nicely demonstrates an essence of a state. "On hold for financial analysis." clearly focuses on the fact that the current situation is a part of some encompassing process and even suggests the next state.

I would say it holds pretty well.

2
  • 2
    These are the most useful definitions for programming in my opinion. I use "status" when I'm willing to basically describe if the operation was successful or not, and "state" for more descriptive and detailed descriptions.
    – cprcrack
    Jul 10, 2018 at 16:46
  • 1
    Your first definition (outcome/stage in a process) makes a lot of sense. I don't feel the same about the second def using the word "final".
    – oferei
    May 16, 2021 at 14:13
5

"State" makes me think of "state machine", and I typically use it to refer to something internal / technical, like, "open", "parsing header", "negotiating formats", "reading text", "reading video", etc. Something a fellow programmer might care about, but not intended (much) for the end user. Maybe if they ask for more details on an error, but not the first thing they see.

"Status" is less techie and more for an end user, e.g. "reading", "error 404", "success 200".

All IMHO.

4

From what I've seen "state" is often used for things that can change and the programmer has at least some modicum of control over how/when it changes (even if indirectly). It also almost always is used to refer to positive states. "You have placed the connection into a disconnected state."

"Status" tends to be the opposite. It tends to be used for things that happen without the programmer's input - and often that the programmer cannot change. It also tends to be used for for negative statuses. "The status of your connection is (checking...) disconnected."

Not the answer you're looking for? Browse other questions tagged or ask your own question.