Learn Mobile Architecture and Development Experience from a Sourcery Developer

I recorded a podcast with Krzysztof Zablocki, who created Sourcery, which is an open-source tool that an iOS developer may have heard about. I was greatly inspired just like last year I’ve seen him. Krzysztof is a developer who leads the iOS team in New York Times and has a goal that aims to improve the developer experience by creating good app architecture and developer tools.

Good architecture is a structure where it’s easier to make the right choice than the wrong one.

I got the impression that he is a person who interprets mobile architecture and programming from a very pragmatic perspective and puts it into practice. He says the standard for distinguishing a good architecture should be judged on how happy the developer who uses it is. Also, he says good architecture is a structure where it’s easier to make the right choice than the wrong one. Because humans tend to choose the easy path when they have multiple choices. The worst thing is to fight the architecture to create a good code.

So if you look at what he’s created until now, it starts from an unexpectedly simple idea, but increases the productivity of developers who program every day, reduce unnecessary repetition to reduce mistakes, or magically force(?) codes to be made with a better structure. His work improves the whole team’s development and debugging experience through a simple method that does not modify existing codes as much as possible if you look at features like data snapshots and others which can recover the app’s status when the user sent a bug report. or the method where you can hide the singleton object which is in charge of app logging using the protocol extension and carrying out unit testing.

Sourcery that Even Apple Engineers Copied

There are better and more popular tools. Sourcery is a tool that automatically generates implementation codes when using protocols such as Equatable or Codable in Swift. There are parts that are supported in Swift itself now, but the default implementation was not initially supported, so it was created when everything had to be manually implemented. Not long after making this, even Apple engineers started using it internally. Funny thing is, they found out about this because the Apple engineers could not send PRs directly to the open source because of the company policy so they had to use Twitter’s private DMs to send patches and request for bug fixes.

Objective-C Playground Revealed Apple’s Lies

Another surprising story is that when Apple announced Swift Playgrounds in WWDC, they said that Objective-C cannot do something like this. In just 12 hours, Objective-C Playground was created and Apple was proven wrong. This project not only supports Objective-C, but also Swift, and it’s much faster than Apple’s Swift Playground beyond comparison. It’s even possible to do hot reloading like Flutter. I learned the keyword ‘Code Injection’ for the first time.

iOS Architecture and Testing

Lastly, before he became an iOS developer, he used to make game engines, develop graphics, and do web/back-end development. He says among them the mobile part is the most reluctant to write test codes. One of the reasons is that MVC provided by Apple is an extremely bad architecture for testing. For testing to work well, there needs to be a class that is in charge of logic that is completely separated from UIKit, but “Apple’s MVC” doesn’t even have an injection and composition so the opinion is that it’s difficult. Then why does Apple use MVC for more than 10 years? There’s a pretty good answer to the question asking whether there would be any changes that would push for a better architecture.

First, mainstream architectures other than MVC(based on the 2017 announcement), there are MVVM and VIPER(or other unidirectional architecture). MVVM needs to have an FRP-like binding, but this is difficult to make and not very compatible with UIKit right away, so it cannot be a candidate, and VIPER isn’t easy to learn. Apple wants new developers to enter the Apple platform easily, so there’s no way they would push difficult architectures like this. For a broad insight into architecture, you can refer to the popular announcement made a few years ago. Good iOS Application Architecture: MVVM vs. MVC vs. VIPER. Now in 2020, since we now have Combine and SwiftUI, is it easier to get out of MVC?

A Developer Who Creates a Practical Code and Tools That Can Help You Today

Since he has experience in freelancing and consulting, he’s an expert in architecture and tooling which increases development productivity and code reusability. Also, it was especially impressive that he mentioned the specific amount of money he earned from the tools he created out of need. Since time directly relates to income for freelancers, if you create a tool to reduce time spent on redundant tasks every day, or codes used in a previous project become reusable, they will count as income right away. If Uncle Bob and GoF were people who show theory and ideals, Krzysztof is like a developer who creates practical codes and tools that will help you today based on that theory and design patterns. I was especially inspired by the way he thought and constantly created something to spread good architecture and get rid of redundant tasks in debugging and coding as much as possible.

Tags: mobile architecture, developer experience, Krzysztof Zabłocki  

개인과 팀이 성장하는 모바일 개발 환경

