LoginSignup
2
3

More than 3 years have passed since last update.

Duck naming

Last updated at Posted at 2013-12-26

ダック・ネーミング

ほとんどの表記では、変数に糖衣構文があまりない。
もし、ドナルド・ダックを呼べば、それは来ることになる。
できれば、値のタイプは、そのキーから推論することができる。

例えば、JSONドキュメントで、これはドナルド

私の規約は・・・

Null

...で始まるキー。

\A\.{3}

例:

  • ...topside-player
  • ...result?
  • ...id#

Array

[]で終了しているキー。

.*\[\]\z

例:

  • ...coordinates[]
  • articles[]
  • 棋[]

Number

#で終了しているキー。

\#\z

例:

  • id#
  • article_id#
  • ...friends#

Hash

{}で終了しているキー。

.*\{\}\z

例:

  • last_move{}
  • ...SearchDocument{}
  • params{}

Boolean

?で終了しているキー。

\?\z

例:

  • ...result?
  • valid?
  • following?

String

他のパターン。

例:

  • ...lang
  • name
  • title

{
  "created#": 1934,
  "name": "Donald Duck",
  "male?": true,
  "...location": null,
  "aliases[]": [
    "Duck Avenger",
    "Superduck",
    "Paperinik",
    "Captain Blue Fantonald"
  ]
}
2
3
0

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
2
3