惯用过程模型

You can call it “beautiful code” when the code also makes it look like the language was made for the problem.

当代码也使该代码看起来像是针对该问题使用的语言时,您可以将其称为“美丽的代码”。

Ward Cunningham

病房坎宁安

If you have a sound continuous integration practice, your pull requests will be automatically evaluated for test coverage and compliance with code conventions. But it’s your teammates who will evaluate the degree to which the submitted code is high quality through being idiomatic. What does this mean?

如果您有良好的持续集成实践,则将自动评估您的拉取请求的测试覆盖范围以及是否符合代码约定。 但是将由您的队友通过惯用方式评估所提交代码的高质量程度。 这是什么意思?

“惯用的”通常是什么意思? (What does “idiomatic” mean in general?)

If we have DuckDuckGo installed, we can pretend our web searches are terminal scripts:

如果我们安装了DuckDuckGo,我们可以假装我们的网络搜索是终端脚本:

The DuckDuckGo search for “idiomatic”
DuckDuckGo搜索“惯用语”

!wikt idiomatic will take us to the Wiktionary page for “idiomatic”, revealing the following definition:

!wikt idiomatic将带我们进入维基词典的“惯用语”页面,其中显示以下定义:

Pertaining or conforming to the natural mode of expression of a language.

保持或符合语言的自然表达方式。

A few links further down is the origin, the Greek “ἴδιος” meaning “private, peculiar, specific, appropriate.”

后面还有几个链接,起源是希腊语“ἴδιος”,意思是“私有,特殊,特定,适当”。

So, in software engineering “idiomatic” means “conforming to the natural mode of expression in a given context”, where that context can be a programming language, like Kotlin or JS, or even a framework like React or RxJava.

因此,在软件工程中,“惯用语”表示“在给定上下文中符合自然表达方式”,其中该上下文可以是诸如Kotlin或JS之类的编程语言,甚至可以是React或RxJava之类的框架。

But like many simple definitions, this can be taken to a harmful extreme. So let’s define some boundaries to prevent misuse.

但是,就像许多简单的定义一样,这可能会带来有害的极端。 因此,让我们定义一些边界以防止滥用。

“成语”不是“时尚”的同义词 (“Idiomatic” is not a synonym of “fashionable”)

Oscar Wilde may have been talking about artistic fashion when he said:

奥斯卡·王尔德(Oscar Wilde)可能在谈论艺术时尚时说:

And, after all, what is a fashion? From the artistic point of view, it is usually a form of ugliness so intolerable that we have to alter it every six months

毕竟,什么是时尚? 从艺术的角度来看,它通常是一种难以忍受的丑陋形式,我们必须每六个月进行一次更改

But he may as well have been talking about frameworks:

但是他也可能一直在谈论框架:

We might arrive at an incorrect conclusion if we assume “the natural mode of expression” in our definition of idiomatic means “the most popular and current form of expression.” We might then go on to say our code is unidiomatic because we are not using the framework-du-jour.

如果在习惯用语定义中假设“自然的表达方式”,即“最流行和最新的表达方式”,我们可能得出错误的结论。 然后,我们可能会继续说我们的代码很简单,因为我们没有使用framework-du-jour。

This is problematic — if we must dismiss code that fails to conform to the latest trend as low quality, we introduce waste as we thrash backwards and forwards when the winds of fashion change. To use another metaphor, a codebase where these changes happen frequently can resemble the lava layers left behind by volcanic eruptions.

这是有问题的—如果我们必须将不符合最新趋势的代码视为低质量而将其丢弃,那么当时尚风向变化时,我们会在前进后退时引入浪费。 使用另一个隐喻,经常发生这些更改的代码库可能类似于火山喷发留下的熔岩层 。

While fashion can and should influence our understanding of the idiomatic, it shouldn’t determine it. In other words, “idiomatic” doesn’t mean “being an edgelord.”

尽管时尚可以并且应该影响我们对惯用语的理解,但是它不应该决定它。 换句话说,“惯用语”并不意味着“成为边缘人” 。

习惯不是骑自行车 (Idiomatic is not bike-shedding)

There should be one-- and preferably only one --obvious way to do it.

The Zen of Python insists there is one good way to do things, but in some languages the cup runneth over with multiple possible approaches to a particular problem. One might imagine that deeply exploring these possibilities in a pull request is required to achieve idiomatic code.

