{"id":654,"date":"2025-08-12T13:36:15","date_gmt":"2025-08-12T06:36:15","guid":{"rendered":"https:\/\/kienthucmo.com\/?p=654"},"modified":"2025-12-09T23:06:15","modified_gmt":"2025-12-09T16:06:15","slug":"kiss-dry-yagni-3-nguyen-tac-vang-trong-phat-trien-phan-mem","status":"publish","type":"post","link":"https:\/\/kienthucmo.com\/vi\/kiss-dry-yagni-3-nguyen-tac-vang-trong-phat-trien-phan-mem\/","title":{"rendered":"KISS, DRY, YAGNI &#8211; 3 nguy\u00ean t\u1eafc v\u00e0ng trong ph\u00e1t tri\u1ec3n ph\u1ea7n m\u1ec1m"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Trong th\u1ebf gi\u1edbi ph\u1ea7n m\u1ec1m, n\u01a1i m\u1ed7i d\u00f2ng code \u0111\u1ec1u c\u00f3 th\u1ec3 l\u00e0 \u201ch\u1ea1t gi\u1ed1ng\u201d cho m\u1ed9t h\u1ec7 th\u1ed1ng v\u1eefng ch\u1eafc ho\u1eb7c m\u1ed9t \u201cqu\u1ea3 bom h\u1eb9n gi\u1edd\u201d c\u1ee7a l\u1ed7i l\u1ea7m, ch\u00fang ta &#8211; nh\u1eefng l\u1eadp tr\u00ecnh vi\u00ean &#8211; c\u1ea7n h\u01a1n c\u1ea3 kh\u1ea3 n\u0103ng vi\u1ebft code ch\u1ea1y \u0111\u01b0\u1ee3c . Ch\u00fang ta c\u1ea7n vi\u1ebft code c\u00f3 th\u1ec3 \u0111\u1ecdc \u0111\u01b0\u1ee3c, d\u1ec5 b\u1ea3o tr\u00ec, v\u00e0 kh\u00f4ng bi\u1ebfn th\u00e0nh g\u00e1nh n\u1eb7ng trong t\u01b0\u01a1ng lai.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ba nguy\u00ean t\u1eafc <strong>KISS<\/strong>, <strong>DRY<\/strong>, v\u00e0 <strong>YAGNI<\/strong> l\u00e0 b\u1ed9 ba \u201ckim ch\u1ec9 nam\u201d \u0111\u00e3 t\u1ed3n t\u1ea1i v\u00e0 ch\u1ee9ng minh gi\u00e1 tr\u1ecb qua h\u00e0ng ch\u1ee5c n\u0103m. Ch\u00fang kh\u00f4ng ph\u1ea3i l\u00e0 nh\u1eefng c\u00e2u kh\u1ea9u hi\u1ec7u su\u00f4ng, m\u00e0 l\u00e0 k\u1ebft tinh c\u1ee7a kinh nghi\u1ec7m x\u01b0\u01a1ng m\u00e1u t\u1eeb v\u00f4 s\u1ed1 d\u1ef1 \u00e1n ph\u1ea7n m\u1ec1m th\u00e0nh c\u00f4ng\u2026 v\u00e0 c\u1ea3 th\u1ea5t b\u1ea1i.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Trong b\u00e0i vi\u1ebft n\u00e0y, ch\u00fang ta s\u1ebd \u0111i s\u00e2u v\u00e0o \u00fd ngh\u0129a, t\u01b0 duy \u0111\u1eb1ng sau, v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng th\u1ef1c t\u1ebf c\u1ee7a ba nguy\u00ean t\u1eafc n\u00e0y. H\u00e3y coi \u0111\u00e2y kh\u00f4ng ch\u1ec9 l\u00e0 ki\u1ebfn th\u1ee9c, m\u00e0 l\u00e0 tri\u1ebft l\u00fd s\u1ed1ng c\u00f2n c\u1ee7a l\u1eadp tr\u00ecnh vi\u00ean.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. T\u1ed5ng quan<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KISS, DRY v\u00e0 YAGNI th\u01b0\u1eddng \u0111\u01b0\u1ee3c g\u1ecdi chung l\u00e0 <strong>&#8220;nguy\u00ean t\u1eafc thi\u1ebft k\u1ebf ph\u1ea7n m\u1ec1m&#8221;<\/strong> (software design principles) ho\u1eb7c c\u1ee5 th\u1ec3 h\u01a1n l\u00e0 <strong>&#8220;nguy\u00ean t\u1eafc l\u1eadp tr\u00ecnh&#8221;<\/strong> (programming principles \/ coding principles).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ch\u00fang thu\u1ed9c nh\u00f3m <strong>&#8220;best practices&#8221;<\/strong> \u2013 t\u1ee9c c\u00e1c ph\u01b0\u01a1ng ph\u00e1p, nguy\u00ean t\u1eafc \u0111\u01b0\u1ee3c c\u00f4ng nh\u1eadn r\u1ed9ng r\u00e3i gi\u00fap code d\u1ec5 b\u1ea3o tr\u00ec, d\u1ec5 m\u1edf r\u1ed9ng v\u00e0 gi\u1ea3m l\u1ed7i.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"533\" src=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/thiet-ke-phan-mem.jpg\" alt=\"thiet ke phan mem\" class=\"wp-image-657\" srcset=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/thiet-ke-phan-mem.jpg 800w, https:\/\/kienthucmo.com\/wp-content\/uploads\/thiet-ke-phan-mem-300x200.jpg 300w, https:\/\/kienthucmo.com\/wp-content\/uploads\/thiet-ke-phan-mem-768x512.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Ngo\u00e0i ba nguy\u00ean t\u1eafc n\u00e0y, c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean c\u00f2n hay nh\u1eafc \u0111\u1ebfn m\u1ed9t s\u1ed1 nguy\u00ean t\u1eafc kh\u00e1c nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SOLID<\/strong> \u2013 5 nguy\u00ean t\u1eafc thi\u1ebft k\u1ebf h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng.<\/li>\n\n\n\n<li><strong>GRASP<\/strong> \u2013 Nguy\u00ean t\u1eafc ph\u00e2n b\u1ed5 tr\u00e1ch nhi\u1ec7m trong OOP.<\/li>\n\n\n\n<li><strong>SoC<\/strong> (Separation of Concerns) \u2013 T\u00e1ch bi\u1ec7t c\u00e1c ph\u1ea7n ch\u1ee9c n\u0103ng \u0111\u1ec3 d\u1ec5 qu\u1ea3n l\u00fd.<\/li>\n\n\n\n<li><strong>SNE<\/strong> (Simple, Not Easy) \u2013 kh\u00e1 gi\u1ed1ng KISS nh\u01b0ng t\u1eadp trung v\u00e0o \u201cgi\u1ea3n l\u01b0\u1ee3c nh\u01b0ng kh\u00f4ng \u0111\u00e1nh \u0111\u1ed5i ch\u1ea5t l\u01b0\u1ee3ng\u201d.<\/li>\n\n\n\n<li><strong>Occam\u2019s Razor<\/strong> \u2013 Ch\u1ecdn gi\u1ea3i ph\u00e1p \u0111\u01a1n gi\u1ea3n nh\u1ea5t c\u00f3 th\u1ec3 m\u00e0 v\u1eabn \u0111\u00e1p \u1ee9ng y\u00eau c\u1ea7u.<\/li>\n\n\n\n<li><strong>Fail Fast<\/strong> \u2013 Ph\u00e1t hi\u1ec7n l\u1ed7i c\u00e0ng s\u1edbm c\u00e0ng t\u1ed1t \u0111\u1ec3 gi\u1ea3m chi ph\u00ed s\u1eeda ch\u1eefa.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Trong ph\u1ea1m vi b\u00e0i vi\u1ebft n\u00e0y ch\u00fang ta s\u1ebd t\u1eadp trung t\u00ecm hi\u1ec3u ch\u00ednh v\u1ec1 KISS, DRY v\u00e0 YAGNI<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. KISS \u2014 Keep It Simple, Stupid<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"736\" height=\"736\" src=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/kiss-avatar.jpg\" alt=\"\" class=\"wp-image-658\" srcset=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/kiss-avatar.jpg 736w, https:\/\/kienthucmo.com\/wp-content\/uploads\/kiss-avatar-300x300.jpg 300w, https:\/\/kienthucmo.com\/wp-content\/uploads\/kiss-avatar-150x150.jpg 150w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">2.1 \u0110\u1ecbnh ngh\u0129a &amp; tri\u1ebft l\u00fd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">KISS l\u00e0 l\u1eddi nh\u1eafc nh\u1edf: Gi\u1eef m\u1ecdi th\u1ee9 \u0111\u01a1n gi\u1ea3n nh\u1ea5t c\u00f3 th\u1ec3. Trong thi\u1ebft k\u1ebf h\u1ec7 th\u1ed1ng v\u00e0 vi\u1ebft code, \u201c\u0111\u01a1n gi\u1ea3n\u201d kh\u00f4ng ph\u1ea3i l\u00e0 b\u1ecf b\u1edbt t\u00ednh n\u0103ng, m\u00e0 l\u00e0 tr\u00e1nh s\u1ef1 ph\u1ee9c t\u1ea1p kh\u00f4ng c\u1ea7n thi\u1ebft.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nh\u1eefng h\u1ec7 th\u1ed1ng ph\u1ee9c t\u1ea1p th\u01b0\u1eddng n\u1ea3y sinh t\u1eeb s\u1ef1 t\u00edch l\u0169y c\u1ee7a nh\u1eefng quy\u1ebft \u0111\u1ecbnh nh\u1ecf nh\u01b0ng kh\u00f4ng \u0111\u01b0\u1ee3c ki\u1ec3m so\u00e1t. M\u1ed9t h\u00e0m ban \u0111\u1ea7u ch\u1ec9 10 d\u00f2ng, sau v\u00e0i l\u1ea7n \u201cch\u1eafp v\u00e1\u201d tr\u1edf th\u00e0nh 200 d\u00f2ng v\u1edbi nhi\u1ec1u nh\u00e1nh r\u1ebd, khi\u1ebfn ng\u01b0\u1eddi \u0111\u1ecdc ph\u1ea3i m\u1ea5t h\u00e0ng gi\u1edd \u0111\u1ec3 hi\u1ec3u.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 V\u00ec sao KISS quan tr\u1ecdng?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>T\u1ed1c \u0111\u1ed9 hi\u1ec3u v\u00e0 b\u1ea3o tr\u00ec<\/strong>: Code \u0111\u01a1n gi\u1ea3n gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean m\u1edbi v\u00e0o d\u1ef1 \u00e1n c\u00f3 th\u1ec3 nhanh ch\u00f3ng n\u1eafm b\u1eaft.<\/li>\n\n\n\n<li><strong>Gi\u1ea3m r\u1ee7i ro l\u1ed7i<\/strong>: M\u1ed7i ph\u1ea7n logic th\u1eeba l\u00e0 m\u1ed9t c\u01a1 h\u1ed9i \u0111\u1ec3 bug xu\u1ea5t hi\u1ec7n.<\/li>\n\n\n\n<li><strong>T\u1ed1i \u01b0u kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng<\/strong>: M\u1ed9t n\u1ec1n t\u1ea3ng \u0111\u01a1n gi\u1ea3n d\u1ec5 d\u00e0ng th\u00eam t\u00ednh n\u0103ng h\u01a1n n\u1ec1n t\u1ea3ng r\u1ed1i r\u1eafm.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 Nguy\u00ean t\u1eafc \u00e1p d\u1ee5ng<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Lu\u00f4n h\u1ecfi: <em>\u201cC\u00f3 c\u00e1ch n\u00e0o ng\u1eafn g\u1ecdn v\u00e0 r\u00f5 r\u00e0ng h\u01a1n kh\u00f4ng?\u201d<\/em><\/li>\n\n\n\n<li>Tr\u00e1nh \u201ct\u1ed1i \u01b0u s\u1edbm\u201d (<em>premature optimization<\/em>).<\/li>\n\n\n\n<li>S\u1eed d\u1ee5ng c\u00e1c c\u1ea5u tr\u00fac v\u00e0 th\u01b0 vi\u1ec7n quen thu\u1ed9c thay v\u00ec \u201cs\u00e1ng t\u1ea1o\u201d nh\u1eefng th\u1ee9 kh\u00f4ng ai hi\u1ec3u.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.4 V\u00ed d\u1ee5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>B\u00e0i to\u00e1n: T\u00ednh t\u1ed5ng gi\u00e1 tr\u1ecb \u0111\u01a1n h\u00e0ng (c\u00f3 gi\u1ea3m gi\u00e1 v\u00e0 thu\u1ebf)<\/strong><br>B\u1ea1n c\u00f3 m\u1ed9t danh s\u00e1ch c\u00e1c s\u1ea3n ph\u1ea9m trong gi\u1ecf h\u00e0ng, m\u1ed7i s\u1ea3n ph\u1ea9m c\u00f3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>price<\/code>: gi\u00e1<\/li>\n\n\n\n<li><code>quantity<\/code>: s\u1ed1 l\u01b0\u1ee3ng<\/li>\n\n\n\n<li>C\u00f3 th\u1ec3 c\u00f3 <code>discount<\/code> (t\u00f9y ch\u1ecdn)<\/li>\n\n\n\n<li>Thu\u1ebf VAT l\u00e0 10%<br>M\u1ee5c ti\u00eau: T\u00ednh t\u1ed5ng s\u1ed1 ti\u1ec1n kh\u00e1ch ph\u1ea3i tr\u1ea3.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u274c C\u00e1ch vi\u1ebft ph\u1ee9c t\u1ea1p, vi ph\u1ea1m KISS<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def calculate_total(cart):\n    total = 0\n    for i in range(len(cart)):\n        product = cart&#91;i&#93;\n        price = product&#91;\"price\"&#93;\n        quantity = product&#91;\"quantity\"&#93;\n        discount = 0\n        if \"discount\" in product:\n            discount = product&#91;\"discount\"&#93;\n        subtotal = price * quantity\n        if discount > 0:\n            subtotal = subtotal - (subtotal * discount)\n        tax = subtotal * 0.1\n        subtotal = subtotal + tax\n        total = total + subtotal\n    return total<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">calculate_total<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">cart<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">range<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">len<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">cart<\/span><span style=\"color: #ECEFF4\">)):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        product <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> cart<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #D8DEE9FF\">i<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        price <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> product<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">price<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        quantity <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> product<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">quantity<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        discount <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">discount<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> product<\/span><span style=\"color: #ECEFF4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            discount <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> product<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">discount<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        subtotal <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> price <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> quantity<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> discount <\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            subtotal <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> subtotal <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">subtotal <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> discount<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> subtotal <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        subtotal <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> subtotal <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> tax<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> total <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> subtotal<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> total<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>V\u1ea5n \u0111\u1ec1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Nhi\u1ec1u bi\u1ebfn t\u1ea1m kh\u00f4ng c\u1ea7n thi\u1ebft.<\/li>\n\n\n\n<li>Qu\u00e1 nhi\u1ec1u b\u01b0\u1edbc tu\u1ea7n t\u1ef1, kh\u00f3 nh\u00ecn ra \u201cb\u1ee9c tranh t\u1ed5ng th\u1ec3\u201d.<\/li>\n\n\n\n<li>V\u00f2ng l\u1eb7p d\u00f9ng <code>range(len(cart))<\/code> kh\u00f4ng c\u1ea7n thi\u1ebft.<\/li>\n\n\n\n<li>Logic gi\u1ea3m gi\u00e1 v\u00e0 thu\u1ebf t\u1ea3n m\u00e1t, kh\u00f3 t\u00e1i s\u1eed d\u1ee5ng.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u2705 C\u00e1ch vi\u1ebft KISS h\u01a1n<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def calculate_total(cart):\n    def item_total(p):\n        subtotal = p&#91;\"price\"&#93; * p&#91;\"quantity\"&#93;\n        subtotal *= (1 - p.get(\"discount\", 0))\n        return subtotal * 1.1  # c\u1ed9ng VAT 10%\n    \n    return sum(item_total(product) for product in cart)<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">calculate_total<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">cart<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">item_total<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">p<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        subtotal <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> p<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">price<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> p<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">quantity<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        subtotal <\/span><span style=\"color: #81A1C1\">*=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> p<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">get<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">discount<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> subtotal <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1.1<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\"># c\u1ed9ng VAT 10%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">sum<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">item_total<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">product<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> product <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> cart<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>T\u1ea1i sao \u0111\u01a1n gi\u1ea3n h\u01a1n?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>R\u00f5 \u00fd \u0111\u1ecbnh<\/strong>: Nh\u00ecn v\u00e0o l\u00e0 hi\u1ec3u ngay \u201ct\u00ednh t\u1ed5ng t\u1eebng s\u1ea3n ph\u1ea9m r\u1ed3i c\u1ed9ng l\u1ea1i\u201d.<\/li>\n\n\n\n<li><strong>\u00cdt bi\u1ebfn t\u1ea1m<\/strong>: Kh\u00f4ng c\u1ea7n l\u01b0u t\u1eebng gi\u00e1 tr\u1ecb trung gian n\u1ebfu ch\u1ec9 d\u00f9ng m\u1ed9t l\u1ea7n.<\/li>\n\n\n\n<li><strong>T\u00e1ch h\u00e0m nh\u1ecf<\/strong>: <code>item_total<\/code> gi\u00fap \u0111\u00f3ng g\u00f3i logic t\u00ednh gi\u00e1 t\u1eebng s\u1ea3n ph\u1ea9m.<\/li>\n\n\n\n<li><strong>D\u1ec5 b\u1ea3o tr\u00ec<\/strong>: N\u1ebfu sau n\u00e0y thu\u1ebf \u0111\u1ed5i t\u1eeb 10% \u2192 8%, ch\u1ec9 c\u1ea7n s\u1eeda m\u1ed9t ch\u1ed7.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>R\u00fat ra t\u1eeb v\u00ed d\u1ee5 n\u00e0y<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KISS<\/strong> kh\u00f4ng ch\u1ec9 l\u00e0 \u201cvi\u1ebft \u00edt d\u00f2ng h\u01a1n\u201d m\u00e0 l\u00e0 gi\u1eef cho \u00fd t\u01b0\u1edfng trong code r\u00f5 r\u00e0ng v\u00e0 d\u1ec5 \u0111\u1ecdc.<\/li>\n\n\n\n<li>Ng\u01b0\u1eddi m\u1edbi v\u00e0o d\u1ef1 \u00e1n \u0111\u1ecdc h\u00e0m KISS s\u1ebd hi\u1ec3u ngay m\u1ee5c \u0111\u00edch v\u00e0 lu\u1ed3ng x\u1eed l\u00fd, kh\u00f4ng ph\u1ea3i \u201cd\u1ecbch\u201d t\u1eebng bi\u1ebfn m\u1ed9t.<\/li>\n\n\n\n<li>Code KISS th\u01b0\u1eddng \u00edt bug h\u01a1n v\u00ec \u00edt \u0111i\u1ec3m r\u1ed1i lo\u1ea1n.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. DRY \u2014 Don\u2019t Repeat Yourself<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1024\" height=\"430\" src=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/dry-principle.png\" alt=\"\" class=\"wp-image-659\" srcset=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/dry-principle.png 1024w, https:\/\/kienthucmo.com\/wp-content\/uploads\/dry-principle-300x126.png 300w, https:\/\/kienthucmo.com\/wp-content\/uploads\/dry-principle-768x323.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">3.1 \u0110\u1ecbnh ngh\u0129a &amp; tri\u1ebft l\u00fd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">DRY k\u00eau g\u1ecdi: <strong>Kh\u00f4ng l\u1eb7p l\u1ea1i ch\u00ednh m\u00ecnh<\/strong>. N\u1ebfu m\u1ed9t logic xu\u1ea5t hi\u1ec7n \u1edf nhi\u1ec1u n\u01a1i, b\u1ea1n \u0111ang nh\u00e2n \u0111\u00f4i kh\u1ed1i l\u01b0\u1ee3ng c\u00f4ng vi\u1ec7c b\u1ea3o tr\u00ec v\u00e0 nh\u00e2n \u0111\u00f4i nguy c\u01a1 l\u1ed7i.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tri\u1ebft l\u00fd DRY n\u1eb1m \u1edf ch\u1ed7: M\u1ed7i \u00fd t\u01b0\u1edfng, m\u1ed7i ph\u1ea7n ki\u1ebfn th\u1ee9c trong h\u1ec7 th\u1ed1ng n\u00ean ch\u1ec9 t\u1ed3n t\u1ea1i \u1edf m\u1ed9t n\u01a1i duy nh\u1ea5t.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> 3.2 V\u00ec sao DRY quan tr\u1ecdng?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>B\u1ea3o tr\u00ec d\u1ec5 d\u00e0ng<\/strong>: Khi c\u1ea7n s\u1eeda \u0111\u1ed5i, b\u1ea1n ch\u1ec9 thay \u0111\u1ed5i m\u1ed9t ch\u1ed7 duy nh\u1ea5t.<\/li>\n\n\n\n<li><strong>Gi\u1ea3m sai s\u00f3t<\/strong>: Kh\u00f4ng lo s\u1eeda \u1edf file n\u00e0y nh\u01b0ng qu\u00ean \u1edf file kh\u00e1c.<\/li>\n\n\n\n<li><strong>T\u00e1i s\u1eed d\u1ee5ng<\/strong>: Logic chung \u0111\u01b0\u1ee3c gom l\u1ea1i th\u00e0nh function, module ho\u1eb7c class, gi\u00fap d\u1ef1 \u00e1n th\u1ed1ng nh\u1ea5t.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 Nguy\u00ean t\u1eafc \u00e1p d\u1ee5ng<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Khi th\u1ea5y m\u00ecnh copy-paste code t\u1eeb file n\u00e0y sang file kh\u00e1c, h\u00e3y d\u1eebng l\u1ea1i v\u00e0 ngh\u0129 c\u00e1ch t\u00e1ch th\u00e0nh h\u00e0m ho\u1eb7c module.<\/li>\n\n\n\n<li>S\u1eed d\u1ee5ng <strong>inheritance<\/strong> ho\u1eb7c <strong>composition<\/strong> trong OOP khi h\u1ee3p l\u00fd.<\/li>\n\n\n\n<li>D\u00f9ng <strong>constant<\/strong> ho\u1eb7c <strong>config file<\/strong> thay v\u00ec hard-code gi\u00e1 tr\u1ecb nhi\u1ec1u l\u1ea7n.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.4 B\u00e0i to\u00e1n: Qu\u1ea3n l\u00fd nh\u00e2n vi\u00ean v\u00e0 t\u00ednh l\u01b0\u01a1ng<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">B\u1ea1n c\u1ea7n vi\u1ebft m\u1ed9t h\u1ec7 th\u1ed1ng nh\u1ecf \u0111\u1ec3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u th\u00f4ng tin nh\u00e2n vi\u00ean.<\/li>\n\n\n\n<li>T\u00ednh l\u01b0\u01a1ng th\u1ef1c nh\u1eadn d\u1ef1a tr\u00ean l\u01b0\u01a1ng c\u01a1 b\u1ea3n, th\u01b0\u1edfng v\u00e0 thu\u1ebf.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u274c C\u00e1ch vi\u1ebft vi ph\u1ea1m DRY (l\u1eb7p code logic gi\u1ed1ng nhau \u1edf nhi\u1ec1u ch\u1ed7)<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def calculate_salary(emp):\n    gross_salary = emp&#91;\"base_salary\"&#93; + emp&#91;\"bonus\"&#93;\n    tax = gross_salary * 0.1\n    net_salary = gross_salary - tax\n    return net_salary\n\ndef print_salary(emp):\n    gross_salary = emp&#91;\"base_salary\"&#93; + emp&#91;\"bonus\"&#93;\n    tax = gross_salary * 0.1\n    net_salary = gross_salary - tax\n    print(f\"{emp&#91;'name'&#93;} nh\u1eadn {net_salary} VND\")<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">calculate_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">emp<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    gross_salary <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">base_salary<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">bonus<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    net_salary <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> tax<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> net_salary<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">print_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">emp<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    gross_salary <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">base_salary<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">bonus<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    net_salary <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> tax<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">f<\/span><span style=\"color: #A3BE8C\">&quot;<\/span><span style=\"color: #EBCB8B\">{<\/span><span style=\"color: #D8DEE9FF\">emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">name<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #EBCB8B\">}<\/span><span style=\"color: #A3BE8C\"> nh\u1eadn <\/span><span style=\"color: #EBCB8B\">{<\/span><span style=\"color: #D8DEE9FF\">net_salary<\/span><span style=\"color: #EBCB8B\">}<\/span><span style=\"color: #A3BE8C\"> VND&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>V\u1ea5n \u0111\u1ec1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Logic t\u00ednh l\u01b0\u01a1ng (<code>gross_salary<\/code>, <code>tax<\/code>, <code>net_salary<\/code>) b\u1ecb <strong>l\u1eb7p l\u1ea1i \u1edf c\u1ea3 hai h\u00e0m<\/strong>.<\/li>\n\n\n\n<li>N\u1ebfu c\u1ea7n thay \u0111\u1ed5i thu\u1ebf t\u1eeb 10% \u2192 8%, b\u1ea1n ph\u1ea3i s\u1eeda <strong>nhi\u1ec1u ch\u1ed7<\/strong>, d\u1ec5 qu\u00ean.<\/li>\n\n\n\n<li>T\u0103ng kh\u1ea3 n\u0103ng bug khi c\u1eadp nh\u1eadt thi\u1ebfu.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u2705 C\u00e1ch vi\u1ebft DRY (gom logic chung v\u00e0o m\u1ed9t ch\u1ed7)<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def net_salary(emp):\n    \"\"\"T\u00ednh l\u01b0\u01a1ng th\u1ef1c nh\u1eadn (\u00e1p d\u1ee5ng DRY)\"\"\"\n    gross_salary = emp&#91;\"base_salary\"&#93; + emp&#91;\"bonus\"&#93;\n    tax = gross_salary * 0.1\n    return gross_salary - tax\n\ndef calculate_salary(emp):\n    return net_salary(emp)\n\ndef print_salary(emp):\n    print(f\"{emp&#91;'name'&#93;} nh\u1eadn {net_salary(emp)} VND\")<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">net_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">emp<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">&quot;&quot;&quot;<\/span><span style=\"color: #A3BE8C\">T\u00ednh l\u01b0\u01a1ng th\u1ef1c nh\u1eadn (\u00e1p d\u1ee5ng DRY)<\/span><span style=\"color: #ECEFF4\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    gross_salary <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">base_salary<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">bonus<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> gross_salary <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> tax<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">calculate_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">emp<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">net_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">emp<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">print_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">emp<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">f<\/span><span style=\"color: #A3BE8C\">&quot;<\/span><span style=\"color: #EBCB8B\">{<\/span><span style=\"color: #D8DEE9FF\">emp<\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">name<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><span style=\"color: #EBCB8B\">}<\/span><span style=\"color: #A3BE8C\"> nh\u1eadn <\/span><span style=\"color: #EBCB8B\">{<\/span><span style=\"color: #88C0D0\">net_salary<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">emp<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #EBCB8B\">}<\/span><span style=\"color: #A3BE8C\"> VND&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>T\u1ea1i sao t\u1ed1t h\u01a1n?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Logic t\u00ednh l\u01b0\u01a1ng ch\u1ec9 t\u1ed3n t\u1ea1i \u1edf m\u1ed9t h\u00e0m duy nh\u1ea5t (<code>net_salary<\/code>).<\/li>\n\n\n\n<li>N\u1ebfu thu\u1ebf \u0111\u1ed5i, ch\u1ec9 c\u1ea7n s\u1eeda m\u1ed9t ch\u1ed7.<\/li>\n\n\n\n<li>C\u00e1c h\u00e0m kh\u00e1c ch\u1ec9 g\u1ecdi l\u1ea1i h\u00e0m chung, kh\u00f4ng copy-paste.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">R\u00fat ra t\u1eeb v\u00ed d\u1ee5 n\u00e0y<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DRY<\/strong> kh\u00f4ng ch\u1ec9 gi\u00fap code g\u1ecdn h\u01a1n, m\u00e0 b\u1ea3o v\u1ec7 b\u1ea1n kh\u1ecfi bug \u201cupdate thi\u1ebfu\u201d.<\/li>\n\n\n\n<li>Nguy\u00ean t\u1eafc DRY \u0111\u1eb7c bi\u1ec7t quan tr\u1ecdng trong d\u1ef1 \u00e1n l\u1edbn, n\u01a1i m\u1ed9t \u0111o\u1ea1n logic c\u00f3 th\u1ec3 xu\u1ea5t hi\u1ec7n \u1edf h\u00e0ng ch\u1ee5c file kh\u00e1c nhau.<\/li>\n\n\n\n<li>DRY = \u201cVi\u1ebft m\u1ed9t l\u1ea7n, d\u00f9ng nhi\u1ec1u l\u1ea7n\u201d \u2192 v\u1eeba ti\u1ebft ki\u1ec7m th\u1eddi gian, v\u1eeba gi\u1ea3m r\u1ee7i ro.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. YAGNI \u2014 You Aren\u2019t Gonna Need It<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" src=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/yagni.jpg\" alt=\"Yagni\" class=\"wp-image-660\" srcset=\"https:\/\/kienthucmo.com\/wp-content\/uploads\/yagni.jpg 600w, https:\/\/kienthucmo.com\/wp-content\/uploads\/yagni-300x300.jpg 300w, https:\/\/kienthucmo.com\/wp-content\/uploads\/yagni-150x150.jpg 150w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">4.1 \u0110\u1ecbnh ngh\u0129a &amp; tri\u1ebft l\u00fd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">YAGNI l\u00e0 l\u1eddi c\u1ea3nh t\u1ec9nh: \u0110\u1eebng x\u00e2y d\u1ef1ng nh\u1eefng th\u1ee9 b\u1ea1n ch\u01b0a c\u1ea7n. Nhi\u1ec1u l\u1eadp tr\u00ecnh vi\u00ean c\u00f3 xu h\u01b0\u1edbng \u201cd\u1ef1 ph\u00f2ng\u201d t\u00ednh n\u0103ng v\u00ec ngh\u0129 r\u1eb1ng \u201csau n\u00e0y s\u1ebd c\u1ea7n\u201d, nh\u01b0ng th\u1ef1c t\u1ebf r\u1ea5t nhi\u1ec1u \u201ct\u00ednh n\u0103ng d\u1ef1 ph\u00f2ng\u201d kh\u00f4ng bao gi\u1edd \u0111\u01b0\u1ee3c d\u00f9ng.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 V\u00ec sao YAGNI quan tr\u1ecdng?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ti\u1ebft ki\u1ec7m th\u1eddi gian<\/strong>: T\u1eadp trung l\u00e0m nh\u1eefng th\u1ee9 hi\u1ec7n t\u1ea1i mang l\u1ea1i gi\u00e1 tr\u1ecb.<\/li>\n\n\n\n<li><strong>Gi\u1ea3m r\u1ee7i ro<\/strong>: M\u1ed7i d\u00f2ng code l\u00e0 m\u1ed9t n\u01a1i ti\u1ec1m \u1ea9n bug, n\u1ebfu ch\u01b0a c\u1ea7n th\u00ec ch\u01b0a n\u00ean vi\u1ebft.<\/li>\n\n\n\n<li><strong>Tr\u00e1nh ph\u1ee9c t\u1ea1p h\u00f3a h\u1ec7 th\u1ed1ng<\/strong>: T\u00ednh n\u0103ng d\u01b0 th\u1eeba l\u00e0m ng\u01b0\u1eddi kh\u00e1c kh\u00f3 hi\u1ec3u code h\u01a1n.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 Nguy\u00ean t\u1eafc \u00e1p d\u1ee5ng<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ch\u1ec9 tri\u1ec3n khai t\u00ednh n\u0103ng khi c\u00f3 y\u00eau c\u1ea7u r\u00f5 r\u00e0ng t\u1eeb s\u1ea3n ph\u1ea9m ho\u1eb7c kh\u00e1ch h\u00e0ng.<\/li>\n\n\n\n<li>N\u1ebfu c\u1ea7n m\u1edf r\u1ed9ng sau n\u00e0y, h\u00e3y thi\u1ebft k\u1ebf code <em>d\u1ec5 m\u1edf r\u1ed9ng<\/em>, thay v\u00ec <em>vi\u1ebft s\u1eb5n<\/em> m\u1ecdi th\u1ee9.<\/li>\n\n\n\n<li>T\u1eadp trung v\u00e0o <strong>MVP (Minimum Viable Product)<\/strong> tr\u01b0\u1edbc.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.4 V\u00ed d\u1ee5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>B\u1ed1i c\u1ea3nh<\/strong><br>Gi\u1ea3 s\u1eed b\u1ea1n \u0111\u01b0\u1ee3c giao nhi\u1ec7m v\u1ee5 vi\u1ebft m\u1ed9t h\u00e0m \u0111\u1ec3 t\u00ednh t\u1ed5ng c\u00e1c s\u1ed1 nguy\u00ean trong m\u1ed9t danh s\u00e1ch (<code>list<\/code>).<br>B\u1ea1n <strong>d\u1ef1 \u0111o\u00e1n<\/strong> r\u1eb1ng t\u01b0\u01a1ng lai c\u00f3 th\u1ec3 c\u1ea7n h\u1ed7 tr\u1ee3 th\u00eam s\u1ed1 th\u1eadp ph\u00e2n, s\u1ed1 ph\u1ee9c, ho\u1eb7c x\u1eed l\u00fd danh s\u00e1ch l\u1ed3ng nhau\u2026 n\u00ean b\u1ea1n vi\u1ebft lu\u00f4n m\u1ed9t phi\u00ean b\u1ea3n &#8220;si\u00eau \u0111a n\u0103ng&#8221; ngay t\u1eeb \u0111\u1ea7u.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u274c C\u00e1ch l\u00e0m vi ph\u1ea1m YAGNI<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def sum_list(lst, allow_float=False, allow_complex=False, recursive=False):\n    total = 0\n    for item in lst:\n        if isinstance(item, int):\n            total += item\n        elif allow_float and isinstance(item, float):\n            total += item\n        elif allow_complex and isinstance(item, complex):\n            total += item.real  # gi\u1ea3 s\u1eed ch\u1ec9 c\u1ed9ng ph\u1ea7n th\u1ef1c\n        elif recursive and isinstance(item, list):\n            total += sum_list(item, allow_float, allow_complex, recursive)\n    return total\n\n# Hi\u1ec7n t\u1ea1i ch\u1ec9 c\u1ea7n c\u1ed9ng s\u1ed1 nguy\u00ean, nh\u01b0ng vi\u1ebft qu\u00e1 ph\u1ee9c t\u1ea1p\nprint(sum_list(&#91;1, 2, 3&#93;))  # 6<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">sum_list<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">lst<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">allow_float<\/span><span style=\"color: #81A1C1\">=False<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">allow_complex<\/span><span style=\"color: #81A1C1\">=False<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">recursive<\/span><span style=\"color: #81A1C1\">=False<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> item <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> lst<\/span><span style=\"color: #ECEFF4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">isinstance<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">int<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            total <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> item<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">elif<\/span><span style=\"color: #D8DEE9FF\"> allow_float <\/span><span style=\"color: #81A1C1\">and<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">isinstance<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">float<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            total <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> item<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">elif<\/span><span style=\"color: #D8DEE9FF\"> allow_complex <\/span><span style=\"color: #81A1C1\">and<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">isinstance<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">complex<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            total <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> item<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">real  <\/span><span style=\"color: #616E88\"># gi\u1ea3 s\u1eed ch\u1ec9 c\u1ed9ng ph\u1ea7n th\u1ef1c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">elif<\/span><span style=\"color: #D8DEE9FF\"> recursive <\/span><span style=\"color: #81A1C1\">and<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">isinstance<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">list<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            total <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">sum_list<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> allow_float<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> allow_complex<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> recursive<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> total<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># Hi\u1ec7n t\u1ea1i ch\u1ec9 c\u1ea7n c\u1ed9ng s\u1ed1 nguy\u00ean, nh\u01b0ng vi\u1ebft qu\u00e1 ph\u1ee9c t\u1ea1p<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">sum_list<\/span><span style=\"color: #ECEFF4\">(&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">&#93;))<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\"># 6<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>V\u1ea5n \u0111\u1ec1<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>B\u1ea1n vi\u1ebft th\u00eam <strong>nhi\u1ec1u t\u00ednh n\u0103ng ch\u01b0a c\u1ea7n thi\u1ebft<\/strong> (float, complex, recursive).<\/li>\n\n\n\n<li>Code kh\u00f3 \u0111\u1ecdc h\u01a1n, kh\u00f3 b\u1ea3o tr\u00ec h\u01a1n.<\/li>\n\n\n\n<li>C\u00f3 kh\u1ea3 n\u0103ng ph\u1ea7n m\u1edf r\u1ed9ng ch\u01b0a bao gi\u1edd \u0111\u01b0\u1ee3c d\u00f9ng, g\u00e2y l\u00e3ng ph\u00ed th\u1eddi gian ph\u00e1t tri\u1ec3n v\u00e0 ki\u1ec3m th\u1eed.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u2705 C\u00e1ch l\u00e0m theo \u0111\u00fang YAGNI<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>def sum_list(lst):\n    total = 0\n    for item in lst:\n        if isinstance(item, int):\n            total += item\n    return total\n\nprint(sum_list(&#91;1, 2, 3&#93;))  # 6<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">def<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">sum_list<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">lst<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> item <\/span><span style=\"color: #81A1C1\">in<\/span><span style=\"color: #D8DEE9FF\"> lst<\/span><span style=\"color: #ECEFF4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">isinstance<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">item<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">int<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            total <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> item<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> total<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #88C0D0\">sum_list<\/span><span style=\"color: #ECEFF4\">(&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #ECEFF4\">&#93;))<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\"># 6<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Gi\u1ea3i th\u00edch<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>B\u1ea1n ch\u1ec9 vi\u1ebft nh\u1eefng g\u00ec c\u1ea7n thi\u1ebft cho y\u00eau c\u1ea7u hi\u1ec7n t\u1ea1i.<\/li>\n\n\n\n<li>N\u1ebfu m\u1ed9t ng\u00e0y n\u00e0o \u0111\u00f3 th\u1eadt s\u1ef1 c\u1ea7n c\u1ed9ng th\u00eam s\u1ed1 th\u1eadp ph\u00e2n ho\u1eb7c danh s\u00e1ch l\u1ed3ng nhau, l\u00fac \u0111\u00f3 m\u1edbi m\u1edf r\u1ed9ng.<\/li>\n\n\n\n<li>Gi\u00fap code g\u1ecdn g\u00e0ng, d\u1ec5 hi\u1ec3u, v\u00e0 ti\u1ebft ki\u1ec7m th\u1eddi gian ph\u00e1t tri\u1ec3n.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>B\u00e0i h\u1ecdc t\u1eeb YAGNI<\/strong>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u0110\u1eebng \u201cti\u00ean tri\u201d cho t\u01b0\u01a1ng lai khi vi\u1ebft code. Vi\u1ec7c d\u1ef1 \u0111o\u00e1n qu\u00e1 nhi\u1ec1u nhu c\u1ea7u c\u00f3 th\u1ec3 khi\u1ebfn ph\u1ea7n m\u1ec1m tr\u1edf n\u00ean ph\u1ee9c t\u1ea1p, t\u1ed1n th\u1eddi gian m\u00e0 ch\u01b0a ch\u1eafc \u0111\u00e3 d\u00f9ng t\u1edbi. T\u1eadp trung gi\u1ea3i quy\u1ebft \u0111\u00fang y\u00eau c\u1ea7u hi\u1ec7n t\u1ea1i, m\u1edf r\u1ed9ng khi c\u1ea7n thi\u1ebft.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">5. M\u1ed1i li\u00ean h\u1ec7 gi\u1eefa KISS, DRY v\u00e0 YAGNI<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ba nguy\u00ean t\u1eafc n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i ri\u00eang l\u1ebb, m\u00e0 b\u1ed5 tr\u1ee3 l\u1eabn nhau:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KISS<\/strong> gi\u1eef code \u0111\u01a1n gi\u1ea3n, gi\u00fap DRY v\u00e0 YAGNI d\u1ec5 \u00e1p d\u1ee5ng.<\/li>\n\n\n\n<li><strong>DRY<\/strong> gi\u00fap h\u1ec7 th\u1ed1ng g\u1ecdn g\u00e0ng, t\u1eeb \u0111\u00f3 KISS \u0111\u01b0\u1ee3c duy tr\u00ec.<\/li>\n\n\n\n<li><strong>YAGNI<\/strong> gi\u1eef cho codebase nh\u1ecf g\u1ecdn, l\u00e0m KISS v\u00e0 DRY tr\u1edf n\u00ean kh\u1ea3 thi.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">N\u1ebfu v\u00ed l\u1eadp tr\u00ecnh nh\u01b0 <strong>x\u00e2y nh\u00e0<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KISS<\/strong> = b\u1ea3n thi\u1ebft k\u1ebf r\u00f5 r\u00e0ng, kh\u00f4ng r\u1ed1i.<\/li>\n\n\n\n<li><strong>DRY<\/strong> = d\u00f9ng chung v\u1eadt li\u1ec7u v\u00e0 k\u1ef9 thu\u1eadt thay v\u00ec l\u00e0m m\u1edbi ho\u00e0n to\u00e0n.<\/li>\n\n\n\n<li><strong>YAGNI<\/strong> = kh\u00f4ng x\u00e2y h\u1ed3 b\u01a1i khi ch\u01b0a ai mu\u1ed1n b\u01a1i.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. Nh\u1eefng sai l\u1ea7m th\u01b0\u1eddng g\u1eb7p khi \u00e1p d\u1ee5ng<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>KISS nh\u01b0ng qu\u00e1 gi\u1ea3n l\u01b0\u1ee3c<\/strong>\n<ul class=\"wp-block-list\">\n<li>Sai: C\u1eaft b\u1ecf t\u00ednh n\u0103ng quan tr\u1ecdng ch\u1ec9 \u0111\u1ec3 code ng\u1eafn.<\/li>\n\n\n\n<li>\u0110\u00fang: Gi\u1eef \u0111\u1ee7 t\u00ednh n\u0103ng, nh\u01b0ng kh\u00f4ng th\u00eam s\u1ef1 ph\u1ee9c t\u1ea1p kh\u00f4ng c\u1ea7n thi\u1ebft.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>DRY nh\u01b0ng \u00e1p d\u1ee5ng c\u1ef1c \u0111oan<\/strong>\n<ul class=\"wp-block-list\">\n<li>Sai: \u00c9p m\u1ecdi th\u1ee9 v\u00e0o m\u1ed9t h\u00e0m duy nh\u1ea5t, d\u1eabn t\u1edbi code kh\u00f3 \u0111\u1ecdc.<\/li>\n\n\n\n<li>\u0110\u00fang: Gom nh\u1eefng ph\u1ea7n <em>th\u1eadt s\u1ef1 chung<\/em>, gi\u1eef s\u1ef1 c\u00e2n b\u1eb1ng.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>YAGNI nh\u01b0ng b\u1ecf qua t\u00ednh to\u00e1n m\u1edf r\u1ed9ng<\/strong>\n<ul class=\"wp-block-list\">\n<li>Sai: Kh\u00f4ng ngh\u0129 t\u1edbi kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng, khi\u1ebfn sau n\u00e0y ph\u1ea3i vi\u1ebft l\u1ea1i t\u1eeb \u0111\u1ea7u.<\/li>\n\n\n\n<li>\u0110\u00fang: Thi\u1ebft k\u1ebf m\u1edf nh\u01b0ng kh\u00f4ng code th\u1eeba.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">7. K\u1ebft lu\u1eadn<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ba nguy\u00ean t\u1eafc <strong>KISS<\/strong>, <strong>DRY<\/strong>, v\u00e0 <strong>YAGNI<\/strong> l\u00e0 n\u1ec1n t\u1ea3ng c\u1ee7a t\u01b0 duy l\u1eadp tr\u00ecnh chuy\u00ean nghi\u1ec7p.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KISS<\/strong> nh\u1eafc b\u1ea1n gi\u1eef m\u1ecdi th\u1ee9 r\u00f5 r\u00e0ng, tr\u00e1nh ph\u1ee9c t\u1ea1p h\u00f3a.<\/li>\n\n\n\n<li><strong>DRY<\/strong> \u0111\u1ea3m b\u1ea3o b\u1ea1n kh\u00f4ng l\u1eb7p l\u1ea1i ch\u00ednh m\u00ecnh, gi\u1ea3m r\u1ee7i ro v\u00e0 t\u0103ng kh\u1ea3 n\u0103ng b\u1ea3o tr\u00ec.<\/li>\n\n\n\n<li><strong>YAGNI<\/strong> gi\u00fap b\u1ea1n t\u1eadp trung v\u00e0o gi\u00e1 tr\u1ecb hi\u1ec7n t\u1ea1i, tr\u00e1nh l\u00e3ng ph\u00ed v\u00e0o nh\u1eefng th\u1ee9 ch\u01b0a ch\u1eafc d\u00f9ng.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Tr\u01b0\u1edbc khi commit code, h\u00e3y t\u1ef1 h\u1ecfi:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KISS<\/strong> \u2014 C\u00f3 c\u00e1ch n\u00e0o \u0111\u01a1n gi\u1ea3n h\u01a1n kh\u00f4ng?<\/li>\n\n\n\n<li><strong>DRY<\/strong> \u2014 M\u00ecnh c\u00f3 l\u1eb7p l\u1ea1i \u1edf \u0111\u00e2u kh\u00f4ng?<\/li>\n\n\n\n<li><strong>YAGNI<\/strong> \u2014 M\u00ecnh c\u00f3 \u0111ang l\u00e0m th\u1eeba kh\u00f4ng?<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">L\u1eadp tr\u00ecnh kh\u00f4ng ch\u1ec9 l\u00e0 \u201ckhi\u1ebfn m\u00e1y t\u00ednh ch\u1ea1y\u201d, m\u00e0 l\u00e0 vi\u1ebft code \u0111\u1ec3 con ng\u01b0\u1eddi hi\u1ec3u v\u00e0 m\u00e1y t\u00ednh th\u1ef1c thi m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3. Ba nguy\u00ean t\u1eafc n\u00e0y ch\u00ednh l\u00e0 c\u1ea7u n\u1ed1i gi\u1eefa ngh\u1ec7 thu\u1eadt v\u00e0 k\u1ef9 thu\u1eadt trong l\u1eadp tr\u00ecnh.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0110\u1ecdc th\u00eam:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/kienthucmo.com\/solid-nguyen-ly-thiet-ke-phan-mem-huong-doi-tuong-ben-vung\/\" data-type=\"post\" data-id=\"22\">SOLID l\u00e0 g\u00ec? Nguy\u00ean l\u00fd ho\u1ea1t \u0111\u1ed9ng v\u00e0 c\u00e1ch \u00e1p d\u1ee5ng v\u00e0o th\u1ef1c ti\u1ec5n<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/kienthucmo.com\/clean-code-nghe-thuat-viet-ma-sach-va-ben-vung-trong-phat-trien-phan-mem\/\" data-type=\"link\" data-id=\"https:\/\/kienthucmo.com\/clean-code-nghe-thuat-viet-ma-sach-va-ben-vung-trong-phat-trien-phan-mem\/\">Clean Code: Ngh\u1ec7 thu\u1eadt vi\u1ebft m\u00e3 s\u1ea1ch v\u00e0 b\u1ec1n v\u1eefng trong ph\u00e1t tri\u1ec3n ph\u1ea7n m\u1ec1m<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">8. T\u00e0i li\u1ec7u tham kh\u1ea3o<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[1] B. W. Kernighan and P. J. Plauger, <em>The Elements of Programming Style<\/em>. New York, NY: McGraw-Hill, 1978.<\/li>\n\n\n\n<li>[2] A. Hunt and D. Thomas, <em>The Pragmatic Programmer: From Journeyman to Master<\/em>. Reading, MA: Addison-Wesley, 1999.<\/li>\n\n\n\n<li>[3] K. Beck, <em>Extreme Programming Explained: Embrace Change<\/em>. Reading, MA: Addison-Wesley, 1999.<\/li>\n\n\n\n<li>[4] ThoughtWorks, \u201cThe DRY Principle,\u201d <em>ThoughtWorks Insights<\/em>. [Online]. Available: <a href=\"https:\/\/www.thoughtworks.com\/insights\" target=\"_blank\" rel=\"noopener\">https:\/\/www.thoughtworks.com\/insights<\/a>.<\/li>\n\n\n\n<li>[5] M. Fowler, \u201cYAGNI,\u201d <em>martinfowler.com<\/em>. [Online]. Available: <a href=\"https:\/\/martinfowler.com\" target=\"_blank\" rel=\"noopener\">https:\/\/martinfowler.com<\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>KISS, DRY v\u00e0 YAGNI th\u01b0\u1eddng \u0111\u01b0\u1ee3c g\u1ecdi chung l\u00e0 &#8220;nguy\u00ean t\u1eafc thi\u1ebft k\u1ebf ph\u1ea7n m\u1ec1m&#8221; (software design principles) ho\u1eb7c c\u1ee5 th\u1ec3 h\u01a1n l\u00e0 &#8220;nguy\u00ean t\u1eafc l\u1eadp tr\u00ecnh&#8221; (programming principles \/ coding principles).<\/p>\n","protected":false},"author":1,"featured_media":2610,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowieHDDA:productID":"","footnotes":""},"categories":[16,17],"tags":[33,34],"class_list":["post-654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cong-nghe-thong-tin","category-cong-nghe-phan-mem","tag-clean-code","tag-nguyen-ly-thiet-ke-phan-mem"],"_links":{"self":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/comments?post=654"}],"version-history":[{"count":5,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":2616,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/654\/revisions\/2616"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/media\/2610"}],"wp:attachment":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}