# Guard clauses > 로직을 수행하기 전에 사전조건이 만족되는지 미리 검사하기. 타이딩 중 하나. 로직을 수행하기 전에 [사전조건](https://wiki.g15e.com/pages/Precondition.txt)이 만족되는지 미리 검사하기. [타이딩](https://wiki.g15e.com/pages/Tidying.txt) 중 하나. 예를 들어 이런 코드를… ```typescript if (condition0) if (!condition1) doSomething() ``` …이렇게 바꾸는 것. ```typescript if (!condition0) return if (condition1) return doSomething() ``` 하지만 7-8개가 넘는 가드가 있는 루틴이라면 다른 조치가 필요할 수 있다. 한편, 함수 하나에 하나의 `return`만 있는 게 좋다는 주장에 대해: > The “rule” about having a single return for a routine came from the days of FORTRAN, where a single routine could have multiple entry and exit points. It was nearly impossible to debug such code. You couldn’t tell what statements were executed. Code with guard clauses is easier to analyze because the preconditions are explicit. --[Tidy first? A personal exercise in empirical software design](https://wiki.g15e.com/pages/Tidy%20First%20-%20A%20personal%20exercise%20in%20empirical%20software%20design.txt) ## Swift [스위프트](https://wiki.g15e.com/pages/Swift%20(progrmaming%20language.txt))는 가드를 [명시적으로 지원](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements/#Guard-Statement)한다. ```swift guard condition else { statements } ``` ## TypeScript [타입스크립트](https://wiki.g15e.com/pages/TypeScript.txt)에서는 user-defined type predicate과 type guard를 이용해서 <타입 추론>을 도울 수 있다.[^1] ## Footnotes [^1]: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates