Any problem in computer science can be solved with one additional layer of indirection. But that usually will create another problem. - David Wheeler

计算机科学中的任何问题都可以通过另外一层间接解决。 但这通常会带来另一个问题。 -大卫·惠勒

Any sufficiently advanced technology is indistinguishable from magic. - Arthur C. Clarke.

任何足够先进的技术都无法与魔术区分开。 -亚瑟·克拉克(Arthur C. Clarke)。

These are two classic truisms. Recently while staring at some code trying to figure out what the heck was going on, I realized the obvious.

这是两个经典的道理。 最近,当我盯着一些代码试图弄清楚到底发生了什么时,我意识到了显而易见的事实。

One additional layer of indirection is indistinguishable from magic. - Scott Hanselman, this morning in a rare moment of clarity while hopped up on Diet Coke.

间接的另一层与魔术是无法区分的。 -斯科特·汉塞尔曼(Scott Hanselman),今天早晨,在罕见的瞬间,当他跳上健怡可乐时。

In recent talk at Mix on ASP.NET MVC (there's video there also) I mentioned that a certain line of code was magic:

在最近关于ASP.NET MVC的Mix上的演讲中(也有视频),我提到过某些代码是不可思议的

      public void Update(int id){try{viewData.Product = db.Products.Single(p => p.ProductID == id);
            //MAGIC STARTS HERE            Binding.UpdateFrom(viewData.Product, Request.Form);            //END MAGIC
            db.SubmitChanges();RedirectToAction("List");}catch (InvalidOperationException err){viewData.ErrorMessage = err.Message;RenderView("edit", viewData);}}

Why did it feel like magic? A few reasons.

为什么感觉像魔术? 有几个原因。

  • It does a LOT. It takes all the values from a Form POST and lines them up with the public Properties in an object instance. This is done in the context of a Form POST to a Controller Action in ASP.NET MVC.

    它做很多。 它从Form POST中获取所有值,并将它们与对象实例中的公共Properties对齐。 这是在ASP.NET MVC中的表单POST到Controller Action的上下文中完成的。

  • It isn't named well. Update is a verb, so that's cool, but the "From" makes me feel inverted.

    它的名字不好。 更新是一个动词,很酷,但是“发件人”使我感到倒立。

  • The parameters are (possibly) in the wrong order. Given the name, I'd have expected UpdateFrom(Form, Product), but even then it doesn't feel write.

    参数(可能)顺序错误。 给定名称,我期望UpdateFrom(Form,Product),但是即使那样它也不会写。

All of this adds up to an impedance mismatch, IMHO. It's too confusing and I'm just a caveman (video). As such, I declare it as black magic.

所有这些加起来导致阻抗失配,恕我直言。 太混乱了,我只是一个穴居人(视频)。 因此,我将其声明为黑魔法。

This magic was brought up to the team (I think I remember hitting someone, there may have been some swearing. ;) ) and Rob changed it in a number of good ways.

这种魔力被带到了团队中(我想我还记得打过某人,可能有一些咒骂。;)), Rob以许多好的方式对其进行了更改。

  • It's discoverable. He hung it off of the Request where you can actually stumble upon in.

    这是可发现的。 他将其挂在“请求”上,您实际上可以在其中找到它。

  • It's named directly. Rather than the inverted UpdateFrom, it is now DeserializeTo which reads better left to right as in Request.DeserializeTo(product).

    它直接命名。 而不是反向的UpdateFrom,它现在是DeserializeTo,它在Request.DeserializeTo(product)中从左到右的读取效果更好。

  • It's simpler. Because it's hanging off the object that was previously a parameter, it has one less parameter and again, reads nicely left to right.

    更简单。 因为它与先前作为参数的对象无关,所以它少了一个参数,并且从左到右读取效果很好。

//FEELS LESS MAGICAL Request.DeserializeTo(viewData.Product);

Jeff Moser's (see I told you I'd mention him twice) fine post talks about how cognitive "chunks" that represent solutions to problems can be more easily stored in our brains if they flow. Scott Bellware has called this concept "solubility." Code that uses frameworks with some balanced between focus on aesthetic and usability is more easily grokked.

杰夫·摩泽( Jeff Moser )(我告诉过你我曾两次提到过他)的精彩文章谈到,代表问题解决方案的认知“块”如何在我们的大脑中流淌更容易地存储。 Scott Bellware将此概念称为“溶解度” 。 使用在美学和可用性之间保持某种平衡的框架的代码更容易被理解。

I don't know if this is the final method, it's probably not, but I really enjoy discussions like this that aim to make things less like magic and more obvious and discoverable.

我不知道这是否是最终的方法,可能不是,但是我真的很喜欢这样的讨论,其目的是使事情变得不那么魔术,而变得更加明显和可发现。

翻译自: https://www.hanselman.com/blog/im-just-a-caveman-the-hanselman-corollary-to-the-clarkewheeler-laws

