1월 10일 (수)
Clarity at the point of use is your most important goal.
// 음.. 사용의 포인트를 명확하게 하는 것은 중요한 목표이다.
Clarity is more important than brevity
// 명확성은 짧게(줄임)는 것보다 중요하다.
// 무슨 의미인지 명확하지 않다면, 무분별하게 단축, 줄임은 지양해야한다.
Write a documentiation comment for every declaration.
// 문서 작성 해라.
Insights gained by writing documentation can have a profound impact on your design,
// 문서 작성에서 얻는 인사이트는 당신의 설계에 매우 깊은 곳에 내재할 수 있다.
so don't put it off
// 그래서 포기하지 마라.
Include all te words needed to aviod ambiguity for a person reading code where the name is usedOmit needless words. Every word in a name should convey salient information at the use site[올바르지 않은 예]
public mutating func removeElement(_ member: Element) -> Element?
allViews.removeElement(cancelButton)
[올바른 예]
public mutating func remove(_ member: Element) -> Element?
allViews.remove(cancelButton) // clearer
Name variables, parameters, and associated types according to their roles, rather than their type constraints.[올바르지 않은 예]
var string = "Hello"
protocol ViewController {
associatedtype ViewType : View
}
class ProductionLine {
func restock(from widgetFactory: WidgetFactory)
}
[올바른 예]
var greeting = "Hello"
protocol ViewController {
associatedtype ContentView : View
}
class ProductionLine {
func restock(from supplier: WidgetFactory)
}
Compensate for weak type information to clarify a parameter's role.[올바르지 않은 예]
func add(_ observer: NSObject, for keyPath: String)
grid.add(self, for: graphics) // vague
[올바른 예]
func addObserver(_ observer: NSObject, forKeyPath path: String)
grid.addObserver(self, forKeyPath: graphics) // clear