9
6

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 3 years have passed since last update.

【Dart】命名規則について

9
Posted at

はじめに

最近、流行りのFlutterを勉強し始めました(乗り遅れてるかも笑)

Swiftとは命名規則が異なっていそうなので調べてみました。

UpperCamelCase(先頭大文字キャメルケース)

classes

class MyClass { ... }

enum types

enum MyEnum { ... }

typedef

typedef MyFunction = ...

type parameters

class MyGenericClass<T> { ... }

lowerCamelCase(先頭小文字キャメルケース)

class members

class MyClass {
  int myVariable = ...

  void myMethod() { ... }
}

top-level definitions

int myGlobalVariable = ...

void myGlobalFunction() { ... }

variables

int myVariable;

parameters

void myFunction(int myParameter) { ... }

named parameters

void myFunction({int namedParameter}) { ... }

lowercase_with_underscores(スネークケース)

  • フォルダ名(my_folder)
  • ファイル名(my_class.dart)
  • ライブラリ名(my_library)

特殊

略語や頭字語

略語や頭字語は、大文字だけの文字列だと読みづらくなりますし、複数の頭字語が連続する場合には曖昧な名前になってしまいます。例えば、「HTTPSFTP」という名前があった場合、それが「HTTPS FTP」なのか「HTTP SFTP」なのかは分かりません。
このような問題を避けるために、略語や頭字語は通常の単語のように大文字で始めます。

class HttpConnection { ... }

var httpRequest = ...

例外

2文字の頭字語(例:IO)は全て大文字で表記されます。
一方、2文字の略語(例:ID)は通常の単語と同じように大文字で始めます。

class DBIOPort {}

var userId = ...  

おわり

ちゃんとドキュメントを読んだはずですが、間違っているところがあるかも知れません
もし間違っている箇所があればコメントで教えてください

9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?