어제 페북에 들어갔다가 어느 회사 iOS팀의 채용 공고를 보게 됐다. 보통 채용 공고는 훑어보면 복지, 기술 스택 등의 키워드 위주로만 몇 개 눈에 띄는데 이 채용 공고는 기술 블로그처럼 내용이 술술 읽혔다. 예전 팀에 있을때 도입하고 싶었던 많은 것들이 이미 구축되어 있었다. 혼자서 팀원들을 설득해가면서 조금씩 도입해봤기 때문에 이만큼의 모바일 개발 환경을 구축하는데에 많은 노력과 시간과 시행착오가 들어갔을 거라는걸 알았다. 고개를 끄덕이면서 읽다가 문득, 내가 쪼렙일때 이 글을 읽었다면 어땠을까란 생각이 들었다. 경험이 부족하고 아는게 별로 없으니 뭐가 좋은건지, 이게 나한테 어떤 영향을 주는지 잘 몰랐을거 같다. 그동안 이런 개발 환경이 있을 때와 없을 때를 다 경험해 봤기 때문에 이제는 안다. 이런 크고 작은 것들이 모여서 내가 회사에서 보내는 시간의 질을 결정한다. 단순하고 반복적인 일이 적고, 개발 도중 흐름을 끊는 사건이 적어야 한다. 그래서 개발에 집중할 수 있는 시간이 많이 확보되는게 업무 시간의 질이고 이 시간이 개발자의 성장과 연결된다.

배포 자동화

“매 커밋마다 모든 코드가 테스트되며, 하루에도 수십 번 구성원들에게 개발 중인 빌드가 공유됩니다.”

배포 자동화는 클릭 한번(혹은 0번)으로 앱을 빌드하고 내부 사용자나 외부 스토어까지 바로 전달할 수 있는 환경을 의미한다. 배포는 단순하고 반복적이면서 자잘하게 시간이 오래걸린다. 예전 팀에 처음 갔을때는 반만 자동화되어있었다. 앱을 배포하려면 먼저 앱 버전이나 빌드 넘버를 올려줘야하는데 이걸 누군가가 수동으로 커밋을 하고, PR을 만들고 규칙에 따라 굳이 테스트도 다 통과해야하고, 마지막으로 또다른 개발자가 PR을 승인 해줘야 비로소 버전을 올릴 수 있었다. 프로세스가 이러하다 보니 구성원들에게 앱을 전달하려고 할때마다 무려 개발자 두 명의 업무 흐름이 끊어졌다. 이런 방법에 문제를 느껴서 꾸준히 개선을 해나갔고 결국에는 시리로 배포를 할 수 있을 정도로 자동화를 해서 배포에 소요되는 노력과 시간을 엄청 줄였다.

개발에 몰입하려면 방해받지 않는 연속된 시간이 정말 중요하다. 특히 개발자에게 30분 두 번은 1시간과 결코 같지 않다. 하루에 수십 번 빌드가 공유된다는건 배포가 완전히 자동화돼있어서 개발자는 업무 중에 배포에 신경쓸 일이 없다는 뜻이고 구성원들도 다른 팀원을 방해할 필요없이 가장 최신의 앱을 설치해볼 수 있다는 뜻이다. CI/CD가 구축되어 있어서 이런 종류의 자잘한 방해 업무가 최대한 없는게 좋은 환경이다.

피쳐 플래그

“피쳐 플래그를 도입하여 사용자에게 매주 배포할 수 있는 환경을 만들었습니다.”

피쳐 플래그란 백엔드가 내려주는 불리언 값으로 앱의 기능을 껐다 켰다 할 수 있는 장치다. 피쳐 플래그가 없으면 어떤 기능이 개발되는 동안에는 마스터 브랜치에 코드를 밀어 넣을수 없어서 별도로 피쳐 브랜치를 관리해야 한다. 기능이 규모가 크고 개발이 오래 걸릴수록 점차 마스터와 피쳐 브랜치가 멀어져서 나중에 합칠때 많은 고생을 한다. 심지어 머지 컨플릭을 잘못 수정해서 코드가 유실되고 기능이 망가지는 일도 겪어봤다. 이런 일을 겪고나면 마스터 브랜치에 코드를 병합하는 일이 중대한 일이 돼서 걱정과 두려움도 생긴다. 열심히 개발해서 테스트까지 잘 마쳤는데 코드 머지하는 마지막 단계에서 문제가 발생할 수 있다는건 개발자를 위축시킨다.

