知乎周源微信_每周源代码10-模式被认为有害

知乎周源微信

知乎周源微信

In my new ongoing quest to read source code to be a better developer, I now present the tenth in an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed.

在我不断追求阅读源代码以成为更好的开发人员的任务中,我现在以每周系列的无数个“每周的源代码”形式介绍第十个。 这是我本周喜欢的一些资料。

Our theme this week is "Patterns Considered Harmful" with examples of source doing things we're "not supposed to do."

本周我们的主题是“被认为有害的模式”,其中包含源代码做我们不应该做的事情的示例。

  • ÜberUtils - Strings from Brad Vincent. Don't like System.String? Well, spot-weld a bunch of useful stuff onto it with C# 3.0 Extension Methods. Brad starts to talk about how his utils might be Considered Harmful:

    ÜberUtils- Brad Vincent的弦乐。 不喜欢System.String? 好吧,使用C#3.0扩展方法将一堆有用的东西点焊在上面。 布拉德开始谈论如何将他的工具视为有害:

    "Now I know some people might argue that this is extension method abuse, but look at how much more power my strings have...and anything that helps me code quicker and smarter is not abuse in my book - it's smart coding!" Here's just two of his many useful additions you can hardly consider harmful:

    “现在我知道有人可能会争论这是扩展方法的滥用,但是看看我的字符串有多大的力量……而任何可以帮助我更快,更聪明地编写代码的东西在我的书中都不会滥用-这是聪明的编码!” 这只是他许多有用的补充中的两个,您几乎不会认为是有害的:

            public static string XOR(string input, string strKey)
            {
                if (IsEmpty(input)) return input;
                string strEncoded = string.Empty;
                int nKeyIndex = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    strEncoded += Convert.ToChar(input[i] ^ strKey[nKeyIndex]);
                    nKeyIndex++;
                    if (nKeyIndex == strKey.Length) nKeyIndex = 0;
                }
                return strEncoded;
            }
    
            public static string ToTitleCase(string Input)
            {
                return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Input);
            }
        
  • This item isn't source, but rather a study topic. I saw that Jeff Atwood had a recent post on "Considered Harmful" docs and mentions the seminal GOTO considered harmful paper. Take a free moment and go read the interesting January 2003 thread of discussion between a number of programmers and Linus Torvalds, creator of Linux about Linus's use of GOTO in the Linux Kernel. Why? Here's a teaser from Linus:

    此项不是来源,而是一个研究主题。 我看到Jeff Atwood最近在“ Considered Harmful”文档上发表了一篇文章,并提到了具有开创意义的GOTO被视为有害论文。 花点时间阅读2003年1月许多程序员与Linux的创建者Linus Torvalds之间有趣的讨论话题,内容涉及Linus在Linux内核中使用GOTO。 为什么? 这是莱纳斯的预告片:

    "No, you've been brainwashed by CS people who thought that Niklaus Wirth (Editor: Author of GOTOs Considered Harmful) actually knew what he was talking about. He didn't. He doesn't have a frigging clue."
    > I thought Edsger Dijkstra coined the "gotos are evil" bit in his
    > structured programming push?
    Yeah, he did, but he's dead, and we shouldn't talk ill of the dead. So these days I can only rant about Niklaus Wirth, who took the "structured programming" thing and enforced it in his languages (Pascal and Modula-2), and thus forced his evil on untold generations of poor CS students who had to learn langauges that weren't actually useful for real work. - Linus

    “不,您已经被CS人士洗脑了,他们认为Niklaus Wirth(编辑:GOTOs被认为有害)的作者实际上知道他在说什么。他没有。他没有严格的线索。” >我认为埃德斯·迪克斯特拉(Essger Dijkstra)在他的著作中创造了“疯狂的东西” >结构化编程推? 是的,他做到了,但他已经死了,我们不应该对死者感到不适。 因此,这些天我只能对尼克劳斯·沃斯(Niklaus Wirth)感到愤怒,他采取了“结构化程序设计”并以他的语言(Pascal和Modula-2)加以实施,从而将他的罪恶带给了无数代不得不学习语言的贫困CS学生。对于实际工作实际上并没有用。 -莱纳斯

    "No, you've been brainwashed by CS people who thought that Niklaus Wirth (Editor: Author of GOTOs Considered Harmful) actually knew what he was talking about. He didn't. He doesn't have a frigging clue."
    > I thought Edsger Dijkstra coined the "gotos are evil" bit in his
    > structured programming push?
    Yeah, he did, but he's dead, and we shouldn't talk ill of the dead. So these days I can only rant about Niklaus Wirth, who took the "structured programming" thing and enforced it in his languages (Pascal and Modula-2), and thus forced his evil on untold generations of poor CS students who had to learn langauges that weren't actually useful for real work. - Linus

    “不,您已经被CS人士洗脑了,他们认为Niklaus Wirth(编辑:GOTOs被认为有害)的作者实际上知道他在说什么。他没有。他没有严格的线索。” >我认为埃德斯·迪克斯特拉(Essger Dijkstra)在他的著作中创造了“疯狂的东西” >结构化编程推? 是的,他做到了,但他已经死了,我们不应该对死者感到不适。 因此,这些天我只能对尼克劳斯·沃思(Niklaus Wirth)感到愤慨,他接受了“结构化编程”的东西,并以他的语言(Pascal和Modula-2)加以实施,从而将他的罪恶带给了无数代必须学习语言的贫困CS学生。对于实际工作实际上并没有用。 -莱纳斯

  • Putting everything all on one line. I'll do a separate post on this, but Lee Holmes (author of the Windows PowerShell Cookbook) and I were doing some PowerShell recently, parsing CSV files and did this. Lee doesn't recommend it, but I think it's pretty:

    将所有内容放在一起。 我将对此单独发表一篇文章,但是Lee Holmes (《 Windows PowerShell食谱》的作者)和我最近正在做一些PowerShell,分析CSV文件并执行了此操作。 Lee不推荐这样做,但我认为它很漂亮:

Import-CSv File.csv | Select File,Hits | Group { $_.File -replace '/hanselminutes_(\d+).*','$1' } | Select Name,{ ($_.Group | Measure-Object -Sum Hits).Sum }
  

Feel free to send me links to cool source that you find hasn't been given a good read.

随时向我发送指向很酷的资源的链接,您发现这些链接没有得到很好的阅读。

翻译自: https://www.hanselman.com/blog/the-weekly-source-code-10-patterns-considered-harmful

知乎周源微信

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值