bjarne stroustrup撰写精美的代码是什么样子

For those of you who are not familiar with the genius of Bjarne Stroustrup, he was the man who gave birth to C++ as a way to apply object-oriented concepts to the C programming language. I think that’s all that needs to be said to establish his authority and influence in the realm of software engineering, so whatever he has to say I believe we would all benefit from paying close attention to it.

对于那些不熟悉Bjarne Stroustrup的天才的人来说,他就是C ++的诞生者,C ++是将面向对象的概念应用于C编程语言的一种方式。 我认为,要确立他在软件工程领域的权威和影响力,就需要说明所有这些,因此,无论他怎么说,我相信我们都会从密切关注中受益。

**Article based off the linked interview below**

**文章摘自下面的链接访谈**

In a recent interview with the reputable AI research scientist and podcaster, Lex Fridman, Bjarne briefly goes over what makes code identifiably beautiful and well-crafted.

在最近一次与著名的AI研究科学家和播客Lex Fridman的访谈中 ,Bjarne简要介绍了使代码可识别的精美和精心制作的原因。

What he says can be directly applied towards the way you program and how you should mentally approach the craftmanship of software in the same way a masterclass artist or sculptor approaches their art.

他所说的内容可以直接应用于您的编程方式,以及如何以与大师级艺术家或雕刻家一样的方式来思考软件的Craft.io。

了解精美的代码框架 (Understand The Framework Of Beautifully Written Code)

What programmers don’t understand is that there is an astronomical difference between what you can do with a programming language and what you should do.

程序员不理解的是,您可以用编程语言执行的操作与应执行的操作之间在天文上有天壤之别。

Just because you can accomplish a programming task in a brute-force way doesn’t mean that that approach is the one you should be taking.

仅仅因为您可以用蛮力方式完成编程任务,并不意味着该方法就是您应该采用的方法。

There exist rules that other highly intellectual and influential programmers have set as the grounds for what good code looks like. Many of these rules can be found in renowned programming books such as Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin — a good place for any budding programmer to start to immediately increase the cleanliness of their code. I’ve also gone over some of these rules in past articles that I’ve written like the ones below.

存在其他优秀知识分子和有影响力的程序员设置的规则,这些规则是好的代码的外观的基础。 这些规则中的许多规则都可以在著名的编程书籍中找到,例如Robert C. Martin编写的Clean Code:Agile Software Craftsmanship手册,这是任何新手程序员立即开始提高其代码清洁度的好地方。 我在过去写过的文章(例如下面的文章)中也回顾了其中一些规则。

Bjarne mentions that these rules are essential for the pathway to well-written code, but aren’t the defining factors for beautifully written code. What the frameworks and rules for good code do accomplish though is providing you a way to make your code readable, scalable, and less prone to the possibility of error or mistakes.

Bjarne提到,这些规则对于通向编写良好代码的途径必不可少,但并不是编写精美代码的决定性因素。 好的代码的框架和规则的确完成了哪些工作,但却为您提供了一种使代码更具可读性,可伸缩性以及不大可能出现错误或错误的方法。

The rules answer the question of what a good programmer does at a very basic level of where and how you should be using a language.

规则回答什么是好的程序员确实在哪里以及如何你应该使用一种语言的一个非常基本的水平的问题。

As he says, you can follow all the rules of chiseling marble, but it doesn’t mean that if you follow all those rules, that you can create a masterpiece matching the likes of Michelangelo.

正如他所说, 您可以遵循凿凿大理石的所有规则,但这并不意味着如果您遵循所有这些规则,就可以创建与米开朗基罗之类作品相匹配的杰作。

At least you have the tools available to get you there, just make yourself conscious of those tools and use them effectively and thoughtfully, and perhaps you’ll give yourself the edge you need to get there.

至少您拥有可以到达那里的工具,只是使自己意识到这些工具并有效,周到地使用它们,也许您将为自己提供到达那里所需的优势。

通往天才级软件Craft.io的道路 (The Path To Genius-Level Software Craftmanship)

You must understand that in order to develop something that is very obviously clean, understandable, optimized, and appreciated, you have to exert A LOT of effort.

您必须了解,要开发出非常明显,清晰易懂,经过优化和赞赏的产品,您必须付出很多努力。

Writing clean code is no easy task as it requires you to be very thoughtful and intentional in your approach, and honestly, you can probably recognize as you’re writing your code and struggling to implement difficult design concepts that you haven’t quite reached that point of expertise or cleanliness quite yet.

编写干净的代码不是一件容易的事,因为它要求您在方法上非常周到和有目的地,并且说实话,您可能会认识到正在编写代码并努力实现尚未达到的困难设计概念的专业知识或清洁程度。

And that’s okay. It takes time to really grow to the point where you can craft beautiful code.

没关系。 真正发展到可以编写精美代码的过程需要时间。

Bjarne suggests that what you can do is intentionally and actively pursue the craftsmanship of code.

Bjarne建议,您可以做的是有意识地,积极地追求代码的精湛Craft.io。

If you think about it, the most famous artists and musicians throughout history are superb craftsmen. They could effectively express their ideas using their tool very well.

如果您考虑一下,历史上最著名的艺术家和音乐家都是精湛的工匠。 他们可以很好地使用自己的工具有效地表达自己的想法。

It doesn’t matter what tools you have to your disposable or what type of experience that you have, if you aren’t able to leverage any of that effectively, then you probably won’t produce the results that you are hoping for.

无论您拥有什么工具来处理一次性物品或拥有哪种类型的体验都没有关系,如果您不能有效地利用这些工具中的任何一种,那么您可能不会获得想要的结果。

The thing is, beautiful code isn’t something that you can actually generate on impulse nor intentionally. Yes, you can work towards it and take the steps to provide what you write with the qualities of great code, but that’s simply not enough.

问题是,漂亮的代码不是一时冲动或有意产生的。 是的,您可以朝着它努力,并采取步骤为您编写的代码提供优质的代码,但这还远远不够。

Do you think Leonardo DaVinci started painting having the Last Supper and the Mona Lisa to become deemed as masterpieces that echo his creative genius throughout the knolls of history?

您认为莱昂纳多·达·芬奇开始以《最后的晚餐》和《蒙娜·丽莎》为代表的绘画成为杰作,在整个历史小节中都与他的创造天才相呼应吗?

No, what Bjarne says a really good piece of code requires is a spark of creative inspiration. An aha moment that’ll drive the crafting of your code through an illusory flow state.

不,Bjarne所说的一段非常好的代码需要激发创意灵感。 令人难以置信的时刻,将通过虚幻的流状态推动代码的编写。

记住,凌乱比美更明显 (Remember That Messy Is More Clearly Identifiable Than Beauty)

Don’t be discouraged by the fact that you probably won’t write the most beautiful code ever seen to man, but what you can do is intentionally move towards that objective with zeal in hopes that you’ll one day obtain that mythical ideal.

不要因为您可能不会编写人类见过的最漂亮的代码而灰心,但是您可以做的是有热情地朝着这个目标迈进,希望您有一天能获得这一神话般的理想。

It’s much easier to recognize ugly and smelly code than to recognize beauty, and that should scare you. That should scare you because you don’t want to seem incompetent or lacking actual effort when someone else reviews your code. It should scare you because looking at it indicates that you potentially created something that won’t stand the test of time or raise alarm for potential error.

识别丑陋和有臭味的代码比识别美感要容易得多, 这应该会吓到您。 这应该使您感到恐惧,因为当其他人查看您的代码时,您不想显得无能或缺乏实际的努力。 它应该使您感到恐惧,因为看着它表明您可能创建了无法经受时间考验或对潜在错误发出警报的东西。

Ugly is easy to identify because the messes always have something in common, but not beauty.

丑陋很容易识别,因为混乱总是有共同点而不是美丽。

Bjarne says beautiful code is harder to identify because the beauty of it stems from the craftmanship of something so innovative and unique that you’d have to think reasonably hard to appreciate and see that. Beauty is identifiably unique and lacks the consistencies of what makes bad code bad. Beauty lies on the spectrum of ingenious thought and artistry.

Bjarne说,很难识别出漂亮的代码,因为它的优美源于某种创新和独特的Craft.io,您必须合理地思考才能欣赏和看到它。 美是可以识别的唯一,并且缺乏使不良代码变坏的一致性。 美在于巧妙的思想和艺术性。

That being said, be a craftsman. Be an artist. Aim to code cleanly and thoughtfully. It should be your goal as a programmer to create code that stands to be completely unique in the solution it provides. Code that completely stands out for its simple approach to complex solutions. Code that is architected so beautifully that it’ll fill the craftsman and those that interact with the result of the code with complete appreciation.

话虽这么说,做个工匠。 做一个艺术家。 旨在清晰,周到地编写代码。 作为程序员,您的目标应该是创建在其提供的解决方案中完全唯一的代码。 以其简单的方法解决复杂问题而完全脱颖而出的代码。 设计精美的代码,使技工和与代码结果进行交互的人员充满了欣赏。

翻译自: https://medium.com/dev-genius/bjarne-stroustrup-on-what-beautifully-written-code-looks-like-c68adb53c740

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值