我只是穴居人-克拉克/惠勒定律的汉塞尔曼推论相关推荐

  1. 20世纪物理学最后一位巨人、黑洞命名者、费曼老师惠勒:万物源自比特

    能量越多,比特翻转得越快.土.气.火.水,归根究底,都是由能量构成,但其不同形态却由信息决定.无论做任何事都需要能量,而要明确说明做了什么也需要信息. --塞思·劳埃德(2006) 量子力学虽然历史不 ...

  2. 惠勒延迟选择实验_肯·惠勒(Ken Wheeler)与开源软件的兴衰

    惠勒延迟选择实验 In this episode of the Versioning Show, Tim and David are joined by Ken Wheeler, a Formidab ...

  3. 1496_关于约翰惠勒与费曼

    全部学习汇总:GreyZhang/g_how_to_study: A key point in my own study is how to study well! (github.com) 我看了一 ...

  4. 惠勒延迟选择实验(转)

    亚存注:这个实验非常有意思,颠覆了我们日常的观念,否定了客观实在性,对唯物主义是一次比较大的打击.物理学到后面越来越接近神学 激光脉冲源(laser pulse source)发出光子,到达半镀银的反 ...

  5. C#练习题答案: 巴路士惠勒改造【难度:4级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

    巴路士惠勒改造[难度:4级]: 答案1: using System; using System.Collections.Generic; using System.Linq;public class ...

  6. csharp高级练习题:巴路士惠勒改造【难度:4级】--景越C#经典编程题库,不同难度C#练习题,适合自学C#的新手进阶训练

    csharp高级练习题:巴路士惠勒改造[难度:4级]: 动机 当压缩符号序列时,使许多相等的符号彼此跟随是有用的,因为它们可以用行程编码进行编码.例如,"aaaabbbbbbbbbbbccc ...

  7. 精明理财人的赚钱八大定律

    赚钱第一定律:你要做羊,还是做狼? 永远是10%的人赚钱,90%的人赔钱,这是市场的铁律,不论是股市,还是开公司.办企业,都不会改变. 如果人人都赚钱,那么谁赔钱,钱从何处来? 天下人不可能都是富人, ...

  8. 焦虑的互联网人及35岁定律

    一.35岁定律 好像现在整个互联网行业都在贩卖焦虑,从之前的30岁淘汰,到现在的35岁,到最新的39.9岁,你会发现,年龄趋势怎么在上升啊,对了兄弟,就是那一批人嘛,他们每年涨一岁,可不就是焦虑年龄越 ...

  9. [韓劇精華]韓國人的128條定律

    http://www.tianya.cn/new/Publicforum/Content.asp?idWriter=0&Key=0&strItem=funinfo&idArti ...

最新文章

  1. 在ie7中overflow: hidden失效问题哦及解决方案
  2. delegate委托
  3. Android 中ContentProvider和Uri详解
  4. (LeetCode 92)Reverse Linked List II
  5. CentOS中使用Docker来部署Tomcat
  6. 谈大学教育2018-01-12
  7. 半关闭函数:高级版的 close 函数
  8. 牛客 -- leetcode -- evaluate-reverse-polish-notation
  9. PRML(2)--绪论(下)模型选择、纬度灾难、决策论、信息论
  10. java运行环境_Windows系统java运行环境配置 | 吴文辉博客
  11. c++101rule
  12. POJ1256 Anagram(回溯法)
  13. Spring配置中bean的id和name属性区分
  14. c/c++入门教程 - 2.4.6 继承、公共继承、保护继承、私有继承、virtual虚继承(概念、语法、方式、构造和析构顺序、同名成员处理、继承同名静态成员处理、多继承语法、菱形继承、钻石继承)
  15. 算法笔记_167:算法提高 矩阵翻转(Java)
  16. linux利用位置参数数组,Shell编程1_变量、参数和数组
  17. [bug解决] TensorFlow安装错误:ERROR Cannot uninstall ‘wrapt‘
  18. c语言d6d0,【单选题】汉字中的十六进制的机内码是D6D0H,那么它的国标码是(·) x2012 A. 5650H B. 5651H C. 5653H D. 5654H...
  19. 搭建用户增长体系,这5个方法告诉你怎么做
  20. 【php-fpm】重启、启动、关闭

热门文章

  1. Linux下c语言文本方式文件读取
  2. 微软虐我千百遍——记一次比较漫长的TFS数据库迁移
  3. 欧特克加入制裁,科技真的无国界吗?
  4. 虚拟机容器嵌合体—— Kata Containers正式走出实验室
  5. Mac教程:如何开启任何来源选项?
  6. 逐梦高新,智赢未来,第四届顺德高新区运动嘉年华正式拉开序幕
  7. 获取img的src 或者给img赋值
  8. AlertPay 简介
  9. 另眼看嘀嘀:打车类应用背后的政策风险
  10. 秒的换算:皮秒、纳秒、微秒、毫秒