반응형

 Apple 개발자 사이트, StackOverFlow 몇가지 참고해서 작성한 자료이다. 초보자들에게 매우 유용한 자료가 될 것이다.

 

기본

1. 영어로 쓴다.
2. 동사로 시작한다.   Device.getMessage();

3. do, does는 쓰지 않는다.

4. 표준 접두사(standard prefixes)를 활용해라 (get, set, is/has/can/etc)

5. 도메인 언어(업계 언어)로 작성해라. 

bankAccount.setMoney(new Money(200)) 보다

bankAccount.deposit(new Money(200))이 더 좋다. 

이유는 추상화 단계가 높고, 업계 용어를 썼기 때문에 더 가깝게 느낀다.

 

6. 객체.동사목적어 패턴으로 작성해라 (주어.동사목적어 패턴)

Device.getMessage(); // 장치가 얻어온다. 메세지를.

Device.isValid();  // 장치가 유효하다.

Device.hasPort(); // 장치가 포트를 가진다.

 

7. 동사 전에 형용사, 부사를 쓰지 않는다.  
  (void) invokeWithTarget: (id) target;
  (void) selectTabViewItem: (NSTabViewItem *) tabViewItem

 

8. 이벤트 함수는 on으로 시작하는게 좋다

보통 on으로 시작하면 콜백함수이다. 콜백함수는 이벤트가 발생하면 불리는 함수이다.

onAvailable()  // Available이 되면(이벤트가 발생하면) 불러지는 함수.

onChanged()

 

Collection Method 부분

  개인적으로 추가/삭제하는 메서드 만들때 아래를 참고해라

1. 추가할 때는 옆에 처럼 따라라.   addElement()

2. 삭제할 때는 옆에 처럼 따라라.   removeElement() 혹은  removeElementAtIndex()

 

 

 

출처/참고자료

 본 자료의 출처는 이 블로그 주인에게 있습니다. 아래의 참고자료들을 짜집기한 내용입니다. 

 

Apple 개발자 공식 Naming Method 사이트

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html

 

Naming Methods

Naming Methods Methods are perhaps the most common element of your programming interface, so you should take particular care in how you name them. This section discusses the following aspects of method naming: General RulesHere are a few general guidelines

developer.apple.com

 

 

https://stackoverflow.com/questions/27139396/method-naming-conventions-for-common-type-of-functions

 

Method naming conventions for common type of functions

Problem description I often find myself thinking about a method name for the function I'm about the write. Like setters and getters to change or get the object's state. Maybe I am using objects no...

stackoverflow.com

 

반응형

'코딩 규칙' 카테고리의 다른 글

Code complete 12장. 기본 데이터형  (0) 2022.07.28
"on"으로 시작하는 메서드에 대한 고찰  (0) 2021.07.07
커밋 컨벤션 관련  (0) 2021.07.06
코딩 컨벤션 관련  (0) 2021.07.06
Git Flow 관련  (0) 2021.07.06