{"id":7711,"date":"2025-04-11T08:54:47","date_gmt":"2025-04-11T01:54:47","guid":{"rendered":"https:\/\/binus.ac.id\/bekasi\/?p=7711"},"modified":"2025-04-11T08:54:47","modified_gmt":"2025-04-11T01:54:47","slug":"code-smells-dan-cara-menghindarinya","status":"publish","type":"post","link":"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/","title":{"rendered":"Code Smells dan Cara Menghindarinya"},"content":{"rendered":"<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7714 aligncenter\" src=\"http:\/\/binus.ac.id\/bekasi\/wp-content\/uploads\/2025\/04\/Gambar1-1.jpg\" alt=\"\" width=\"451\" height=\"301\" \/><span style=\"font-size: 10pt\">Figure 1. Kode Program (Sumber: https:\/\/www.pexels.com\/)<\/span><\/p>\n<p>Dalam dunia pengembangan perangkat lunak, kualitas kode adalah hal yang sangat krusial. Salah satu indikator rendahnya kualitas kode adalah <strong>Code Smell<\/strong> \u2014 istilah yang digunakan untuk menyebut gejala pada kode yang terlihat salah, meskipun belum tentu menyebabkan bug secara langsung.<\/p>\n<h3>Apa Itu Code Smell?<\/h3>\n<p>Istilah <strong>Code Smell<\/strong> pertama kali dipopulerkan oleh <strong>Kent Beck<\/strong> dalam buku <em>&#8220;Refactoring: Improving the Design of Existing Code&#8221;<\/em> oleh <strong>Martin Fowler<\/strong>. Code Smell adalah <strong>indikasi adanya masalah dalam struktur kode<\/strong> yang bisa menyulitkan pemeliharaan, pengujian, dan pengembangan lanjutan.<\/p>\n<h3><\/h3>\n<h3>Contoh Code Smells Umum dan Cara Menghindarinya<\/h3>\n<ol>\n<li><strong>Duplicated Code<\/strong><\/li>\n<\/ol>\n<p>Masalah: Blok kode yang sama muncul di beberapa tempat.<\/p>\n<p><em>Solusi:<\/em> Refactor dengan membuat method\/function reusable. Gunakan prinsip DRY (<em>Don&#8217;t Repeat Yourself<\/em>).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7713 aligncenter\" src=\"http:\/\/binus.ac.id\/bekasi\/wp-content\/uploads\/2025\/04\/Gambar2.png\" alt=\"\" width=\"210\" height=\"196\" \/><\/p>\n<ol start=\"2\">\n<li><strong>Long Method<\/strong><\/li>\n<\/ol>\n<p>Masalah: Fungsi terlalu panjang dan melakukan banyak hal.<\/p>\n<p>Solusi: Pecah menjadi beberapa fungsi yang lebih kecil dan jelas (prinsip SRP &#8211; Single Responsibility Principle).<\/p>\n<ol start=\"3\">\n<li><strong>Large Class<\/strong><\/li>\n<\/ol>\n<p>Masalah: Kelas menangani terlalu banyak tanggung jawab.<\/p>\n<p>Solusi: Bagi menjadi beberapa kelas sesuai tanggung jawabnya masing-masing.<\/p>\n<ol start=\"4\">\n<li><strong>Primitive Obsession<\/strong><\/li>\n<\/ol>\n<p>Masalah: Menggunakan tipe data primitif untuk hal kompleks (misalnya menggunakan string untuk menyimpan email, phone number, dll).<\/p>\n<p>Solusi: Bungkus data tersebut dalam class khusus (value object).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7712 aligncenter\" src=\"http:\/\/binus.ac.id\/bekasi\/wp-content\/uploads\/2025\/04\/Gambar3.png\" alt=\"\" width=\"240\" height=\"212\" \/><\/p>\n<ol start=\"5\">\n<li><strong>Speculative Generality<\/strong><\/li>\n<\/ol>\n<p>Masalah: Menambahkan kode \u201cuntuk berjaga-jaga\u201d yang belum diperlukan.<\/p>\n<p>Solusi: Fokus pada kebutuhan sekarang (YAGNI &#8211; You Aren\u2019t Gonna Need It).<\/p>\n<p>&nbsp;<\/p>\n<h3>Cara Menghindari dan Mengatasi Code Smells<\/h3>\n<ul>\n<li><strong>Refactoring Secara Berkala<\/strong>: Lakukan refactor kecil setelah menambahkan fitur untuk menjaga struktur tetap rapi.<\/li>\n<li><strong>Code Review dan Pair Programming:<\/strong> Melibatkan orang lain akan membantu menemukan bau yang tidak terdeteksi sendiri.<\/li>\n<li><strong>Ikuti Prinsip SOLID dan Clean Code:<\/strong> Panduan desain yang baik dapat mencegah code smell sejak awal.<\/li>\n<li><strong>Gunakan Static Code Analysis Tools:<\/strong> Tools seperti SonarQube, PMD, ESLint, dan lainnya bisa mendeteksi code smell secara otomatis.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 10pt\">Referensi:<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 10pt\">Martin Fowler. Refactoring: Improving the Design of Existing Code, 2nd Edition, Addison-Wesley, 2018.<\/span><\/li>\n<li><span style=\"font-size: 10pt\">Kent Beck &amp; Martin Fowler. <a href=\"https:\/\/martinfowler.com\/bliki\/CodeSmell.html\">https:\/\/martinfowler.com\/bliki\/CodeSmell.html<\/a><\/span><\/li>\n<li><span style=\"font-size: 10pt\">Robert C. Martin. Clean Code: A Handbook of Agile Software Craftsmanship, 2008.<\/span><\/li>\n<li><span style=\"font-size: 10pt\">SonarSource Documentation: https:\/\/docs.sonarsource.com<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Figure 1. Kode Program (Sumber: https:\/\/www.pexels.com\/) Dalam dunia pengembangan perangkat lunak, kualitas kode adalah hal yang sangat krusial. Salah satu indikator rendahnya kualitas kode adalah Code Smell \u2014 istilah yang digunakan untuk menyebut gejala pada kode yang terlihat salah, meskipun belum tentu menyebabkan bug secara langsung. Apa Itu Code Smell? Istilah Code Smell pertama kali [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":7714,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[345],"tags":[],"class_list":["post-7711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-science-software-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.4.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Code Smells dan Cara Menghindarinya - BINUS @Bekasi - Kampus Beken Asyik | Business Service and Technology<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Code Smells dan Cara Menghindarinya - BINUS @Bekasi - Kampus Beken Asyik | Business Service and Technology\" \/>\n<meta property=\"og:description\" content=\"Figure 1. Kode Program (Sumber: https:\/\/www.pexels.com\/) Dalam dunia pengembangan perangkat lunak, kualitas kode adalah hal yang sangat krusial. Salah satu indikator rendahnya kualitas kode adalah Code Smell \u2014 istilah yang digunakan untuk menyebut gejala pada kode yang terlihat salah, meskipun belum tentu menyebabkan bug secara langsung. Apa Itu Code Smell? Istilah Code Smell pertama kali [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/\" \/>\n<meta property=\"og:site_name\" content=\"BINUS @Bekasi - Kampus Beken Asyik | Business Service and Technology\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-11T01:54:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/binus.ac.id\/bekasi\/wp-content\/uploads\/2025\/04\/Gambar1-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"451\" \/>\n\t<meta property=\"og:image:height\" content=\"301\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/binus.ac.id\/bekasi\/#website\",\"url\":\"https:\/\/binus.ac.id\/bekasi\/\",\"name\":\"BINUS @Bekasi - Kampus Beken Asyik | Business Service and Technology\",\"description\":\"Binus kampus komunitas kreatif Bekasi dengan visi membangun universitas yang berkelas dunia di tahun 2020 mendatang, sebagai langkah menuju visi tersebut, BINA NUSANTARA kampus komunitas kreatif mengambil suatu langkah mantap untuk membuka jaringan pendidikan di Kota Bekasi.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/binus.ac.id\/bekasi\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/binus.ac.id\/bekasi\/wp-content\/uploads\/2025\/04\/Gambar1-1.jpg\",\"width\":451,\"height\":301},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/#webpage\",\"url\":\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/\",\"name\":\"Code Smells dan Cara Menghindarinya - BINUS @Bekasi - Kampus Beken Asyik | Business Service and Technology\",\"isPartOf\":{\"@id\":\"https:\/\/binus.ac.id\/bekasi\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/#primaryimage\"},\"datePublished\":\"2025-04-11T01:54:47+00:00\",\"dateModified\":\"2025-04-11T01:54:47+00:00\",\"author\":{\"@id\":\"https:\/\/binus.ac.id\/bekasi\/#\/schema\/person\/0093f9a535f53c255093cb9273f60a88\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/binus.ac.id\/bekasi\/2025\/04\/code-smells-dan-cara-menghindarinya\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/binus.ac.id\/bekasi\/#\/schema\/person\/0093f9a535f53c255093cb9273f60a88\",\"name\":\"editorarticle\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/binus.ac.id\/bekasi\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cd7fa27148001ad24ed966c031d91645eee771a6f7fe3b565b46a75ad24f4df6?s=96&d=mm&r=g\",\"caption\":\"editorarticle\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/posts\/7711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/comments?post=7711"}],"version-history":[{"count":2,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/posts\/7711\/revisions"}],"predecessor-version":[{"id":7716,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/posts\/7711\/revisions\/7716"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/media\/7714"}],"wp:attachment":[{"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/media?parent=7711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/categories?post=7711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binus.ac.id\/bekasi\/wp-json\/wp\/v2\/tags?post=7711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}