{"id":19,"date":"2025-07-22T02:44:32","date_gmt":"2025-07-22T02:44:32","guid":{"rendered":"https:\/\/kienthucmo.com\/?p=19"},"modified":"2025-10-24T20:03:09","modified_gmt":"2025-10-24T13:03:09","slug":"clean-code-nghe-thuat-viet-ma-sach-va-ben-vung-trong-phat-trien-phan-mem","status":"publish","type":"post","link":"https:\/\/kienthucmo.com\/vi\/clean-code-nghe-thuat-viet-ma-sach-va-ben-vung-trong-phat-trien-phan-mem\/","title":{"rendered":"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"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>C\u00f3 m\u1ed9t s\u1ef1 th\u1eadt bu\u1ed3n m\u00e0 ai l\u00e0m dev c\u0169ng t\u1eebng tr\u1ea3i qua: <strong>code ch\u1ea1y \u0111\u01b0\u1ee3c kh\u00f4ng \u0111\u1ed3ng ngh\u0129a v\u1edbi code t\u1ed1t<\/strong>. Hmm&#8230;th\u1eadt \u0111\u1ea5y. B\u1ea1n c\u00f3 th\u1ec3 vi\u1ebft m\u1ed9t \u0111o\u1ea1n code khi\u1ebfn ch\u01b0\u01a1ng tr\u00ecnh ho\u1ea1t \u0111\u1ed9ng ngon l\u00e0nh h\u00f4m nay, nh\u01b0ng ch\u1ec9 c\u1ea7n 2 tu\u1ea7n sau quay lai, v\u00e0 kh\u00f4ng tin v\u00e0o m\u1eaft m\u00ecnh, l\u00fac \u0111\u00f3 b\u1ea1n s\u1ebd t\u1ef1 h\u1ecfi:<br><em>\u201cHmm&#8230;m\u00ecnh vi\u1ebft ra \u0111\u1ed1ng n\u00e0y thi\u1ec7t h\u1ea3 tr\u1eddi&#8230;!?\u201d<\/em><\/p>\n<\/blockquote>\n\n\n\n<p>\u0110\u1eebng lo (thi\u1ec7t ra l\u00e0 c\u0169ng n\u00ean lo m\u1ed9t ch\u00fat), ch\u00e0o m\u1eebng b\u1ea1n \u0111\u1ebfn v\u1edbi th\u1ebf gi\u1edbi c\u1ee7a <strong>Clean Code<\/strong> \u2014 n\u01a1i code kh\u00f4ng ch\u1ec9 \u201cch\u1ea1y \u0111\u01b0\u1ee3c\u201d, m\u00e0 c\u00f2n \u201c\u0111\u1ecdc \u0111\u01b0\u1ee3c\u201d, \u201chi\u1ec3u \u0111\u01b0\u1ee3c\u201d v\u00e0 \u201cb\u1ea3o tr\u00ec \u0111\u01b0\u1ee3c m\u00e0 kh\u00f4ng ph\u00e1t \u0111i\u00ean\u201d.<\/p>\n\n\n\n<p>Trong h\u00e0nh tr\u00ecnh tr\u1edf th\u00e0nh m\u1ed9t l\u1eadp tr\u00ecnh vi\u00ean si\u00eau c\u1ea5p vip pro, n\u01a1i \u0111\u1ed3ng nghi\u1ec7p s\u1ebd kh\u00f4ng c\u00f2n s\u1ee3 h\u00e3i khi \u0111\u1ecdc code c\u1ee7a b\u1ea1n, clean code l\u00e0 th\u1ee9 v\u0169 kh\u00ed b\u00ed m\u1eadt. N\u00f3 gi\u00fap b\u1ea1n:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tr\u00e1nh vi\u1ebft ra nh\u1eefng \u0111o\u1ea1n m\u00e3 khi\u1ebfn ch\u00ednh b\u1ea1n trong t\u01b0\u01a1ng lai s\u1ebd gh\u00ea s\u1ee3 b\u1ea3n th\u00e2n.<\/li>\n\n\n\n<li>L\u00e0m vi\u1ec7c nh\u00f3m kh\u00f4ng c\u00f2n l\u00e0 \u0111\u1ecba ng\u1ee5c.<\/li>\n\n\n\n<li>D\u1ec5 debug, d\u1ec5 m\u1edf r\u1ed9ng, v\u00e0 quan tr\u1ecdng l\u00e0\u2026 d\u1ec5 s\u1ed1ng.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Clean code kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t kh\u00e1i ni\u1ec7m th\u1ea7n b\u00ed hay h\u1ecdc thu\u1eadt cao si\u00eau. N\u00f3 l\u00e0 c\u00e1ch \u0111\u1ec3 b\u1ea1n <strong>\u0111\u1ed1i x\u1eed t\u1eed t\u1ebf v\u1edbi ch\u00ednh m\u00ecnh v\u00e0 ng\u01b0\u1eddi kh\u00e1c trong team<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<p>Trong b\u00e0i vi\u1ebft n\u00e0y, m\u00ecnh s\u1ebd c\u00f9ng b\u1ea1n:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Gi\u1ea3i m\u00e3 Clean Code l\u00e0 g\u00ec, v\u00ec sao n\u00f3 quan tr\u1ecdng.<\/li>\n\n\n\n<li>\u0110i qua c\u00e1c nguy\u00ean t\u1eafc s\u1ed1ng c\u00f2n nh\u01b0 <strong>DRY<\/strong>, <strong>KISS<\/strong>, <strong>SOLID<\/strong> (nghe h\u01a1i h\u1ecdc thu\u1eadt nh\u01b0ng th\u1ef1c ra d\u1ec5 hi\u1ec3u l\u1eafm, m\u1ed7i t\u1ed9i \u00e1p d\u00f9ng \u0111\u01b0\u1ee3c kh\u00f4ng th\u00ec  m\u00ecnh c\u0169ng kh\u00f4ng r\u00f5).<\/li>\n\n\n\n<li>Nh\u00ecn l\u1ea1i nh\u1eefng l\u1ed7i &#8220;huy\u1ec1n tho\u1ea1i&#8221; m\u00e0 ai c\u0169ng t\u1eebng d\u00ednh khi vi\u1ebft code nh\u01b0 r\u1eafn b\u00f2.<\/li>\n\n\n\n<li>V\u00e0 cu\u1ed1i c\u00f9ng, c\u00f9ng \u0111i\u1ec3m qu\u00e1 t\u00e0i li\u1ec7u chu\u1ea9n ch\u1ec9nh t\u1eeb c\u00e1c \u201cti\u1ec1n b\u1ed1i ng\u00e0nh code\u201d \u0111\u01b0\u1ee3c \u0111\u00fac k\u1ebft sau khi tr\u1ea3i qua nh\u1eefng \u0111au kh\u1ed5 m\u00e0 b\u1ea1n ho\u1eb7c \u0111\u1ed3ng nghi\u1ec7p c\u1ee7a b\u1ea1n \u0111\u00e3 g\u00e2y ra.<\/li>\n<\/ul>\n\n\n\n<p>C\u00f2n gi\u1edd th\u00ec&#8230; c\u00f9ng d\u1ecdn s\u1ea1ch \u0111\u1ed1ng spaghetti code nh\u00e9<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Clean Code l\u00e0 g\u00ec?<\/h2>\n\n\n\n<p>Kh\u00e1i ni\u1ec7m <strong>\u201cClean Code\u201d<\/strong> \u0111\u01b0\u1ee3c gi\u1edbi thi\u1ec7u v\u00e0 ph\u1ed5 bi\u1ebfn r\u1ed9ng r\u00e3i b\u1edfi <strong>Robert C. Martin<\/strong>, th\u01b0\u1eddng \u0111\u01b0\u1ee3c bi\u1ebft \u0111\u1ebfn v\u1edbi bi\u1ec7t danh <strong>Uncle Bob<\/strong> \u2013 m\u1ed9t trong nh\u1eefng \u201ct\u01b0\u1ee3ng \u0111\u00e0i s\u1ed1ng\u201d trong ng\u00e0nh ph\u00e1t tri\u1ec3n ph\u1ea7n m\u1ec1m. Trong cu\u1ed1n s\u00e1ch <em>Clean Code: A Handbook of Agile Software Craftsmanship<\/em>, \u00f4ng \u0111\u1ecbnh ngh\u0129a:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cClean code always looks like it was written by someone who cares.\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>N\u00f3i c\u00e1ch kh\u00e1c, <strong>clean code l\u00e0 \u0111o\u1ea1n m\u00e3 \u0111\u01b0\u1ee3c vi\u1ebft ra v\u1edbi s\u1ef1 tr\u00e2n tr\u1ecdng d\u00e0nh cho ng\u01b0\u1eddi \u0111\u1ecdc k\u1ebf ti\u1ebfp<\/strong> \u2013 c\u00f3 th\u1ec3 l\u00e0 \u0111\u1ed3ng nghi\u1ec7p, kh\u00e1ch h\u00e0ng, hay ch\u00ednh b\u1ea1n sau v\u00e0i tu\u1ea7n m\u1ea5t ng\u1ee7 v\u00ec deadline.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/i.pinimg.com\/736x\/43\/74\/05\/437405ce89a86caaa76427e8fa4fe008.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/i.pinimg.com\/736x\/43\/74\/05\/437405ce89a86caaa76427e8fa4fe008.jpg\" alt=\"Clean Code l\u00e0 g\u00ec?\"\/><\/a><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\">V\u1eady clean code c\u00f3 \u0111\u1eb7c \u0111i\u1ec3m g\u00ec?<\/h4>\n\n\n\n<p>M\u1ed9t \u0111o\u1ea1n m\u00e3 \u0111\u01b0\u1ee3c coi l\u00e0 \u201cclean\u201d th\u01b0\u1eddng s\u1ebd:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>D\u1ec5 \u0111\u1ecdc<\/strong>: Nh\u00ecn v\u00e0o l\u00e0 hi\u1ec3u \u0111\u01b0\u1ee3c \u0111o\u1ea1n code \u0111\u00f3 \u0111ang l\u00e0m g\u00ec m\u00e0 kh\u00f4ng c\u1ea7n \u0111o\u00e1n.<\/li>\n\n\n\n<li><strong>D\u1ec5 hi\u1ec3u<\/strong>: Bi\u1ebfn, h\u00e0m, class \u0111\u1ec1u c\u00f3 t\u00ean r\u00f5 r\u00e0ng, nh\u1ea5t qu\u00e1n.<\/li>\n\n\n\n<li><strong>D\u1ec5 thay \u0111\u1ed5i<\/strong>: Khi c\u1ea7n th\u00eam t\u00ednh n\u0103ng m\u1edbi, b\u1ea1n kh\u00f4ng ph\u1ea3i &#8220;\u0111\u1eadp \u0111i x\u00e2y l\u1ea1i&#8221;.<\/li>\n\n\n\n<li><strong>D\u1ec5 test<\/strong>: Code s\u1ea1ch th\u01b0\u1eddng t\u00e1ch bi\u1ec7t logic r\u00f5 r\u00e0ng, d\u1ec5 vi\u1ebft unit test.<\/li>\n\n\n\n<li><strong>Kh\u00f4ng r\u1ed1i<\/strong>: \u00cdt l\u1eb7p l\u1ea1i, kh\u00f4ng ph\u1ee5 thu\u1ed9c lung tung, kh\u00f4ng b\u1ecb \u201chard-code\u201d.<\/li>\n<\/ul>\n\n\n\n<p>Ng\u01b0\u1ee3c l\u1ea1i, <strong>bad code<\/strong> l\u00e0 ki\u1ec3u khi\u1ebfn ng\u01b0\u1eddi ta \u0111\u1ecdc xong ph\u1ea3i th\u1ed1t l\u00ean:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cHmm&#8230;me keep&#8230;!!!\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>Ho\u1eb7c c\u0169ng c\u00f3 th\u1ec3 h\u1ecd im l\u1eb7ng, nh\u01b0ng v\u1ebb m\u1eb7t, \u00e1nh m\u1eaft&#8230;.h\u1ecd l\u1ea1 l\u1eafm.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">T\u1ea1i sao \u0111\u1ecbnh ngh\u0129a clean code l\u1ea1i quan tr\u1ecdng?<\/h4>\n\n\n\n<p>V\u00ec \u0111\u00e2y l\u00e0 n\u1ec1n m\u00f3ng cho m\u1ecdi d\u1ef1 \u00e1n ph\u1ea7n m\u1ec1m ch\u1ea5t l\u01b0\u1ee3ng. M\u1ed9t h\u1ec7 th\u1ed1ng c\u00f3 th\u1ec3 c\u00f3 h\u00e0ng ngh\u00ecn d\u00f2ng code. N\u1ebfu kh\u00f4ng s\u1ea1ch t\u1eeb \u0111\u1ea7u, m\u1ed7i l\u1ea7n s\u1eeda l\u00e0 m\u1ed9t l\u1ea7n \u0111\u01b0\u1ee3c cosplay lao c\u00f4ng &#8220;\u0111\u00e0o b\u1edbi&#8221; trong \u0111\u1ed1ng l\u1ed9n x\u1ed9n \u2013 v\u00e0 \u0111i\u1ec1u n\u00e0y g\u00e2y t\u1ed1n th\u1eddi gian, d\u1ec5 khi\u1ebfn bug &#8220;sinh s\u1ea3n&#8221;, kh\u00f3 ph\u00e1t tri\u1ec3n d\u00e0i h\u1ea1n.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. T\u1ea7m quan tr\u1ecdng, vai tr\u00f2 v\u00e0 l\u1ee3i \u00edch c\u1ee7a Clean Code<\/h2>\n\n\n\n<p>Vi\u1ebft <strong>clean code<\/strong> kh\u00f4ng ch\u1ec9 l\u00e0 th\u00f3i quen t\u1ed1t \u2013 \u0111\u00f3 l\u00e0 n\u1ec1n t\u1ea3ng \u0111\u1ec3 x\u00e2y d\u1ef1ng ph\u1ea7n m\u1ec1m c\u00f3 kh\u1ea3 n\u0103ng ph\u00e1t tri\u1ec3n b\u1ec1n v\u1eefng, c\u1ea3 v\u1ec1 m\u1eb7t k\u1ef9 thu\u1eadt l\u1eabn con ng\u01b0\u1eddi. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 nh\u1eefng l\u00fd do v\u00ec sao clean code n\u00ean \u0111\u01b0\u1ee3c coi l\u00e0 &#8220;\u01b0u ti\u00ean h\u00e0ng \u0111\u1ea7u&#8221; trong m\u1ecdi d\u1ef1 \u00e1n ph\u1ea7n m\u1ec1m nghi\u00eam t\u00fac.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1. T\u0103ng t\u00ednh b\u1ec1n v\u1eefng cho d\u1ef1 \u00e1n<\/h3>\n\n\n\n<p>M\u1ed9t d\u1ef1 \u00e1n ph\u1ea7n m\u1ec1m kh\u00f4ng bao gi\u1edd \u201cx\u00e2y xong l\u00e0 xong\u201d. N\u00f3 lu\u00f4n thay \u0111\u1ed5i \u2013 th\u00eam t\u00ednh n\u0103ng, s\u1eeda l\u1ed7i, t\u1ed1i \u01b0u hi\u1ec7u su\u1ea5t, h\u1ed7 tr\u1ee3 n\u1ec1n t\u1ea3ng m\u1edbi\u2026 Ch\u00ednh v\u00ec v\u1eady, code c\u1ea7n ph\u1ea3i d\u1ec5 thay \u0111\u1ed5i m\u00e0 kh\u00f4ng ph\u00e1 v\u1ee1 to\u00e0n b\u1ed9 h\u1ec7 th\u1ed1ng.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Clean code gi\u00fap b\u1ea1n refactor v\u1edbi s\u1ef1 t\u1ef1 tin.<\/p>\n<\/blockquote>\n\n\n\n<p>V\u00ed d\u1ee5: n\u1ebfu c\u00e1c module \u0111\u01b0\u1ee3c vi\u1ebft r\u00f5 r\u00e0ng, kh\u00f4ng ph\u1ee5 thu\u1ed9c lung tung, vi\u1ec7c \u0111\u1ed5i API ho\u1eb7c logic x\u1eed l\u00fd s\u1ebd ch\u1ec9 c\u1ea7n c\u1eadp nh\u1eadt \u0111\u00fang ch\u1ed7. Ng\u01b0\u1ee3c l\u1ea1i, n\u1ebfu code r\u1ed1i r\u1eafm, m\u1ed7i l\u1ea7n s\u1eeda gi\u1ed1ng nh\u01b0 &#8220;r\u00fat m\u1ed9t c\u1ecdng m\u00ec trong \u0111\u0129a spaghetti&#8221; \u2013 d\u1ec5 r\u1ed1i tung m\u1ecdi th\u1ee9.<\/p>\n\n\n\n<p><strong>Clean code<\/strong> c\u0169ng gi\u00fap onboarding th\u00e0nh vi\u00ean m\u1edbi nhanh h\u01a1n. Thay v\u00ec m\u1ea5t c\u1ea3 tu\u1ea7n \u0111\u1ec3 hi\u1ec3u \u201ccode n\u00e0y \u0111ang l\u00e0m g\u00ec\u201d, m\u1ed9t ng\u01b0\u1eddi m\u1edbi ch\u1ec9 c\u1ea7n \u0111\u1ecdc qua \u0111\u00e3 c\u00f3 th\u1ec3 n\u1eafm \u0111\u01b0\u1ee3c logic, nh\u1edd v\u00e0o c\u00e1ch \u0111\u1eb7t t\u00ean r\u00f5 r\u00e0ng, c\u1ea5u tr\u00fac d\u1ec5 hi\u1ec3u, v\u00e0 h\u00e0m chia nh\u1ecf theo ch\u1ee9c n\u0103ng.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2. T\u0103ng n\u0103ng su\u1ea5t v\u00e0 \u0111\u1ed9 tin c\u1eady<\/h3>\n\n\n\n<p><strong>Clean code<\/strong> kh\u00f4ng vi\u1ebft nhanh h\u01a1n, nh\u01b0ng gi\u00fap \u0111\u1ecdc nhanh h\u01a1n, debug nhanh h\u01a1n v\u00e0 l\u00e0m vi\u1ec7c hi\u1ec7u qu\u1ea3 h\u01a1n v\u1ec1 l\u00e2u d\u00e0i.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Khi h\u00e0m ng\u1eafn g\u1ecdn, bi\u1ebfn \u0111\u1eb7t t\u00ean r\u00f5 r\u00e0ng, dev s\u1ebd \u00edt m\u1eafc l\u1ed7i h\u01a1n trong qu\u00e1 tr\u00ecnh s\u1eeda ho\u1eb7c m\u1edf r\u1ed9ng t\u00ednh n\u0103ng.<\/li>\n\n\n\n<li>Khi code d\u1ec5 test (nh\u1edd t\u00e1ch bi\u1ec7t logic), vi\u1ec7c vi\u1ebft unit test ho\u1eb7c CI\/CD tr\u1edf n\u00ean \u0111\u01a1n gi\u1ea3n \u2013 gi\u1ea3m kh\u1ea3 n\u0103ng bug tr\u00e0n v\u00e0o production.<\/li>\n\n\n\n<li>Khi m\u1ed9t l\u1ed7i x\u1ea3y ra, <strong>clean code <\/strong>gi\u00fap b\u1ea1n x\u00e1c \u0111\u1ecbnh nguy\u00ean nh\u00e2n d\u1ec5 h\u01a1n, v\u00ec t\u1eebng ph\u1ea7n c\u1ee7a h\u1ec7 th\u1ed1ng \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf r\u00f5 r\u00e0ng v\u00e0 t\u00e1ch bi\u1ec7t.<\/li>\n<\/ul>\n\n\n\n<p>M\u1ed9t c\u00e2u n\u00f3i quen thu\u1ed9c trong gi\u1edbi l\u1eadp tr\u00ecnh:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201cCh\u00fang ta \u0111\u1ecdc code nhi\u1ec1u h\u01a1n vi\u1ebft code. V\u1eady t\u1ea1i sao kh\u00f4ng vi\u1ebft n\u00f3 \u0111\u1ec3 d\u1ec5 \u0111\u1ecdc?\u201d<\/p>\n<\/blockquote>\n\n\n\n<p><strong>Clean code<\/strong> gi\u00fap b\u1ea1n ti\u1ebft ki\u1ec7m h\u00e0ng gi\u1edd m\u1ed7i tu\u1ea7n ch\u1ec9 v\u00ec\u2026 \u00edt ph\u1ea3i \u0111o\u00e1n code h\u01a1n.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3. C\u1ee7ng c\u1ed1 tinh th\u1ea7n teamwork v\u00e0 truy\u1ec1n \u0111\u1ea1t \u00fd t\u01b0\u1edfng<\/h3>\n\n\n\n<p>D\u00f9 b\u1ea1n l\u00e0m vi\u1ec7c trong startup 3 ng\u01b0\u1eddi hay t\u1eadp \u0111o\u00e0n 3000 ng\u01b0\u1eddi, ph\u1ea7n m\u1ec1m lu\u00f4n l\u00e0 <strong>m\u1ed9t s\u1ea3n ph\u1ea9m h\u1ee3p t\u00e1c<\/strong>. V\u00e0 m\u00e3 ngu\u1ed3n \u2013 ch\u00ednh l\u00e0 ng\u00f4n ng\u1eef chung gi\u1eefa c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean.<\/p>\n\n\n\n<p>Khi m\u1ed9t ng\u01b0\u1eddi vi\u1ebft clean code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ng\u01b0\u1eddi kh\u00e1c \u0111\u1ecdc v\u00e0o hi\u1ec3u ngay m\u1ee5c \u0111\u00edch c\u1ee7a \u0111o\u1ea1n code.<\/li>\n\n\n\n<li>\u00cdt x\u1ea3y ra hi\u1ec3u nh\u1ea7m khi s\u1eeda code ng\u01b0\u1eddi kh\u00e1c.<\/li>\n\n\n\n<li>D\u1ec5 review pull request, d\u1ec5 \u0111\u01b0a feedback.<\/li>\n\n\n\n<li>M\u1ed1i quan h\u1ec7 v\u1edbi \u0111\u1ed3ng nghi\u1ec7p \u0111\u01b0\u1ee3c c\u1ea3i thi\u1ec7n \u0111\u00e1ng k\u1ec3<\/li>\n<\/ul>\n\n\n\n<p>\u0110i\u1ec1u n\u00e0y kh\u00f4ng ch\u1ec9 t\u0103ng hi\u1ec7u qu\u1ea3 giao ti\u1ebfp trong team, m\u00e0 c\u00f2n x\u00e2y d\u1ef1ng v\u0103n h\u00f3a l\u00e0m vi\u1ec7c t\u00f4n tr\u1ecdng l\u1eabn nhau. Clean code l\u00e0 c\u00e1ch b\u1ea1n th\u1ec3 hi\u1ec7n tr\u00e1ch nhi\u1ec7m tr\u01b0\u1edbc l\u00e0 v\u1edbi b\u1ea3n th\u00e2n sau l\u00e0 v\u1edbi \u0111\u1ed3ng \u0111\u1ed9i.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Vi\u1ebft code s\u1ea1ch l\u00e0 h\u00e0nh \u0111\u1ed9ng \u201cgi\u00fap ng\u01b0\u1eddi kh\u00e1c hi\u1ec3u m\u00ecnh\u201d \u2013 m\u1ed9t trong nh\u1eefng k\u1ef9 n\u0103ng quan tr\u1ecdng nh\u1ea5t khi l\u00e0m vi\u1ec7c nh\u00f3m.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">2.4. (B\u1ed5 sung) Gi\u1ea3m chi ph\u00ed ph\u00e1t tri\u1ec3n v\u1ec1 l\u00e2u d\u00e0i<\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t l\u1ee3i \u00edch \u00edt \u0111\u01b0\u1ee3c n\u00f3i t\u1edbi, nh\u01b0ng r\u1ea5t th\u1ef1c t\u1ebf: clean code gi\u00fap gi\u1ea3m chi ph\u00ed b\u1ea3o tr\u00ec, s\u1eeda l\u1ed7i v\u00e0 ph\u00e1t tri\u1ec3n t\u00ednh n\u0103ng m\u1edbi.<\/p>\n\n\n\n<p>Nhi\u1ec1u doanh nghi\u1ec7p r\u01a1i v\u00e0o t\u00ecnh tr\u1ea1ng: c\u00e0ng ph\u00e1t tri\u1ec3n l\u00e2u, code c\u00e0ng r\u1ed1i, s\u1eeda g\u00ec c\u0169ng s\u1ee3 \u201cv\u1ee1 d\u00e2y chuy\u1ec1n\u201d, d\u1eabn \u0111\u1ebfn tr\u00ec tr\u1ec7. Khi \u0111\u00f3, chi ph\u00ed \u201cgi\u1eef cho d\u1ef1 \u00e1n s\u1ed1ng s\u00f3t\u201d cao h\u01a1n nhi\u1ec1u l\u1ea7n chi ph\u00ed vi\u1ebft t\u1eeb \u0111\u1ea7u \u2013 t\u1ea5t c\u1ea3 b\u1eaft ngu\u1ed3n t\u1eeb vi\u1ec7c kh\u00f4ng duy tr\u00ec code s\u1ea1ch ngay t\u1eeb \u0111\u1ea7u.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. C\u00e1c nguy\u00ean t\u1eafc c\u1ed1t l\u00f5i trong clean code<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u0110\u1eb7t t\u00ean c\u00f3 \u00fd ngh\u0129a<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>T\u00ean bi\u1ebfn\/h\u00e0m\/class l\u00e0 \u201cgiao di\u1ec7n\u201d \u0111\u1ea7u ti\u00ean m\u00e0 ng\u01b0\u1eddi \u0111\u1ecdc ti\u1ebfp x\u00fac. N\u1ebfu t\u00ean kh\u00f4ng r\u00f5 r\u00e0ng, ng\u01b0\u1eddi \u0111\u1ecdc ph\u1ea3i l\u1ee5c t\u00ecm code b\u00ean trong \u0111\u1ec3 hi\u1ec3u, g\u00e2y l\u00e3ng ph\u00ed th\u1eddi gian.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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 g(u):\n    return u.split('@')&#91;1&#93;<\/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\">g<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">u<\/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\"> u<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">split<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">@<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/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 get_user_email_domain(email):\n    return email.split('@')&#91;1&#93;<\/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\">get_user_email_domain<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">email<\/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\"> email<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">split<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">@<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">)&#91;<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">&#93;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>B\u1ea1n \u0111\u1ecdc h\u00e0m l\u00e0 bi\u1ebft ngay m\u1ee5c \u0111\u00edch m\u00e0 kh\u00f4ng c\u1ea7n soi chi ti\u1ebft.<\/p>\n<\/blockquote>\n\n\n\n<p><strong>Tr\u00e1nh:<\/strong> vi\u1ebft t\u1eaft m\u01a1 h\u1ed3 (<code>dt<\/code>, <code>tmp<\/code>, <code>i2<\/code>) ho\u1eb7c \u0111\u1eb7t t\u00ean chung chung (<code>data<\/code>, <code>process<\/code>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2  Do One Thing (M\u1ed7i h\u00e0m ch\u1ec9 l\u00e0m m\u1ed9t vi\u1ec7c)<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>H\u00e0m l\u00e0m qu\u00e1 nhi\u1ec1u vi\u1ec7c khi\u1ebfn b\u1ea1n kh\u00f3 test, kh\u00f3 debug, v\u00e0 d\u1ec5 sinh l\u1ed7i khi thay \u0111\u1ed5i m\u1ed9t ph\u1ea7n nh\u1ecf.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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>function handleOrder(order) {\n    validateOrder(order);\n    saveOrderToDatabase(order);\n    sendConfirmationEmail(order);\n    generateInvoice(order);\n}<\/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: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">handleOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">validateOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">saveOrderToDatabase<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">sendConfirmationEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #88C0D0\">generateInvoice<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/strong><br>T\u00e1ch nh\u1ecf:<\/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>function validateOrder(order) { ... }\nfunction saveOrder(order) { ... }\nfunction sendEmail(order) { ... }\nfunction generateInvoice(order) { ... }\n<\/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: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">validateOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">saveOrder<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">generateInvoice<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><span style=\"color: #D8DEE9FF\"> ... <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.3  DRY (Don\u2019t Repeat Yourself)<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>L\u1eb7p l\u1ea1i code khi\u1ebfn b\u1ea1n ph\u1ea3i s\u1eeda \u1edf nhi\u1ec1u n\u01a1i khi thay \u0111\u1ed5i logic \u2192 d\u1ec5 s\u00f3t l\u1ed7i.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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>price_with_tax = price + price * 0.1\n# \u1ede ch\u1ed7 kh\u00e1c l\u1ea1i vi\u1ebft y chang\ntotal = amount + amount * 0.1<\/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: #D8DEE9FF\">price_with_tax <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> price <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> price <\/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: #616E88\"># \u1ede ch\u1ed7 kh\u00e1c l\u1ea1i vi\u1ebft y chang<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">total <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0.1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/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 add_tax(amount):\n    TAX_RATE = 0.1\n    return amount + amount * TAX_RATE<\/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\">add_tax<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">amount<\/span><span style=\"color: #ECEFF4\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    TAX_RATE <\/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\"> amount <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> amount <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> TAX_RATE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.4  Comment \u0111\u00fang c\u00e1ch<\/h3>\n\n\n\n<p><strong>Nguy\u00ean t\u1eafc:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Gi\u1ea3i th\u00edch \u201ct\u1ea1i sao\u201d<\/strong>, kh\u00f4ng ch\u1ec9 \u201cl\u00e0m g\u00ec\u201d.<\/li>\n\n\n\n<li>Code r\u00f5 r\u00e0ng th\u00ec kh\u00f4ng c\u1ea7n comment d\u00f2ng-d\u00f2ng.<\/li>\n<\/ul>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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>\/\/ C\u1ed9ng 1 v\u00e0o bi\u1ebfn count\ncount = count + 1;<\/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\">\/\/<\/span><span style=\"color: #D8DEE9FF\"> C\u1ed9ng <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> v\u00e0o bi\u1ebfn count<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">count <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> count <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/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>\/\/ Th\u00eam 1 v\u00e0o count \u0111\u1ec3 t\u00ednh c\u1ea3 s\u1ea3n ph\u1ea9m hi\u1ec7n t\u1ea1i\ncount += 1;<\/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\">\/\/<\/span><span style=\"color: #D8DEE9FF\"> Th\u00eam <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> v\u00e0o count \u0111\u1ec3 t\u00ednh c\u1ea3 s\u1ea3n ph\u1ea9m hi\u1ec7n t\u1ea1i<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">count <\/span><span style=\"color: #81A1C1\">+=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.5  KISS (Keep It Simple, Stupid)<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>Gi\u1ea3i ph\u00e1p c\u00e0ng \u0111\u01a1n gi\u1ea3n, c\u00e0ng d\u1ec5 b\u1ea3o tr\u00ec. Over-engineering (d\u00f9ng thi\u1ebft k\u1ebf ph\u1ee9c t\u1ea1p khi ch\u01b0a c\u1ea7n) s\u1ebd t\u1ef1 bi\u1ebfn b\u1ea1n th\u00e0nh \u201cn\u1ea1n nh\u00e2n\u201d c\u1ee7a ch\u00ednh m\u00ecnh.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/strong> D\u00f9ng microservices cho app TODO 1 &#8211; 2 ng\u01b0\u1eddi d\u00f9ng. <br><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/strong> D\u00f9ng script \u0111\u01a1n ho\u1eb7c monolith cho t\u1edbi khi th\u1ef1c s\u1ef1 c\u1ea7n t\u00e1ch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.6  Early Return<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>Gi\u1ea3m \u0111\u1ed9 s\u00e2u c\u1ee7a <code>if\/else<\/code>, gi\u00fap code ph\u1eb3ng h\u01a1n, d\u1ec5 \u0111\u1ecdc h\u01a1n.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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>if (user != null) {\n    if (user.isActive()) {\n        sendEmail(user);\n    }\n}<\/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\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user <\/span><span style=\"color: #81A1C1\">!=<\/span><span style=\"color: #D8DEE9FF\"> null<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/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: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">isActive<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>V\u00ed d\u1ee5 t\u1ed1t:<\/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>if (user == null) return;\nif (!user.isActive()) return;\nsendEmail(user);<\/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\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> null<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">!<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">isActive<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">sendEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.7  SOLID Principles (OOP)<\/h3>\n\n\n\n<p>B\u1ed9 5 nguy\u00ean t\u1eafc thi\u1ebft k\u1ebf h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng gi\u00fap h\u1ec7 th\u1ed1ng d\u1ec5 m\u1edf r\u1ed9ng v\u00e0 b\u1ea3o tr\u00ec:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>S<\/strong>ingle Responsibility \u2013 M\u1ed7i class ch\u1ec9 l\u00e0m m\u1ed9t vi\u1ec7c.<\/li>\n\n\n\n<li><strong>O<\/strong>pen\/Closed \u2013 M\u1edf r\u1ed9ng \u0111\u01b0\u1ee3c, h\u1ea1n ch\u1ebf s\u1eeda \u0111\u1ed5i code c\u0169.<\/li>\n\n\n\n<li><strong>L<\/strong>iskov Substitution \u2013 Class con c\u00f3 th\u1ec3 thay th\u1ebf class cha m\u00e0 kh\u00f4ng ph\u00e1 v\u1ee1 logic.<\/li>\n\n\n\n<li><strong>I<\/strong>nterface Segregation \u2013 Interface nh\u1ecf, chuy\u00ean bi\u1ec7t.<\/li>\n\n\n\n<li><strong>D<\/strong>ependency Inversion \u2013 Ph\u1ee5 thu\u1ed9c v\u00e0o abstraction, kh\u00f4ng ph\u1ea3i implementation.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">3.8  Vi\u1ebft test t\u1ef1 \u0111\u1ed9ng<\/h3>\n\n\n\n<p><strong>V\u00ec sao quan tr\u1ecdng:<\/strong><br>Code kh\u00f4ng test gi\u1ed1ng nh\u01b0 \u201cc\u1ea7u kh\u00f4ng tay v\u1ecbn\u201d \u2013 v\u1eabn \u0111i \u0111\u01b0\u1ee3c, nh\u01b0ng nguy hi\u1ec3m. Test gi\u00fap:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ph\u00e1t hi\u1ec7n bug s\u1edbm<\/li>\n\n\n\n<li>T\u1ef1 tin khi refactor<\/li>\n\n\n\n<li>\u0110\u1ea3m b\u1ea3o code ho\u1ea1t \u0111\u1ed9ng \u0111\u00fang nh\u01b0 mong \u0111\u1ee3i<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.9 YAGNI (You Aren\u2019t Gonna Need It)<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>\u0110\u1eebng vi\u1ebft code cho nh\u1eefng t\u00ednh n\u0103ng \u201cc\u00f3 th\u1ec3 c\u1ea7n trong t\u01b0\u01a1ng lai\u201d khi ch\u01b0a c\u00f3 y\u00eau c\u1ea7u th\u1ef1c t\u1ebf.<br>L\u1eadp tr\u00ecnh vi\u00ean hay c\u00f3 xu h\u01b0\u1edbng \u201cth\u00eam cho ch\u1eafc\u201d \u2192 k\u1ebft qu\u1ea3 l\u00e0 complexity t\u0103ng, maintenance kh\u00f3 h\u01a1n.<\/p>\n\n\n\n<p>T\u00ecm hi\u1ec3u th\u00eam: <a href=\"https:\/\/kienthucmo.com\/vi\/kiss-dry-yagni-3-nguyen-tac-vang-trong-phat-trien-phan-mem\/\">https:\/\/kienthucmo.com\/vi\/kiss-dry-yagni-3-nguyen-tac-vang-trong-phat-trien-phan-mem\/<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.10  Separation of Concerns (T\u00e1ch bi\u1ec7t m\u1ed1i quan t\u00e2m)<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>M\u1ed7i module\/class n\u00ean gi\u1ea3i quy\u1ebft m\u1ed9t \u201cm\u1ed1i quan t\u00e2m\u201d (concern) duy nh\u1ea5t. Giao di\u1ec7n UI kh\u00f4ng n\u00ean x\u1eed l\u00fd logic business, v\u00e0 ng\u01b0\u1ee3c l\u1ea1i.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>T\u1ea7ng Controller nh\u1eadn request \u2192<\/li>\n\n\n\n<li>Giao cho Service x\u1eed l\u00fd logic \u2192<\/li>\n\n\n\n<li>Repository truy xu\u1ea5t d\u1eef li\u1ec7u.<\/li>\n<\/ul>\n\n\n\n<p>C\u00e1ch n\u00e0y gi\u00fap b\u1ea1n thay \u0111\u1ed5i m\u1ed9t ph\u1ea7n m\u00e0 kh\u00f4ng l\u00e0m h\u1ecfng to\u00e0n h\u1ec7 th\u1ed1ng.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.11 Law of Demeter (Nguy\u00ean t\u1eafc t\u1ed1i thi\u1ec3u h\u00f3a ph\u1ee5 thu\u1ed9c)<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>M\u1ed9t object ch\u1ec9 n\u00ean giao ti\u1ebfp v\u1edbi \u201ch\u00e0ng x\u00f3m g\u1ea7n\u201d c\u1ee7a n\u00f3, kh\u00f4ng n\u00ean bi\u1ebft qu\u00e1 nhi\u1ec1u v\u1ec1 c\u1ea5u tr\u00fac b\u00ean trong object kh\u00e1c.<br>\u2192 Gi\u1ea3m coupling, t\u0103ng t\u00ednh b\u1ea3o tr\u00ec.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5 x\u1ea5u:<\/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>order.customer.address.city.name<\/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: #D8DEE9FF\">order<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">customer<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">address<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">city<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9FF\">name<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u0110i\u1ec1u n\u00e0y t\u1ea1o ra chu\u1ed7i ph\u1ee5 thu\u1ed9c d\u00e0i, thay \u0111\u1ed5i b\u1ea5t k\u1ef3 t\u1ea7ng n\u00e0o \u0111\u1ec1u g\u00e2y l\u1ed7i d\u00e2y chuy\u1ec1n.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.12  Refactor th\u01b0\u1eddng xuy\u00ean<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>Code s\u1ea1ch kh\u00f4ng t\u1ef1 nhi\u00ean m\u00e0 c\u00f3, n\u00f3 l\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a li\u00ean t\u1ee5c c\u1ea3i ti\u1ebfn. Sau khi pass test, h\u00e3y d\u00e0nh th\u1eddi gian t\u1ed1i \u01b0u t\u00ean, t\u00e1ch h\u00e0m, lo\u1ea1i b\u1ecf duplication.<br>Refactor s\u1edbm gi\u00fap tr\u00e1nh \u201cn\u1ee3 k\u1ef9 thu\u1eadt\u201d t\u00edch t\u1ee5.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.13  Defensive Programming (L\u1eadp tr\u00ecnh ph\u00f2ng th\u1ee7)<\/h3>\n\n\n\n<p><strong>\u00dd ngh\u0129a:<\/strong><br>Gi\u1ea3 s\u1eed input lu\u00f4n c\u00f3 th\u1ec3 sai v\u00e0 x\u1eed l\u00fd tr\u01b0\u1eddng h\u1ee3p x\u1ea5u ngay t\u1eeb \u0111\u1ea7u \u2192 tr\u00e1nh bug kh\u00f3 l\u01b0\u1eddng.<\/p>\n\n\n\n<p><strong>V\u00ed d\u1ee5:<\/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>function divide(a, b) {\n    if (b === 0) throw new Error(\"Cannot divide by zero\");\n    return a \/ b;\n}<\/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: #D8DEE9FF\">function <\/span><span style=\"color: #88C0D0\">divide<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">a<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> b<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/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: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">b <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\">= <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> throw new <\/span><span style=\"color: #88C0D0\">Error<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Cannot divide by zero<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><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\"> a <\/span><span style=\"color: #81A1C1\">\/<\/span><span style=\"color: #D8DEE9FF\"> b;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">L\u01b0u \u00fd: Khi n\u00e0o <em>kh\u00f4ng<\/em> n\u00ean \u00e1p d\u1ee5ng c\u1ef1c \u0111oan<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DRY qu\u00e1 m\u1ee9c<\/strong> \u2192 t\u1ea1o abstraction kh\u00f3 hi\u1ec3u, gi\u1ea3m readability.<\/li>\n\n\n\n<li><strong>KISS qu\u00e1 m\u1ee9c<\/strong> \u2192 gi\u1ea3i ph\u00e1p qu\u00e1 \u0111\u01a1n gi\u1ea3n, thi\u1ebfu t\u00ednh linh ho\u1ea1t khi y\u00eau c\u1ea7u thay \u0111\u1ed5i.<\/li>\n\n\n\n<li><strong>YAGNI qu\u00e1 c\u1ee9ng<\/strong> \u2192 \u0111\u00f4i khi b\u1ecf qua vi\u1ec7c chu\u1ea9n b\u1ecb tr\u01b0\u1edbc cho ki\u1ebfn tr\u00fac, d\u1eabn \u0111\u1ebfn refactor t\u1ed1n k\u00e9m.<\/li>\n\n\n\n<li><strong>SOLID<\/strong> \u00e1p d\u1ee5ng sai ng\u1eef c\u1ea3nh \u2192 l\u00e0m code ph\u1ee9c t\u1ea1p h\u01a1n so v\u1edbi l\u1ee3i \u00edch th\u1ef1c t\u1ebf.<\/li>\n\n\n\n<li>&#8230;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. C\u00e1c quy chu\u1ea9n\/t\u00e0i li\u1ec7u clean code ch\u00ednh th\u1ee9c<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>T\u00e0i li\u1ec7u \/ Quy chu\u1ea9n<\/th><th>N\u1ed9i dung ch\u00ednh<\/th><th>Gi\u00e1 tr\u1ecb th\u1ef1c t\u1ebf \/ \u1ee8ng d\u1ee5ng<\/th><\/tr><\/thead><tbody><tr><td><strong>Clean Code \u2013 Robert C. Martin<\/strong><\/td><td>Cu\u1ed1n s\u00e1ch kinh \u0111i\u1ec3n gi\u1edbi thi\u1ec7u kh\u00e1i ni\u1ec7m clean code, c\u00e1ch \u0111\u1eb7t t\u00ean, t\u1ed5 ch\u1ee9c h\u00e0m, class, x\u1eed l\u00fd l\u1ed7i, vi\u1ebft comment, v\u00e0 nhi\u1ec1u nguy\u00ean t\u1eafc gi\u00fap code d\u1ec5 \u0111\u1ecdc, d\u1ec5 b\u1ea3o tr\u00ec.<\/td><td>L\u00e0 \u201cs\u00e1ch g\u1ed1i \u0111\u1ea7u gi\u01b0\u1eddng\u201d c\u1ee7a l\u1eadp tr\u00ecnh vi\u00ean. N\u00ean \u0111\u1ecdc ch\u1eadm, \u00e1p d\u1ee5ng t\u1eebng ch\u01b0\u01a1ng v\u00e0o d\u1ef1 \u00e1n th\u1ef1c t\u1ebf.<\/td><\/tr><tr><td><strong>The Clean Coder \u2013 Robert C. Martin<\/strong><\/td><td>Kh\u00f4ng t\u1eadp trung v\u00e0o k\u1ef9 thu\u1eadt code, m\u00e0 n\u00f3i v\u1ec1 t\u01b0 duy, th\u00e1i \u0111\u1ed9, tr\u00e1ch nhi\u1ec7m v\u00e0 \u0111\u1ea1o \u0111\u1ee9c ngh\u1ec1 nghi\u1ec7p c\u1ee7a l\u1eadp tr\u00ecnh vi\u00ean chuy\u00ean nghi\u1ec7p.<\/td><td>Gi\u00fap x\u00e2y d\u1ef1ng mindset nghi\u00eam t\u00fac, bi\u1ebft n\u00f3i \u201ckh\u00f4ng\u201d v\u1edbi y\u00eau c\u1ea7u b\u1ea5t h\u1ee3p l\u00fd, v\u00e0 b\u1ea3o v\u1ec7 ch\u1ea5t l\u01b0\u1ee3ng code.<\/td><\/tr><tr><td><strong>Refactoring \u2013 Martin Fowler<\/strong><\/td><td>Tr\u00ecnh b\u00e0y chi ti\u1ebft c\u00e1c \u201cm\u1eabu refactor\u201d \u2013 c\u00e1ch c\u1ea3i ti\u1ebfn code m\u00e0 kh\u00f4ng thay \u0111\u1ed5i h\u00e0nh vi, c\u00f9ng v\u1edbi l\u00fd do v\u00e0 chi\u1ebfn l\u01b0\u1ee3c.<\/td><td>C\u1ef1c k\u1ef3 h\u1eefu \u00edch khi c\u1ea7n d\u1ecdn d\u1eb9p code c\u0169 ho\u1eb7c t\u1ed1i \u01b0u ki\u1ebfn tr\u00fac. K\u1ebft h\u1ee3p t\u1ed1t v\u1edbi test t\u1ef1 \u0111\u1ed9ng.<\/td><\/tr><tr><td><strong>Google Style Guides<\/strong><\/td><td>B\u1ed9 quy chu\u1ea9n coding style cho c\u00e1c ng\u00f4n ng\u1eef nh\u01b0 Python, Java, JavaScript, C++\u2026 Bao g\u1ed3m c\u00e1ch \u0111\u1eb7t t\u00ean, format code, vi\u1ebft comment, t\u1ed5 ch\u1ee9c file.<\/td><td>Gi\u00fap team c\u00f3 code style th\u1ed1ng nh\u1ea5t, d\u1ec5 \u0111\u1ecdc. C\u00f3 th\u1ec3 \u00e1p d\u1ee5ng tr\u1ef1c ti\u1ebfp ho\u1eb7c t\u00f9y ch\u1ec9nh cho d\u1ef1 \u00e1n n\u1ed9i b\u1ed9.<\/td><\/tr><tr><td><strong>SOLID Principles<\/strong><\/td><td>5 nguy\u00ean t\u1eafc thi\u1ebft k\u1ebf h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng: Single Responsibility, Open\/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.<\/td><td>C\u1ea3i thi\u1ec7n kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng v\u00e0 b\u1ea3o tr\u00ec c\u1ee7a h\u1ec7 th\u1ed1ng OOP. N\u00ean h\u1ecdc k\u00e8m v\u00ed d\u1ee5 th\u1ef1c t\u1ebf \u0111\u1ec3 tr\u00e1nh \u00e1p d\u1ee5ng c\u1ef1c \u0111oan.<\/td><\/tr><tr><td><strong>DRY \/ KISS \/ YAGNI<\/strong><\/td><td>Ba nguy\u00ean t\u1eafc n\u1ec1n t\u1ea3ng: tr\u00e1nh l\u1eb7p code (DRY), gi\u1eef gi\u1ea3i ph\u00e1p \u0111\u01a1n gi\u1ea3n (KISS), v\u00e0 kh\u00f4ng vi\u1ebft th\u1ee9 ch\u01b0a c\u1ea7n (YAGNI).<\/td><td>Gi\u00fap code g\u1ecdn nh\u1eb9, d\u1ec5 \u0111\u1ecdc, gi\u1ea3m chi ph\u00ed b\u1ea3o tr\u00ec.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. C\u00e1c l\u1ed7i th\u01b0\u1eddng g\u1eb7p khi vi\u1ebft code kh\u00f4ng clean<\/h2>\n\n\n\n<p>D\u00f9 ai c\u0169ng mong mu\u1ed1n code c\u1ee7a m\u00ecnh r\u00f5 r\u00e0ng v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec, nh\u01b0ng trong th\u1ef1c t\u1ebf, r\u1ea5t nhi\u1ec1u l\u1eadp tr\u00ecnh vi\u00ean \u2014 \u0111\u1eb7c bi\u1ec7t l\u00e0 khi l\u00e0m vi\u1ec7c d\u01b0\u1edbi \u00e1p l\u1ef1c th\u1eddi gian \u2014 d\u1ec5 m\u1eafc ph\u1ea3i nh\u1eefng l\u1ed7i c\u01a1 b\u1ea3n khi\u1ebfn code tr\u1edf n\u00ean r\u1ed1i r\u1eafm, kh\u00f3 \u0111\u1ecdc v\u00e0 kh\u00f3 m\u1edf r\u1ed9ng. Nh\u1eefng l\u1ed7i n\u00e0y kh\u00f4ng ch\u1ec9 \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn hi\u1ec7u su\u1ea5t l\u00e0m vi\u1ec7c c\u00e1 nh\u00e2n m\u00e0 c\u00f2n g\u00e2y kh\u00f3 kh\u0103n cho c\u1ea3 nh\u00f3m khi b\u1ea3o tr\u00ec ho\u1eb7c ph\u00e1t tri\u1ec3n t\u00ednh n\u0103ng m\u1edbi. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 l\u1ed7i ph\u1ed5 bi\u1ebfn th\u01b0\u1eddng g\u1eb7p:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u0110\u1eb7t t\u00ean bi\u1ebfn\/h\u00e0m m\u01a1 h\u1ed3, thi\u1ebfu ng\u1eef ngh\u0129a:<\/strong> D\u00f9ng t\u00ean nh\u01b0 <code>data<\/code>, <code>temp<\/code>, <code>handle()<\/code> khi\u1ebfn ng\u01b0\u1eddi \u0111\u1ecdc kh\u00f4ng hi\u1ec3u r\u00f5 m\u1ee5c \u0111\u00edch. T\u00ean n\u00ean th\u1ec3 hi\u1ec7n \u0111\u01b0\u1ee3c vai tr\u00f2 v\u00e0 \u00fd ngh\u0129a c\u1ee7a bi\u1ebfn ho\u1eb7c h\u00e0m.<\/li>\n\n\n\n<li><strong>Vi\u1ebft h\u00e0m qu\u00e1 d\u00e0i, l\u1ed3ng nhau nhi\u1ec1u:<\/strong> M\u1ed9t h\u00e0m th\u1ef1c hi\u1ec7n qu\u00e1 nhi\u1ec1u vi\u1ec7c khi\u1ebfn vi\u1ec7c b\u1ea3o tr\u00ec v\u00e0 ki\u1ec3m th\u1eed tr\u1edf n\u00ean kh\u00f3 kh\u0103n. H\u00e3y t\u00e1ch th\u00e0nh c\u00e1c h\u00e0m nh\u1ecf, m\u1ed7i h\u00e0m ch\u1ec9 n\u00ean l\u00e0m m\u1ed9t nhi\u1ec7m v\u1ee5 r\u00f5 r\u00e0ng.<\/li>\n\n\n\n<li><strong>Code l\u1eb7p l\u1ea1i, kh\u00f3 test:<\/strong> Sao ch\u00e9p c\u00f9ng m\u1ed9t \u0111o\u1ea1n code \u1edf nhi\u1ec1u n\u01a1i l\u00e0m t\u0103ng r\u1ee7i ro l\u1ed7i v\u00e0 t\u1ed1n c\u00f4ng s\u1eeda \u0111\u1ed5i. N\u00ean t\u00e1ch ph\u1ea7n d\u00f9ng chung th\u00e0nh h\u00e0m ho\u1eb7c module ri\u00eang.<\/li>\n\n\n\n<li><strong>Comment sai c\u00e1ch ho\u1eb7c th\u1eeba th\u00e3i:<\/strong> Ghi ch\u00fa l\u1ea1i nh\u1eefng \u0111i\u1ec1u hi\u1ec3n nhi\u00ean ho\u1eb7c kh\u00f4ng c\u1eadp nh\u1eadt theo code th\u1ef1c t\u1ebf khi\u1ebfn ng\u01b0\u1eddi kh\u00e1c hi\u1ec3u sai. Comment ch\u1ec9 n\u00ean gi\u1ea3i th\u00edch <em>\u201ct\u1ea1i sao\u201d<\/em> thay v\u00ec <em>\u201cl\u00e0m g\u00ec\u201d<\/em>.<\/li>\n\n\n\n<li><strong>Ph\u00e1 v\u1ee1 nguy\u00ean t\u1eafc Single Responsibility:<\/strong> M\u1ed9t class ho\u1eb7c h\u00e0m \u0111\u1ea3m nh\u1eadn qu\u00e1 nhi\u1ec1u ch\u1ee9c n\u0103ng s\u1ebd kh\u00f3 m\u1edf r\u1ed9ng v\u00e0 d\u1ec5 g\u00e2y l\u1ed7i. M\u1ed7i th\u00e0nh ph\u1ea7n ch\u1ec9 n\u00ean c\u00f3 <em>m\u1ed9t l\u00fd do \u0111\u1ec3 thay \u0111\u1ed5i<\/em>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. K\u1ebft lu\u1eadn<\/h2>\n\n\n\n<p>Vi\u1ebft <strong>clean code<\/strong> kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t k\u1ef9 thu\u1eadt xa x\u1ec9 d\u00e0nh cho nh\u1eefng ng\u01b0\u1eddi \u201cr\u1ea3nh r\u1ed7i ch\u0103m ch\u00fat code cho \u0111\u1eb9p\u201d, m\u00e0 l\u00e0 <strong>n\u1ec1n t\u1ea3ng s\u1ed1ng c\u00f2n<\/strong> \u0111\u1ec3 ph\u1ea7n m\u1ec1m t\u1ed3n t\u1ea1i, ph\u00e1t tri\u1ec3n v\u00e0 th\u00e0nh c\u00f4ng.<\/p>\n\n\n\n<p>Code s\u1ea1ch gi\u1ed1ng nh\u01b0 m\u1ed9t cu\u1ed1n s\u00e1ch hay: b\u1ea5t k\u1ef3 ai m\u1edf ra c\u0169ng hi\u1ec3u m\u1ea1ch truy\u1ec7n, kh\u00f4ng c\u1ea7n t\u00e1c gi\u1ea3 \u0111\u1ee9ng b\u00ean gi\u1ea3i th\u00edch. N\u00f3 gi\u00fap c\u1ea3 team t\u1ef1 tin ph\u00e1t tri\u1ec3n t\u00ednh n\u0103ng m\u1edbi, refactor m\u00e0 kh\u00f4ng lo \u201c\u0111\u1eadp v\u1ee1\u201d th\u1ee9 g\u00ec, v\u00e0 gi\u1eef cho d\u1ef1 \u00e1n b\u1ec1n v\u1eefng theo n\u0103m th\u00e1ng.<\/p>\n\n\n\n<p>M\u1ed9t l\u1eadp tr\u00ecnh vi\u00ean chuy\u00ean nghi\u1ec7p kh\u00f4ng ch\u1ec9 <strong>khi\u1ebfn ph\u1ea7n m\u1ec1m ch\u1ea1y \u0111\u01b0\u1ee3c<\/strong>, m\u00e0 c\u00f2n khi\u1ebfn <strong>ng\u01b0\u1eddi kh\u00e1c mu\u1ed1n l\u00e0m vi\u1ec7c v\u1edbi m\u00ecnh<\/strong> \u2013 v\u00e0 clean code ch\u00ednh l\u00e0 ng\u00f4n ng\u1eef chung \u0111\u1ec3 k\u1ebft n\u1ed1i.<\/p>\n\n\n\n<p>H\u00e3y nh\u1edb: <strong>Code b\u1ea1n vi\u1ebft h\u00f4m nay ch\u00ednh l\u00e0 di s\u1ea3n b\u1ea1n \u0111\u1ec3 l\u1ea1i cho t\u01b0\u01a1ng lai.<\/strong> Vi\u1ebft n\u00f3 nh\u01b0 th\u1ec3 b\u1ea1n s\u1ebd ph\u1ea3i b\u1ea3o tr\u00ec n\u00f3 su\u1ed1t 5 n\u0103m t\u1edbi\u2026 v\u00ec r\u1ea5t c\u00f3 th\u1ec3, \u0111i\u1ec1u \u0111\u00f3 s\u1ebd x\u1ea3y ra.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. T\u00e0i li\u1ec7u tham kh\u1ea3o<\/h2>\n\n\n\n<p>[1] R. C. Martin, <em>Clean Code: A Handbook of Agile Software Craftsmanship<\/em>. Upper Saddle River, NJ: Prentice Hall, 2008.<br>[2] R. C. Martin, <em>The Clean Coder: A Code of Conduct for Professional Programmers<\/em>. Upper Saddle River, NJ: Prentice Hall, 2011.<br>[3] M. Fowler, <em>Refactoring: Improving the Design of Existing Code<\/em>. Boston, MA: Addison-Wesley, 2018.<br>[4] OpenDev, \u201cKienthucmo,\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/software-engineering\/\">https:\/\/kienthucmo.com\/en\/software-engineering\/<\/a>. [Accessed: Oct. 24, 2025].<br>[6] OpenDev, \u201cWhat is SOLID? Principles, how it works, and practical applications,\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/\" data-type=\"link\" data-id=\"https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/\">https:\/\/kienthucmo.com\/en\/what-is-solid-principles-how-it-works-and-practical-applications\/<\/a>. [Accessed: Oct. 24, 2025].<br>[7] OpenDev, \u201cKISS, DRY, YAGNI \u2013 3 Golden Principles in Software Development\u201d [Online]. Available: <a href=\"https:\/\/kienthucmo.com\/en\/kiss-dry-yagni-3-golden-principles-in-software-development\/\">https:\/\/kienthucmo.com\/en\/kiss-dry-yagni-3-golden-principles-in-software-development\/<\/a>. [Accessed: Oct. 24, 2025].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clean Code kh\u00f4ng ch\u1ec9 gi\u00fap ph\u1ea7n m\u1ec1m ch\u1ea1y \u0111\u00fang m\u00e0 c\u00f2n gi\u1eef cho d\u1ef1 \u00e1n d\u1ec5 \u0111\u1ecdc, d\u1ec5 b\u1ea3o tr\u00ec v\u00e0 b\u1ec1n v\u1eefng. <\/p>\n","protected":false},"author":1,"featured_media":2351,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowieHDDA:productID":"","footnotes":""},"categories":[16],"tags":[33],"class_list":["post-19","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cong-nghe-thong-tin","tag-clean-code"],"_links":{"self":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/19","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=19"}],"version-history":[{"count":15,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":2357,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/posts\/19\/revisions\/2357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/media\/2351"}],"wp:attachment":[{"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kienthucmo.com\/vi\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}