開源日報 每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,堅持閱讀《開源日報》,保持每日學習的好習慣。
今日推薦開源項目:《再放送 rrweb》
今日推薦英文原文:《Programming Is an Art — Stop Treating It Like It』s Not》

今日推薦開源項目:《再放送 rrweb》傳送門:項目鏈接
推薦理由:這個項目是一個 JS 庫,可以用於記錄用戶的操作並重放。它的錄製部分用於記錄下用戶的操作,並將對應的事件傳入函數中;在需要回放的時候,可以選擇項目自帶的回放功能或是它提供的附帶播放器。而且對於一些不希望在回放中展現出的保密內容,只要為 HTML 元素添加指定類就能在回放中通過添加空佔位元素等方式無視它。
今日推薦英文原文:《Programming Is an Art — Stop Treating It Like It』s Not》作者:Zachary Minott
原文鏈接:https://medium.com/better-programming/programming-is-an-art-stop-treating-it-like-its-not-85fb82d14a4b
推薦理由:編程的藝術性體現在使用更好的想法設計與編寫代碼,使其能夠滿足可讀性可拓展性等未來可能出現的需求

Programming Is an Art — Stop Treating It Like It』s Not

It』ll make you a much better programmer

On the surface, programming appears to mask itself as a science that serves to power the functionality of the applications that we work with on a daily basis. But really, it is so much more than that. Code is very intricately crafted, and when put together into its cohesive structure, we can see that it outputs the most beautiful and interactive experiences.

Essentially, we as programmers aren』t just problem-solvers and critical thinkers, but we』re artists and creators. We have the power to utilize skills and ingenuity to generate objects of beauty. Objects that』ll impact and change lives, just as a painter or musician inspires those with their work.

What I believe sets a great programmer apart from a good programmer is the perspective they take towards their work and the relationship they build with their craft.

The Issue With Not Focusing on Carefully Crafted Code

The problem is that most programmers don』t treat the craft as an art form. They focus too much on achieving the desired outcome rather than crafting the most elegant solution. Throwing around algorithms, an endless amount of code, and meaningless variable names like a five-year-old finger painter just smearing paint all over the canvas. See, you still get a painting, but by no means does it signify a thing of beauty.

I believe the dreaded 「If it works, don』t touch it」 is extraordinarily bad advice.
「It is not enough for code to work.」―Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship
If it works on the first go, that』s simply just the rough draft. You must refactor and think very carefully about what other programmers will think and do when they see your code. Do they understand the functions? Are there unnecessary comments vomited everywhere? Do the variables and functions have clearly defined names about what they do? Are the functions and classes small? Is this reusable? Can it be extended?

Or is it just absolute chaos that makes other developers cringe because it amounts to a monolithic wall of text that is very difficult to understand or modify?

Great code is something that anyone can look at and be able to grasp in a very minimal amount of time. Make your code very readable and self-commenting not only for the purpose of others but for yourself. Too often, we write code just to leave without knowing or remembering what we』ve done.

Great code is also something that doesn』t need to be modified and can be extended with ease. You don』t want your entire program to break because there was a simple modification to the code. A function should serve a specific purpose and maintain that purpose throughout its lifetime.

So stop running around like a headless chicken banging what used to be your head against your keyboard until you』ve got something that works. Programming is hard — I get it. But not designing your code like an artist details their work makes it seem like you didn』t put much thought or effort into writing it in the first place.
「If you can get today』s work done today, but you do it in such a way that you can』t possibly get tomorrow』s work done tomorrow, then you lose.」―Martin Fowler, Refactoring: Improving the Design of Existing Code

Why You Must Embody the Mind of an Artist

Leonardo da Vinci was perhaps one of the greatest artists of all time, with masterful paintings such as the Mona Lisa and The Last Supper. What separated him from other artists of his time? He paid great attention to detail. He would study cadavers to understand the anatomy of the human body, which he used to craft very realistic paintings where every brushstroke he took was purposeful and with care.

Be the Da Vinci of programming. Pay great attention to the way you write your code. Notice the details, understand the purpose, think about its reusability and utility. Direct your thoughts towards masterfully writing beautiful and elegant code. Be an engineer, be a painter, be a writer, be a musician, and think about how everything you write will ultimately come together into one cohesive application that』ll function with extreme fluidity.

That being said, enjoy the path to creation. Enjoy focusing on the purpose and detail of your code. Ultimately, seeing yourself as an artist will allow you to take unique approaches to your code and experiment with it in new ways. It』ll not only improve your skills as a developer, but it』ll also make you happier and more productive as a result because it』ll make you realize that you always had more freedom, autonomy, and creative power in the work that you created than you formerly thought.
「The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct.」―Donald E. Knuth, Selected Papers on Computer Science

Conclusion

I』m not saying that your code has to be perfect. Perfect code and software don』t exist, but what I』m saying is that you shouldn』t just be splattering paint on a canvas. You』re creating something amazing out of nothing, and your goal should be to create something that others would love to interact with. To create something that』ll change lives.

So use that goal to motivate yourself to create the best code you can possibly write. It』ll create the best outcome and afford your application more room for potential growth.
「You Can』t Write Perfect Software. Did that hurt? It shouldn』t. Accept it as an axiom of life. Embrace it. Celebrate it. Because perfect software doesn』t exist. No one in the brief history of computing has ever written a piece of perfect software. It』s unlikely that you』ll be the first. And unless you accept this as a fact, you』ll end up wasting time and energy chasing an impossible dream.」 — Andrew Hunt, The Pragmatic Programmer: From Journeyman to Master

下載開源日報APP:https://openingsource.org/2579/
加入我們:https://openingsource.org/about/join/
關注我們:https://openingsource.org/about/love/