Python的Zen坚信有一种做事的好方法,但是在某些语言中,杯具解决了特定问题的多种可能方法。 可能有人会想,要获得惯用的代码,就需要在请求请求中深入探索这些可能性。

Of course we want to improve the code, but continually proposing alternative approaches that have no advantages over the original is simply wasteful churn and degenerates into bike-shedding — pointless arguments about trivialities. In other words, continually insisting “I would have done it this way” is not a path to the idiomatic.

当然,我们想改进代码,但是不断提出比原始方法没有优势的替代方法只是浪费的搅动,并退化为自行车脱落 -关于琐碎性的毫无意义的争论。 换句话说,不断坚持“ 会以这种方式做到”并不是通俗的做法。

Photo by Alexander Shustov on Unsplash
亚历山大· 舒斯托夫 ( Alexander Shustov)在Unsplash上拍摄的照片

惯用语不只是关注文档 (Idiomatic is not just following the docs)

One then may think that it is enough to follow closely whatever docs are provided for a language or framework to know what is idiomatic. However, this fails to capture the situation where documentation has diverged from best practice for that context.

然后,人们可能会认为,密切关注提供给语言或框架的所有文档以了解什么是惯用语言就足够了。 但是,这无法解决文档在此情况下偏离最佳实践的情况。

This situation is surprisingly common. Often at the time the tools are first written, our understanding is less mature. A community of best practice evolves slowly. For instance, the classes and documentation authored in the early days of Java do not reflect later robust Java practice as reflected in Joshua Bloch’s brilliant Effective Java.

这种情况出奇地普遍。 通常在首次编写工具时,我们的理解还不成熟。 最佳实践社区发展缓慢。 例如,在Java早期编写的类和文档并没有反映约书亚·布洛赫(Joshua Bloch)出色的《 有效的Java》中反映的后来的健壮的Java实践。

The canonical text for writing idiomatic Java
编写惯用Java的规范文本

Famously, the early java.util.Date class contains mutator methods for the year, day, and hour. Thus it contradicts Item 15: Minimize mutability. The later ZonedDateTime corrects this mistake. In this case, even though java.util.Date is part of the Java API, imitating this class in hopes of obtaining idiomatic Java is wrong.

著名的是,早期的java.util.Date类包含用于年,日和小时的mutator方法。 因此,它与第15项:最小化可变性相矛盾。 稍后的ZonedDateTime纠正了此错误。 在这种情况下,即使java.util.Date是Java API的一部分,但是模仿此类以获取惯用Java也是错误的。

那么什么是惯用的? (What then is idiomatic?)

Therefore, the idiomatic lies on a knife-edge: respecting a modern community of practice, but not unduly influenced by its fashions. Respecting the docs, but respecting them enough to discard them when they contradict proven engineering practices. Exploring the possibilities of the language, but not exhausting oneself in debates like: “you can also do it this way in Kotlin…” It is the job of the tech lead to navigate these rocks and shoals.

因此,惯用语是最前沿的:尊重现代实践社区,但又不受其方式的过分影响。 尊重文档,但是要尊重文档,以防它们与可靠的工程实践相抵触而将其丢弃。 探索语言的可能性,但不要在诸如“您也可以在Kotlin中做到这一点……”之类的辩论中精疲力尽。这是技术领导者在这些岩石和浅滩上航行的工作。

Photo by Daniel Pelaez Duque on Unsplash
Daniel Pelaez Duque在Unsplash上拍摄的照片

为什么? (Why?)

If idiomatic code is so difficult to achieve then why even bother?

如果惯用代码很难实现,那为什么还要麻烦呢?

招聘 (Hiring)

If your project respects a well-established idiom, you will have an easier task bringing in new friends to help your endeavour. Experienced developers will have done their time in engineering cargo-cults and will be vigilantly avoiding these. Similarly, those who appreciate nuance and consistency will want to avoid the endless churn of a latest-framework hype shop. If you can demonstrate in your interactions with prospective employees that you have found a middle way between stale old practices and fashion churn, you will attract talent.

如果您的项目尊重成熟的习惯用法,那么您将可以轻松地吸引新朋友来帮助您。 经验丰富的开发人员将在工程货运领域投入大量时间,并会警惕地避免这种情况。 同样,那些欣赏细微差别和一致性的人会希望避免最新框架炒作商店的无休止搅动。 如果您能在与潜在员工的互动中证明您发现过时的做法与时尚的流失之间处于中间位置,您将吸引人才。

入职 (Onboarding)

A project that conforms to an idiom will be easier for a new hire to understand. They will find the right things in the right places, and their early contributions will fit better.

符合习语的项目对于新员工来说更容易理解。 他们将在正确的地方找到正确的事物,并且他们的早期贡献会更合适。

技术债务 (Technical debt)

Unidiomatic code begets unidiomatic code. Ignoring the framework idiom, you warp the supplied components into your own unusual structure. Because you’ve departed from the intention of the framework, you will have to add more and more workarounds as time passes. These workarounds will attract bugs and, yes, technical debt.

单语代码生成单语代码。 忽略框架习惯用法,将提供的组件扭曲为自己的异常结构。 因为您偏离了框架的意图,所以随着时间的流逝,您将不得不添加越来越多的解决方法。 这些变通办法将吸引bug,是的,这是技术债务。

良好的公民意识 (Good citizenship)

If you follow the idiom, external dependencies will match your code and will be easy to integrate. Conversely, parts of your own code can be open-sourced with little modification since they match the expectations of a community of practice.

如果您遵循惯用语,则外部依赖项将与您的代码匹配,并且易于集成。 相反,由于您的部分代码符合实践社区的期望,因此无需进行任何修改就可以开源。

Photo by Rinson Chory on Unsplash
Rinson Chory在Unsplash上的照片

怎么样? (How?)

We’ve already established that developer docs are not enough to obtain the idiomatic. And we all know that random Medium articles can be a mixed bunch. What then is needed?

我们已经确定,开发人员文档不足以获取惯用语。 而且我们都知道,中型随机文章可能是一堆杂乱的文章。 那需要什么呢?

堆栈溢出 (Stack Overflow)

Stack Overflow can be a great source for the idiomatic when we are learning a new framework. But not in our normal way of use. Just Googling when we get stuck and relying on Stack Overflow solutions is a dangerous path, since we learn the bare minimum to deliver our story without understanding the idiomatic.

当我们学习新框架时,堆栈溢出可能是习惯用法的重要来源。 但不是我们通常的使用方式。 当我们陷入困境并依靠Stack Overflow解决方案时,仅谷歌搜索是一条危险的道路,因为我们在不了解惯用语的情况下学到了最少的内容来讲述我们的故事。

A better strategy can be to follow a Stack Overflow tag, and watch how different answers appear and attract votes.

更好的策略是遵循Stack Overflow标签 ,并观察不同的答案如何出现并吸引选票。

A favourited tag on Stack Overflow.
Stack Overflow上的收藏夹标签。

You can even find some framework authors answering questions on their work. Here is an answer to a question about RxJava by library author David Karnok:

您甚至可以找到一些框架作者来回答有关其工作的问题。 这是库作者David Karnok对RxJava的一个问题的答案:

When you get more confident, you can attempt your own answers to questions on the tag. In this way, you are submitting your own understanding to review by your peers. This is a great way to check your understanding.

当您变得更有信心时,您可以尝试自己回答标签上的问题。 通过这种方式,您可以提交自己的理解,以供同行评审。 这是检查您的理解的好方法。

图书 (Books)

Yes, good old-fashioned ink on paper can help here. Unlike so many articles on the internet, books from reputable publishing companies are vetted and edited heavily. If you don’t know where to start, a book can be an excellent guide. It’s often worth shelling out for the book and working through it slowly, rather than rushing in and writing code that does not conform to the idiom.

是的,好的老式墨水可以在这里起到帮助作用。 与互联网上的许多文章不同,著名出版公司的书籍经过严格审查和编辑。 如果您不知道从哪里开始,那本书可能是一个很好的指南。 值得一读,慢慢阅读它,而不是匆匆忙忙编写与该成语不符的代码。

满足学习需求 (Fulfilling the need for learning)

While finding a balance may mean that you don’t use the latest framework, engineers may become frustrated that they are missing out on experience with a technology that will be important for their careers in the future. In this case, it’s important to give an outlet for experimentation. Maintaining 20% time for personal projects is not only good for speed, since 100% utilisation is wasteful, but it’s also a chance for engineers to try the latest toys to keep their skills up-to-date. Alternatively, low-risk, modularised, isolated parts of the codebase may be suitable for experiments with new technologies without departing too far from the idiomatic core.

虽然找到平衡可能意味着您没有使用最新的框架,但是工程师可能会因为缺少对未来的职业至关重要的技术而感到沮丧。 在这种情况下,提供用于实验的出口很重要。 保持20%的时间用于个人项目不仅有益于速度,因为100%的利用率很浪费,而且还为工程师提供了尝试最新玩具以保持其技能最新水平的机会。 或者,代码库的低风险,模块化,隔离的部分可能适合使用新技术进行实验,而又不会偏离惯用语核。

给它点时间 (Give it time)

Unfortunately we are most likely to write unidiomatic code at the beginning of a project with a new framework. This is the “danger zone”: where we’re a competent enough programmer to deliver features, but not familiar enough with the framework to write idiomatic code. This should be kept in mind when framework switches are considered: not only will there be a gap in delivery as developers learn the new framework, but there will also be a gap in quality as the early work does not conform with the idiomatic. This early code may need to be reworked when we later discover the idiom has been misunderstood. Better sooner than later, before it grows legs and takes the project down a path that no-one can follow…

不幸的是,我们最有可能在具有新框架的项目开始时编写单项代码。 这是“危险地带”:我们是一个足够有能力的程序员来提供功能,但对框架编写惯用代码不熟悉。 考虑框架转换时,应牢记这一点:开发人员学习新框架时,不仅交付方面会存在差距,而且由于早期工作不符合惯用方法,因此质量也会存在差距。 当我们后来发现该习惯用法被误解时,可能需要重新编写此早期代码。 事与愿违,事与愿违。

结论 (Conclusion)

One final doubt, “idiomatic” sounds a bit like another word we use for people we don’t like. Yes, it’s cognate with “idiot” from the Greek idiṓtēs meaning “private citizen” or “layman”. So be idio-matic in the sense that your code is private, or peculiar, to a community of practice. But don’t be an “idio-t”: don’t write your own peculiar, private code that no-one outside will understand!

最后一个疑问,“惯用语”听起来有点像我们为不喜欢的人使用的另一个词。 是的,它与希腊语idiṓtēs中的 “白痴”同义 “私人公民”或“外行” 因此,在您的代码对实践社区而言是私有的或特殊的意义上,应是习惯性的。 但是请不要成为“白痴”:不要编写自己的奇特的,私人的代码,外界不会有人理解!

翻译自: https://medium.com/swlh/idiomatic-code-a73f17f0f287

惯用过程模型


http://www.taodudu.cc/news/show-2703919.html

相关文章:

  • 电脑查找电子书资源,speedceo浏览器下载PDF文件阅读分享
  • 基于单片机自制MP3播放器,开源所有电路图,单片机程序
  • JavaScript系列(一):浏览器及内核介绍
  • oracle 电子书大全
  • 电子书专题
  • alook浏览器_Alook浏览器app下载|Alook浏览器安卓版下载 v3.4.1 - 跑跑车安卓网
  • Java 并发专题 :FutureTask 实现预加载数据 在线看电子书、浏览器浏览网页等
  • 安卓电子书格式_纯干货|提升电子书阅读体验的四点感受
  • 使用python爬取电子书_怎样用python3爬取电子书网站所有下载链接
  • 个人常用软件及浏览器插件分享
  • typora 浏览器预览_Gitbook+Typora创建技术文档
  • 使用 Visual Studio 2005中的ASP.NET 移动控件创建电子书浏览器应用程序
  • 【云原生之kubernetes实战】在k8s环境下部署BookBrowser电子书浏览器
  • 云原生之使用Docker部署BookBrowser电子书浏览器
  • 最好用的三款电脑端epub阅读器
  • epub 电子书文件如何使用浏览器打开
  • 机器学习与机器视觉 姜教授ZJU
  • 中职计算机应用专业核心素养的,基于职业发展的中职学生核心素养的研究与培养...
  • 【观察】戴尔科技:未来企业的创新平台,数字中国的坚实底座
  • Python.习题六 字典与集合(上)
  • 赋能数字化生命力,让企业未来焕发青春
  • 故障分析 | 使用--force批量导入数据导致部分数据丢失的问题
  • 对话MVP | 清华博士马福辰:希望成为社区和生态发展强有力的“助攻”
  • UOS主动安全防护计划(UAPP)正式发布,共建信创基础软件平台安全底座
  • 他,1年9个月获清华博士学位,一作身份发27篇SCI,组队击败NASA打破“航天奥林匹克”欧美垄断...
  • ag-grid在Vue项目中的基本使用
  • Dynamic programming 1
  • Dynamic Programming(1)
  • leetCode 357. Count Numbers with Unique Digits | Dynamic Programming | Medium
  • python字典操作首字母与星期的对应_python:第五章 字典与集合作业

惯用过程模型_惯用代码相关推荐

  1. 惯用过程模型_惯用的Ruby:编写漂亮的代码

    惯用过程模型 Ruby is a beautiful programming language. Ruby是一种美丽的编程语言. According to Ruby's official web pa ...

  2. 惯用过程模型_惯用左手的软件用户的请求

    惯用过程模型 在以右手为主的世界中,左撇子人民面临许多挑战. 对于生活在他们压迫之下的10%的人来说,这可能令人发疯. 在20世纪初期,我的左撇子祖父被迫在学校里用右手写字,这使他的笔迹完全难以辨认. ...

  3. 惯用过程模型(process models)

    惯用过程模型 力求达到软件开发的结构和秩序,其活动和任务都是按照过程的特定指引顺序进行的. 一.瀑布模型(经典的生命周期) 提供一个系统的.顺序的软件开发方法: 瀑布模型的变形为 V 模型: 瀑布模型 ...

  4. 采用CSS+JS实现简洁的滑动导航栏_网页代码站(www.webdm.cn)

    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  5. 鼠标指向变成英文导航(CSS)_网页代码站(www.webdm.cn)

    1 <title>鼠标指向变成英文导航(CSS)_网页代码站(www.webdm.cn)</title> 2 <style type="text/css&quo ...

  6. html页面文字随机效果,教你用javascript实现随机标签云效果_附代码

    标签云是一套相关的标签以及与此相应的权重.典型的标签云有30至150个标签.权重影响使用的字体大小或其他视觉效果.同时,直方图或饼图表是最常用的代表约12种不同的权数.因此,标签云彩能代表更多的权,尽 ...

  7. QuickMenu 超强悍菜单_网页代码站(www.webdm.cn)

    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x ...

  8. 很不错的JS+CSS滑动门_网页代码站(www.webdm.cn)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 摘自人民网体育频道的JS卷角翻转方块图片切换_网页代码站(www.webdm.cn)

    1 <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  10. java 摄像头 win7_Win7系统下JAVA摄像头调用_实例代码介绍

    Win7系统下JAVA摄像头调用_实例代码介绍.由于要搞个人脸识别登录(JAVACV),百度谷歌了一下午,找了网上简单的样例代码来试,可是老是调试不过,出现CaptureDeviceManager.g ...

最新文章

  1. java应用部署docker_Docker部署JavaWeb项目实战
  2. Java面向对象编程篇1——类与对象
  3. rto初始化和计算_TCP系列15—重传—5、Linux中RTO的计算
  4. Activiti(6.0)任务管理服务TaskaskService
  5. sencha touch 2中list控件分组排序
  6. 德标螺纹规格对照表_国标德标对照表
  7. micropython(esp8266)SG90舵机控制
  8. Windows10连接局域网打印机
  9. 银屑病与大肠相关机制(调研手稿五)
  10. 飞机实时动态查询接口代码调用服务
  11. android 强制退出程序,Android 强制且彻底的退出app
  12. 2023.02.09 草图大师厨房效果图1skp素材效果图
  13. 外媒:布兰妮歌曲成反恐神器 英海军用其吓退海盗
  14. 计算机基础知识学习题,超全的计算机基础知识题库【精心整理_完全免费】.pdf...
  15. 【STB】未来机顶盒的发展方向
  16. 张帆:人类移民火星最大的问题是缺少适宜的大气
  17. 游戏服务器列表为空,游戏服务器列表为空
  18. adb pull安装的apk
  19. source 命令与./命令
  20. DNS错误,IP通,域名不通,上不去网,解决办法,电脑QQ可以上,浏览器上不去网

热门文章

  1. NodeJS实现HTTP/HTTPS代理 - 刘春龙的博客
  2. Order Siblings by 排序
  3. Java 给PDF文件添加水印
  4. 关于Proximal Methods,近端梯度下降的理解
  5. 正睿20秋季普转提day3
  6. MySQL——事务(Transaction)详解
  7. 为什么现在android UI设计能火起来?
  8. 使用HSqlDB的SQL/JRT功能
  9. java实现树形菜单
  10. 微信小程序正则表达式截取_微信小程序实现简单input正则表达式验证功能示例...