<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Olivier Bazin on Medium]]></title>
        <description><![CDATA[Stories by Olivier Bazin on Medium]]></description>
        <link>https://medium.com/@obazin?source=rss-89c7e5c25daa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Olivier Bazin on Medium</title>
            <link>https://medium.com/@obazin?source=rss-89c7e5c25daa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 00:14:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@obazin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I didn’t set out to write a Lichess client]]></title>
            <link>https://medium.com/@obazin/i-didnt-set-out-to-write-a-lichess-client-cc4d445b1a28?source=rss-89c7e5c25daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4d445b1a28</guid>
            <category><![CDATA[lichess-org]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chess]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Olivier Bazin]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 15:33:03 GMT</pubDate>
            <atom:updated>2026-06-21T15:47:49.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PiZ3oZEJHHx5Ju0r.png" /></figure><h3>AI Wrote the Endpoints. I Wrote the Library.</h3><blockquote><em>I didn’t set out to write a Lichess client : i was building a complete chess training application, and I needed to integrate a handful of Lichess API features to make it work. The easy path would have been to wire up just those few endpoints for myself and move on. But open source gives me something every single day, and rather than build only for me, I wanted to give a little of it back — a real, complete, reusable library instead of a private helper. </em><em>litchee is that: the detour that became its own thing.</em></blockquote><p>I built a Rust client that covers every documented operation in the Lichess API. All 184 of them — users, games, tournaments, puzzles, studies, broadcasts, board and bot play, the opening explorer, the tablebase. One person, a few days, evenings mostly.</p><p>The endpoints were the easy part.</p><p>That sentence would have been a lie three years ago, so let me be honest about why it isn’t one now — and about what actually turned out to be hard.</p><h3>Why API clients are usually half-finished</h3><p>Open the client library for almost any large API and you’ll find the same thing: the popular 20% is covered, the rest is a // TODO or simply absent. <strong>This isn&#39;t laziness. It&#39;s economics</strong>. Writing a binding for an endpoint nobody on your team uses - reading the spec, modelling the response, writing the test - costs the same as writing one everybody uses, and pays back far less. So a single maintainer rationally stops at the endpoints they need. Completeness was a luxury you bought with a team.</p><p>I went in assuming litchee would be the same: cover board and bot play well, gesture at the rest. That&#39;s not what happened, and the reason is worth being precise about.</p><h3>What changed: breadth got cheap</h3><p>Lichess publishes an OpenAPI spec. I vendored it into the repo as a git submodule and treated it as the source of truth — not documentation to read, but a contract to conform to. <strong>From there, generating an endpoint became a mechanical loop</strong>: point an AI at the spec entry, get the request shape, the response DTO, and a test fixture built from the spec’s own example.</p><p><strong>The cost of <em>breadth</em> — the thing that used to make complete clients uneconomical — fell close to zero</strong>. Forty endpoints or four hundred, the marginal one was no longer expensive.</p><p>I want to be careful here, because this is the part that gets oversold. T* <em>he AI did not “build the library.” It produced volume</em>*. Correct-looking, spec-shaped, test-backed volume — but volume. And volume, on its own, is not a library. It’s a junk drawer.</p><h3>The catch: 184 endpoints don’t add up to one library</h3><p>Here is the thing nobody warns you about. When breadth is free, you generate a lot of it, and very quickly you’re staring at 184 endpoints that were each written in isolation. <strong>Each one is locally reasonable. Together they’re incoherent</strong> — different naming, different error handling, different shapes for the same idea, the same DTO modelled three slightly different ways.</p><p>A library is not a pile of endpoints. A library is a set of <em>promises that hold across all of them</em>. That coherence is the entire value, and it’s exactly what generation-in-isolation destroys. So the real work — the part that took the time — was deciding what those promises were and forcing every generated piece to obey them.</p><p>A few of the ones I committed to and didn’t break:</p><ul><li><strong>One concern per file.</strong> Each business concern (board, swiss, puzzles…) is a single flat file holding its endpoints, its DTOs, and its tests together.</li><li><strong>Hard size limits.</strong> No file over 900 lines, no function over 20. When something strains, it gets split. This sounds arbitrary; in practice it’s the pressure that keeps any single piece from quietly becoming a mess.</li><li><strong>Every DTO is </strong><strong>Lichess-prefixed.</strong> LichessGame, LichessUser, LichessToken. Boring, and you always know what you&#39;re holding.</li><li><strong>Builders for anything with options</strong>, so a request with twelve optional parameters doesn’t become a twelve-argument function.</li></ul><p>None of these are clever. That’s the point. <strong>They’re decisions, and an AI won’t make them for you</strong> — it will happily generate code that violates every one, because each violation is locally fine. They’re only wrong in aggregate, and aggregate is the one thing a per-endpoint generator can’t see.</p><h3>The part I couldn’t hand off: the public surface</h3><p>If I had to name the single thing that stayed stubbornly, irreducibly human, it was deciding what to make pub.</p><p><strong>Marking something public <em>is</em> deciding what the library is</strong>. It’s a promise you can’t take back without breaking everyone who believed you. The generated code doesn’t know that a field being public is a contract; it just knows the field exists. So the shape of the crate — what’s exported, what’s hidden, how the module tree mirrors the API’s concerns, what a caller actually touches — was a series of small, deliberate, one-way decisions.</p><h3>Error handling is design, not generation</h3><p>The clearest place this shows up is errors.</p><p><strong>The lazy version of “handle errors” is a single catch-all: something went wrong, here’s a string</strong>. An AI will give you that instantly, and it’s useless to the person calling your code, because they can’t <em>react</em> to it. They can only log it.</p><p>I wanted a caller to be able to match on <em>what</em> went wrong. So the taxonomy was something I designed by hand, and then let the AI fill in.</p><p>A SwissUnauthorizedEdit variant is the whole argument in miniature. The Lichess API returns 401 when you try to edit a Swiss tournament you don&#39;t own - the same status code as &quot;your token is invalid,&quot; but a completely different problem with a completely different fix. No generator infers that distinction from a status code. I only found it by reading the spec like a person who&#39;d have to debug it later. Modelling it as its own variant is design work. The AI couldn&#39;t have known it mattered, because <em>mattering</em> is a human judgement.</p><p>And this is where it stops being a matter of taste and becomes a matter of correctness. <strong>An API is not just a set of URLs — it’s a contract</strong>. It comes with rules about how it may be used: rate limits you must back off from, scopes a token must carry, states in which an operation is simply not allowed. Those rules aren’t optional extras a client can round off; they’re the terms of the contract. <strong>A serious client is precisely the one that implements them — that turns “this is forbidden” into a value the caller can see and obey, rather than a surprise they discover in production</strong>.</p><p>There’s a natural fit here that’s easy to miss. Deterministic, exhaustive error handling and a faithfully-respected API contract are the same work seen from two sides. Every rule the API imposes is, on the client’s side, an error it must be able to name and hand back. <strong>Map the contract completely and your error type writes itself; model your errors as one specific variant per failure mode and you’ve transcribed the contract.</strong> The catch-all string fails on both counts at once: it neither respects the contract nor lets the caller honour it. So this isn’t a flourish you add for polish — it’s the most basic obligation a client has to the service it speaks to, and it’s exactly the obligation a generator, working one endpoint at a time, has no way to even perceive.</p><h3>Complete also has to mean correct</h3><p>There’s a quieter kind of work that breadth-for-free doesn’t touch: making the thing hold up in production.</p><p>It’s worth being clear about <em>why</em> this isn’t optional, because it’s tempting to treat it as polish you get to later. Completeness is a promise. When I say litchee covers all 184 operations, <strong>a reader hears &quot;I can rely on all 184&quot; - that&#39;s the entire point of claiming completeness in the first place</strong>. So the moment any one of them disintegrates on real input, the promise was false. And a false promise of completeness is <em>worse</em> than an honest gap: an absent endpoint tells you the truth up front and you plan around it, while a present-but-broken one lies to you until the worst possible moment - under load, in production, on the one input you didn&#39;t test. Breadth that isn&#39;t correct doesn&#39;t expand what the library can do; it expands the surface on which it can betray you.</p><p>There’s a second reason, more specific to how this code came to exist. A spec describes the happy path — it gives one tidy example per endpoint, and a generator, quite reasonably, makes that example pass. But <strong>production is the <em>unhappy</em> path: the malformed chunk, the dropped connection, the burst that trips a rate limit, the stream that stays open for an hour</strong>. None of that is in the spec, so none of it is in the generated code. The example is exactly the input you will almost never see at scale; the inputs you <em>will</em> see are the ones nobody wrote down. Closing that gap is not generation filling in a blank — it’s a person anticipating what the wire actually does.</p><p>Lichess streams many endpoints as newline-delimited JSON — event streams, live board state, game exports — one JSON value per line, with blank keep-alive lines in between. The naive version splits the response on newlines and hopes each line is whole. It isn’t: the network hands you bytes in arbitrary chunks, and a JSON object routinely arrives split across two of them. So there’s a small, unglamorous buffer that reassembles lines across chunk boundaries, skips the keep-alives, and yields a clean Stream of typed values. It&#39;s a few dozen lines, it has nothing to do with any particular endpoint, and it&#39;s the kind of correctness no spec describes and no generator volunteers.</p><p>The same goes for token redaction so secrets don’t leak into logs, for read timeouts that don’t strangle a long-lived stream, for honouring Retry-After. None of it is breadth. All of it is the difference between &quot;covers the API&quot; and &quot;safe to depend on.&quot;</p><h3>The bottleneck moved</h3><p>So here’s what I actually learned, and it’s the only claim in this piece I’d defend hard.</p><p><strong>AI didn’t make architecture matter less. It made it matter *more</strong>* — because it removed the thing that used to absorb all the effort. When typing 184 endpoints by hand was the cost, that cost dominated everything; you never got far enough to feel the design problems. Now the typing is nearly free, and what’s left standing, fully exposed, is the part that was always the real work: the invariants, the error taxonomy, the public surface, the judgement about what this library <em>is</em>.</p><p><strong>The bottleneck moved from typing to taste. AI is a breadth multiplier. It is not an architect, and the more breadth it gives you, the more architect you have to be.</strong></p><p>I’m genuinely unsure where the line settles as these tools get better. Maybe some of the taste becomes mechanical too. But for now, the honest report from building one complete client, solo, is this: the machine wrote the endpoints, and that turned out to be the part that didn’t need me. The library — the promises, the shape, the judgement calls — is the part that did.</p><h3>What’s next</h3><p>The surface is complete, and that was always meant to be a foundation, not the finish line. As it stands, the client mirrors the API faithfully: one method per operation, typed in, typed out. That’s the right base layer — but it’s a low-level one. Nobody wakes up wanting to “call the game-export endpoint with eight parameters and fold a stream into an accumulator.” They wake up with a <em>question</em>.</p><p>So the next layer is a facade over the raw endpoints — a small set of higher-level features that answer the questions people actually ask:</p><ul><li><em>What’s the average rating of the opponents in my last twenty losses</em> — am I losing up, or losing down?</li><li><em>Which puzzle themes do I consistently overlook</em> — the tactics I keep missing without noticing?</li><li><em>How does my time control or time of day correlate with my results?</em></li></ul><p><strong>Not one of these is a new endpoint. Every one is a <em>composition</em> of endpoints that already exist:</strong> the losses question folds game export with a result filter and a rating average; the puzzle-themes question joins puzzle activity against theme metadata. And this is the thread I want to pull through one last time, because it’s the same one running through everything above — that composition is only possible because the client is complete.</p><p>A partial client doesn’t merely make these features harder; it makes some of them impossible, and you don’t get to know which ones in advance. The feature you want next month might hinge on the single endpoint a 20%-coverage client never bothered to implement. <strong>Completeness is what keeps the whole space of compositions open — it’s the substrate, and the facade is simply what you get to build once the ground is laid</strong>. You can’t compose your way to a feature out of endpoints that aren’t there.</p><p>And the shape repeats one final time. The 184 endpoints — the breadth — were the cheap, generated part. Deciding <em>which</em> questions are worth answering, and what it should feel like to ask them, is taste again. Completeness made the features possible; choosing and shaping them is the human work, same as it ever was. Which is a fitting place to draw the 1.0 line: freeze the complete, faithful surface, then build the opinionated layer on top of it — in the open.</p><p>litchee is on <a href="https://crates.io/crates/litchee">crates.io</a> and <a href="https://github.com/obazin/litchee">GitHub</a>, listed among the client libraries in the <a href="https://lichess.org/api">Lichess API docs</a>, and featured in <a href="https://this-week-in-rust.org/blog/2026/06/17/this-week-in-rust-656/">This Week in Rust #656</a>. It&#39;s MIT, and I&#39;m about to freeze the API for 1.0 - so don&#39;t hesitate to send me feedback while it&#39;s still cheap to change.</p><p><em>Originally published at </em><a href="https://dev.to/obazin/i-didnt-set-out-to-write-a-lichess-client-1hgf"><em>https://dev.to</em></a><em> on June 21, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4d445b1a28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From 10 to 100 products: Templates are our best friends (part 2)]]></title>
            <link>https://medium.com/cheerz-engineering/from-10-to-100-products-templates-are-our-best-friends-part-2-4a8b819743b3?source=rss-89c7e5c25daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a8b819743b3</guid>
            <category><![CDATA[templating]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[codable]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Olivier Bazin]]></dc:creator>
            <pubDate>Thu, 06 Aug 2020 12:08:08 GMT</pubDate>
            <atom:updated>2020-08-06T12:22:28.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ak-6owh6a73kwviYBPRAfQ.jpeg" /></figure><p>When we started to develop our own view generator, we decided to share a unique format between all platforms (cf <a href="https://medium.com/cheerz-engineering/from-10-to-100-products-templates-are-your-best-friend-33ff45b81a03">first article of this serie</a>). Considering that, the iOS code needed to be stable for both parsing and generating views. The code needed also flexibility to absorb new features and new products. We can wrap this up by two code rules: the format is fixed and it evolves through time.</p><h3>Parsing a fixed format</h3><p>For the first rule, the easiest way to provide a fixed format is by having non-nullable variables and all possible variations described. In Swift, it is very easy to parse this type of data using Decodable protocol. Once those data are ready, there are very easy to use for view generation, considering all variation are already known.</p><p>For every item on the page, we chose to have a list containing all variation of item. For each variation, we have a specific parser. For example for pictures data :</p><pre>struct TemplateEditablePictureElementData: Decodable {<br>    var x: Double<br>    var y: Double<br>    var width: Double<br>    var height: Double<br>    var anchor: Anchor<br>    var z_index: Int<br> <br>    var type: String<br>    var key: String<br>}<br> <br>struct TemplateForcedImageElementData: Decodable {<br>    var x: Double<br>    var y: Double<br>    var width: Double<br>    var height: Double<br>    var anchor: Anchor<br>    var z_index: Int<br> <br>    var type: String<br>    var key: String<br> <br>    var asset_key: String<br>}</pre><p>As you can see, each struct has a type field, that will help the parser finding the right Decodable structure. We chose to implement an enum with the behavior to decode depending on the type :</p><pre>enum AvailableElementTypeData {<br>    case pictureElement(TemplateEditablePictureElementData)<br>    case forcedImageElement(TemplateForcedImageElementData)<br>}<br> <br>extension AvailableElementTypeData: Decodable {<br>    private enum CodingKeys: String, CodingKey {<br>        case type<br>    }<br> <br>    init(from decoder: Decoder) throws {<br>        let container = try decoder.container(keyedBy: CodingKeys.self)<br>        let type = try container.decode(String.self, forKey: .type)<br> <br>        let singleValueContainer = try decoder.singleValueContainer()<br>        switch type {<br>        case &quot;editable-picture&quot;:<br>            self = .pictureElement(try singleValueContainer.decode(TemplateEditablePictureElementData.self))<br>        case &quot;forced-image&quot;:<br>            self = .forcedImageElement(try singleValueContainer.decode(TemplateForcedImageElementData.self))<br>        default:<br>            throw TemplateReadingError.invalidBoxingType<br>        }<br>    }<br>}</pre><p>Once each item of the page is ready to be parsed, a page is decoded very easily :</p><pre>struct TemplatePageData: Decodable {<br>    var type: String<br>    var key: String<br>    var background_color: String<br> <br>    var width: Double<br>    var height: Double<br> <br>    var elements: [AvailableElementTypeData]<br>}</pre><h3>Time and fixed format</h3><p>Once the data can be easily parsed, we need to make sure they can evolve through time, in accordance with the 2nd rules we have established. The data we parse is different from the one used in the application. What is fixed is the data used inside the application. By separating the parsed data with the internal data, we can easily have different parser version. Knowing that, if the server include new values, we don’t have to update the whole application, only the parsing and eventually add field to the fixed data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/0*6upxQls_6qndrEhD" /></figure><p>When asked for a template, the server will always send the higher version available, making last features available for the user. The response data will contain the version of the template. To get the right version, we defined a struct that will parse the version. This version is used to find the right parser and then to decode the template.</p><pre>enum DefinitionKey: String, CodingKey {<br>        case definition<br>}<br> <br>struct MinimumParsing: Decodable {<br>    var definition_version: Int<br>}<br> <br>func decode(from decoder: Decoder) throws -&gt; Template {<br>        let container = try decoder.container(keyedBy: DefinitionKey.self)<br>        let minimumParsing = try container.decode(MinimumParsing.self, forKey: .definition)<br>        let converter = try getConverter(for: minimumParsing)<br>        return try converter.decodeTemplate(from: container)<br>}</pre><p>During a decode procedure, if some error has occurred, an error will be thrown. This error is speared to the view layer of the application. We make sure the user will never use an outdated template or an unhandled version.</p><h3>Separation is key</h3><p>With our two main rules about the data, we need to have a strong separation between code layers. The parsed data is only available in a layer and is transformed to the next data layer. By enforcing this code, we make a point about respecting the first principle of SOLID: separation of concern. Developing a template engine is making sure to have a strong separation between the data and the generated views.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a8b819743b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cheerz-engineering/from-10-to-100-products-templates-are-our-best-friends-part-2-4a8b819743b3">From 10 to 100 products: Templates are our best friends (part 2)</a> was originally published in <a href="https://medium.com/cheerz-engineering">Cheerz Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From 10 to 100 products : templates are your best friend]]></title>
            <link>https://medium.com/cheerz-engineering/from-10-to-100-products-templates-are-your-best-friend-33ff45b81a03?source=rss-89c7e5c25daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/33ff45b81a03</guid>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[templating]]></category>
            <dc:creator><![CDATA[Olivier Bazin]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 15:25:11 GMT</pubDate>
            <atom:updated>2020-08-04T15:56:06.248Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ak-6owh6a73kwviYBPRAfQ.jpeg" /></figure><h3>From 10 to 100 products: Templates are our best friends</h3><p>When we moved from having less than 10 products in our application to more than 10, we decided it was time to reconsider our technical stack. One of the issue that slow us to release new products, was the absence of a centralized format to describe products. We also needed a way to describe how a user customize its product.</p><h3>Defining the product template</h3><p>What is a product: a subset of pages, containing either texts either images a user can update. This is the simplest definition of what a template is and it is very easy to write in code</p><pre>struct TemplatePage {<br>    var elements: [BoxingElement]<br>}<br> <br>protocol BoxingElement { }<br> <br>struct TextElement: BoxingElement { }<br> <br>struct PictureElement: BoxingElement { }</pre><p>Next, we need to know how the elements are placed inside the page. For that, we were inspired by a famous format: css. Each product pages should at least have a size, and each elements of the page should have a size and a position, linked to an anchor system.</p><pre>struct TemplatePage {<br>    var id: String<br> <br>    var elements: [BoxingElement]<br>    var size: CGSize<br>}<br> <br>protocol BoxingElement {<br>    var id: String<br> <br>    var size: CGSize<br>    var position: CGPoint<br>    var anchor: Anchor<br>}<br> <br>enum Anchor {<br>    case left<br>    case middle<br>    case right<br>}</pre><h3>Generate views from template format</h3><p>Considering this simple template format, the implementation on iOS required a system to generate UIView (in the future the associated SwiftUI views) for each visual element: text or picture. We also wanted to have a specific layer that will handle the visual representation of the template. For that, we wrote classes for each elements that generates with the same input (template data) and the same output (a UIView element). This solution is a simple implementation of the Factory method pattern.</p><p>Note: Factory method pattern definition: “Define an interface for creating an object, but let subclasses decide which class to instantiate. The Factory method lets a class defer instantiation it uses to subclasses.” (<a href="https://en.wikipedia.org/wiki/Factory_method_pattern">https://en.wikipedia.org/wiki/Factory_method_pattern</a>)</p><p>The first type of factory produce a basic page. Depending on the screen size of the phone, this factory will create a basic page. The second type of factory produce each UIView depending on the BoxingElement. For example, the factory associated to the type TextElement will produce a TextView at a specific location.</p><pre>protocol ElementFactory {<br>    func createView(from boxingElement: BoxingElement) -&gt; UIView<br>}</pre><p>Since all our elements are defined the same way with a position and a size, and all elements need to be resized depending on the screen size, we decided to implement this part using TDD. We first implemented the test to calculate the right position and size, and then implemented the associated code. By already having test on content, we strengthens the application stability and the sharing between all platforms (iOS, Android and Web).</p><h3>Configure display with user choices</h3><p>Once all views are displayed, they need to display user choices and react to them. We choose to describe all user interactions in a ContentPage.</p><pre>struct ContentPage {<br>    var texts: [TextData]<br>    var pictures: [PictureData]<br>}<br> <br>struct TextData {<br>    var elementId: String<br>    var value: String<br>}<br> <br>struct PictureData {<br>    var elementId: String<br>    var imagePath: String<br>    var cropPosition: CGRect<br>}</pre><p>Once we defined what a user can change, the factory code needs to be updated. UIViews needs to be created and updated depending on this content:</p><pre>protocol ElementFactory {<br>    func createView(from boxingElement: BoxingElement, data: ContentPage) -&gt; UIView<br>    func update(view: UIView, from boxingElement: BoxingElement, data: ContentPage)<br>}</pre><p>Not only our factory will product a UIView, it will also update the view depending on how the user interacted with it. Being able to update the view directly will allow the code to directly respond to user update.</p><h3>Displaying and updating all pages</h3><p>Once we are able to generate a Page, we are able to create a list containing all product pages. We choose not to use directly the Page data for the list, but a simple Model that describes the data. The main reason is Page will stay in the data layer and Model will be in a “view” layer. The Model implements IdentifiableType from RxDataSources and is binded to a UICollectionView.</p><p><em>Note: RxDataSources is a public framework working based on RxSwift. It allows developers to bind data to list, and the framework automatically updates the list</em> (<a href="https://github.com/RxSwiftCommunity/RxDataSources">https://github.com/RxSwiftCommunity/RxDataSources</a>)</p><p>The architecture of the project contains:</p><ul><li>ViewController</li><li>ViewModel that bind the Model to the view</li><li>Model that describes the list</li><li>Factories to generate the needed views</li><li>Service</li></ul><p>The Service is the last and an important part of the architecture. Since our code needs to be flexible for future feature development, we choose not to call the factories from the ViewModel. This Service make sure the data are ready to use and transform them using the Factories. All those separation will limit through time our ViewModel size and will make sure we have clear Services that can be understood by all developers. You can consider this pattern a MVVM(+S) or a light VIPER.</p><h3>Make an architecture evolve</h3><p>When starting this project, we wanted to have the simplest architecture possible, and an architecture that can evolve through time. We did not choose to implement a strong architecture like VIPER, and instead we use a basic one we knew: MVVM while taking account of SOLID principles.</p><p>The project architecture is also directly linked to the UIView generation, which the core feature of the project. We wanted to make clear for all current and future developers how it can evolve while staying stable.</p><p>We hope that you found this article useful and we would be very happy to discuss it with you. Don’t hesitate to comment, and even better, to visit us in Paris or in upcoming Cocoaheads or Swift Paris sessions. Stay tuned for next episodes ;-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33ff45b81a03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cheerz-engineering/from-10-to-100-products-templates-are-your-best-friend-33ff45b81a03">From 10 to 100 products : templates are your best friend</a> was originally published in <a href="https://medium.com/cheerz-engineering">Cheerz Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing internal dependencies : module separation without pain]]></title>
            <link>https://medium.com/cheerz-engineering/managing-internal-dependencies-module-separation-without-pain-a7e06edb4aae?source=rss-89c7e5c25daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7e06edb4aae</guid>
            <category><![CDATA[xcodeproj]]></category>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[modularity]]></category>
            <dc:creator><![CDATA[Olivier Bazin]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 16:42:53 GMT</pubDate>
            <atom:updated>2020-08-04T15:54:30.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2EcdJSO_x6W-FGe5fm1CJg.jpeg" /></figure><h3>iOS dependencies: modules separation without pain</h3><p>At Cheerz, we try to do our best to propose to our clients an app with the best possible experience and regular updates to add new products, UX/UI refinements and so on. With years, we finally have more than 80k lines of code to manage and of course we need to have a clean organisation of our codebase to be able to efficiently deal with it.</p><p>To keep things tidy we decided to use internal pods to separate concerns into dedicated frameworks. First this approach seemed to be a very good choice, but within last months we understood that finally it had many drawbacks, and we wanted to tell you the story of how we decided to change our mind.</p><h3>Private pods approach: pain points</h3><p>By operating a modular separation relying on private pods, we had to put each private framework in a dedicated github repo. But doing so, we had to face these pain points :</p><ul><li>Very often we had to make several Pull Requests (one for each repo) to cover the entire perimeter of a feature. For instance, a global change in our Order List View (API change + view) depended on 3 repository : our API pod, our GUI pod and of course the main app. It was therefore difficult for developers to clearly understand the global purpose of a feature because of this split</li><li>Our code quality tracking tools were configured for our main repo (app’s one) so we had to repeat config process for each framework</li><li>Same thing for our CI : we had to add as many circle projects as we had libraries (with the aditionnal cost implied by this)</li><li>We had to manage each podspec to deal with lib versioning, but in our case without seeing any benefit : we always needed the last version of all our pods</li><li>Some of our pods came with an Example app (crucial to make some independant UI tests, for example), so we also had to manage the Podfile of these examples</li><li>Some of our pods needed same pods than the main app, so to resolve all the dependency map properly, we needed to always check that all podspecs and podfiles asked for the same version of the same pod (internal or external) : recursive and reverse dependency cycles</li><li>For this reason, the app release process was really painful : we needed to follow a dependency map to first release the most used library, and then, one by one, release each pod. Only then we could try to change the Podfile of our main app (to integrate last versions of released pods) and if all was successfull, we could only now create our release branch and switch to “normal release” tasks : our release was 90% a pod release, 10% an app release :-(</li></ul><h3>Switching to xcodeprojs</h3><p>Clearly, the price to pay was too expensive for the benefits, but we really wanted to keep a good separation and we knew that our modular approach was justified. So we ask ourselves : “How to have best of both worlds ? “ “How to keep things tidy but without all this pain”. To employ a metaphore, let’s say we were trying to put clothes into dedicated boxes, but, because we always need to open these boxes, we want them in our house, accessible, not in separated cellars.</p><p>Then we remembered that few months before we tried something by putting all our models in a dedicated handmade xcodeproj. After all, what cocoapods do for us ? A unique xcodeproj (Pods.xcodeproj) embedding all our dependencies. Well, that was exactly the solution we searched for : we decided to convert all of our pods in dedicated xcodeprojs, living in the same workspace (so in the same codebase).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*FwG1ggphSBlWiSyb" /></figure><p>This approach saved us a lot of time : approximatively 2 hours per release and about 10 minutes for each relatively important PR. Even more important, we obtained a shared consciousness that we only have one and only one app, and now we are no more trusting only the example target of a module, by configuring our ci to always launch integration tests which challenge the global coherence of our project.</p><p>For this reason, we wanted to share with you the steps to operate this migration, and list the main issues we had to solve (don’t be afraid, you will have to face these only one time ;-) )</p><h3>Migration Guide and how to solve main problems</h3><ul><li>The following article is a very good starting point : <a href="https://medium.com/@youvalv/cocoapods-for-an-existing-multi-project-workspace-1fb73f46fede">https://medium.com/@youvalv/cocoapods-for-an-existing-multi-project-workspace-1fb73f46fede</a></li><li>Create your xcodeprojs with xcode, targetting a dedicated folder that belongs to your global project, at the same level as your main app. The idea here is the let cocoapods work for you : you don’t link this project to your main workspace by hand, you set targets for theses projects directly in the Podfile file. Next pod install command will create the link</li><li>Remove all your previous private pods declaration in the main Podfile : you want to break the dependencies between the main project and the internal pods. This step is effective because it will highlight all the broken references in the internal framework. We will use these error messages as a follow-up to the good integration of the framework as xcodeproj. Indeed, if this integration succeeds, the errors will no longer have to be. Bonus point: it will be possible to keep the same name of the pod’s framework for the xcodeproj’s framework</li><li>Bundle APIs : When working on a pod, the framework resources (assets, xib, storyboard etc.) are placed in bundles defined in the Podspec file.</li></ul><pre># Podspec example<br>    s.subspec &#39;Core&#39; do |cs|<br><br>    ...<br><br>    cs.resource_bundles = {<br>        &#39;assets&#39; =&gt; [&#39;Resources/*.xcassets&#39;],<br>        &#39;strings&#39; =&gt; [&#39;Resources/**/*.lproj/*.strings&#39;],<br>        &#39;storyboards&#39; =&gt; [&#39;Resources/**/*.{lproj,storyboard}&#39;]<br>    }</pre><ul><li>These bundles will be accessible from the main project using Bundle.url(/service/forresource: withExtension:). After migrating the pod framework as an xcodeproj project, it will be no longer necessary to place these resources in specific bundles. This led you to use only the bundle of the current library, calling Bundle (for:) to retrieve a resource.</li><li>The classical oversight : in your main Podfile, you have to set explicitly the xcodeproj in a target section with the keyword “project”. Knowing that Cocoapods generates the xcworkspace, the resolution of the links between the different xcodeproj projects in the xcworkspace has to be done by the command pod install. It is necessary to specify to Cocoapods each project which will be used during this resolution. This keyword is also referenced in each target of the Podfile :</li></ul><pre># Podfile example<br><br>workspace &#39;MainApplication.xcworkspace&#39;<br>project &#39;MainApplication.xcodeproj&#39;<br>project &#39;Framework1/Framework1.xcodeproj&#39;<br>project &#39;Framework2/Framework2.xcodeproj&#39;<br><br>target MainApplication do<br>  project &#39;MainApplication.xcodeproj&#39;<br>  pod &#39;...&#39;<br>end<br><br>target &#39;Framework1&#39; do<br>  project &#39;Framework1/Framework1.xcodeproj&#39;<br>  pod &#39;...&#39;<br>end<br><br>target &#39;Framework2&#39; do<br>  project &#39;Framework2/Framework2.xcodeproj&#39;<br>  pod &#39;...&#39;<br>end</pre><ul><li>Be careful, if you have several configs in your main app (debug, adhoc, release … and so on) to set them also in your modules. If not, you won’t be able to build correctly</li><li>Modules used by main app must be declared as “Embed &amp; sign”. If these same modules are also used by another ones (transitive dependency), the must be declared (in the target of the consumming module) as “Do not Embed”. If you don”t do this, you will believe that everything works great, but next time you release to app store, the upload phase of the ipa will fail.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sk15bfiKJy3EEeofASx6_A.png" /><figcaption><em>In the main app, CheerzUtils is configured to be “Embed &amp; sign”</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBLU1dFWoaW1SGR72eyRYA.png" /><figcaption><em>The same module, linked in CheerzAPI, is configured to be “Do not embed”</em></figcaption></figure><h3>Conclusion: What we learned?</h3><p>Clearly, we are now convinced that there many ways to manage internal dependencies and the main criteria to make a choice is to answer to the question “How often do you need to tweak your libs?” If your internal modules are only here to synthesize and expose very deep abstractions or to collect extensions on primitive types, that’s perfectly ok to use internal pods. But if your features imply by themselves that you will always need to “open the box”, don’t be rude with yourself, and you can try this approach.</p><p>We hope that you found this article useful and we would be very happy to discuss it with you. Don’t hesitate to comment, and even better, to visit us in Paris or in upcoming Cocoaheads or Swift Paris sessions.</p><p>Stay tuned for next episodes ;-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7e06edb4aae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cheerz-engineering/managing-internal-dependencies-module-separation-without-pain-a7e06edb4aae">Managing internal dependencies : module separation without pain</a> was originally published in <a href="https://medium.com/cheerz-engineering">Cheerz Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making business logic clear with Reactive Programming]]></title>
            <link>https://medium.com/cheerz-engineering/making-business-logic-clear-with-reactive-programming-b26b21277ee7?source=rss-89c7e5c25daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/b26b21277ee7</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Olivier Bazin]]></dc:creator>
            <pubDate>Mon, 27 May 2019 13:11:23 GMT</pubDate>
            <atom:updated>2019-05-30T22:10:16.306Z</atom:updated>
            <content:encoded><![CDATA[<p>At Cheerz, we wanted recently to write our custom GooglePlaces based component, to allow our customers to input their shipping address in a trustable way. Why custom? Because we needed to have more control on requests number, characters needed to perform a search, custom timeouts and so on. We naturally chose RxSwift/RxCocoa to help us dealing with search scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kueo28GEgsmjNvAqsqDEQw.jpeg" /><figcaption>KISS: Keep It Simple and Stupid!</figcaption></figure><h3><strong>Let’s list our needs</strong></h3><p>Ask ourselves the question “What ingredients do we need to create this component?” Well, we want our new screen with:</p><ul><li>A tableView</li><li>A searchBar at top of the screen</li><li>A way to wire the search performed by the user to a Google request</li><li>Display autocomplete results in our tableView</li><li>A way to wire the address selection performed by the user to an auto-dismiss of our screen, going back to our address form, filled by the selection</li></ul><p><strong>Business Rules</strong>: no search unless search text has at least 4 characters, and we don’t want, if the user uses his device very quickly, to launch a request for each character but only when a pause is made (for example 0.5 s of non-activity)</p><h3><strong>Traditional way of thinking</strong></h3><p>Seeing these bullet points, we might be tempted to use only the classical tools provided by Apple : UISearchBarDelegate, UITableViewDataSource, and UITableViewDelegate, essentially.</p><p>Problem with this approach: classical delegation methods don’t allow you to write some code which deals synthetically with different moments of your flow. Let’s take the example of the text search. You have to :</p><ul><li>implement the delegate method textInputChange</li><li>In this method, you have to write a condition (like text.count &gt; 3) and if this condition is met, call Google services</li><li>But wait! We said we want to group user inputs to do not call Google services too often. So you also have to implement a timer to regularly make calls if the input has changed. Why a timer? Because calculating the difference of time between each input isn’t sufficient: you will never know if the last char is really the last in the user’s intention</li></ul><p>So basically, you need for this simple work, because the delegate method of the timer <strong>is another piece of code</strong> than the searchBar one, to write some flags, i.e “currentSearch”, “timeSinceLastSearch”, and so on. We all know that such flags are a real pain to maintain, and our component is likely to be very stateful and therefore not bugproof.</p><h3><strong>From flags to observers</strong></h3><p>We can now say in a very simple way what a flag is: <strong>setting a value representing the fact that something happened with or without a value attached to this thing</strong>. Later in the lifecycle of the application, we will, therefore, be able to write conditions implying several flags and make decisions (calling Google, waiting for a while …etc …). But because these values represent the past we must, of course, reset them when needed in order to <strong>always have a concrete representation of at state</strong>. Then, and only then, we can rely on them and <strong>react to changes</strong> which happened.</p><p>In other words, relying on flags is a simple but not so trustable way to connect events between them in order to write conditions and business rules.</p><p>But what if we could write these rules before these events even occurred? In our example, could be great if we could synchronize user input, time criteria, and minimum chars rule in a simple and declarative way, expressing our entire scenario in its simplicity?</p><p>Well, with Rx, we can write something like</p><pre>searchText<br>.orEmpty<br>.distinctUntilChanged<br>.throttle(0.3)<br>.filter{ $0.count &gt; 3}</pre><p>Let’s see this chain in details</p><h3><strong>From separated properties to unified observable sequence</strong></h3><p>If we look at the rx-ification of the UISearchBar class (accessible from searchBar.rx), we can see we have a “text” property, which type is ControlProperty&lt;String?&gt;. A method can be called on it: asObservable(). This is exactly what we looked for: a direct wire between a UI Component and the code responsible to react to its changes.</p><p>To do so, the text property is really our starting point, and with Rx we will connect it to the work we need to perform in a very simple way:</p><ul><li>First, we need to specify .orEmpty() in our Rx chain to be able to include text deletion in it.</li><li>Then, we can declare that we want a minimum separation between two firing events of 0.3 seconds with .throttle(0.3) : without any timer, we now have the guarantee that even if the user inputs his search very fast Rx will sequence it into reasonable time chunks.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*GZ-WfqiyGs0KaiJg9PhR4A.png" /><figcaption>A visual representation of what Throttle accomplishes</figcaption></figure><ul><li>After that, we need .distinctUntilChanged to exclude consecutive identical search patterns</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_VFIZCrz9dyj-q-gEtxthg.png" /><figcaption>Ignoring a “2” because it immediately follows another one</figcaption></figure><ul><li>Finally, we can specify our Rx chain to exclude patterns with a char length prior to 4 with filter{ $0.count &gt; 3}</li></ul><h3><strong>Conclusion: Observable streams as atomic business flows</strong></h3><p><strong>Readability:</strong> the operation of connecting user search, Google calls, appearance/disappearance of results is now expressed in a very synthetic way. All our rules are now described in an observables+operators chain, and if we need to change something, all is in its place :-).</p><p><strong>Self-documented</strong> code: the implementation of the search stream is so concise that a plain sentence to explain it should be longer than the code itself!</p><p>Even more importantly, we have now a <strong>natural-language-like</strong> expression of our business rules, so feedbacks between devs and other tech actors (POs, UXs for example) is way easier!!</p><p>Hope you’re now convinced that Rx can be easy and even simpler than some of the classical implementations we are used to manipulate.</p><h3>To dive in the Rx’s sea :</h3><ul><li><a href="https://rxmarbles.com/">RxMarbles</a>, a gold mine of schematic approach to Rx’s operators</li><li>The great Book of Florent Pillet, Marin Todorov, Junior Bontognali and Scott Gardner RxSwift: <a href="https://store.raywenderlich.com/products/rxswift">Reactive<strong> </strong>Programming with Swift</a></li><li>The <a href="https://github.com/ReactiveX/RxSwift">RxSwift’s Github repo</a> itself is full of playgrounds, documentation, examples … All you need can be found here!</li></ul><p>Do you want to see more than what we’ve shown here?</p><p>Don’t hesitate to contact us, it would be a pleasure to talk, or even to welcome for you for a coffee at our office (France 🇫🇷-&gt; Paris 🏙-&gt; Place de Clichy / Saint Lazare 🚊)!</p><p>Just so you know, <strong>we are hiring engineers</strong>! Don’t hesitate to <a href="/service/mailto:jobs@cheerz.com"><strong>contact us</strong></a>, or check <a href="https://welovedevs.com/app/company/cheerz">our page here</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b26b21277ee7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cheerz-engineering/making-business-logic-clear-with-reactive-programming-b26b21277ee7">Making business logic clear with Reactive Programming</a> was originally published in <a href="https://medium.com/cheerz-engineering">Cheerz Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>