개발 인원이 적어서 한번에 기능 하나만 개발할 수 있고 그 사이 앱을 배포할 일이 없다면 이런 환경의 필요성을 느끼지 못할 수 있다. 그러나 피쳐 플래그가 구축되어 있으면 여러 개발자가 동시에 각자 다른 기능 개발을 하면서도 마스터 브랜치 하나만 유지하면 되기 때문에 브랜치 관리가 훨씬 쉽고 그 와중에 실배포도 무리없이 할 수 있다. 개발이 덜 된 코드가 있더라도 백엔드 값을 통해 미완성 기능을 유저한테 숨길 수 있기 때문이다. 이렇게 되면 개발자는 브랜치 관리나 머지 컨플릭 등에 신경을 덜 쓰고 온전히 개발에 더 집중할 수 있다. 피쳐 플래그의 또 다른 장점은 출시된 기능에 문제가 발견됐을때 임시 방편으로 기능을 꺼버려서 유저한테 미치는 영향을 줄일 수 있다는 점도 있다.

코드 리뷰와 짝 프로그래밍

“코드 리뷰는 iOS 팀의 핵심 문화입니다. (중략) 페어 프로그래밍을 종종 활용합니다.”

이민석 이노베이션아카데미 학장님은 ‘리뷰 없이 만들어진 코드는 사채다’라는 말을 하셨다. 정말 공감가는 말이었다. 업계에서 기술 부채라는 용어를 쓰는데, 개발자 한명이 혼자서 만든 코드는 고리대금 악성 사채처럼 기술 부채를 많이 발생시킨다는 뜻이다. 자신이 짠 코드를 자신과 동일시 하거나 지나친 애착을 가지고 변화로부터 보호하려는건 정말 좋지 않다. 코드는 팀원들 모두와 공동명의로 된 자산이라는 생각으로 다뤄야한다. 코드 리뷰를 하면 기술 공유가 되고 팀이 전체적으로 같이 성장한다. 개발하다 보면 가끔씩 자만감에 ‘이건 진짜 완결성 있게 만든거같다. 리뷰에서도 별다른 의견이 나올만한 부분이 없겠지’ 싶은데도 다른 동료의 눈에서 개선점이 발견되고 새로운 아이디어가 생기고 몰랐던 기술을 배울수 있다. 서로의 코드를 보여주지 않고 지적하지 않으면 개인으로나 팀으로나 성장할 수 없다.

짝 프로그래밍은 코드 리뷰의 상위 호환이다. 개발 실력이 비슷한 두 명이 하는것보다는 비대칭적인 실력을 가진 두 명이 하는게 효과적이다. 구글에서는 짝 프로그래밍을 거쳐 만들어진 코드는 코드 리뷰 승인을 받은 것으로 간주한다고 한다. 짝 프로그래밍까지는 아니지만 내가 신입일 때 사수님이 옆자리에 앉혀놓고 코딩을 하고 디버깅을 하는 모습을 보여준 경험에 대해서는 예전 글에서도 언급한 적이 있는데 정말 큰 도움이 됐고 아직까지 기억에 남는다. 얼마 전에는 내가 알려주는 입장에서 신입 개발자와 짝 프로그래밍을 했는데 반응도 좋았고, 나도 생각을 정리하고 설계를 더 탄탄하게 할 수 있는 좋은 계기였다. 시니어 개발자와 하는 짝 프로그래밍은 주니어 개발자에게 정말 값진 시간이다. 나보다 잘하는 사람으로부터 기술과 노하우를 1대1로 전수받고 질문도 마음껏 할 수 있는 기회는 어디가서 돈 주고도 못 산다.

단순하고 반복적인 일이 적고, 온전히 개발에 오래 집중할 수 있는 시간이 많은게 좋은 환경이다.

그러기 위해서는 반복적인 업무를 자동화하는게 필수적이다. 또한 코드 리뷰 문화가 자리 잡혀 있으면 개인은 물론 팀이 전체적으로 같이 성장할 수 있다. 위 기준와 사례를 통해서 어떤 회사를 가야할지, 어떤 팀에 가야할지, 혹은 어떻게 자신의 주변 상황을 개선해야 더 성장할 수 있을지 고민인 주니어 개발자분들에게 도움이 됐으면 한다.

Tags: mobile platform, growth, mobile ci/cd