#naming closing, closed 대신 will close, did close

1 minute read

override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate.
    // Save data if appropriate. See also applicationDidEnterBackground:.

Use “did” or “will” for methods that are invoked to notify the delegate that something has happened or is about to happen.

Naming Methods, developer.apple.com

pre-event, post-event를 will, did를 써서 구분한다. 쌈박하네. windows에서 보기 힘든 네이밍이다. uikit UIViewController 클래스에서 처음 봤다.

It is important to note that there are two groups of events: events raised before a state of the system changes, called pre-events, and events raised after a state changes, called post-events. An example of a pre-event would be Form.Closing, which is raised before a form is closed. An example of a post-event would be Form.Closed, which is raised after a form is closed.

Event Design, docs.microsoft.com

반면 내가 익숙한 .net은 pre-event는 -ing, post-event는 -ed를 붙여서 구분한다.

-ed는 hit처럼 원형과 과거형, 과거분사가 같은 불규칙 동사 때문에 일관되게 쓸 수 없어서 별로다. 이것도 웃기긴 하다. 문법부터 단어 사용까지 다 틀리면서 과거형, 과거 분사만 잘 챙기니 말이다. hitted로 쓰면 어때?

문법 문제가 아니더라도 눈에 확 띄는 규칙이 있어서 will, did가 더 마음에 든다.