© Wallace Wang 2017

Wallace Wang, macOS Programming for Absolute Beginners, 10.1007/978-1-4842-2662-9_25

25. Defensive Programming

Wallace Wang

(1)San Diego, California, USA

Programmers tend to be optimistic, because when they write code, they assume that it will work correctly. However, it's often better to be more pessimistic when it comes to programming. Instead of assuming your code will work the first time, it's safer to assume your code won't work at all. This forces you to be extra careful when writing Swift code to make sure it does exactly what you want and doesn't do anything unexpected.

No program is error-free. Rather than waste time hunting down problems, it's far better to anticipate them and do your best to prevent them from creeping ...

Get macOS Programming for Absolute Beginners: Developing Apps Using Swift and Xcode now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.