知乎周源微信_每周源代码41-搜索代码,共享代码和阅读代码(和注释)-程序员宅基地

技术标签: python  github  java  linux  搜索引擎  

知乎周源微信

知乎周源微信

I really advocate folks reading as much source as they can because you become a better writer by reading as much as writing. That's the whole point of the Weekly Source Code - reading code to be a better developer.

我真的提倡人们阅读尽可能多的资料,因为您会通过阅读和写作而成为更好的作家。 这就是每周源代码的重点-阅读代码以成为一名更好的开发人员。

Reading code in Open Source projects is a good way to learn, especially if the project has been around a while and been successful, or if you already respect the team of people working on it. Less reliably, you can find snippets of code by searching and sharing code.

在开放源代码项目中阅读代码是一种学习的好方法,特别是如果该项目已经进行了一段时间并且取得了成功,或者您已经尊重从事该项目的团队的话。 不太可靠的是,您可以通过搜索和共享代码来查找代码片段。

搜索代码 (Searching Code)

There's basically three players in the "Code Search Engine" space. These are the ones I bump into all the time. There could be others.

“代码搜索引擎”空间中基本上有三个参与者。 这些都是我一直碰到的。 可能还有其他。

  • Koders.com (where Phil Haack used to work)

    Koders.com (Phil Haack曾在哪里工作)

  • Krugle - MSDN is using Krugle to power the MSDN Code Search Preview that searches MSDN Library, MSDN Code Gallery, and CodePlex.

    克鲁格 -MSDN使用Krugle来驱动MSDN代码搜索预览,该搜索可搜索MSDN库,MSDN代码库和CodePlex。

    • (Note, the Krugle MSDN Code Search is going up and down, as it's in preview and they are actively developing it. If you get a login dialog, that's why. Wait a while.)

      (请注意,由于处于预览状态,Krugle MSDN代码搜索正在上升和下降,并且他们正在积极地开发它。如果出现登录对话框,这就是为什么。请稍等。)

    Krugle - MSDN is using Krugle to power the MSDN Code Search Preview that searches MSDN Library, MSDN Code Gallery, and CodePlex.

    克鲁格 -MSDN使用Krugle来驱动MSDN代码搜索预览,该搜索可搜索MSDN库,MSDN代码库和CodePlex。

  • Google Code Search - If you have lots of code on your site you can make its existence explicit to Google by extending your Sitemap to include the CodeSearch extensions. You can also point them to your Subversion repo if it's publically available.

    谷歌代码搜索 -如果您的网站上有很多代码,则可以通过扩展Sitemap使其包含CodeSearch扩展名,使其对Google明确。 您还可以将他们指向您的Subversion仓库(如果它是公开的)。

  • Codase - Been around forever, and still up and running, but nothing new on their homepage for 4 years? What's up? Weird. I don't count them as a player, but they were first, as far as I can see.

    Codase-一直存在并且仍在运行中,但是四年来首页上没有新内容吗? 这是怎么回事? 奇怪的。 我不认为他们是一名球员,但据我所知,他们是第一名。

Searching the web is 99% free text search, as you know. Every once in a while, I'll use an advanced technique like searching with "filetype:ppt" or with a numeric range like "$1500..$3000" but seriously, that's like once in a 100 searches or less. I challenge you if you say you use it more. Free text searching almost always gets it right, unless you're searching for homonyms or something general.

众所周知,网上搜索是99%的免费文本搜索。 每隔一段时间,我将使用一种高级技术,例如使用“ filetype:ppt”搜索或使用数字范围(例如“ $ 1500 .. $ 3000”)进行搜索,但实际上,这就像每100次搜索或更少一次。 如果您说更多使用它,我会挑战您。 自由文本搜索几乎总能正确解决,除非您要搜索同音异义词或一般名称。

Because free text is so good, while I like the idea of a code search engine and I do use them, I'm not sure if I need anything more than a "code-specific free text search." I personally believe that being really specific in your search query is a really good way to filter your way out of the ONE result you need.

因为自由文本非常好,所以虽然我喜欢代码搜索引擎的想法并且确实使用它们,但是我不确定是否需要除“特定于代码的自由文本搜索”之外的任何东西。 我个人认为,在搜索查询中非常具体是一种从所需的一个结果中过滤出自己的方式的好方法。

