크로스 플랫폼/Flutter <Dart>

[Dart] Effective Dart 스타일 가이드 요약

TaeGyeong Lee 2023. 10. 12. 14:58

개요

공식 문서에서 각 변수, 파일에 대한 명명 가이드 제공. 크게 3가지 스타일로 나뉩니다.

  • UpperCamelCase : 각 단어 첫 문자 대문자 
  • lowerCamelCase : 첫 단어 모두 소문자, 나머지 단어 첫 문자 대문자
  • lowercase_with_underscores : 모두 소문자, _ 사용

 

UpperCamelCase

  • 클래스
class SliderMenu;
  • 익스텐션
extension ExamlpeExtension
  • 사용자 정의 타입
typedef CustomTypeA

 

lowerCamelCase

  • 기타 변수명 및 constant 변수
userName

 

lowercase_with_underscores

  • 디렉토리 명
screen_user
  • 파일 명 (dart 파일 뿐만 아니라, 이미지 등 정적 리소스 파일 명 또한 모두 포함)
sign_up.dart
  • 패키지 import 시 패키지명
import 'dart:math' as math_dart_package;

 

참고 자료

 

Effective Dart: Style

Formatting and naming rules for consistent, readable code.

dart.dev