![]() ![]() The fact that Swift puts a very strong emphasis on type safety is hard to miss - with its static type checks, a powerful generics system, and the need to do things like type erasure in order for the compiler to be able to verify our code’s structure as it’s being compiled. ![]() Let’s start with the first keyword - safety. Let’s take a look at a few different things that can be good to keep in mind in order to make our own code follow those principles. So, what exactly are those goals? The about page on Swift’s official website lists three keywords: Safe in terms of minimizing developer mistakes, Fast when it comes to speed of execution, and Expressive, in that Swift aims to be as clear and as easy to understand as possible. After all, while Swift’s various APIs, conventions and language features tend to change over time, its fundamental goals mostly remain the same - so if we can write our own code in ways that matches those goals, then we’ll have a much better chance of making our code feel natural and clear within any given Swift context. In a way, a simple answer to the above question could be “code that’s well-aligned with Swift’s core set of goals”. This week, let’s take a closer look at Swift’s core set of conventions, to try to come up with an answer to the question of what really does make code “Swifty”? Aligned goals Add Swift 4’s introduction of key paths and Codable, Swift 5.1’s function builders, property wrappers and opaque return types, and many more APIs and features that have been introduced over the years - and it’s starting to become quite clear that what makes code “Swifty” is somewhat of a moving target. However, while Swift’s core syntax hasn’t changed that much since its original introduction, its conventions have dramatically shifted over time.įor example, many Swift developers remember the transition from Swift 2 to Swift 3 as a big change in terms of syntax, but the majority of those changes weren’t really syntax changes - they were changes to the standard library’s API based on a new set of naming conventions. Within the Swift community, the phrase “Swifty code” is often used to describe code that follows the conventions that are currently the most popular. After all, syntax-wise, most “C-influenced” languages look incredibly similar - to the point where you could write Swift in ways that almost makes it look like JavaScript, or C#, or C itself. Although programming languages are formally defined by their syntax, the ways in which they get used in practice are arguably just as much determined by their current conventions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |