开源日报 每天推荐一个 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/