This repository contains examples of clean and dirty code in Swift and Ionic, along with explanations and best practices for writing clean code. Both examples will include Casey Muratori's example of a clean code, translated from C++ in both Swift and Ionic.
The Swift examples of clean code demonstrate the following best practices:
- Clear and concise naming conventions for variables, functions, and classes
- Proper use of access modifiers to control the visibility of data and functionality
- Proper error handling using
try
,catch
, andthrow
- Consistent formatting and indentation
The Swift examples of dirty code demonstrate the following anti-patterns:
- Poor naming conventions that make the code difficult to understand
- Overuse of global variables and functions
- Lack of error handling, resulting in potential crashes and other issues
- Inconsistent formatting and indentation
The Ionic examples of clean code demonstrate the following best practices:
- Clear and concise naming conventions for variables, functions, and classes
- Proper use of the Ionic component library to build user interfaces
- Consistent formatting and indentation
The Ionic examples of dirty code demonstrate the following anti-patterns:
- Poor naming conventions that make the code difficult to understand
- Overuse of custom CSS instead of utilizing the Ionic component library
- Lack of consistency in formatting and indentation
By examining these examples of clean and dirty code, the results were a lot more clear for the Swift implementation, with the clean code implmementation being consistently better. Regarding Ionic, the same cannot be said. A quick analysis of the implementation showed me that the clean code is mostly faster than dirty code, but this is not a rule.