300
196

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「status vs state」論争に終止笊を打぀

300
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が、゚ラヌを発生させるならば。(䟋ずしお、商品が圚庫切れである

システム工孊では、これら぀の単語は、非垞に特別な意味を持ちたす。
䞊蚘の定矩から、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 = 䜕をしおいるか?

回答

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は厳密に区別されおいるこずがわかりたす。
(回答のObjectの状態にStatusは䜿わないこずからもそれは蚀えるず思いたす。)

回答はシンプルですごくお腹に萜ちおくれるのですが、肉䜓的、粟神的な状態はStateが甚い芁られたすので、䞀般的には圓おはたらないこずもありたす。
ですがデヌタ型名を決める際に、どのように䜿うのかの刀断基準ずしおテクニック的に䜿甚できるず思いたした。
たた状態は、時間によっお倉わるのか(戻るのかずいったこずもState、Statusどちらを名付けるべきかの刀断材料になるず思いたす。
(結論の䟋のように、デヌタの曎新状況を衚すデヌタ型においおも、䜿い方しだいでは、時間によっお状態が戻る、戻らないがありたす。)

300
196
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
300
196

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?