{"id":24436,"date":"2019-02-26T17:04:13","date_gmt":"2019-02-26T22:04:13","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=24436"},"modified":"2019-02-27T07:30:25","modified_gmt":"2019-02-27T12:30:25","slug":"when-to-adopt-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/02\/26\/when-to-adopt-swift\/","title":{"rendered":"When to Adopt Swift"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/marcoarment\/status\/1099406116516253696\">Marco Arment<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/marcoarment\/status\/1099406116516253696\">\n<p>Add up all of the time you&rsquo;ve spent learning Swift from scratch, accommodating its strictness, fighting its buggy tools, migrating your code through language changes, and re-learning APIs and conventions as they&rsquo;ve changed over the last 5 years.<\/p>\n<p>I&rsquo;ve spent zero time doing that.<\/p>\n<p>I&rsquo;ll jump in when it&rsquo;s so old, boring, and slow-moving that nobody bothers to tell people to move to Swift because they&rsquo;re all busy geeking out and fussing over a newer language.<\/p>\n<p>[&#8230;]<\/p>\n<p>I know the basics. I&rsquo;ve written a few thousand lines of Swift, including an entire simple app. I just choose not to write it the vast majority of the time.<\/p>\n<\/blockquote>\n\n<p>I think migration is no longer much of an issue. The tooling is still buggy but getting much better. However, there is absolutely a time cost, and you have to think about what you&rsquo;re trying to do. Is it worth switching if you&rsquo;re going to write Objective-C-style code in Swift? One could argue that&rsquo;s the worst of both worlds. Learning to really take advantage of Swift is rewarding but takes time. And you&rsquo;re limited in how Swifty you can be if you have an existing Objective-C codebase. For a new app or a major rewrite, I think most developers should bite the bullet. In other situations, it&rsquo;s less clear. We don&rsquo;t know yet whether Apple is going to redesign its APIs for Swift, although Mojave&rsquo;s <a href=\"https:\/\/developer.apple.com\/documentation\/network\">Network framework<\/a> is an interesting example of functionality that&rsquo;s available in both languages but second-class in Objective-C.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/chockenberry\/status\/1099743694113038336\">Craig Hockenberry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/chockenberry\/status\/1099743694113038336\">\n<p>Another thing I&rsquo;ve noticed: type safety slows down the prototyping stage where you just want it to work, not be perfect. Quick and dirty leads to great experiences.<\/p>\n<p>(I&rsquo;ve switched back to Obj-C, too.)<\/p>\n<\/blockquote>\n\n<p>I think it really depends on the type of code. In some cases, particularly at the model and with algorithms, I feel like I&rsquo;m going much faster with Swift. There&rsquo;s less boilerplate, the standard library offers a lot that Foundation doesn&rsquo;t, and the strong typing helps with both thinking and refactoring. But other times, particularly when interacting a lot with Cocoa, it can feel like it gets in the way. There are impedance mismatches and blind alleys. Some of this can be smoothed over with more code.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/kocienda\/status\/1099746543739916289\">Ken Kocienda<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/kocienda\/status\/1099746543739916289\">\n<p>&#x1F4AF;. I think the most underrated productivity metric in programming is the time it takes to make one iteration. I work hard to keep this cycle time short and cheap. More iterations produces better results.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/chockenberry\/status\/1099749189888630784\">Craig Hockenberry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/chockenberry\/status\/1099749189888630784\"><p>I had high hopes that playgrounds would speed up iteration. That&rsquo;s been a bust: either inexplicable errors or slower than just compiling some test code.<\/p><\/blockquote>\n<p>Unfortunately, this has been my experience as well.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/kocienda\/status\/1099804080740884480\">Ken Kocienda<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/kocienda\/status\/1099804080740884480\">\n<p>Learning Swift didn&rsquo;t teach me anything new about how to think about my programs. It didn&rsquo;t expand my mind. What&rsquo;s more, its type safety hinders some of the ad-hoc flexibility that helps when writing the kinds of UI programs I typically write.<\/p>\n<p>Over other languages, Swift doesn&rsquo;t help me with what&rsquo;s actually hard about writing code: thinking through exactly what I want to happen. Once I know that, writing the code is mostly a matter of idioms, conventions, tooling, and richness and availability of good libraries.<\/p>\n<\/blockquote>\n\n<p>I didn&rsquo;t find Swift mind expanding in a theoretical sense, as it mostly brings together ideas that had already appeared in other languages. But it absolutely is in a practical sense because it makes these tools available for real-world code, written in a platform-blessed language. It also refines them in ways that make them more approachable.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1099696746857406464\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1099696746857406464\">\n<p>It feels like a cult. Swifters can&rsquo;t leave well enough alone. They&rsquo;re morally repulsed if you&rsquo;re not using Swift, and they have to knock on your door and convert you to the faith.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/roryprior\/status\/1099699293877866498\">Rory Prior<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/roryprior\/status\/1099699293877866498\">\n<p>Marco&rsquo;s reasons are perfectly valid for him, but they really only apply to indie developers or people who get to make the call about the language used for projects, being a Swift refusenik is career suicide otherwise.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/colincornaby\/status\/1100255599760003072\">Colin Cornaby<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/colincornaby\/status\/1100255599760003072\"><p>Still confused by the amount of fuss over Marco&rsquo;s tweet about Swift. No one is cancelling Swift just because Marco isn&rsquo;t using it. Him holding off on adopting Swift doesn&rsquo;t threaten anyone else. He&rsquo;s just doing what he thinks is most responsible for his product.<\/p><p>[&#8230;]<\/p><p>Also:<\/p><p>&ldquo;Swift is super easy to learn way easier than Obj-C so easy kids are learning it on their iPads&rdquo;<\/p><p>&ldquo;But if you don&rsquo;t learn it now you&rsquo;re going to be forever behind and never useful as a developer again&rdquo;<\/p><\/blockquote>\n\n<p>It&rsquo;s relatively easy to learn the basics, but it takes a long time to master. In a sense, everyone is always behind those who started learning any language before them. But learning is not linear, and also there are any number of other things to learn besides a particular language. No one is ahead at everything. The question is what it&rsquo;s most important for <em>you<\/em> to learn <em>now<\/em>.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/bwebster\/status\/1100176629681123329\">Brian Webster<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/bwebster\/status\/1100176629681123329\">\n<p>Swift:<\/p>\n<pre>(lldb) expr -l Swift -- import PowerPhotos\n(lldb) expr -l Swift -- let $view = unsafeBitCast(0x600003b132c0, PowerPhotos.IPPhotoSelectionView.self)\n(lldb) expr -l Swift -- print($view.description)<\/pre>\n<p>ObjC:<\/p>\n<pre>(Lldb) po [0x600003b132c0 description]<\/pre>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/davedelong\/status\/1100189154770591744\">Dave DeLong<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/davedelong\/status\/1100189154770591744\"><p>Add this to your <tt>~\/.lldbinit<\/tt>:<\/p>\n<pre>command regex objc 's\/^(.+)$\/expr -O -l objc++ -- %1\/'<\/pre>\n<p>Now you can do:<\/p>\n<pre>(lldb) objc [0x600003b132c0 description]<\/pre><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/kastiglione\/status\/1100239845174079488\">Dave Lee<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/kastiglione\/status\/1100239845174079488\">\n<p>Another option is overloading po to provide custom behavior for memory addresses:<\/p>\n<pre>command regex po\ns\/(0x[[:xdigit:]]+)$\/expr -lobjc -O -- %1\/\ns\/(.+)\/expr -O -- %1\/<\/pre>\n<p>This makes <code>po<\/code>&rsquo;ing 0x76543210 treat it as objc. Any other expression gets default <code>po<\/code> behavior.<\/p>\n<\/blockquote>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2018\/06\/10\/on-my-misalignment-with-apples-love-affair-with-swift\/\">On My Misalignment With Apple&rsquo;s Love Affair With Swift<\/a>.<\/p>\n\n<p id=\"when-to-adopt-swift-update-2019-02-27\">Update (2019-02-27): <a href=\"https:\/\/twitter.com\/vadimshpakovski\/status\/1100689400944648192\">Vadim Shpakovski<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/vadimshpakovski\/status\/1100689400944648192\">\n<p>Open-source libraries written in Obj-C are slowly dying. They&rsquo;re not maintained or authors rewrite them in Swift. This trend is probably unstoppable. And if your code uses third-party components, you literally have no choice.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Marco Arment: Add up all of the time you&rsquo;ve spent learning Swift from scratch, accommodating its strictness, fighting its buggy tools, migrating your code through language changes, and re-learning APIs and conventions as they&rsquo;ve changed over the last 5 years. I&rsquo;ve spent zero time doing that. I&rsquo;ll jump in when it&rsquo;s so old, boring, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-02-26T22:04:17Z","apple_news_api_id":"029a6f14-f4ed-4609-b3b9-4d4816ae4026","apple_news_api_modified_at":"2019-02-27T12:30:30Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AAppvFPTtRgmzuU1IFq5AJg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,31,1610,317,30,1609,54,71,901,226],"class_list":["post-24436","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-ios-12","tag-lldb","tag-mac","tag-macos-10-14","tag-objective-c","tag-programming","tag-swift-programming-language","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=24436"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24436\/revisions"}],"predecessor-version":[{"id":24438,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24436\/revisions\/24438"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=24436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=24436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=24436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}