Sometimes, however, when searching code you will occasionally want the advanced techniques.

但是,有时在搜索代码时,您偶尔会需要高级技术。

Here's some examples:

这里有一些例子:

If you're looking for a specific implementation of something, like an MD5 hash or a BTree, these search engines can be really useful. They can't tell you anything about quality though.

如果您正在寻找某种特定的实现,例如MD5哈希或BTree,则这些搜索引擎会非常有用。 他们无法告诉您有关质量的任何信息。

共享码 (Sharing Code)

在您的博客上...(On your blog...)

I started using SyntaxHighlighter on my blog for all my code snippets and I'm bummed I didn't start earlier. The best aspect of it is that all my snippets are inside of <pre> tags. That means they're easily indexed and not littered with markup. The syntax highlighting is added on the client side by JavaScript. I use the PreCode plugin in Windows Live Writer and wrote up on I do it on my blog. It's fast becoming THE way to post code inline. I even convinced ScottGu (by doing it for him without asking) to use SyntaxHighlighter when I converted the Nerddinner PDF to HTML.

我开始在自己的博客上使用SyntaxHighlighter编写所有代码段,但我感到很沮丧,因为我没有更早开始。 最好的方面是我所有的代码片段都在<pre>标记内。 这意味着它们很容易被索引并且不会乱成一团。 语法高亮显示是通过JavaScript在客户端添加的。 我在Windows Live Writer中使用PreCode插件,并在我的博客上写了关于它的内容。 它正Swift成为内联发布代码的方式。 当我将Nerddinner PDF转换为HTML时,我什至说服了ScottGu(无需询问即可为他完成此操作)使用SyntaxHighlighter

在网络上或通过IM ... (On the web or via IM...)

You know by know that pasting code in an IM window is a recipe for pain, and misplaced emoticons. I use code-pasting services for this instead.

您知道,在IM窗口中粘贴代码是痛苦和表情符号放置不当的秘诀。 我为此使用代码粘贴服务。

I really like using Josh Goebel's Pastie for sharing code, although he doesn't formally support C# or VB. I'm slowly moving to Gist.Github.com though.

我非常喜欢使用Josh Goebel的Pastie共享代码,尽管他并不正式支持C#或VB。 不过,我正在慢慢迁移到Gist.Github.com

The best social-code-sharing snippet sites are:

最好的社交代码共享代码段站点是:

  • Pastie.org - Favorite of Rubyists and the "original." Couldn't be simpler.

    Pastie.org-Ruby主义者和“原始人”的最爱。 再简单不过了。

  • Pastebin.com - Favorite of IRC users and supports C# and dozens of other languages. Also nice because it supports "expiration" of your code in a day or a month. Nice for email or IM.

    Pastebin.com -IRC用户的最爱,并支持C#和许多其他语言。 也很不错,因为它支持您的代码在一天或一个月内“到期”。 非常适合用于电子邮件或IM。

  • Gist.GitHub.com - Winner for best name, as "Gist" (pronounced "Jist") meaning "Essense" is a great way to express what you're trying to, ahem, express. Just the gist. Supports virtually all languages as well as a "private" option. It also supports versioning, which is unique. This makes sense since Github is a "social source control system." Here's a screencast explaining how this concept can by taking to the next level.

    Gist.GitHub.com-最佳名称的获胜者,“ Gist ”(发音为“ Jist”)意思是“ Essense”,是表达您想要表达的一种好方法。 只是要点。 支持几乎所有语言以及“专用”选项。 它还支持唯一的版本控制。 这是有道理的,因为Github是“社交资源控制系统”。 这是一个截屏视频,解释了如何将这个概念带入新的高度

I've had an interesting conversation or two about making sharing code easier with Jeff. We'll see where that goes.

关于让Jeff更轻松地共享代码,我进行了一两个有趣的谈话。 我们将看到结果。

代码注释 (Code Comments)

Kind of unrelated, but still fun...I think that every developer should have a blog, or at least an outlet for writing. Those that don't, often use Code Comments to express themselves.

有点无关,但仍然很有趣...我认为每个开发人员都应该有一个博客,或者至少要有一个写作渠道。 那些没有的人通常使用代码注释来表达自己。

