LoginSignup
281
188

More than 1 year has passed since last update.

「status vs state」論争に終止符を打つ

Last updated at Posted at 2017-06-18

StateとStatus、共に「状態」を意味する英単語です。
「~状態」というデータ型を定義するとき、どちらをつけるべきか悩むことがあります。
一旦Stateと名付けたものの、やっぱりStatusかなとなることもしばしば。

疑問

例えば、データの取得状況において、「更新前」「更新中」「更新済み」などの状態を管理するデータ型名はStatus、Stateどちらをつけるべきでしょうか?

結論

この結論は、そのデータ型をどのように使うかで、StatusとStateどちらをつけても誤りではないということです。
つまりどのように使うかで、StatusとStateを決める必要があります。

例えば上記のデータ型をもちいて、「データの更新状況をユーザーに表示する」ことに使うのであれば、「Status」と名付けても問題ないと思います。
(ステータスバーのように。また、ユーザーはそれをみて自ら次のアクションがとれます。例えば更新中なら終わるまで待つ。更新前なら更新ボタンを押す。つまりこれらの状態は、何らかのアクションの結果でもあります。また時間が経てば、状態は「更新前」に戻るかもしれません。)

一方そのデータ型を「処理の分岐や管理、監視する」ために使用するのであれば、Stateと名付けたほうがしっくり来るかと思います。
(画面表示時に、データが更新中ならば、ローディングを表示する。完了後にローディングを取り除き、画面を更新して表示するようにする。またこれらの状態は、何らかの変更によって状態が遷移します。しかし時間によって状態が変わることはありません。)

このように、「データの取得状況を管理するデータ型」だからStatusと名付けるべき、もしくはStateと名付けるべきということではなく、そのデータ型をどのように使用するのかで決める必要があります。

以下Stateと名付けるべきときとStatusと名付けるべきとを表にしました。

名付けるべき使用例 参考例
status * 何らかの結果として使用する場合
* 進捗状況を表す場合
OSの返り値(exit status)、HTTPステータスコード(200 OK, 404 NOT FOUND)、プロジェクトの進捗(調査中、テスト中)、社会的地位、ステータスバー
state * 観測的に使用する場合
* 時間ではなく、何らかの変更によって状態が自動的に遷移する場合
ステートマシン、物体の状態(固体、液体、蒸気)

イメージ的には以下
State
stateイメージ図.png

Status
statusイメージ図.png

調査内容詳細

以下、上記の結論と理由に至った調査結果をまとめました。

English Stack Exchangeから

status vs state

質問は例として、プロジェクト(Project)や物体(Object)においてStateとStatusはどういった違いがあるのかを聞いています。

回答1

In that context, status would refer to the progress of a project, e.g. in testing, in preliminary research, etc. State would refer more to the condition of a project, e.g. green-lighted, cancelled, on hold for financial analysis.

