Sunday, June 12, 2016

WLC - Write Less Code

Given two solutions to a problem, the one with less code is usually better. 

Plite of the Programmer


Our job as programmers is to deliver value to customers. We deliver value by identifying needs, translating them into requirements, and writing code to meet those requirements. The difficulty of the task is compounded by the fact that requirements are constantly, unpredictably changing. Even after we finally ship, the story isn’t over. Code is a living thing that must be maintained, usually well beyond anyone's expectations.

Over the lifetime of a product, we will edit code 10x more than we write code, and we will read code 10x more than we edit it. Each token we add to our code may be read over 100 times. Every token we save could save up to 100 token-thoughts and 10 future edits. The key to our productivity is writing less code.

Why Count Tokens?


Tokens are the smallest meaningful element in code. Tokens are a more objective measure of code size since lines can have any number of tokens. Measuring tokens also ignores white-space and comments. Last, measuring tokens doesn't penalize using clear names. ‘Occupations’ is just as good a name under the token metrics as ‘occus’ or other hard to understand abbreviations.

Don't abbreviate words. Saving keystrokes only saves writing the code. It doesn't save edits or reading. Abriviations make reading harder. Since reading code dominates our time, abbreviations are a losing proposition. Only use shortened words if the shortened version is used at least as commonly in speech.

Measuring tokens is a simple, effective metric that lets us make decisions quickly and get on with solving problems and delivering value.

Why ‘Write Less Code’?


It's a simple concept with depth. Amateurs and masters both can apply and learn from it. A more accurate metric might be refactorability. We spend most of our time refactoring code, not writing it. Refactorability is the code-quality metric. It can be broken down into code size, clarity, and structure. Of the three, size is the only one that can be objectively measured, and while clarity and structure are important, both are usually improved by reducing code size. Refactorability is not something a novice will understand. ‘Write less code’ is an excellent guiding principle for all programmers.

How to Write Less Code


All other good coding practices essentially reduce code size. Two of the most important, and most often violated coding practices for reducing code-size are DRY and ZEN.

DRY


Don't. Repeat. Yourself. Don't you dare repeat yourself ;). The most problematic artifacts I've seen, both from novice and expert programmers, is code repetition. The big problem with repetition is it compounds the complexity of refactoring. Not only do we have to fix two or more things instead of one, but we have to understand how they all interact. Plus it bloats the code-base making it hard to understand.

DRY is a subtle art. The first, obvious level is ‘don't copy-paste your code,’ but as we level-up, we start to realize anything gzip might compress potentially violates DRY. The ultimate measure is, as always, refactorability. How many code-points need to change for a common refactor? Is there a way to reduce repetition to reduce the complexity of refactorability?

ZEN


Build it with Zero Extra Nuts (more commonly known as YAGNI). Because it is impossible to
predict future requirements, adding anything to our code that isn't strictly necessary to meet current requirements is not only a waste of time now, but it will haunt us for at least 10x future edits and 100x future reads.

It is fun to add cool features, but the master knows the only thing that matters is delivering value to the customer.

Write Less Code - Formalized


My hypothesis, and my experience, comes down to this:

  • Given two different functions, modules or programs
  • that both meet or exceed the problem's requirements, both correctness and performance
  • the one with less tokens is always better
  • as long as it doesn't sacrifice clarity.

The Practice of Writing Less Code


As with everything in life, writing less code is a practice. There is no point where we will master it. There is always another layer of deeper understanding. We are always learning how to make our code DRYer and more ZEN. We must constantly be looking for ways to meet requirements with less code.

