<?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 Anisha Inas on Medium]]></title>
        <description><![CDATA[Stories by Anisha Inas on Medium]]></description>
        <link>https://medium.com/@anishainas?source=rss-4151b75d0164------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AzCgs4rctaakludC5-cvjQ.jpeg</url>
            <title>Stories by Anisha Inas on Medium</title>
            <link>https://medium.com/@anishainas?source=rss-4151b75d0164------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:02:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anishainas/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[Traveloka Android Dynamic Feature Module: Pilot Project]]></title>
            <link>https://medium.com/traveloka-engineering/traveloka-android-dynamic-feature-module-pilot-project-9843c1285e18?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/9843c1285e18</guid>
            <category><![CDATA[mobile-app-architecture]]></category>
            <category><![CDATA[dynamic-feature-module]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[modern-android]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 10:36:52 GMT</pubDate>
            <atom:updated>2021-09-29T08:51:52.339Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Authors: </em><a href="https://medium.com/@anishainas"><em>Anisha Inas Izdihar</em></a><em> (Android Software Engineer) &amp; </em><a href="https://medium.com/@yusufcn"><em>Yusuf Cahyo Nugroho</em></a><em> (Android Software Engineer)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCtIXT197vkNn0ER1msLQA.png" /><figcaption>Illustration by the Momentum Team</figcaption></figure><p><em>Editor’s Note:</em></p><p><em>Today, Inas &amp; Yusuf took us back to 2019 to walk us through the various challenges (along with their novel workarounds through trials &amp; errors given the lack of official &amp; community supports back then) in attempting to adopt an Android framework that could deliver modules to devices dynamically while maintaining sound integration with non-dynamic modules in the Traveloka app. This is the first out of their three articles in a series.</em></p><p><em>Anisha Inas Izdihar &amp; Yusuf Cahyo Nugroho are both Android software engineers currently working on developing new feature in Flight to help users discover personalized travel destinations as well as on architecture-related projects such as Dynamic Feature Module migration respectively.</em></p><h3>Background</h3><p>When Google first introduced <a href="https://developer.android.com/guide/app-bundle/play-feature-delivery">Dynamic Feature Module</a> (DFM), an app serving framework that lets Android devices download code and resources on demand to serve new or different features to users, it was so <em>fresh from the oven</em> back then that there weren’t many how-to articles or guidelines. Moreover, the absence of DFM support from some of the libraries we used and the large highly-coupled multi-module code base that we already had, posed even more challenges to migrate the code to support DFM.</p><p>This article won’t guide you on how to implement DFM step by step since there are already many how-to articles such as <a href="https://proandroiddev.com/developing-your-own-dynamic-feature-3c48378e3065">Developing your own Dynamic Feature</a> or <a href="https://medium.com/mindorks/dynamic-feature-modules-the-future-4bee124c0f1">Android Dynamic Feature Modules : The Future</a> for your perusal. Instead, we will share our experience in solving the challenges we encountered when implementing DFM as our pilot project, which hopefully will be a useful reference when you want to embark on the same journey.</p><p>One of the many advantages of DFM that piqued our interest the most was the app size reduction. By implementing DFM, we can dynamically deliver some features to our installed app across users globally or even to specific countries. Therefore, the initial app’s size can be minimal specific to the users’ needs. Engineers also have better development experience since build time will be shorter. You can find more information about DFM and its benefits in <a href="https://developer.android.com/guide/app-bundle/play-feature-delivery">Overview of Play Feature Delivery</a>.</p><p>What we typically do in Traveloka with a new technology that we want to adopt is put it through a pilot project first that, once proven successful, could be implemented organization wide. The objective is to quickly identify as many problems as we can before requesting other engineers to use it in their products to speed up the development process. For the DFM pilot project, we picked one module in our codebase — let’s call it the pilot module — and migrated it to a dynamic module without worrying about the details. Therefore in the process, we might comment out some codes, put TODO comments on method implementations, or even change some logic as needed.</p><h3>Problem #1: The Absence of a Solid Modularized Codebase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*jXp6YMIc0qojMPbyAN1qUw.png" /><figcaption><strong>Figure 1. Old (left) vs new (right) module structure</strong></figcaption></figure><p>The left image above in figure 1 shows our initial multi-module structure. Modules with the suffix -api are API modules that only contain contracts like interface and data type (used by an interface as a parameter or a return type in its function). Modules without that suffix are Implementation modules. They contain classes that implement the interface from an API module and other implementation details codes. The goal is to convert one of the implementation modules to DFM without involving any API module.</p><p>In order to convert the pilot module to a DFM, we need to alter some dependencies structure. Given that a DFM module must depend on the App module, the latter could no longer depend on the pilot module to avoid circular dependency. After removing that dependency, we can then easily attach or detach the pilot module from the build (at the expense of not being able to use any of its features) and the app can still be compiled and run properly.</p><p>But here’s the problem: if we were to remove the pilot module dependency from the App module, both of which are tightly coupled, there will be errors. Therefore, we need to refactor some of our code so that the App module will not refer to anything from the pilot module.</p><p>To explain why they are so tightly coupled and how we solved the issue, please refer to <a href="https://medium.com/traveloka-engineering/dagger-and-multi-module-traveloka-android-app-c6c42b63db3f">Dagger and Multi-module Traveloka Android App</a>. Considering the steep resources to decouple the modules, we chose to comment out some codes and changed some of our pilot project’s logic to quickly meet the requirements.</p><p>After the module is decoupled, we removed the implementation project(‘:pilot’) declaration from the App module’s <strong>build.gradle</strong> file and added the implementation project(‘:app’) declaration to the pilot module. We also replaced the line apply plugin: ‘com.android.library’ with apply plugin<strong>:</strong> ‘com.android.dynamic-feature’ in the pilot module’s <strong>build.gradle</strong> file.</p><p>As you can see in the new module structure in figure 1 above, the pilot module now depends on the App module, a reverse from the previous structure and as such, building the app is now independent of the pilot module.</p><h3>Problem #2: ShrinkResource Incompatibility with DFM</h3><p>After decoupling both modules above, we ran into the following error when executing the Gradle’s sync command:</p><blockquote>Resource shrinker cannot be used for multi-apk applications</blockquote><p>It turned out <a href="https://developer.android.com/studio/build/shrink-code.html#shrink-resources">Resource Shrinking</a>, a compile-time task, when enabled in the Android Gradle Plugin (AGP), will reduce significant app size by automatically removing unused resources, had not supported DFM yet. With such a constraint, we could have set the shrinkResources property as false. However, <a href="https://medium.com/googleplaydev/shrinking-apks-growing-installs-5d3fcba23ce2">size does matter</a> for production apps. Here are our attempts to solve this problem:</p><h3>First Attempt: Add DFM support to AGP</h3><p>The obvious (and ideal) fix is for Google to add DFM support to AGP. We had reported this issue to Google. But apparently, someone already submitted <a href="https://issuetracker.google.com/issues/120517460">it</a> prior. Thereafter, Google released a fix, albeit only in the unstable version of AGP to date.</p><p>In a nutshell:</p><p>✓ Easy peasy. No effort from our side.</p><p>✗ Sporadic fix releases. It took Google almost two years to release a fix. But until this article is written, we still can’t use it because it is still unavailable in stable versions.</p><h3>Second Attempt: Modify AGP</h3><p>While still hoping for Google to release the fix in the stable version, we decided to search for a solution to that error on our own &amp; along the way we stumbled upon the <a href="https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/scope/VariantScopeImpl.java">AGP source code</a>. After reading the code, we discovered that the error occurred because Gradle checks for &amp; throws that error if either variantType or globalScope variable returns true for being or having a dynamic feature respectively as you can see in the code snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f35e970ef5a1b4d6a49933410657fce7/href">https://medium.com/media/f35e970ef5a1b4d6a49933410657fce7/href</a></iframe><p>We think that one of the reasons to have that conditional logic in place is to prevent unexpected bugs due to DFM.</p><p>One such possible bug is, let’s say we have a resource called <strong>ic_abc.xml</strong> that is only used by pilot module. If we enable ShrinkResource, whose function is to detect &amp; remove resources unused by the App module and its dependencies, there can be a problem after we restructure pilot module into DFM. ShrinkResource can’t detect that the file is actually still used because App module no longer depends on pilot module as shown in figure 2. Resource <strong>ic_abc.xml</strong> will be deleted and the bug will occur when we open an Activity in Dynamic Module that <em>expects</em> to use <strong>ic_abc.xml</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*iDri6rihnL1md-WIh8FFBA.png" /><figcaption><strong>Figure 2. ShrinkResource visibility before (left) vs after (right) pilot module is restructured into DFM</strong></figcaption></figure><p>Knowing that, we decided to put a comment on the issue tracker and asked Google to either remove the constraint imposed by that conditional logic on ShrinkResource or at least consider creating a new flag such as ForceShrinkResources that places the decision to shrink resources on the end user. This way we will bear the risk of unexpected bugs by due diligence on our part. But they haven’t responded to date.</p><p>Undeterred by their absence of response, we thought why not just modify their AGP jar file directly and remove the conditional logic that checks for DFM. It would work, right? But how to modify the jar file? None of us had done it before.</p><p>After some research, we found a cool Java bytecode editor called <a href="https://github.com/Col-E/Recaf">Recaf</a> that we used to modify the AGP jar file. But, a jar file is written in bytecode (a low-level programming language similar to the assembly language, one level away from ones &amp; zeros of the machine code that is on the other end of the spectrum from high-level languages such as Kotlin or Java). But eventually, not only did we manage to successfully remove the checker logic, but our modified AGP instance also worked gracefully to date.</p><p>In a nutshell:</p><p>✓ We can (re)enable ShrinkResources plugin.</p><p>✗ Need to modify the jar file for every new AGP update.</p><p>✗ Potential unexpected side effects from forcing AGP to run with DFM.</p><h3>Third Attempt: Create script to remove unused resources</h3><p>In the end, we decided not to use the 2nd approach because of the costly drawbacks aforementioned. Instead, in this third iteration, we manually remove our unused resources for every release. These are the complete steps:</p><h4>1. Create a resources.txt File</h4><p>The text file contains information about unused resources that we can remove. It is generated when we build an app with shrinkResources enabled. To produce it, we need to do these:</p><ul><li>Ensure DFM has an empty array in app/build.gradle because as mentioned before ShrinkRecources does not work with DFM → dynamicFeatures = []</li><li>Enable ShrinkResources in app/build.gradle → shrinkResources = true</li><li>Build the app. → gradlew app:assemble&lt;build-variant-name&gt;</li><li>Wait until the build is successful</li><li>Locate the created <strong>resources.txt</strong> in app/build/outputs/mapping/&lt;build-variant-name&gt;/resources.txt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8IanDacxAYa8TuDd5nKNcg.gif" /><figcaption>Figure 3. Creating a resources.txt file</figcaption></figure><h4>2. Modify resources.txt to the expected format</h4><p>It’s time to extract some information from resources.txt that we care about. The steps we need to do are:</p><ul><li>Remove all lines as they are not relevant except lines with the following entry:</li></ul><blockquote>Skipped unused resource res/drawable-xxhdpi-v4/ic_launcher_background.png: 767 bytes (replaced with small dummy file of size 67 bytes)</blockquote><ul><li>Modify every entry in step a above to look like this: res/drawable-xxhdpi-v4/ic_launcher_background.png</li></ul><blockquote>Hint: Use multiple cursors to highlight multiple selections at once by doing the key combination of option + drag on your Mac (on Windows, it’s alt + drag).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Lydza81KoVbh7ZjMznENRg.gif" /><figcaption>Figure 4. Formatting resources.txt</figcaption></figure><h4>3. Run ResourceCleaner.jar</h4><p>After step 2, we now have a file that contains all used resources. We can manually find and remove all the resources one by one, but that would be very tedious. Instead, we write a script to automate the process. You can see the source code below.</p><p><a href="https://github.com/yeuristic/android-resource-cleaner">yeuristic/android-resource-cleaner</a></p><h4>4. Revert changes in the first step</h4><p>Now that we have removed all unused resources, we can disable ShrinkResources again and add our module to <strong>build.gradle</strong> dynamic feature list → shrinkResources = true and dynamicFeatures = [&#39;:pilot&#39;]</p><h4>5. Build the project</h4><p>If the build fails, there’s a possibility that previously removed resources are still used by unused methods or classes. You can delete the method or the class and try to rebuild again.</p><h4>6. Commit, Push, and Create a PR</h4><p>In Traveloka, we repeat this process for each release cycle. But, we haven’t integrated it into our build pipeline for two reasons. First, we utilize the generated code from AGP to detect unused resources. Everytime Google updates the AGP, the generated code format might change and we would need to modify our script accordingly. Second, our script will also delete resources used by unused codes. We need to manually remove them first to make the build successful. So, it’s impossible to automate all of these.</p><p>In a nutshell:</p><p>✓ Remove unused resources and avoid unwanted side effects from modifying AGP jar file.</p><p>✗ Considerable manual efforts.</p><p>✗ Unused resources from Dynamic Feature Module can’t be detected.</p><p>✗ Unused resources from 3rd party libraries can’t be removed.</p><h3>Problem #3: DFM Incompatibility with Dart &amp; Henson</h3><p>When we tried to build our project, another error occurred below:</p><blockquote>Failed to apply plugin [id ‘dart.henson-plugin’] ‘android’ or ‘android-library’ plugin required.`</blockquote><p>The error message was quite clear, <a href="https://github.com/f2prateek/dart">Dart &amp; Henson library</a> that we use for our app navigation was not compatible with DFM yet to date. We reported this issue to the project owner via their Github and they quickly responded that we should make a PR and test it ourselves. We checked out their code and we found that the library also has a similar checker employed by AGP that causes projects with dynamic feature modules to fail to build. The required adjustments were relatively simple and they immediately accepted <a href="https://github.com/f2prateek/dart/pull/241">our PR</a>.</p><p>If you experience errors due to incompatible libraries or plugins with DFM, we recommend that you submit an issue to their owners or maintainers like we did and hopefully, they either fix it themselves or merge yours. Otherwise, you should probably find a workaround like what we did for Problem 2 above.</p><h3>Problem #4: Failed to Generate External Resources entry in R class</h3><p>We encountered yet another build error when our pilot module used external resources:</p><blockquote>Unresolved reference: color_from_other_module</blockquote><p>Since Traveloka Android app uses standardized view components from our in-house design library called Momentum, we couldn’t just move or duplicate the resources into our dynamic module. We also wondered the reason this issue occurred only in dynamic modules.</p><p>Behind the scene, AGP merges all the resources needed in a module like the illustration below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5yGRXCfVrf3IkfT3" /><figcaption>Figure 5. R files generation of regular module</figcaption></figure><p>Module C depends on module B, which depends on module A. When we compile the project, each module will generate an R class file that contains all the needed resources. Module A does not depend on any module &amp; thus, its R class will only include its own resources. However, since module B depends on module A, its R class will contain not only its own resources, but also the resources from all the modules it depends on. You get the idea for Module C.</p><p>But a problem arises if we migrate the C module for example to a dynamic module as its R class will no longer contain its dependents’ module resources &amp; therefore will fail to compile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E0iDFXDzqbynGVYa" /><figcaption>Figure 6. R files generation of dynamic module</figcaption></figure><p>To fix this, we need to specify the resources’ full package name to refer to the correct generated R class.</p><p>R.color_from_other_module → com.other.module.R.color_from_other_module</p><p>For Kotlin classes, we can use import aliases like below:</p><pre>import com.other.module.R as BaseR<br>import com.dynamic.module.R</pre><pre>val localColor = getColor(R.color.color_from_current_module)</pre><pre>val otherColor = getColor(BaseR.color.colour_from_other_module)</pre><h3>First Attempt</h3><p>When we build the project, the build log will show us all codes, which failed to link the resources. After that, we manually add the full package name one by one to the failing resources. Obviously, this is a very tedious job.</p><h3>Second Attempt</h3><p>Since we plan to implement DFM for many other modules, we looked into automating this process. Android already provides a Gradle task to generate the R classes containing IDs for resources used in a module. With this in mind, we decided to create a Gradle plugin that depends on the existing Gradle task mentioned before. This plugin will automatically add the full package name or add import aliases for Kotlin classes when a dynamic module feature refers to a resource from another module. You can use our plugin and learn more about how it works on the link below.</p><p><a href="https://github.com/yeuristic/dynamic-feature-resource-migration">yeuristic/dynamic-feature-resource-migration</a></p><h3>And At Last…</h3><p>After solving the problems mentioned above, we could successfully build our project. Our App now has regular modules and a dynamic feature module that coexist harmoniously (at least that’s what we thought by the time we completed the pilot project). We finished this pilot project around early 2019. Back then, not many people had tried DFM yet. Thus any error we encountered was mostly solved through trial and error. Though issues like the ShrinkResources plugin are still not fixed, you should be able to find workarounds more easily on the internet.</p><p>Since this is only a pilot project, we’re still unable to show you the real impact after implementing DFM. This article will be the first of a three part series of DFM implementation for Traveloka Android App. Please look forward to the second part where we will share our experience as well as challenges in implementing our first on-demand feature delivery called Budget Planner (I invite you to try it on the Traveloka app where you can explore holiday destinations with budget and timeline in mind 😜). The article will also show you how our app compares to before and after we implement DFM.</p><p>We are constantly exploring new technologies to build scalable systems. Check out <a href="https://www.traveloka.com/en/careers">Traveloka’s career page</a> and join us on our adventure!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9843c1285e18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/traveloka-engineering/traveloka-android-dynamic-feature-module-pilot-project-9843c1285e18">Traveloka Android Dynamic Feature Module: Pilot Project</a> was originally published in <a href="https://medium.com/traveloka-engineering">Traveloka Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Finalest final.”: Database Migration & Data Seeding]]></title>
            <link>https://medium.com/pplcewesemua2019/finalest-final-database-migration-data-seeding-4f4ce2427d19?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f4ce2427d19</guid>
            <category><![CDATA[data-migration]]></category>
            <category><![CDATA[dataseeding]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Fri, 24 May 2019 03:21:16 GMT</pubDate>
            <atom:updated>2019-05-24T03:21:16.637Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Database Migration</h3><p>Pada aplikasi sumbang.in, kami menggunakan DBMS PostgreSQL untuk menyimpan data. Data disimpan dalam tabel berisi row untuk tiap data dengan kolom yang mendeskripsikan isi data yang bersesuaian. Django menyediakan layanan Object Relational Mapper (ORM) agar pengguna tidak perlu lagi perlu secara manual membuat tabel dengan bahasa SQL. Kita dapat membentuk skema database dengan Django models dan Django akan secara otomatis memetakannya di SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxA5GPJTwnH_vLHjKPjDVw.png" /><figcaption>Kelas Model Alamat</figcaption></figure><p>Di models.py kita perlu mendefinisikan objek apa saja yang kita perlukan. Fields yang mendeskripsikan objek disertakan berikut dengan tipe data masing-masing field dan constraint yang diinginkan. Untuk membuat database di SQL, kita tidak hanya membuat models.py di Django saja, kita harus melakukan migration. Jika database sudah terbuat di SQL namun kita mengubah sesuatu di models.py kita juga perlu melakukan migration ulang.</p><p>Pertama lakukan perintah<strong> python manage.py makemigrations </strong>agar Django secara otomatis membuat migration file yang berisi bagaimana cara Django perlu membuat tabel database sesuai dengan yang kita buat di models.py.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-8EwuAefhuaHPf3lAkX_rQ.png" /><figcaption>Isi file migration initial</figcaption></figure><p>Untuk membuat perubahan di database lakukan command <strong>python manage.py migrate. </strong>Sekarang database SQL akan tersimpan sesuai dengan yang didefinisikan di models.py. Lakukan makemigrations dan migrate ulang jika melakukan perubahan di models.py,</p><h3>Data Seeding</h3><p>Kita bisa mempopulasikan database dengan data awal sehingga kita tidak perlu membuat data ulang setiap kali database direset. Fixture adalah kumpulan data yang dapat diimport ke database oleh Django. Fixture dapat dibuat dalam bentuk JSON atau YAML. Buat <strong>fixture </strong>kemudian gunakan perintah <strong>manage.py loaddata &lt;nama_fixture&gt;. </strong>Setiap kali loaddata dipanggil maka data yang sudah ada di database akan dihapus dan diganti dengan yang ada di file fixture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GqVzmDaYD4TZh6n04T9pA.png" /><figcaption>file fixture dan models.py</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRTE8gCpvIKENgbYLPj6-A.png" /><figcaption>Alamat yang terbentuk di PostgreSQL</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAhWOplLfvTVHvJqLpXHzQ.png" /><figcaption>User yang terbentuk di PostgreSQL</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f4ce2427d19" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/finalest-final-database-migration-data-seeding-4f4ce2427d19">“Finalest final.”: Database Migration &amp; Data Seeding</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Situ ngejek?!?”: Testing: Mock Object, Stub(Test Isolation)]]></title>
            <link>https://medium.com/pplcewesemua2019/situ-ngejek-testing-mock-object-stub-test-isolation-9e19386bfcce?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e19386bfcce</guid>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 19:28:22 GMT</pubDate>
            <atom:updated>2021-06-20T18:39:32.800Z</atom:updated>
            <content:encoded><![CDATA[<h3>“Lo ngejek?!?”: Testing: Mock Object, Stub(Test Isolation)</h3><p>Bukan, bukan mock ngejek ngatain…</p><h3>Beyond TDD: Test Isolation</h3><p>Pada suatu hari saya ingin mengcek coverage instrumentation test Android. Lalu tiba-tiba: FAILED. Beberapa test di change password ada yang gagal. Apa yang terjadi? Ternyata password yang digunakan untuk melakukan test sudah diganti, jadi jelas saya tidak dapat menggunakan password yang lama. Setiap kali akun di database diganti, begitu juga dengan test saya. Padahal kan yang ingin saya cek behavior Androidnya saja???</p><p>Disinilah mengapa Test Isolation sangat penting. Dikutip dari artikel milik <a href="https://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs">Sujit Kumar</a>, suatu tes harus memenuhi <strong>3A </strong>yaitu Arrange, Act, dan Assert. Yang menarik adalah <strong>Arrange </strong>yaitu data yang digunakan pada tes tidak boleh dependen pada environment. Karena kita hanya ingin menguji behavior dari suatu activity, seharusnya apa yang terjadi di belakang tidak perlu menjadi masalah. Misalnya kita ingin memastikan akan muncul peringatan jika pengguna memasukkan password yang salah. Tetapi untuk mengetahui password salah atau tidak kita perlu mengirimkan request ke API. Jadi, apa yang bisa dilakukan?</p><h3>Mock Object vs. Stub</h3><p>Fowler menulis <a href="https://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs">artikel</a> yang menarik tentang hal ini. Menurut Fowler, Mock melakukan behavior verification sedangkankan Stub digunakan untuk state verification. Apa maksudnya? Penjelasan berikut ini diambil dari <a href="https://callistaenterprise.se/blogg/teknik/2010/11/12/stubs-n-mocks/">artikel</a> milik Magnus Ekstrand.</p><h4>Stub</h4><p>Stub adalah suatu kelas yang mengembalikan (hard coded) data dari method dan funtionnya. Stub biasa digunakan pada unit test untuk menguji class atau method yang memberikan output untuk input yang diketahui. Stub bisa dilakukan dengan mengimplementasi interface yang ingin ditest dan bisa ditambahkan/mengoverride method baru dari yang sudah ada.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*DDVPnvLeJMs4QbBbuIBIWA.png" /><figcaption>Stub Kelas EditProfile pada test</figcaption></figure><p>Stubbing bisa juga dilakukan sebagai inner class. Potongan kode diatas adalah contoh stubbing yang dilakukan pada kelas Edit Profile. Activity Edit Profile menampilkan data yang disampaikan oleh activity sebelumnya yang melalui intent. Karena saya hanya menjalankan activity EditProfile saja, maka tidak akan ada intent yang disampaikan dari activity sebelumnya. Agar tidak mendapat null exception, maka saya membuat mengisi intent palsu.</p><h4><strong>Mock Object</strong></h4><p>Berbeda dengan stub, mock object diciptakan dengan menggunakan framework. Penggunaan mock lebih fleksibel dari stub karena tidak bergantung pada implementasi yang sudah ada. Berikut ini adalah contoh dari penggunaan mock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*exdpg-m8pQgXNTmQFyReHA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*0CR2RJ4X55XNvxCmt58wrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAPyUiTfIwSFiLx6bKCbLA.png" /></figure><p>Sebelumnya, untuk melakukan test behavior Android kita perlu mengujinya dengan memberi input data yang asli seperti pada database sehingga dapat mengembalikan response yang diberikan. Dengan cara seperti itu, data input perlu diupdate setiap database diganti. Test juga akan fail jika terdapat gangguan pada server. Dengan ini kita menggunakan mock API dengan kembalian response yang kita atur sendiri sehingga kita tidak perlu lagi bergantung pada environment.</p><h3><strong>Source</strong></h3><ul><li><a href="https://github.com/ghsukumar/SFDC_Best_Practices/wiki/F.I.R.S.T-Principles-of-Unit-Testing">ghsukumar/SFDC_Best_Practices</a></li><li><a href="https://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs">Mocks Aren&#39;t Stubs</a></li><li><a href="https://callistaenterprise.se/blogg/teknik/2010/11/12/stubs-n-mocks/">Difference between Stubs &#39;n&#39; Mocks | Callista Enterprise</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e19386bfcce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/situ-ngejek-testing-mock-object-stub-test-isolation-9e19386bfcce">“Situ ngejek?!?”: Testing: Mock Object, Stub(Test Isolation)</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Arsitek-arsitekan”: Software Architecture and Docker Orchestration]]></title>
            <link>https://medium.com/pplcewesemua2019/arsitek-arsitekan-software-architecture-and-docker-orchestration-10b7d8787577?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/10b7d8787577</guid>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 17:56:50 GMT</pubDate>
            <atom:updated>2019-05-02T03:44:16.347Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Software Architecture?</h3><p>Apa yang kita harapkan dari sebuah rumah? Aman, nyaman, kuat, dan lebih bersyukur lagi kalau tampilannya bagus. Agar memenuhi kriteria itu, maka rumah perlu dibangun dengan baik, mulai dari bahan bangunannya hingga ke teknik pembangunannya. Hal ini berlaku juga dalam pengembangan Perangkat Lunak.</p><p>Software architecture adalah proses perwujudan karakteristik perangkat lunak seperti flexibility, scalability, feasibility, reusability, dan security kedalam suatu rancangan solusi terstruktur yang memenuhi kebutuhan teknis dan bisnis.</p><h3>Why Software Architecture is Important</h3><p>Software Architecture dibutuhkan untuk memastikan terpenuhinya kebutuhan teknis dan bisnis. Perangkat lunak dengan rancangan yang buruk selain dapat menghambat terpenuhinya kebutuhan operasional juga dapat menghambat developer dalam mengembangkan software. Software yang baik harus memiliki scalability yang baik. Dengan arsitektur yang tidak baik bisa saja terjadi saat dimana software tidak bisa dikembangkan lagi karena hambatan teknologi.</p><h3>Software Architecture in sumbang.in</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3s-Ijrf1T0BHXozFdBnbKw.png" /></figure><h4>1. Android App</h4><p>Aplikasi Android sumbang.in kami kembangkan dengan Java. Kami menemukan berbagai kendala pada proses pengembangan karena desain arsitektur Android kami yang buruk. Kami belum menggunakan arsitektur Android seperti MVC, MVP, atau MVVM. Hal ini menyebabkan tiap kelas activity menjadi monster class yang memiliki banyak responsibility. Selain itu, struktur proyek kami juga menyebabkan kelas menjadi sulit dites. Apakah bisa diperbaiki? Tentu, tapi perlu MAJOR refactoring. Bisa selesai semester ini? h3h3h3h3hh3h3hh3h3h.</p><p>Aplikasi kami menampilkan data yang diambil dari API. Kami menggunakan Retrofit yaitu library yang digunakan untuk berhubungan dengan API. Untuk penyimpanan gambar kami menggunakan Firebase. Kami memanfaatkan layanan OneSignal untuk pengaturan push notification.</p><h4>2. Django REST API</h4><p>Aplikasi sumbang.in menggunakan Django REST Framework untuk APInya. Mengapa? Selain karena kami sudah berpengalaman menggunakan Django, Django REST Framework juga menawarkan banyak kelebihan yang menarik seperti interface yang dapat dengan sederhana dikonfigurasi. Kami dapat dengan lebih sederhana merancang API dengan fitur yang dimiliki Django.</p><h4>3. PostgreSQL</h4><p>Why? Why not? Dengan PostgreSQL data kami dapat diakses melalui PGAdmin yang sangat mempermudah untuk modifikasi tabel/data.</p><h4>4. Firebase</h4><p>Firebase kami gunakan untuk menyimpan gambar sehingga di API Kita hanya perlu menyimpan url gambar saja. Ketika gambar perlu ditampilkan, aplikasi Android hanya perlu menampilkan gambar yang ada di url.</p><h4>5. OneSignal</h4><p>Kami menggunakan OneSignal untuk simulasi scheduling pemrosesan donasi. Ketika user mengkonfirmasi suatu transaksi, maka kita juga mengirim request ke onesignal untuk menjadwalkan tiga jenis push notification. Ketika masing-masing push notification diterima, handler pada Android akan mengirimkan request ke API untuk mengganti status transaksi.</p><h3>Docker Orchestration</h3><p>Current condition: Push Gitlab →Pull image di Container →Recreate Container API →makemigrations →Seed data manual →Gunakan API</p><p>What we want: Push Gitlab →Gunakan API :)</p><p>Apa kendala tim kami? Di awal pengembangan proyek saya sudah mencoba berbagai cara untuk melakukan docker orchestration dengan docker-compose. Dengan docker compose seharusnya kita dapat mengkonfigurasikan container apa saja yang akan kita gunakan, tetapi gagal maning gagal maning. Sumber yang ada di internet tentang penggunaan docker compose di portainer juga minim. Saya sudah membuat docker compose namun sayangnya belum menemukan cara menjalankan script tersebut.</p><p>Waktu itu pernah diadakan Guest Lecture yang memaparkan cara penggunaan docker swarm, salah satu layanan docker orchestration. Tapi sayangnya portainer yang digunakan untuk PPL tidak memiliki fitur yang dibutuhkan seperti services dan swarm. Terdapat layanan lain yang dapat digunakan untuk melakukan docker orchestration yaitu dengan Kubernets seperti yang dipaparkan kelompok PPL LearnFazz. Namun, docker orchestration sebenarnya tidak diminta oleh product owner kami sehingga kami lebih fokus ke pengembangan proyek.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10b7d8787577" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/arsitek-arsitekan-software-architecture-and-docker-orchestration-10b7d8787577">“Arsitek-arsitekan”: Software Architecture and Docker Orchestration</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Jadi gua yang stress”: Django API Stress and Penetration Testing]]></title>
            <link>https://medium.com/pplcewesemua2019/jadi-gua-yang-stress-django-api-stress-and-penetration-testing-6938971360f3?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/6938971360f3</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[stress-testing]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Wed, 17 Apr 2019 20:49:04 GMT</pubDate>
            <atom:updated>2019-05-24T04:29:46.073Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is stress testing?</h3><p>Stress testing adalah jenis tes yang akan mengevaluasi stabilitas dan reliability suatu sistem. Tes ini akan menguji ketahanan sistem serta error handling pada kondisi ekstrim. Salah satu guna dari tes ini adalah untuk menentukan pada batas apa sistem tidak akan lagi mampu melayani.</p><p>Jika sistem tidak dapat melayani pengguna dalam kondisi ekstrim, hal ini bisa sangat merugikan pemilik jasa dan pengguna. Kondisi ekstrim yang dimaksud misalnya pada saat siak war. Website yang tidak didesain dengan baik dapat membuat website hanya dapat diakses beberapa orang sehingga mahasiswa kehilangan kesempatan untuk memilih mata kuliah yang diinginkan secara adil.</p><p>Terdapat beberapa tool yang dapat digunakan untuk melakukan stress testing. Contohnya yaitu <a href="https://locust.io/"><strong>Locust</strong></a><strong>. </strong>Locust adalah open source load testing tool yang dapat digunakan untuk menyimulasikan jutaan pengguna untuk menguji sistem.</p><h3>Stress Testing Example with Locust</h3><p>Pertama, install locust di mesin anda dengan <strong>pip install locustio,</strong>kemudian buat locust file yang berisi code yang akan dijalankan untuk stress testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dH2kyAdGbZZ1kwCcvc3sHA.png" /><figcaption>locustfile.py</figcaption></figure><p>File diatas jika dijalankan akan menguji end point get transaction. Pada kelas WebsiteUser terdapat atribut min_wait dan max_wait untuk mengatur jeda antara request user.</p><p>Untuk menjalankan stress testing, buka directory locustfile.py kemudian jalankan perintah <strong>locust — host=&lt;host_name&gt;</strong>. Host name berisi url aplikasi yang akan dites. Setelah itu, buka url locust yang berjalan. Kita akan diminta untuk menentukan jumlah user yang akan disimulasikan dan hatch rate nya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*hbqxwQyFxh7GJ9gumt5muA.png" /></figure><p>Setelah tes dijalankan, kita bisa melihat performa API kita seperti berikut. Kami menemukan bahwa API mulai kewalahan ketika menerima 100 request user bersamaan. Semakin banyak user, semakin tinggi failuresnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DOanou5v68jGuN70hNsIwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nktuv26ISf-uRf3JTK0vPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TnwETxQXHwlmOsN812qUwA.png" /></figure><p>Ternyata didapatkan bahwa terjadi kegagalan pada saat membuat koneksi pada database.</p><h3>What is penetration testing?</h3><p>Penetration testing akan melakukan simulasi cyber attack untuk mencari kelemahan sistem khususnya dalam hal security. Contoh kelemahan sistem yang dapat terjadi pada sumbang.in yaitu orang luar yang dapat mengubah status transaksi pengguna. Hal ini sangat tidak kita inginkan, oleh karena itu kami mengatur API untuk selalu meminta autentikasi dari pengirim request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*rMYlG41cA9PcpHBJIbnWtQ.png" /></figure><p>Namun usaha menerapkan autentikasi bisa saja tidak cukup. Terdapat banyak lagi serangan yang mungkin saja dapat menembus security sistem. Tahapan dalam melakukan penetration test seperti pada situs <a href="https://www.imperva.com/learn/application-security/penetration-testing/">https://www.imperva.com/learn/application-security/penetration-testing/</a> adalah sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*NRjWAGLHg_m8Cx-s.jpg" /></figure><h4><strong>1. Planning and reconnaissance</strong></h4><p>Tentukan scope tes. Misal pada project sumbang.in kami ingin menguji response yang dapat diterima oleh API kami.</p><h4><strong>2. Scanning</strong></h4><p>Pada langkah ini kita ingin melihat respon API terhadap segala jenis serangan</p><h4><strong>3. Gaining Access</strong></h4><p>Di tahap ini akan dicoba web application attacks seperti cross-site scripting, SQL injection, dan backdoor untuk menemukan kelemahan sistem. Jika berhasil masuk ke sistem, maka akan dicoba berbagai tindakan seperti mencuri data, intercept traffic, dan lainnya.</p><h4><strong>4. Maintaining access</strong></h4><p>Serangan diuji apakah dapat bertahan cukup lama tanpa langsung diatasi</p><h4><strong>5. Analysis</strong></h4><p>Hasil dari setiap langkah kemudian dilihat dan dievaluasi bagian sistem apa saja yang dapat ditingkatkan untuk mencegah kerugian dari serangan luar</p><h3>Security Check in sumbang.in</h3><p>Terdapat beberapa cara untuk menguji keamanan API sumbang.in. Di antaranya yaitu:</p><h4>1. Menjalankan Command ‘check’ dari Django</h4><p>Terdapat pengaturan di project Django yang sensitif dan harus dirahasiakan seperti secret_key. Pengaturan seperti DEBUG juga harus diset False untuk project yang dideploy di production. Jika DEBUG diset True, maka semua orang yang mengakses URL Api bisa melihat apa saja endpoint API. Django menyediakan command yang dapat digunakan untuk mengecek kebutuhan dasar security di Django yaitu dengan command berikut:</p><pre>(base) sumbangin_backend&gt;manage.py check --deploy</pre><pre>System check identified some issues:</pre><pre>WARNINGS:<br>?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and ena<br>bling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.<br>?: (security.W006) Your SECURE_CONTENT_TYPE_NOSNIFF setting is not set to True, so your pages will not be served with an &#39;x-content-type-options: nosniff&#39; header. You should<br>consider enabling this header to prevent the browser from identifying content types incorrectly.<br>?: (security.W007) Your SECURE_BROWSER_XSS_FILTER setting is not set to True, so your pages will not be served with an &#39;x-xss-protection: 1; mode=block&#39; header. You should co<br>nsider enabling this header to activate the browser&#39;s XSS filtering and help prevent XSS attacks.<br>?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set<br> this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.<br>?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.<br>?: (security.W016) You have &#39;django.middleware.csrf.CsrfViewMiddleware&#39; in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie m<br>akes it more difficult for network traffic sniffers to steal the CSRF token.<br>?: (security.W018) You should not have DEBUG set to True in deployment.<br>?: (security.W019) You have &#39;django.middleware.clickjacking.XFrameOptionsMiddleware&#39; in your MIDDLEWARE, but X_FRAME_OPTIONS is not set to &#39;DENY&#39;. The default is &#39;SAMEORIGIN&#39;<br>, but unless there is a good reason for your site to serve other parts of itself in a frame, you should change it to &#39;DENY&#39;.</pre><pre>System check identified 8 issues (0 silenced).</pre><h4>2. Fitur Dynamic Application Security Testing (DAST) Gitlab</h4><p>Gitlab memiliki fitur untuk melakukan pengecekan terhadap kelemahan web. Caranya mudah, kita hanya perlu menambahkan job dast di gitlab-ci.yml seperti berikut</p><pre>include:<br>  template: DAST.gitlab-ci.yml<br>  <br>stages:<br>  - dast<br><br>variables:<br>  DAST_WEBSITE: https://webmu.com/<br><br>dast:<br>  stage: dast</pre><p>Setelah pipeline dijalankan maka gitlab akan melaporkan kelemahan web yang ditemukan seperti cross-site scripting, HTTP parameter override, dan lainnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*YPZBwEt7cOa7EZIe7TpnoQ.png" /><figcaption>contoh kelemahan yang ditemukan</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6938971360f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/jadi-gua-yang-stress-django-api-stress-and-penetration-testing-6938971360f3">“Jadi gua yang stress”: Django API Stress and Penetration Testing</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Ngide pake state pattern”: Design Pattern and Refactoring in sumbang.in]]></title>
            <link>https://medium.com/pplcewesemua2019/ngide-pake-state-pattern-design-pattern-and-refactoring-in-sumbang-in-9ea03c0fe626?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ea03c0fe626</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[code-smells]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Wed, 17 Apr 2019 19:41:00 GMT</pubDate>
            <atom:updated>2019-04-17T19:41:00.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Design Pattern</h3><p>Menurut <a href="https://sourcemaking.com/design_patterns">sourcemaking.com</a>, design pattern adalah suatu solusi umum terhadap masalah yang sering ditemukan pada software development. Design pattern telah digunakan banyak orang sehingga kualitasnya teruji, dengan begitu pengembangkan software dapat berjalan lebih baik karena terhindar dari masalah yang perlu diatasi. Pengaplikasian design pattern disesuaikan dengan masalah apa yang ingin diatasi (atau dihindari). Penggunaan design pattern yang berlebihan atau tidak sesuai justru dapat menimbulkan masalah. Secara umum terdapat 3 jenis design pattern yaitu:</p><ol><li><strong>Creational design pattern: </strong>berhubungan dengan instansiasi suatu class</li><li><strong>Structural design pattern: </strong>berhubungan dengan komposisi class dan object</li><li><strong>Behavioral design pattern: </strong>berhubungan dengan bagaimana antar objek berkomunikasi</li></ol><h3>Design Pattern in sumbang.in Android App</h3><h4><strong>Singleton (Creational)</strong></h4><p>Design pattern singleton digunakan untuk memastikan bahwa hanya ada satu instance dari suatu class yang ada. Pada aplikasi sumbang.in kami menggunakan singleton untuk shared preference pengguna. Alasannya cukup jelas, karena kami ingin menyimpan data aplikasi di satu tempat saja. Berikut ini adalah contoh implementasinya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YlbkRnGXHHy-ZA41ZmzUCA.png" /><figcaption>class shared preference</figcaption></figure><h4>Builder (creational)</h4><p>Builder design pattern digunakan untuk menyembunyikan construction object yang kompleks. Retrofit sendiri telah menyediakan implementasi dari design pattern builder sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHFodX2MccANQeHguvmdeQ.png" /></figure><p>Konstruksi objek retrofit ini kompleks dan melibatkan banyak elemen lain sehingga implementasinya disembunyikan. Di sumbang.in project, Retrofit.builder disembunyikan lagi dalam kelas <strong>ServiceGenerator. </strong>Dengan ini, untuk membuat objek retrofit maka kami hanya perlu memanggil <strong>ServiceGenerator.createService(UserService.class)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R2zBTHrdqiPLyPnS3r-EEw.png" /></figure><h4>Composite (structural)</h4><p>Composite pattern merepresentasikan susunan hierarchical layaknya tree. Contoh yang paling jelas dari composite design pattern terdapat pada file xml. Contohnya pada file xml berikut ini komponen LinearLayout berperan sebagai parent yang memiliki banyak children meliputi TextView, EditText, LinearLayout, dan lainnya. Children LinearLayout dapat memiliki children juga dan seterusnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LISJSeaGvtaenGBKZrgZw.png" /></figure><h3>Design Pattern in Django REST API sumbang.in</h3><h4>Template Method (Behavioral)</h4><p>Template method mendefinisikan skeleton suatu algoritma kedalam subclass. Kelas yang menggunakan template method juga dapat mendefinisikan ulang langkah algoritma tersebut. Contoh implementasinya pada project kami terdapat pada views.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*iZEoOOo3-2BeCDopX32X7w.png" /></figure><p>AddressView dan ManageUserView memiliki dua fungsi yang berbeda, satu untuk mengelola alamat dan satunya mengelola profil pengguna. Tetapi, kedua kelas ini sama-sama ditujukan untuk mendapatkan dan mengupdate objek. Oleh karena itu, kedua kelas ini menggunakan kelas generics.RetrieveUpdateAPIView. Kelas generics menyembunyikan implementasi algoritma untuk menghandle request GET, POST, dan PATCH. AddressView dan ManageUserView dapat mengatur implementasi tersebut dengan mengoverride variable dan method yang sudah didefinisikan.</p><h4>Abstract Factory (Creational)</h4><p>Pattern ini digunakan karena kita ingin membuat objek berbeda namun masih berhubungan. UserManager bertugas untuk membuat objek user dan superuser. Yang berbeda diantaranya adalah superuser hanya membutuhkan email dan password, sedangkan user membutuhkan data lain seperti alamat, nomor hp, dan lainnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mdB3QNm8zRkQCFHbgbMhtw.png" /></figure><h3>What is Refactoring?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/0*LfIzJungh9dfBEDj.jpg" /><figcaption>y’all smell that code?</figcaption></figure><p>Refactoring adalah proses modifikasi software tanpa mengubah perilaku eksternal dari kode, namun meningkatkan struktur internalnya. Refactoring biasa dilakukan dalam langkah-langkah kecil yang tidak mengubah fungsionalitas software. Kita butuh melakukan refactor pada kode hingga memenuhi prinsip <a href="https://medium.com/pplcewesemua2019/clean-code-in-sumbang-in-app-9dd08cf5dc20"><strong>clean code</strong></a>. Code yang tidak clean ditandai dengan adanya code smells. Code smell merupakan karakteristik kode yang dapat mengindikasikan masalah yang lebih dalam. Terdapat banyak jenis code smells dan cara <a href="https://www.industriallogic.com/blog/smells-to-refactorings-cheatsheet/"><strong>mengatasinya</strong></a><strong>. </strong>Pada artikel ini saya akan menceritakan bagaimana saya mengatasi beberapa code smells pada sumbang.in</p><h4>Long method, Duplicated Code, Feature Envy → Extract Method</h4><p>Long method memiliki kode dengan kemungkinan didalamnya terdapat fungsi yang tidak relevan dengan tujuan method itu sendiri (feature envy), selain itu sangan mungkin juga terdapat duplicated code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGEcsLO4yvb5JqbdQxcN6w.png" /><figcaption>Before</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*sn2mTo1e7J05c8HW7R2CWA.png" /><figcaption>After</figcaption></figure><p>Pada contoh di atas saya mengekstraksi bagian kode yang mengatur value dari kumpulan text view. Barisan kode tersebut tidak sesuai diletakkan di onCreate selain itu ternyata di bagian kode yang lain terdapat juga baris untuk mengatur value dari textviews yang sama.</p><h4>Conditional Complexity → Simplify Conditional Statements</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*z_iaFNJb3rRIKWuWBIpXvA.png" /><figcaption>before</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*TVuYF-xlVeAhCCqOoSbHbQ.png" /><figcaption>after</figcaption></figure><p>Sebelum direfactor method sangat panjang karena terdapat dua bagian conditional statements yang berbeda. Statements tersebut sebenarnya dapat disederhanakan menjadi satu bagian saja.</p><p>Sebelumnya saya membuat ide untuk menggunakan state pattern seperti <a href="https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2019/PPLB3/blob/b31063a94506f576544e5f1e5e06c63a99260043/sumbangin_backend/api/Transaction.py"><strong>berikut</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*YX3ID4w9AA6_dETeazQyxw.png" /></figure><p>Namun saya sadar, menggunakan state pattern untuk project ini terkesan overkill sehingga saya menghandle perubahan status di views.py saja. Terlebih lagi python bukan bahasa OOP sehingga penggunaannya sebenarnya tidak begitu perlu karena sudah diatur di models.py</p><h4><strong>Primitive Obsession → Replace data value with object</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H16rp8kJnlkOT_4Nsw9jeQ.png" /><figcaption>after</figcaption></figure><p>Dilanjutkan dari variabel sebelumnya, string yang menandakan status transaksi barang sekarang digantikan dengan variabel. Jika ada perubahan, maka kita hanya perlu mengganti value dari variabel status tersebut saja tidak perlu mengganti semua nilai string.</p><h4><strong>Complex constructor → Replace constructor with design pattern</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BefSE-C1vo3j6JLXb_28w.png" /><figcaption>before using service generator</figcaption></figure><p>Pada bagian design pattern, saya sudah menjelaskan tentang Builder pattern. Potongan kode di atas belum menerapkan Builder pattern sehingga terlihat berantakan apalagi service ini akan digunakan di tiap activity. Dengan menggunakan builder pattern maka kita hanya perlu memanggil <strong>ServiceGenerator.createService(TransactionService.class) </strong>saja.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ea03c0fe626" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/ngide-pake-state-pattern-design-pattern-and-refactoring-in-sumbang-in-9ea03c0fe626">“Ngide pake state pattern”: Design Pattern and Refactoring in sumbang.in</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Boom boom boom (Gotta GIT that)”]]></title>
            <link>https://medium.com/pplcewesemua2019/boom-boom-boom-gotta-git-that-e6f26b5d6ecc?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6f26b5d6ecc</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Wed, 03 Apr 2019 04:51:14 GMT</pubDate>
            <atom:updated>2019-04-17T15:20:33.426Z</atom:updated>
            <content:encoded><![CDATA[<h3>4W1H Git</h3><h4>What is Git?</h4><p>Git adalah sistem <em>version control </em>yang digunakan untuk mencatat <em>history </em>perubahan kode. Dalam pengembangan <em>software</em>, anggota tim bekerja secara paralel, Git akan mencatat apa saja perubahan yang terjadi sehingga anggota tim dapat bekerja secara teratur. Terdapat layanan repository yang disediakan seperti GitLab yang berguna untuk menyimpan seluruh kode dan catatan perubahannya.</p><h4>Who use Git?</h4><p>Semua developer seharusnya menggunakan git.</p><h4>Why use Git?</h4><p>Karena bekerja secara paralel, <em>version control system </em>seperti Git dibutuhkan untuk menghindari terjadinya konflik. Git akan memberi tahu developer jika terdapat konflik dan akan meminta developer untuk menyelesaikan konflik tersebut. Git memungkinkan kita untuk kembali ke versi kode yang lebih lama jika terdapat masalah pada kode yang telah dimodifikasi.</p><h4><strong>Where can you use Git?</strong></h4><p>On every machine with git installed! Cek apakah git sudah terinstall dengan command git --version. Buat repository lokal dengan cara menginisialisasi suatu folder menjadi git repository dengan command git init.</p><h4>How to use Git?</h4><p>Berikut ini adalah beberapa command basic yang harus diketahui:</p><ul><li><strong>git config</strong>: digunakan untuk mengatur nama dan email yang digunakan saat melakukan commit</li><li><strong>git init: </strong>untuk inisialisasi repositori lokal</li><li><strong>git clone [url]: </strong>untuk mendownload kode beserta semua catatan <em>history </em>dari suatu repository di server</li><li><strong>git add [file]: </strong>untuk menambahkan file yang dibuat ke staging area sebelum dapat dicommit</li><li><strong>git commit: </strong>untuk melakukan commit pada perubahan di staging area. Untuk menambahkan pesan commit tanpa membuka text editor dapat digunakan command git commit -m “[pesan]”.</li><li><strong>git reset [file]: </strong>mengeluarkan file dari tahap staging namunn tetap menjaga perubahan yang telah dilakukan</li><li><strong>git status: </strong>mendaftarkan file apa saja yang belum dicommit dan belum masuk staging</li><li><strong>git rm [file]: </strong>menghapus file dari directory</li><li><strong>git log: </strong>mendaftarkan <em>history </em>commit yang sudah dilakukan</li><li><strong>git branch: </strong>Untuk melihat branch apa saja yang ada. Hapus branch dengan command git branch -d “[nama_file]”</li><li><strong>git branch -b “[nama_branch]”: </strong>membuat branch baru.</li><li><strong>git merge “[nama_branch]”: </strong>menggabungkan branch nama_branch dengan branch saat ini</li><li><strong>git push [remote_name] [branch_name]: </strong>menambahkan seluruh file yang sudah kita commit ke repository di server</li><li><strong>git pull: </strong>meng-fetch perubahan yang ada di server ke lokal</li><li><strong>git stash: </strong>menyimpan semua tracked files yang dimodifikasi temporarily</li></ul><h3>Git flow pada sumbang.in project:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlg-WoxO84w8Ea2nI7xzRw.png" /></figure><p>Sebelumnya berikut ini adalah branch yang digunakan pada project sumbang.in:</p><ul><li><strong>Master</strong>: Branch ini protected. Hanya owner atau maintainer saja yang bisa melakukan merge ke branch ini. Branch staging akan dimerge ke master dengan persetujuan product owner.</li><li><strong>sit_uat: </strong>merupakan branch staging. Hasil sprint setiap minggu dikumpulkan di dalam branch ini</li><li><strong>user story: </strong>merupakan branch dimana anggota tim mengerjakan task sprint masing-masing.</li><li><strong>task: </strong>merupakan branch opsional jika ingin mengerjakan bagian kecil dari user story</li><li><strong>hot fix: </strong>branch yang digunakan untuk membenarkan kesalahan di <strong>master</strong></li><li><strong>cold fix: </strong>branch yang digunakan untuk membenarkan kesalahan di staging</li></ul><ol><li>Dari <strong>master</strong> buat branch <strong>sit_uat</strong>. Hanya gitlab owner yang bisa melakukan merge ke branch <strong>master</strong>.<em> command: </em><strong>git checkout -b sit_uat</strong></li><li>Checkout dari branch <strong>sit_uat</strong> dan bikin branch baru untuk tiap backlog item dengan penamaan US-&lt;nomor_user_story&gt;-&lt;judul_user_story&gt;. Develop user story di branch ini. <em>command: </em><strong>git checkout -b US-12-Riwayat_barang</strong></li><li>Untuk masing-masing task boleh dibuat branch baru. Checkout dari branch <strong>US-….</strong> dan buat branch baru dengan penamaan &lt;nomor_US&gt;-&lt;nama_task&gt;, develop task di branch tersebut. <em>command: </em><strong>git checkout -b 12-ganti_models</strong></li><li>Develop task kalian di branch story masing-masing. Untuk tiap perubahan yang berarti, maka commit pekerjaan kalian. <em>command: </em><strong>git add [nama_file] </strong>kemudian <strong>git commit -m “commit message yang berarti”</strong></li><li>Sebelum melakukan push ke branch user story harus melakukan pull dari sit_uat dan branch US remote dahulu. State test yang sudah ada sesudah pull tidak boleh berubah dari green ke red. <em>command: </em><strong>git pull origin sit_uat, git pull origin US-12-Riwayat_barang, </strong>dan jika sudah selesai <strong>git push origin US-12-Riwayat_barang</strong></li><li>Jika sudah lolos test maka branch user story bisa dilakukan merge request ke branch <strong>sit_uat</strong>. Di branch <strong>sit_uat</strong> tidak boleh lagi ada error. Untuk melakukan merge ke branch ini code dari user story sudah harus lolos test dan code review dari minimal dua orang yang tidak terlibat dalam development.</li><li>Deliver release dari <strong>sit_uat</strong> ke <strong>master</strong> jika sudah disetujui oleh product owner</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6f26b5d6ecc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/boom-boom-boom-gotta-git-that-e6f26b5d6ecc">“Boom boom boom (Gotta GIT that)”</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Kenapa Sprint Review-nya cepet banget???” A Walkthrough of Scrum Framework]]></title>
            <link>https://medium.com/pplcewesemua2019/kenapa-sprint-review-nya-cepet-banget-a-walkthrough-of-scrum-framework-a746f7e70bdf?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/a746f7e70bdf</guid>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[sprint]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Wed, 03 Apr 2019 04:11:06 GMT</pubDate>
            <atom:updated>2019-04-04T07:47:00.282Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will help you to understand Scrum framework, one of Agile software development implementations. I will show you how my team PPL Cewe Semua implement this framework in our project and what we learned during the process. Technical terms in the framework will be defined as I walked you through each steps of Scrum events. Before that, I will introduce you to the concepts of Agile software development I got from <a href="https://blogs.harvard.edu/markshead/"><strong>Mark Shead</strong></a><strong>’s </strong>video on Youtube. Lets get started…</p><h3>What is Agile?</h3><p>Agile is not a methodology, a way of developing software, nor a framework. Agile is a set of values that the teams use to make decisions on how to develop software. By following these values, it is believed that teams will be able to develop software better. Below is the values and principles according to <a href="http://agilemanifesto.org/"><strong>Agile Manifesto</strong></a>:</p><h4>Values</h4><ul><li>Individuals and interactions over processes and tools</li><li>Working software over comprehensive documentation</li><li>Customer collaboration over contract negotiation</li><li>Responding to change over following a plan</li></ul><h4>Principles</h4><ol><li>Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.</li><li>Welcome changing requirements, even late in development. Agile processes harness change for the customer’s competitive advantage.</li><li>Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.</li><li>Business people and developers must work together daily throughout the project.</li><li>Build projects around motivated individuals. Give them the environment and support they need, and trust them to get the job done.</li><li>The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.</li><li>Working software is the primary measure of progress.</li><li>Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.</li><li>Continuous attention to technical excellence and good design enhances agility.</li><li>Simplicity–the art of maximizing the amount of work not done–is essential.</li><li>The best architectures, requirements, and designs emerge from self-organizing teams.</li><li>At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.</li></ol><h3>What is Scrum?</h3><p>According to <a href="https://www.scrum.org/resources/what-is-scrum"><strong>scrum.org</strong></a>, Scrum is not a methodology. Although it follows a methodical approach, in practice Scrum does not tie its followers to a certain sets of rules. Scrum is a framework that follows Agile values and principles. Below is the image that portrays each events in Scrum framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqLh6IHWKjwg-P8YSFTy2g.png" /><figcaption>Scrum Framework</figcaption></figure><h3>Scrum Implementation in sumbang.in Project</h3><h4>Values</h4><ol><li>We don’t rely on tools to be productive</li><li>Make the code works! Write documentation later</li><li>Do what the client said, no matter what they said in the beginning.</li><li>Change always happen, adapt!</li></ol><h4>Principles</h4><ol><li>We always give the APK of our app to the product owner before Sprint reviews.</li><li>Adapt to change, I had to change the flow of changing password even if it is different from what we planned in the beginning</li><li>We have to come up with a finished product every sprint review.</li><li>Always communicate with the product owner when there are unclear requirements</li><li>We are a close-knitted group so it was not really a problem to help and motivate each other</li><li>We have scrum meeting every Tuesdays and Thursdays. We also have a coding marathon each Monday and a day before Sprint review. It helps us to get more productive!</li><li>We have to make sure to give minimum viable product each sprint.</li><li>We have a routine we follow each sprints</li><li>By implementing TDD, we can prevent many undetected errors as our project grew</li><li>Each sprint we have to make a feasible goal. Move the task to the next sprint if the task is impossible to work on in one sprint</li><li>My team is always open to each other, ask for help and someone will help you right away!</li><li>Every sprint retrospective we reflect on what we’ve done in the last Sprint. We give feedback to each other so we can do better next time.</li></ol><h4>Before Sprint</h4><p>When developing product we have sets of requirements and goals that needs to be met called <strong>product backlog</strong>. This product backlog is made by <strong>Product owner, </strong>the person who represents the final user’s best interest, and has the authority to say what goes into the final product. Product backlog is also called <strong>user story</strong>.</p><blockquote>Lessons learned: Don’t think product backlog as a feature that you can work on over the span of few sprints. If you think a backlog needs more times to work on, break it down to smaller backlogs. Try to make each backlog as independent as possible.</blockquote><h4>Sprint Planning</h4><p>Sprint is a predetermined time frame within which the team completes sets of tasks from the Backlog. The length of time depends on the needs of the team, for PPL 2019 we have two weeks to create minimum viable product. <strong>Minimum Viable Product (MVP)</strong> must be a fully functional product with just enough features to satisfy early customers. This product features will be updated on each Sprint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/0*HdL4AyIXBh2LwWKF.png" /><figcaption>Minimum Viable Product Illustration (hackernoon.com)</figcaption></figure><p>The MVP of each sprint is defined in <strong>Sprint goal, </strong>determined by the product owner<strong>. </strong>When we have the have the sprint goals we can choose the related <strong>backlog items</strong> from product backlog. This sets of backlog items is called <strong>Sprint backlog</strong>. <strong>Scrum master </strong>is responsible for promoting and supporting the implement of Scrum in team. Scrum master helps the development team to break down the chosen backlog items into smaller <strong>tasks. </strong>The development team will chose what tasks they will do for the Sprint.</p><blockquote>Lessons learned: It’s hard for team members to do their job if there are dependent backlogs. Make sure to plan your sprint accordingly.</blockquote><h4><strong>Daily Scrum</strong></h4><p><strong>Daily scrum</strong> is a quick meeting for the team members to give their progress updates. The team can choose their own time to have daily scrum. The meeting isn’t necessarily daily, for our project PPL Cewe Semua have daily scrum each Tuesdays and Thursdays.</p><h4>Sprint Review</h4><p>After the Sprint period ends, the team will presents their work during the period to product owner. During <strong>sprint review, </strong>product owner will evaluate what has been done and what has not been done related to the sprint goal. Product owner can either accept or reject the product. A product of Sprint is called an <strong>increment </strong>if the product owner accept the product.</p><h4>Sprint Retrospective</h4><p>In <strong>sprint retrospective</strong>, Scrum master will help the team members to identify what lessons they learned during the Sprint period to improve their productivity for their next Sprints. The team members can have peer review to help each other to understands better. The product of this event is <strong>sprint experiment, </strong>a set of ideas the team member can try to improve their productivity. For example, my team figured rather than doing one backlog alone, it is best to do pair programming for each backlog.</p><h4>After Sprint</h4><p>The Sprint doesn’t end here. Sprint is a recurring process that will only end if there are no more backlog items left in product backlog defined at the beginning of the project. The team members will continue to do sprint planning, daily scrum, sprint review, sprint retrospective, and back again. Each sprint will produce an MVP with incremented features along with each Sprints.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a746f7e70bdf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/kenapa-sprint-review-nya-cepet-banget-a-walkthrough-of-scrum-framework-a746f7e70bdf">“Kenapa Sprint Review-nya cepet banget???” A Walkthrough of Scrum Framework</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Susaaah”: Instrumented TDD for Android]]></title>
            <link>https://medium.com/pplcewesemua2019/susaaah-instrumented-tdd-for-android-986f8e4e8d31?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/986f8e4e8d31</guid>
            <category><![CDATA[espresso]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[instrumented-test]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Wed, 03 Apr 2019 04:00:26 GMT</pubDate>
            <atom:updated>2019-04-03T04:00:26.626Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*aD76sC-pxMc7u5qN.png" /><figcaption>Time graph comparing TDD and no TDD (<a href="https://cheesecakelabs.com/">https://cheesecakelabs.com/</a>)</figcaption></figure><p>Gambar tadi mengilustrasikan efek dari penerapan TDD dan tidak TDD. Dengan menerapkan test driven development, waktu yang dihabiskan di awal untuk menulis test memang banyak. Namun, seiring dengan berkembangnya ukuran project dan banyaknya perubahan pada kode maka kemungkinnya timbul error pada program akan lebih tinggi. Dengan TDD, developer wajib untuk menjaga kebenaran test untuk setiap perubahan yang dia buat. Berikut ini adalah workflow dalam penerapan TDD. Saya menemukan bahwa TDD membantu saya untuk menyelesaikan masalah secara lebih modular dan membantu saya menyusun strategi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*3p7YmlL_QtuQdWZ_.png" /><figcaption>TDD Cycle (<a href="https://cheesecakelabs.com/">https://cheesecakelabs.com/</a>)</figcaption></figure><ol><li>RED: Hal pertama yang harus dilakukan developer adalah membuat test. Test ini akan dipastikan failed (RED) karena developer belum mengimplementasikan fungsionalitas kode yang benar.</li><li>GREEN: Setelah test ditulis maka developer baru bisa mengimplementasi kode yang benar. Kode yang ditulis tidak perlu efektif dan memenuhi kaidah clean code, yang penting test yang dibuat sebelumnya dapat dijalankan dengan baik.</li><li>REFACTOR: Pada tahap ini developer diharuskan untuk memodifikasi code yang telah mereka buat sebelumnya agar lebih efektif dan memenuhi clean code. Seluruh bagian yang dirubah harus tetap memenuhi test yang sebelumnya sudah berhasil dijalankan.</li></ol><h3>Contoh TDD pada fitur mengganti password</h3><p>Saya akan memberi contoh bagaimana saya mengimplementasikan TDD pada saat mengembangkan fitur mengganti password pada project sumbang.in. Kami menggunakan instrumented test dengan memanfaatkan library espresso.</p><h4>Membuat test, code belum bisa dicompile (RED)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*eXS0yl1sfWrBz3RDWNr9dA.png" /></figure><p>Pertama saya membuat seluruh test untuk segala kemungkinan behavior yang saya harapkan ketika user menggunakan aplikasi. Berikut ini salah satu potongan code yang saya buat</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aty3-eL0ufyiPLoVKhbPyw.png" /><figcaption>Example of change password test</figcaption></figure><p>Potongan kode ini merupakan behavior yang saya harapkan untuk terjadi ketika password yang diinput terlalu panjang. Saat saya menuliskan kode ini, program tidak dapat dicompile karena terdapat resource yang belum dibuat. Hal ini diperbolehkan, kita hanya perlu melengkapinya di tahap selanjutnya.</p><h4>Melengkapi class dan potongan code hingga bisa dicompile (RED)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*GCyh0LyPij7H9hS4PC0xoQ.png" /><figcaption>Completing code</figcaption></figure><p>Pada tahap sebelumnya, program belum dapat dicompile karena terdapat beberapa resource yang belum didefinisikan. Pada tahap ini kita harus melengkapi resource tersebut agar test bisa dijalankan dan failed. Kita belum perlu mengimplementasikan logic yang benar di java class terlebih dahulu.</p><h4>Implementasi logic (GREEN)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ko5RAXgywXv2UtKjkWRxeg.png" /><figcaption>Logic implementation one by one until all tests passed</figcaption></figure><p>Setelah semua test ditulis dan dapat dicompile sehingga fail, maka tahap selanjutnya adalah mengimplementasi kode hingga seluruh test yang dibuat sebelumnya berhasil dijalankan.</p><h4>Optimasi kode dan menjaga kondisi agar semua tes passed (REFACTOR)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C0XKzMiZ0hElIlMNGy0N2w.png" /></figure><p>Walaupun kode sudah lolos test, namun kode yang saya tulis masih belum clean dan terdapat banyak baris untuk melakukan debug. Pada tahap refactor saya melakukan beberapa perubahan dengan tetap menjaga kebenaran code sehingga dapat tetap lolos test. Berikut ini adalah contoh refactor dengan melakukan extract method pada edit profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*_Kx7smYT95tihNf18vTNdA.png" /></figure><p>Pada potongan kode ini saya mengextract bagian setText tiap view dan mengumpulkannya kedalam method bernama displayTextData karena setText dilakukan di beberapa tempat. Dengan ini saya menerapkan konsep DRY.</p><p>Berikut tadi adalah bagaimana cara saya menerapkan TDD pada sprint sebelumnya. Setiap kali merge request ada kemungkinan terjadinya conflict. Setelah melakukan resolve conflict harus dipastikan lagi kode team member lain dapat tetap lolos tes bersama dengan perubahan yang kita buat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=986f8e4e8d31" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/susaaah-instrumented-tdd-for-android-986f8e4e8d31">“Susaaah”: Instrumented TDD for Android</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“?”: Clean Code in sumbang.in App]]></title>
            <link>https://medium.com/pplcewesemua2019/clean-code-in-sumbang-in-app-9dd08cf5dc20?source=rss-4151b75d0164------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dd08cf5dc20</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anisha Inas]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 04:54:02 GMT</pubDate>
            <atom:updated>2019-03-18T06:09:00.399Z</atom:updated>
            <content:encoded><![CDATA[<h3>“Tolong review yaaa”: Clean Code in sumbang.in App</h3><p>Definisi <em>clean code </em>ada bermacam-macam. Satu hal yang pasti, kode dikatakan <em>clean </em>jika kode dapat dimengerti dengan baik oleh orang selain penulis. Diambil dari buku Clean Code oleh Robert C. Martin, berikut ini adalah beberapa panduan <em>clean code </em>dengan contoh aplikasinya pada pengembangan aplikasi sumbang.in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*BmNrNJ5-g5RLRgbQ" /></figure><h3>General rules</h3><h4><strong>1. Follow standard conventions</strong></h4><p>Harus terdapat konsistensi dalam penulisan kode. Dalam penulisan kode, masing-masing bahasa pemrograman serta <em>framework </em>memiliki aturannya tersendiri. Konvensi penulisan kode untuk Python yang umum digunakan adalah PEP 8, sedangkan untuk Android dengan java terdapat banyak, salah satunya adalah AOSP.</p><ul><li><a href="https://www.python.org/dev/peps/pep-0008/">PEP 8 -- Style Guide for Python Code</a></li><li><a href="https://source.android.com/setup/contribute/code-style">AOSP Java Code Style for Contributors | Android Open Source Project</a></li></ul><h4><strong>2. KISS: Keep it simple stupid</strong></h4><p>Kode harus dijaga agar tetap <em>simple, </em>artinya masing-masing kelas, fungsi, interface, dan lainnya harus diberi nama yang jelas dan <em>logic </em>di dalamnya tidak terbelit-belit. Penjelasan lebih lanjut akan diberikan di bawah.</p><h4><strong>3. Boy scout rule. Leave the campground cleaner than you found it.</strong></h4><p>Pengembangan <em>software</em> umumnya dikerjakan dalam sebuah tim. Terkadang anggota tim dapat menulis kode yang tidak rapi. Tanggung jawab merapikan kode bukan hanya milik penulis asli, namun juga tanggung jawab anggota tim lainnya.</p><h3><strong>Understandability tips</strong></h3><h4><strong>1. Be consistent</strong></h4><p>Tentukan kesepakatan dalam mengembangkan software di awal sehingga tidak terjadi kesalahpahaman. Salah satu hal yang harus disepakati adalah git flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*c60ek_qfpPcq3MwAvA81rA.png" /></figure><h4><strong>2. Use explanatory variables</strong></h4><p>Beri nama variabel yang memang menggambarkan isi dan kegunaan dari variabel yang dimaksud. Misal jangan menamakan variabel dengan nama ‘x’. Variabel dengan nama seperti ‘x’, ‘i’, atau ‘y’ boleh digunakan jika konteksnya misal sebagai index pada loop.</p><h4><strong>3. Avoid logical dependency. Don’t write methods which works correctly depending on something else in the same class.</strong></h4><p>Method yang memiliki coupling tinggi dengan method lain memungkinkan adanya error yang tidak terdeteksi. Untuk menghindarinya kita dapat menggunakan pure function. Fungsi dikatakan pure jika:</p><ul><li>Mengembalikan nilai yang dikomputasi hanya berdasarkan argumen fungsi</li><li>Mengembalikan nilai yang sama untuk argumen yang sama, apapun yang terjadi di luar fungsi</li></ul><p>Pure function lebih mudah di-test karena tidak dipengaruhi oleh faktor lain.</p><h4><strong>4. Avoid negative conditionals.</strong></h4><p>Misal jangan gunakan variabel isNotAStudent, melainkan gunakan !(isAStudent).</p><h3><strong>Names rules</strong></h3><h4><strong>1. Choose descriptive and unambiguous names.</strong></h4><p>Berikut adalah contoh konvensi penamaan komponen pada Android development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*pTJVj0p1TBSPK-_4G38uww@2x.jpeg" /></figure><h4><strong>2. Make meaningful distinction.</strong></h4><p>Misal dalam suatu layout xml terdapat form password dan form konfirmasi password. Komponen dapat diberi id <em>edittext_signin_password</em> dan <em>edittext_signin_passwordconfirmation</em></p><h4><strong>3. Replace magic numbers with named constants.</strong></h4><p>Daripada menggunakan angka konstanta yang dapat membingungkan, sebaiknya disimpan sebagai variabel. Berlaku juga untuk konstanta string. Misalnya untuk url API di Android sebaiknya diatur di build.config</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*9CXfiMCnkzSet5cS7Rzdcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*dPsy6ghDxbucaG4FpgzVRg.png" /></figure><h3><strong>Functions rules</strong></h3><h4><strong>1. Small.</strong></h4><p>Usahakan suatu method dapat ditampilkan dalam satu layar</p><h4><strong>2. Do one thing.</strong></h4><p>Misalnya fungsi berikut ini hanya bertugas untuk mengganti text pada suatu view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*r7bbByG1nWtFAdsWIYKOLw.png" /></figure><h4><strong>3. Use descriptive names.</strong></h4><p>Satu method harus melakukan pekerjaan sesuai dengan nama method. Sebagaimana pada contoh fungsi setText di atas.</p><h4><strong>4. Prefer fewer arguments.</strong></h4><p>Jangan sampai suatu fungsi memiliki argumen yang terlalu banyak. Jika tidak bisa dikurangi artinya fungsi harus direfactor agar menjadi fungsi yang lebih kecil.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*e-KOD3yY1ExUKutW.png" /></figure><h3><strong>Comments rules</strong></h3><p>Jika kita perlu memberikan komentar pada kode kita, artinya kode masih belum bagus karena pembaca tidak bisa langsung mengerti apa yang kita buat. Berikan komentar jika memang perlu, misalnya memberi komentar <em>to do, </em>memberi warning pada fungsi yang tidak <em>thread safe, </em>dan hal-hal yang memang perlu lainnya.</p><h3><strong>Source code structure</strong></h3><h4><strong>1. Separate concepts vertically.</strong></h4><p>Method atau variabel yang saling berhubungan sebaiknya letaknya berdekatan agar tidak kesulitan mencari lokasinya.</p><h4><strong>2. Keep lines short.</strong></h4><p>Pindahkan potongan kode jika line sudah terlalu panjang. Pada IDE biasanya terdapat garis yang menandakan jika line sudah terlalu panjang.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dd08cf5dc20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pplcewesemua2019/clean-code-in-sumbang-in-app-9dd08cf5dc20">“?”: Clean Code in sumbang.in App</a> was originally published in <a href="https://medium.com/pplcewesemua2019">PPL cewe semua!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>