There was a great post at StackOverflow asking for the "best comment in source code you have ever encountered." This, of course, turned into a list of the worst comments ever found in source code, because that's how programmers work, right? Best == Worst. ;) A lot like the Daily WTF.

StackOverflow上有一篇很棒的帖子,要求“您遇到过的源代码中的最佳注释”。 当然,这变成了源代码中发现的最糟糕的注释的列表,因为这就是程序员的工作方式,对吗? 最好==最差。 ;)非常类似于Daily WTF

You can find some interesting stuff if you use the code search engines to search for stuff that shouldn't ordinarily be in code. This guy searched the Linux Source Code for swear words and graphed them over time.

如果您使用代码搜索引擎搜索通常不应该包含在代码中的内容,则可以找到一些有趣的内容。 这个家伙在Linux源代码中搜索了脏话,并随着时间的流逝对它们进行了图示

Some other non-explicit examples...

其他一些非显式的示例...

  • Found on Koder's searching for Poop

    Koder搜索船尾时发现

    Found on Koder's searching for Poop ; Poor-man's Object-Oriented Programming
    ;                   or
    ;                  POOP
    (module POOP
       (import Utility)

    Koder的船尾搜寻中发现; 穷人的面向对象程序设计; 要么; 船尾(模块POOP (导入实用程序)

  • Found on Krugle searching for Mind-Numbing

    发现在克鲁格搜索精神

    // mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
    439 // OR the 2.0 calling convention (no ptions) - we really love backward compat, don't we?

    //头脑麻木:让调用者使用理智的调用约定(按照javadoc,3个参数), 439 //或2.0调用约定(无配置)-我们真的很喜欢向后兼容,不是吗?

  • Found on Google Search searching for Hate

    Google搜索中搜索“仇恨”

     # God, I hate DTDs.  I really do.  Why this idiot standard still
     # plagues us is beyond me.
      
  • Found on Google Search searching for Horrible

    Google搜索上找到了可怕的内容

     case 'H':
          horrible++;
          break;
      
  • Found on Koders searching for "God Himself"...not really a comment, but interesting.

    在寻找“上帝自己”的科德斯上发现的……不是真正的评论,而是有趣的。

     (c.query_gender().equals("male") ? "He" : (c.query_gender().equals("female") ? "She" : "It"))
              + " is " +
              ((c.query_level() == client.WIZ_GOD) ?
                    "the Almighty God himself\n\rBeware of his wrath if you don't follow his laws!" :
                    ((c.query_level() > client.MORTAL) ? "a powerful immortal" : "a puny mortal")))+ "\n\r"
      
  • Found on Google Search searching for "profoundly bad"

    Google搜索中找到了“严重错误”

    if isinstance(real_child, SilentMock):
       raise TypeError("Replacing a mock with another mock is a profoundly bad idea.\n" +
        "Try re-using mock \"%s\" instead" % (name,))
      
  • Found on Google Search looking for "Pure Evil"

    Google搜索中找到“纯罪恶”

     my $db = delete $access->{db};
              # This is pure evil.
              $db->DESTROY;
      
  • Found on Google Search searching for Poop, but only in Ruby files.

    Google搜索中搜索Poop,但仅在Ruby文件中找到。

    "Stimpy-drool",
    "poopy",
    "poop",
    "craptacular carpet droppings",
      

I'm sure if you search, you'll find lots of great stuff in comments, much more colorful than this. For example, the Greatest Code Comment Ever (Line 107) hit tip to Cam Soper:

我敢肯定,如果您进行搜索,您会在评论中找到很多很棒的东西,比这更丰富多彩。 例如,有史以来最伟大的代码注释(第107行)提示了Cam Soper

uint32 sign=[fh readUInt32BE];
uint32 marker=[fh readUInt32BE];
uint32 chunklen=[fh readUInt32BE];
off_t nextchunk=[fh offsetInFile]+((chunklen+3)&~3);
// At this point, I'd like to take a moment to speak to you about the Adobe PSD format.
// PSD is not a good format. PSD is not even a bad format. Calling it such would be an
// insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having
// worked on this code for several weeks now, my hate for PSD has grown to a raging fire
// that burns with the fierce passion of a million suns.
// If there are two different ways of doing something, PSD will do both, in different
// places. It will then make up three more ways no sane human would think of, and do those
// too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide
// that *these* particular chunks should be aligned to four bytes, and that this alignement
// should *not* be included in the size? Other chunks in other places are either unaligned,
// or aligned with the alignment included in the size. Here, though, it is not included.
// Either one of these three behaviours would be fine. A sane format would pick one. PSD,
// of course, uses all three, and more.
// Trying to get data out of a PSD file is like trying to find something in the attic of
// your eccentric old uncle who died in a freak freshwater shark attack on his 58th
// birthday. That last detail may not be important for the purposes of the simile, but
// at this point I am spending a lot of time imagining amusing fates for the people
// responsible for this Rube Goldberg of a file format.
// Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this,
// I had to apply to them for permission to apply to them to have them consider sending
// me this sacred tome. This would have involved faxing them a copy of some document or
// other, probably signed in blood. I can only imagine that they make this process so
// difficult because they are intensely ashamed of having created this abomination. I
// was naturally not gullible enough to go through with this procedure, but if I had done
// so, I would have printed out every single page of the spec, and set them all on fire.
// Were it within my power, I would gather every single copy of those specs, and launch
// them on a spaceship directly into the sun.
//
// PSD is not my favourite file format.

Enjoy your search and read more code!

享受您的搜索并阅读更多代码!

翻译自: https://www.hanselman.com/blog/the-weekly-source-code-41-searching-code-sharing-code-and-reading-code-and-comments

知乎周源微信

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cunfuxiao7305/article/details/109082867

智能推荐

艾美捷Epigentek DNA样品的超声能量处理方案-程序员宅基地

文章浏览阅读15次。空化气泡的大小和相应的空化能量可以通过调整完全标度的振幅水平来操纵和数字控制。通过强调超声技术中的更高通量处理和防止样品污染,Epigentek EpiSonic超声仪可以轻松集成到现有的实验室工作流程中,并且特别适合与表观遗传学和下一代应用的兼容性。Epigentek的EpiSonic已成为一种有效的剪切设备,用于在染色质免疫沉淀技术中制备染色质样品,以及用于下一代测序平台的DNA文库制备。该装置的经济性及其多重样品的能力使其成为每个实验室拥有的经济高效的工具,而不仅仅是核心设施。

11、合宙Air模块Luat开发:通过http协议获取天气信息_合宙获取天气-程序员宅基地

文章浏览阅读4.2k次,点赞3次,收藏14次。目录点击这里查看所有博文  本系列博客,理论上适用于合宙的Air202、Air268、Air720x、Air720S以及最近发布的Air720U(我还没拿到样机,应该也能支持)。  先不管支不支持,如果你用的是合宙的模块,那都不妨一试,也许会有意外收获。  我使用的是Air720SL模块,如果在其他模块上不能用,那就是底层core固件暂时还没有支持,这里的代码是没有问题的。例程仅供参考!..._合宙获取天气

EasyMesh和802.11s对比-程序员宅基地

文章浏览阅读7.7k次,点赞2次,收藏41次。1 关于meshMesh的意思是网状物,以前读书的时候,在自动化领域有传感器自组网,zigbee、蓝牙等无线方式实现各个网络节点消息通信,通过各种算法,保证整个网络中所有节点信息能经过多跳最终传递到目的地,用于数据采集。十多年过去了,在无线路由器领域又把这个mesh概念翻炒了一下,各大品牌都推出了mesh路由器,大多数是3个为一组,实现在面积较大的住宅里,增强wifi覆盖范围,智能在多热点之间切换,提升上网体验。因为节点基本上在3个以内,所以mesh的算法不必太复杂,组网形式比较简单。各厂家都自定义了组_802.11s

线程的几种状态_线程状态-程序员宅基地

文章浏览阅读5.2k次,点赞8次,收藏21次。线程的几种状态_线程状态

stack的常见用法详解_stack函数用法-程序员宅基地

文章浏览阅读4.2w次,点赞124次,收藏688次。stack翻译为栈,是STL中实现的一个后进先出的容器。要使用 stack,应先添加头文件include<stack>,并在头文件下面加上“ using namespacestd;"1. stack的定义其定义的写法和其他STL容器相同, typename可以任意基本数据类型或容器:stack<typename> name;2. stack容器内元素的访问..._stack函数用法

2018.11.16javascript课上随笔(DOM)-程序员宅基地

文章浏览阅读71次。<li> <a href = "“#”>-</a></li><li>子节点:文本节点(回车),元素节点,文本节点。不同节点树:  节点(各种类型节点)childNodes:返回子节点的所有子节点的集合,包含任何类型、元素节点(元素类型节点):child。node.getAttribute(at...

随便推点

layui.extend的一点知识 第三方模块base 路径_layui extend-程序员宅基地

文章浏览阅读3.4k次。//config的设置是全局的layui.config({ base: '/res/js/' //假设这是你存放拓展模块的根目录}).extend({ //设定模块别名 mymod: 'mymod' //如果 mymod.js 是在根目录,也可以不用设定别名 ,mod1: 'admin/mod1' //相对于上述 base 目录的子目录}); //你也可以忽略 base 设定的根目录,直接在 extend 指定路径(主要:该功能为 layui 2.2.0 新增)layui.exten_layui extend

5G云计算:5G网络的分层思想_5g分层结构-程序员宅基地

文章浏览阅读3.2k次,点赞6次,收藏13次。分层思想分层思想分层思想-1分层思想-2分层思想-2OSI七层参考模型物理层和数据链路层物理层数据链路层网络层传输层会话层表示层应用层OSI七层模型的分层结构TCP/IP协议族的组成数据封装过程数据解封装过程PDU设备与层的对应关系各层通信分层思想分层思想-1在现实生活种,我们在喝牛奶时,未必了解他的生产过程,我们所接触的或许只是从超时购买牛奶。分层思想-2平时我们在网络时也未必知道数据的传输过程我们的所考虑的就是可以传就可以,不用管他时怎么传输的分层思想-2将复杂的流程分解为几个功能_5g分层结构

基于二值化图像转GCode的单向扫描实现-程序员宅基地

文章浏览阅读191次。在激光雕刻中,单向扫描(Unidirectional Scanning)是一种雕刻技术,其中激光头只在一个方向上移动,而不是来回移动。这种移动方式主要应用于通过激光逐行扫描图像表面的过程。具体而言,单向扫描的过程通常包括以下步骤:横向移动(X轴): 激光头沿X轴方向移动到图像的一侧。纵向移动(Y轴): 激光头沿Y轴方向开始逐行移动,刻蚀图像表面。这一过程是单向的,即在每一行上激光头只在一个方向上移动。返回横向移动: 一旦一行完成,激光头返回到图像的一侧,准备进行下一行的刻蚀。

算法随笔:强连通分量-程序员宅基地

文章浏览阅读577次。强连通:在有向图G中,如果两个点u和v是互相可达的,即从u出发可以到达v,从v出发也可以到达u,则成u和v是强连通的。强连通分量:如果一个有向图G不是强连通图,那么可以把它分成躲个子图,其中每个子图的内部是强连通的,而且这些子图已经扩展到最大,不能与子图外的任一点强连通,成这样的一个“极大连通”子图是G的一个强连通分量(SCC)。强连通分量的一些性质:(1)一个点必须有出度和入度,才会与其他点强连通。(2)把一个SCC从图中挖掉,不影响其他点的强连通性。_强连通分量

Django(2)|templates模板+静态资源目录static_django templates-程序员宅基地

文章浏览阅读3.9k次,点赞5次,收藏18次。在做web开发,要给用户提供一个页面,页面包括静态页面+数据,两者结合起来就是完整的可视化的页面,django的模板系统支持这种功能,首先需要写一个静态页面,然后通过python的模板语法将数据渲染上去。1.创建一个templates目录2.配置。_django templates

linux下的GPU测试软件,Ubuntu等Linux系统显卡性能测试软件 Unigine 3D-程序员宅基地

文章浏览阅读1.7k次。Ubuntu等Linux系统显卡性能测试软件 Unigine 3DUbuntu Intel显卡驱动安装,请参考:ATI和NVIDIA显卡请在软件和更新中的附加驱动中安装。 这里推荐: 运行后,F9就可评分,已测试显卡有K2000 2GB 900+分,GT330m 1GB 340+ 分,GT620 1GB 340+ 分,四代i5核显340+ 分,还有写博客的小盒子100+ 分。relaybot@re...

推荐文章

热门文章

相关标签