43 comments:

  1. After reading your more recent Jan 28th 2017 "Your SOUP is Leaking - Crafting Acronyms" article along with your thoughtful ZEN article and that principle's relationship to frameworks, I thought there might be a good alternative acronym to WLC that relates the two principles: ULC - Use Less Code.

    Through both thoughtful choices when sourcing 3rd party frameworks or modules and consideration in how to assemble or integrate them with your own code efforts, "Use" could include but also expand beyond just the code you create in a project.

    While it is actually more pronounceable, I'm not sure a 'hulk' without the H sounds all that elegant. :)

    ReplyDelete
    Replies
    1. I love that idea! WLC certainly isn't an elegant acronym by any stretch. "Hulk" means strength, not a terrible association with "ULC." I'll try it out.

      I do like that "use" is more general than "write".

      Delete
  2. This was such a thorough and insightful read. i am glad i got to read it. you have a way with words and on top of that you are quite knowledgable. keep posting more

    ReplyDelete
  3. I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one do my essay

    ReplyDelete
  4. I read this article, it is really informative one. Your way of writing and making things clear is very impressive. Thank you for sharing such an informative article. thesis proofreading

    ReplyDelete
  5. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. Mua Tài khoản Grammarly Premium

    ReplyDelete
  6. Tan Binh valve has many years of experience in the field of industrial valves. Production meets DIN, BS, JIS standards… Tan Binh After more than 10 years of supplying materials for the water industry Our company is now a reliable partner for most companies providing water treatment systems in the local area. Hanoi as well as nationwide. van công nghiệp, Van cửa, van điện từ

    ReplyDelete
  7. Today, the demand for modern sanitary products and equipment with preeminent features is increasing day by day. That's why many sanitary ware companies were born. To meet the essential needs of our customers. So what are the advantages of today's sanitary ware products? Let's find out detailed information with the Great World of Lights Showroom through the article below. More: https://bitly.com.vn/hfn52q

    ReplyDelete
  8. Nội thất Kfa đã có trên 10 năm kinh nghiệm trong thiết kế và thi công nội thất, được hàng nghìn khách hàng tin tưởng - đem đến sự hài lòng cho cả những khách hàng khó tính nhất
    Phong cách tropical trong thiết kế nội thất
    Phong cách tropical là gì? Xem chi tiết ngay
    Vách ngăn phòng khách là gì
    Có Nên Sử Dụng Thảm Phòng Khách Hay Không

    ReplyDelete
  9. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. nên mua điện thoại nào dưới 10 triệu

    ReplyDelete
  10. Thanks for publishing such best knowledge with us. You are doing such a great job. This info is very helpful for everyone. Keep it up. Thanks.Read more info about high quality dissertation services

    ReplyDelete
  11. This blog is basically related to programmer. They can get many tips form this article. While I am service provider of Pest Extermination Services in New York. My experts given you reliable service.

    ReplyDelete


  12. Hey friend, it is very well written article, thank you for the valuable and useful information you provide in this post. Keep up the good work! FYI, Pet Care adda
    can i use flipkart axis bank credit card anywhere, think again the power of knowing what you don t know pdf,mental health essay

    ReplyDelete
  13. đá mỹ nghệ
    Mẫu lăng mộ đá

    LĂNG MỘ ĐÁ - ĐÁ MỸ NGHỆ 35
    Điện thoại: 0912984468
    Email: phongthuy35@gmail.com
    Địa chỉ: Làng nghề truyền thống đá mỹ nghệ Ninh Bình – Thôn Xuân Phúc,
    xã Ninh Vân, huyện Hoa Lư, tỉnh Ninh Bình

    *************

    ReplyDelete
  14. giá sàn bê tông siêu nhẹ bao nhiêu
    chi phí xây dựng nhà khung thép
    Sàn bê tông nhẹ
    Trụ sở chính : Địa chỉ : Thôn 2 - Yên Sở - Hoài Đức - Hà nội.
    Văn phòng : Số 25 - Dốc Thành công - Ba Đình - Hà nội



    ReplyDelete
  15. While there are several types of construction projects, most of them fall into one of two categories: Building Construction and Industrial Construction. They can overlap, however each type requires its own process- including planning, designing, and executing (not to mention the different necessary permits). interior design

    ReplyDelete
  16. Điều hòa Funiki 2 chiều 24000BTU HSH24TMU sử dụng môi chất làm lạnh R32 vừa được tập đoàn Hòa Phát cho ra mắt vào đầu 2022 nhằm thay thế model cũ SH24MMC. Ngoài những tính năng củ, sản phẩm được trang bị nhiều tính năng mới tiến tiến mang đến cho người tiêu dùng trải nghiệm giá trị đích thực. Vua Điều Hòa chuyên phân phối các dòng điều hòa Funiki chính hãng với mức giá tốt. Hãy liên hệ ngay với chúng tôi để được hưởng những ưu đãi tốt nhất nhé!

    ReplyDelete
  17. Khi bé bị sốt hoặc gặp một số bệnh về hô hấp như ho, viêm mũi, đau họng,... thì các bà mẹ sẽ có xu hướng tắt máy lạnh trong nhà nhưng có bao giờ bạn thử tìm hiểu, trẻ em bị sốt cao có nên nằm điều hòa hay không?

    ReplyDelete
  18. tấm xi măng cemboard thái lan
    Tấm Cemboard SCG Thái Lan
    Tấm xốp Eco XPS Foam Panel
    Tấm Cemboard Vĩnh Tường


    NHÀ PHÂN PHỐI TẤM XI MĂNG CEMBOARD

    Địa chỉ: Tầng 3, tòa nhà Shodex, số 245 Tam Trinh, Hoàng Mai, Hà Nội

    Điện thoại: 024 66604646 - Hotline: 0928 688 695

    Email: tatphu.com@gmail.com

    ReplyDelete
  19. Chiếc điều hòa Casper inverter 12000BTU GC-12IS32 sẽ là sự lựa chọn hàng đầu trong phân khúc điều hòa inverter giá rẻ có công suất 12000BTU. Sản phẩm được hãng Casper cho ra mắt vào năm 2021 hứa hẹn sẽ mà Model điều hòa thông dụng được nhiều tin tưởng lựa chọn. Tính năng iClean trên điều hòa Casper sẽ tự động làm sạch thông minh, giúp ngăn chặn sự hình thành vi khuẩn, nấm mốc ở bên trong dàn lạnh, tối ưu hoạt động, hạn chế số lần vệ sinh và tăng tuổi thọ của máy lạnh.

    ReplyDelete
  20. Dựa trên thông tin bảng mã lỗi điều hòa Akito, bạn dễ dàng xác định được nguyên nhân và có biện pháp phù hợp khi gặp phải lỗi E0.

    ReplyDelete
  21. Điều hòa Multi LG 2 chiều 42000BTU A5UW42GFA1 chính hãng được sản xuất và nhập khẩu trực tiếp từ nhà máy LG tại Thái Lan. Dàn nóng điều hòa Multi LG A5UW42GFA1 không chỉ được thiết kế hữu ích và mà còn giúp tiết kiệm không gian chắc chắn sẽ mang đến những trải nghiệm tốt nhất cho người dùng.

    ReplyDelete
  22. Điều hòa Panasonic 9000BTU 2 chiều inverter XZ9XKH-8 được thiết kế với những đường nét thanh mảnh hiện đại. Điều hoà được nhập khẩu chính hãng từ Malaysia được với những công nghệ tiên tiến và hiện đại nhất. Điều hoà Panasonic hứa hẹn mang đến cho người dùng những sự trải nghiệm tuyệt vời trong cuộc sống.

    ReplyDelete
  23. Việc sử dụng điều hòa Aqua không đúng cách sẽ gây ra nhiều sự lãng phí, không tối ưu hóa năng suất hoạt động của điều hòa. Trong khi cách sử dụng điều hòa Aqua đúng sẽ giúp hệ thống vận hành ổn định hơn, chính xác, kéo dài tuổi thọ và tiết kiệm điện hơn rất nhiều. Hiểu được vấn đề mà đang số khách hàng đang gặp phải như trên, Vua Điều Hòa sẽ tổng hợp đầy đủ chi tiết cách sử dụng và gửi đến bạn ngay trong bài viết này.

    ReplyDelete
  24. Dàn lạnh điều hòa Daikin Multi treo tường CTKM50RVMV là dàn lạnh treo tường tiêu chuẩn hệ Multi 1 chiều. Dàn lạnh Daikin CTKM50RVMV có thể kết nối được với tất cả các model dàn nóng 1 chiều Multi 2018 sử dụng gas R32: 3MKM52, 4MKM68, 4MKM80 và 5MKM100.

    ReplyDelete
  25. Dàn lạnh âm trần Daikin Multi nối ống gió CDXP25RVMV thuộc hệ điều hòa Multi Daikin 2 chiều. Dàn lạnh điều hoà có thể kết hợp với tất cả model dàn nóng điều hoà 1 chiều và 2 chiều sử dụng môi chất Gas R32. Daikin CDXP25RVMV với thiết kế nhỏ gọn, giấu ống gió và nhiều tính năng hiện đại sẽ là sự lựa chọn hoàn hảo dành cho kiến trúc không gian nhà bạn.

    ReplyDelete
  26. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work.cấy mi giá bao nhiêu

    ReplyDelete
  27. Điều hòa Daikin inverter không mát hay điều hòa Daikin thông thường (không inverter) không mát thì cũng do cùng nguyên nhân. Vì trên thực tế thì cơ chế hoạt động của 2 sản phẩm gần như là tương đương, chỉ khác công nghệ inverter (tiết kiệm điện năng) mà thôi.

    ReplyDelete
  28. Dàn nóng điều hòa Daikin Multi 4MXM68RVMV là dàn nóng điều hòa Multi 2 chiều phù hợp với nhiều gia đình, đây là dòng điều hòa tổng hợp phù hợp với nhiều gia đình. Với công suất 24000BTU, dàn nóng Daikin Multi MXM68RVMV 2 chiều có thể kết nối với đa dàn lạnh với tổng công suất kết nối lên đến 144% công suất dàn nóng.

    ReplyDelete
  29. Điều hòa Panasonic kêu to dễ khiến người dùng khó chịu, đặc biệt là trong khi ngơi, họp hành,... Còn điều hoà Panasonic chảy nước thì khiến sàn, tường nhà bị dơ bẩn. Vậy thì giải pháp khắc phục cho 2 lỗi này là như thế nào? Chúng ta cùng xem chi tiết ở dưới bài viết này nhé!

    ReplyDelete
  30. Điều hòa Sumikura 1 chiều 9000BTU APS/APO-092/Citi là một sản phẩm thuộc phân khúc điều hòa giá rẻ được nhập khẩu chính hãng về Việt Nam với nhiều công nghệ tiên tiến đến từ Nhật Bản. Điều hòa Sumikura với mức giá phải chăng, thiết kế hiện đại, tính năng thông minh mang đến cảm giá cảm mát lạnh, mát lạnh cho người dùng.

    ReplyDelete
  31. Điều hòa Sumikura 2 chiều 12000BTU APS/APO-H120/Citi là sản phẩm mới đến từ hãng điều hòa Sumikura. Với chất lượng vượt trội được khẳng định qua dây chuyền công nghệ hiện đại đền từ Nhật bản. Điều Hòa Sumikura 2 chiều 12000BTU APS/APO-H120/Citi không chỉ có thiết kế đẹp mà còn mang đến sự vận hành cực kỳ êm ái, bền bỉ với thời gian.

    ReplyDelete
  32. Điều hòa Sumikura APS/APO-H240DC với 2 chiều vừa làm lạnh, sưởi ấm hiệu quả thích hợp với những nơi có khí hậu thất thường như miền Bắc Việt Nam. Điều hòa Sumikura không chỉ có thiết kế đẹp mà sản phẩm còn được trang bị nhiều tính năng hiện đại, hứa hẹn sẽ làm lòng bất kỳ vị khách hàng khó tính nào.

    ReplyDelete
  33. Điều hòa cây và điều hòa treo tường hiện nay là hai dòng sản phẩm khá phổ biến trên thị trường và được rất nhiều người phân vân lựa chọn. Tuy nhiên, với những không gian có diện tích không quá lớn như chung cư, nhà ở thì vấn đề nên mua điều hòa cây hay treo tường vẫn là câu hỏi khó giải đáp.

    ReplyDelete
  34. Dàn nóng điều hòa LG Multi A3UQ30GFD0 được trang bị công nghệ inverter tiết kiệm điện, môi chất tiên tiến R410A. Điều hòa Multi LG này có thể kết nối tối đa với 3 dàn lạnh tiết kiệm không gian, phù hợp với nhiều căn hộ bị hạn chế chỗ lắp đặt dàn nóng. Đây sẽ là sự lựa chọn phù hợp và tối ưu cho gia đình bạn.

    ReplyDelete
  35. Điều hòa Multi là một trong những dòng sản phẩm được người dùng nghĩ đến đầu tiên khi có ý định lắp điều hòa cho chung cư. Tuy nhiên, rất ít người biết tường tận thông tin về loại điều hòa này, chẳng hạn như ưu nhược điểm, kinh nghiệm lựa chọn hay chi phí lắp. Chính vì thế trong bài viết này, chúng tôi sẽ giúp bạn giải đáp những lưu ý khi lắp đặt điều hòa Multi cho chung cư.

    ReplyDelete
  36. Với thời tiết oi bức tại Việt Nam, máy điều hoà rất được ưa chuộng, hầu như mỗi nhà đều lắp đặt máy điều hoà. Các thương hiệu máy điều hoà càng ngày càng đa dạng, các sản phẩm cũng ngày một phong phú, trong đó phải kể đến thương hiệu Daikin. Đây là thương hiệu máy điều hoà không khí xuất xứ tại Nhật với chất lượng được đánh giá top đầu trên thế giới. Daikin đã cung cấp rất nhiều dòng máy như điều hoà dân dụng, máy lọc không khí dân dụng, điều hoà không khí thương mại….Điều hòa 18000btu của Daikin cũng rất được ưa chuộng và được người tiêu dùng đánh giá cao về mọi mặt. Cùng tìm hiểu đâu là top 5 điều hoà Daikin 18000btu tốt nhất thị trường hiện nay nhé.

    ReplyDelete
  37. new style online Many people like each other very much because PG slots are the new slots that are open for service. pgslot เว็บตรง

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. This comment has been removed by the author.

    ReplyDelete
  40. an important helper for us to make money more easily than before. Which this game is suitable for สล็อต

    ReplyDelete

Note: Only a member of this blog may post a comment.