{"id":25996,"date":"2019-07-17T16:21:55","date_gmt":"2019-07-17T20:21:55","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=25996"},"modified":"2019-07-17T16:23:02","modified_gmt":"2019-07-17T20:23:02","slug":"branches-and-continuous-integration","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/07\/17\/branches-and-continuous-integration\/","title":{"rendered":"Branches and Continuous Integration"},"content":{"rendered":"<p><a href=\"http:\/\/khanlou.com\/2019\/07\/continuous-integration\/\">Soroush Khanlou<\/a> (<a href=\"https:\/\/twitter.com\/khanlou\/status\/1151221533005602822\">tweet<\/a>):<\/p>\n<blockquote cite=\"http:\/\/khanlou.com\/2019\/07\/continuous-integration\/\"><p>A problem presents itself, however. You need to build a feature that takes 1,000 lines of code, but you&rsquo;d like to merge it in in smaller chunks. How can you merge the code in if it&rsquo;s not finished?<\/p><p>Broadly, the strategy is called &ldquo;branch by abstraction&rdquo;. You &ldquo;branch&rdquo; your codebase, not using git branches, but rather branches in the code itself. There&rsquo;s is no one way to do branch by abstraction, but many techniques that are all useful in different situations.<\/p><p>[&#8230;]<\/p><p>Of course, the humble <code>if<\/code> statement is also a great way to apply this technique; use it liberally with feature flags to turn features on and off. (A feature flag doesn&rsquo;t have to be complicated. A global constant boolean gets you pretty far. Feature flags don&rsquo;t have to come from a remote source! However, I would recommend against compile-time <code>#if<\/code> statements, however. Code that doesn&rsquo;t get compiled might as well be dead.)<\/p><\/blockquote>\n\n<p>Branches are just not very useful for managing features or major releases for which development will take a long time (during which you will keep working on the shipping version). They&rsquo;re great when you want to make a bug fix release based on an old version, and thereafter plan for the branch to die. But, otherwise, you spend a lot of time merging changes back and forth between two active branches and still end up with a potentially difficult integration at the end. It&rsquo;s better to use feature flags and potentially extra <tt>Info.plist<\/tt> files and Xcode targets to support simultaneous development of multiple versions.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/02\/01\/comparing-xcode-target-build-settings\/\">Comparing Xcode Target Build Settings<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/07\/26\/conditional-compilation-in-swift\/\">Conditional Compilation in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/06\/22\/xcode-8-tips-and-issues\/\">Xcode 8 Tips and Issues<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/09\/25\/using-xcode-targets\/\">Using Xcode Targets<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/08\/16\/xcode-build-setting-transformations\/\">Xcode Build Setting Transformations<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/05\/29\/the-unofficial-guide-to-xcconfig-files\/\">The Unofficial Guide to xcconfig Files<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Soroush Khanlou (tweet): A problem presents itself, however. You need to build a feature that takes 1,000 lines of code, but you&rsquo;d like to merge it in in smaller chunks. How can you merge the code in if it&rsquo;s not finished?Broadly, the strategy is called &ldquo;branch by abstraction&rdquo;. You &ldquo;branch&rdquo; your codebase, not using git [&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-07-17T20:21:59Z","apple_news_api_id":"8554ab9e-7a10-4f8f-8454-00976cdff831","apple_news_api_modified_at":"2019-07-17T20:23:10Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AhVSrnnoQT4-EVACXbN_4MQ","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":[27,377,31,30,71,376,226],"class_list":["post-25996","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-craft","tag-git","tag-ios","tag-mac","tag-programming","tag-versioncontrol","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25996","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=25996"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25996\/revisions"}],"predecessor-version":[{"id":26002,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25996\/revisions\/26002"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=25996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=25996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=25996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}