When referring to a specific object, you typically want to use state, e.g. cold, hot, liquid, solid (this refers to the object's physical state). The status of an object is rarely used or mentioned, unless it is something that moves or transforms, in which case it is used to mean distance or progress.

簡約

文脈によりますが、Status はプロジェクトの進捗です。例として、「テスト中」「予備調査中」など。
State はより多くのプロジェクトの状態になります。例として「グリーンライト」「中止」「財務分析のための保留」

特定の物体にたいしては、一般的に state を使います。例えば、「冷たい」「熱い」「液体」「固体」(これらは物体の自然科学のstateです)。
statusは物体に対して使用することはありません。
しかしながら、それが何らかの移動、変形するのであれば、その距離、進捗を表す際に用いられます。

回答2

I find the systems engineering definition useful here. A system is in a certain "state" at a point in time when the system meets a pre-defined set of criterion, i.e. on shopping website, a user's shopping cart enters a different state when the customer adds an item to it.

A "status", in the context of states of a system, describes the transition into a state. For example, the user of our online shop may attempt to add an item to their cart. The transition into the state that describes the item being in the cart may be blocked if the status of the transition signals an error (i.e. the item is out of stock).

In systems engineering, these two words have very specific meanings. From the definitions above, it could also be inferred that a state exists (or does not exist) irrespective of time. A status, however, describes the outcome of an action at a particular point in time. The difference here, I think, holds true even outside the context of systems engineering.

In the context that you describe, the definitions above are still relevant. The state of the project maybe described as, "component A is complete but component B is not; the project is 60% complete overall". This description of the state of the project would be the same at any point in time given unchanged progress of components A and B and unchanged outside influences. The status of the project however would almost certainly change with time, likely with respect to a deadline.

こちらはまずショッピングサイトを例にしてStatusとStateを説明してくれています。

簡約

私は、よくシステム工学の定義から理解します。
システムは、ある時点において、確定された"state"の中にあります。
それはそのシステムが、予め定義された基準の集合を満たす時です。
例として、ショッピングサイト上において、ユーザーが商品をカートに追加した時、ユーザーのショッピングカートは異なった state に移動します。
(※ おそらくカートに「商品がないというstate」から「あるというstate」にということを言いたいのだと理解。)

"Status"は、システムのstatesの文脈において、あるstateへの遷移です。
例えば、オンラインショップのユーザが、商品をカートに追加するとします。
この時カートの中に商品があるというstateへの遷移は、ブロックされるかもしれません。
もしその遷移へのstatusが、エラーを発生させるならば。(例として、商品が在庫切れである)

システム工学では、これら2つの単語は、非常に特別な意味を持ちます。
上記の定義から、stateは、時間に関係なく、存在する(もしくは存在しない)と推測することが出来ます。
一方、statusはある特定の時点におけるアクションの結果になります。
ここの違いがシステム工学だけでなく、他においても同じであると思います。

質問にあてはめると、上記の定義が関係していきます。
プロジェクトのstateは、もしかしたら「コンポーネントAは完了である、しかしコンポーネントBはまだである。プロジェクトは全体として60%である」と言った具合に記述します。
この時プロジェクトのstateは、コンポーネントA、Bの進捗もしくは、外部からの影響から変更されなければ、常に時間に関係なく同じである可能性があります。
一方プロジェクトのstatusは、ほぼ疑いなく時間に追随して状態が変わる可能性があります。
例えば、「デットライン」のように。
(※ 期日が来ると自動的にStatusがdeadlineに変わると言いたいのだと理解)

Stackoverflowから

名前の取り決め: "State" vs "Status"

質問

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?

名前つけるときに、StateとStatusどちらをつければいいのか?

回答1

IMO:

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

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

上記は一番アップボートが多かった回答。

  • Status = 調子はどう?
  • State = 何をしているか?

回答2

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.

簡約

それは文脈に依存します。

Stateは一般的に、属性の全てのstateになります。 - 特定の時点における、取りうる値や関連の全て。

Statusは、多くのある時点です。それはつまり、何かにおける過程や作業工程になります。 - 汚れているか (従って保存する必要がある)、完了しているか、入力待機中か、など

調査内容まとめ

「English Stack Exchange」は英語を学ぶ人のためのサイトなので、一般的に英語ネイティブの方がStateとStatusをどのように使い分けているのかを解説されています。
回答の中には、Statusが使われるところでは、別にStateも使えるんじゃないかしらと行った意見もありました。
「Stackoverflow」は、プログラマーのためのサイトで、質問もStateとStatusどちらを名付けるべきかといった質問になっています。
また回答を一行でまとめていくと以下のようになるかと思います。

  1. Stateはより様々な状態を表せるが、Statusは物体(Object)では使用されない。もし使うのであれば、その変形や移動の進捗、距離において使う。
  2. Stateは時間に関係せず、Status時間に関係する。
  3. Stateは 「今何をしているか」であり、Statusは「調子はどうか」である。
  4. Stateは属性が取りうる全ての値であり、Statusは多くの時点である。

上記から、技術的な用語としては、StateとStatusは厳密に区別されていることがわかります。
(回答2のObjectの状態にStatusは使わないことからもそれは言えると思います。)

回答3はシンプルですごくお腹に落ちてくれるのですが、肉体的、精神的な状態はStateが用い要られますので、一般的には当てはまらないこともあります。
ですがデータ型名を決める際に、どのように使うのかの判断基準としてテクニック的に使用できると思いました。
また状態は、時間によって変わるのか(戻るのか)といったこともState、Statusどちらを名付けるべきかの判断材料になると思います。
(結論の例のように、データの更新状況を表すデータ型においても、使い方しだいでは、時間によって状態が戻る、戻らないがあります。)

281
188
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
281
188