Cocycles is a new code search service that enables code to be found by functionality. In this article, Cocycles team member Jonathan explains the idea behind this approach to code searching.

Cocycles是一项新的代码搜索服务,可通过功能查找代码。 在本文中,Cocycles团队成员Jonathan解释了这种代码搜索方法背后的想法。



We’re all familiar with it: that moment when you’re forced to abandon your code editor, interrupt your workflow and open your browser to search for a code snippet or explanation of how to code something. It can be a time consuming and frustrating process.

我们都熟悉它:那一刻,当您被迫放弃代码编辑器,中断工作流程并打开浏览器以搜索代码片段或如何编写代码的说明时。 这可能是一个耗时且令人沮丧的过程。

For years, I’ve found myself mostly turning to familiar search engines like Google and Bing, submitting queries like “JavaScript parsing HTTP headers” and praying that someone, somewhere, has asked about this, and that someone else has provided a useful answer and even a working snippet.

多年以来,我发现自己主要转向熟悉的搜索引擎,例如Google和Bing,提交“ JavaScript解析HTTP标头”之类的查询,并祈祷某个地方有人问了这个问题,并且其他人已经提供了有用的答案,甚至是一个工作片段。

Google and Bing can understand English pretty well, but they can’t read code. Sometimes luck’s on our side, and sometimes it’s not.

Google和Bing可以很好地理解英语,但是他们看不懂代码。 有时候运气就在我们这边,有时候却不是。

However, it doesn’t have to be like this. In April 2016, GitHub reported that it holds over 35 million repositories. That’s a whole lot of code lines! I’m willing to bet that most of what developers search for every single day already lies somewhere around the open-source web. Up till now, the problem has been that we can’t easily find it. This is why we built Cocycles, a search engine for code.

但是,不必一定是这样。 2016年4月,GitHub 报告称其拥有超过3500万个存储库。 这是很多代码行! 我敢打赌,开发人员每天搜索的大多数内容已经位于开源网站周围。 到目前为止,问题在于我们无法轻松找到它。 这就是为什么我们构建了Cocycles ( 代码搜索引擎)的原因。

In this article, I’ll introduce this new tool, explaining how it works and how to use it.

在本文中,我将介绍这个新工具,并解释其工作方式和使用方法。

Cocycles:功能代码搜索引擎 (Cocycles: a Functional Code Search Engine)

More than anything else, Cocycles is a method of organizing knowledge and making it accessible. Cocycles does something fairly easy to describe, but incredibly challenging to do: it aspires to be able to find every piece of code in the open-source domain, catalogue it, and make it easy to find and use. So, it needs to do three things:

最重要的是,Cocycles是一种组织知识并使之可访问的方法。 Cocycles所做的事情相当容易描述,但是却具有巨大的挑战:它渴望能够在开源域中找到每段代码,对其进行分类,并使其易于查找和使用。 因此,它需要做三件事:

  1. know what every piece of code actually does知道每段代码实际上是做什么的
  2. understand what is it you are actually looking for了解您实际上在寻找什么
  3. match the two, sit tight and wait for the “Thank you” flowers.匹配两个,坐紧,等待“谢谢”花。

In reality, this is an ongoing process, in which community cooperation is a major key.

实际上,这是一个持续的过程,社区合作是主要的关键。

Cocycles is a technology that learns to understand what each piece of code does. It looks not only at the code’s signature, text or documentation, but also — and primarily — at its functionality. Cocycles understands code and what it does. It’s actually able to tell which pieces of code are best for swapping two elements in a given array, or creating a random string, and is able to identify them and even understand the connections between different pieces.

Cocycles是一种学习了解每段代码的功能的技术。 它不仅查看代码的签名,文本或文档,而且(主要)查看其功能 。 Cocycles了解代码及其功能。 实际上,它能够分辨出哪段代码最适合交换给定数组中的两个元素或创建随机字符串,并且能够识别它们甚至理解不同段之间的联系。

It currently supports JavaScript, and additional languages are planned later in 2016.

它目前支持JavaScript,其他语言计划在2016年晚些时候推出。

搜索普通英语代码 (Searching for Code in Plain English)

Cocycles is able to understand English. It’s also designed to understand developers. To achieve this, Cocycles uses natural language processing algorithms to understand the description of the code you need and find what you’re looking for.

摩托车能够听懂英语。 它还旨在了解开发人员 。 为此,Cocycles使用自然语言处理算法来了解所需代码的描述并找到所需的内容。

So when searching via Cocycles, it’s best to describe what you need in the same way you’d search for it in a search engine like Google, Bing and others. Unlike these, however, Cocycles is able to understand code, and therefore will translate your query into the desired code functionality.

因此,通过Cocycles进行搜索时,最好以与在Google,Bing等搜索引擎中搜索所需的方式相同的方式描述您的需求。 但是,与这些不同,Cocycles能够理解代码,因此会将查询转换为所需的代码功能。

For example, if you need to swap two elements in a given array, you should simply search for “swap elements”. If you need to parse the headers of an HTTP request, search for “parse http headers”. And when looking for a function to create a random string, try searching for “create random str”.

例如,如果需要交换给定数组中的两个元素,则只需搜索“交换元素”。 如果您需要解析HTTP请求的标头,请搜索“解析http标头”。 并且在寻找创建随机字符串的函数时,请尝试搜索“ create random str”。

Thanks to semantic capabilities, Cocycles is also able to understand that “String” is the same as “Str” and “Create” might mean “Generate”. Furthermore, you can try looking for something broader, such as “timer”, and find useful timer classes with different methods.

借助语义功能,Cocycles还能够理解“字符串”与“ Str”相同,而“创建”可能意味着“生成”。 此外,您可以尝试寻找更广泛的内容,例如“ timer”,并使用不同的方法找到有用的计时器类。

Another neat feature is called “Cocycles Immediate”. When Cocycles knows exactly what it is you’re looking for, it will provide an immediate description of the desired result with important key info — as seen in the image below, which shows a search for “angular isStr”:

另一个简洁的功能称为“立即Cocycles”。 当Cocycles确切知道您要查找的内容时,它将通过重要的键信息立即提供所需结果的描述-如下图所示,其中显示了对“ angular isStr”的搜索:

学习代码的工作原理 (Learning How the Code Works)

When opening a result unit, Cocycles takes you in to an IDE-like interactive exploration mode. It allows you not only to view the full source implementation itself, but also interact with the code. Hovering over certain parts will highlight matching parts; clicking on a certain variable or function will move you to its definition; and soon it will be possible to jump between files and even entire projects. This takes Cocycles out of the world of “snippets” and into the world of learning, exploring and making code useful. This last view will adapt to fit various types of results. For example, if the selected result is a class, Cocycles will list its methods and will offer a quick browse between them.

打开结果单元时,Cocycles将带您进入类似于IDE的交互式探索模式。 它不仅使您可以查看完整的源代码实现本身,还可以与代码进行交互。 将鼠标悬停在某些部分上会突出显示匹配的部分; 单击某个变量或函数将使您转到其定义; 很快就有可能在文件甚至整个项目之间跳转。 这使Cocycles走出了“片段”的世界,进入了学习,探索并使代码有用的世界。 最后一个视图将适合各种类型的结果。 例如,如果选定的结果是一个类,那么Cocycles将列出其方法并提供它们之间的快速浏览。

When available, Cocycles will also provide the full original documentation for every code unit found. Even cooler, it will find real usage examples from which you can learn how to use the code you find and how other people did so. If needed, you can also view the code’s source in GitHub directly.

可用时,Cocycles还将为找到的每个代码单元提供完整的原始文档。 更酷的是,它将找到真实的用法示例,您可以从中学习如何使用找到的代码以及其他人是如何使用的。 如果需要,您还可以直接在GitHub中查看代码的源代码。

展望未来 (Looking Into the Future)

Cocycles isn’t perfect. The technological challenges are massive. It’s a process, and an ongoing endeavor to organize all the code in the world and make it accessible.

摩托车并不是完美的。 技术挑战是巨大的。 这是一个过程,也是一项持续的工作,目的是组织世界上的所有代码并使其可访问。

It’s being built with help from the community, and by advice from some of the web community’s leading lights. It’s free, and built to last.

它是在社区的帮助下以及Web社区中一些领先者的建议下构建的。 它是免费的,并且经久耐用。

We also understand that the future lies in providing even more value to people — by harnessing more of the potential hidden in the open-source world.

我们还理解,未来在于通过利用更多隐藏在开源世界中的潜力为人们提供更多价值。

For example, we should be able to identify in real time when a developer is making a mistake, or is writing less than optimal code. We need to be able to offer an instant solution based on open-source code. We’re currently working on something that will offer all of this and more. We have a newsletter you can subscribe to, and a Twitter feed, if you want to be notified of updates.

例如,我们应该能够实时识别开发人员犯错或编写的代码不够理想的时间。 我们需要能够提供基于开源代码的即时解决方案。 我们目前正在研究可以提供所有更多功能的产品。 如果您想收到更新通知,可以订阅我们的时事通讯和Twitter feed 。

It’s yours to use, and any kind of feedback, ideas or thoughts would be gratefully welcomed. Visit cocycles.com and tell us what you think!

它是您的使用,任何反馈,想法或想法都将受到欢迎。 访问cocycles.com ,告诉我们您的想法!

翻译自: https://www.sitepoint.com/find-javascript-code-snippets-by-functionality-with-cocycles/

使用Cocycles按功能查找JavaScript代码段相关推荐

  1. C# 代码中调用 Javascript 代码段以提高应用程序的配置灵活性(使用 Javascript .NET 与 Jint)...

    一般来说,我们需要在开发应用软件的配置文件中,添加一些参数,用于后续用户根据实际情况,自行调整. 配置参数,可以放在配置文件中.环境变量中.或数据库表中(如果使用了数据库的话).通常,配置数据,以 k ...

  2. 10个棘手的用于面试的JavaScript代码段

    点击关注下方卡片关注我???????? 回复"面试"查阅 面试精选文章 求职面试并非完全可以预测,但我们仍然经常看到常见的棘手问题.让我们看看其中的10个,经常出现在面试中的. 1 ...

  3. 你现在可以使用的10个JavaScript代码段

    毫无疑问,JavaScript是Web开发中最流行的编程语言之一.无论您使用的是React,Vue还是Angular,都只是JavaScript.围绕JS展开了广泛而重要的生态系统,提供了无数的框架和 ...

  4. Javascript代码段记录: utils

    浏览器检查 /*** @property browser check browser agent* @property {Boolean} browser.webkit Webkit 浏览器检查* @ ...

  5. 【备忘录】JavaScript代码段儿

    日期格式化:  getDate: function(){ var now = new Date();return now.getFullYear() + preZero(now.getMonth() ...

  6. JavaScript代码块(代码段)

    JavaScript代码块(代码段) 代码块就是使用 <script> 标签包含的 JavaScript 代码段. 示例1 在下面示例中,使用了两个 <script> 标签分别 ...

  7. 懒惰的人有福了——VS代码段编辑器SnippetEditor 可对vs所有代码段进行编辑和创建包括C#\J#\VB.NET等...

    这个版本不仅支持VS2005.2008而且还支持VS2010的代码段编辑 启动画面虽然是写着VB 代码段 但是仍旧支持C#与其它语言的代码段包括J#\VB.NET\xml\html等的创建.编辑修改等 ...

  8. 15个简易高效的代码段

    1.不循环地重复一个字符串 此 JavaScript 代码段将展示如何在不使用任何循环的情况下重复字符串.我们将通过JavaScript 中的repeat()方法来构建一个数字,该数字将作为你需要的数 ...

  9. 购物车的收货地址js php,Javascript实现购物车功能的详细代码

    我们肯定都很熟悉商品购物车这一功能,每当我们在某宝某东上购买商品的时候,看中了哪件商品,就会加入购物车中,最后结算.购物车这一功能,方便消费者对商品进行管理,可以添加商品,删除商品,选中购物车中的某一 ...

最新文章

  1. iPad mini时隔四年更新,搭载A12芯片,起售价2999
  2. Unity3D Adam Demo的学习与研究
  3. pycharm开发python时出现控制台显示中文乱码
  4. 交大网院计算机第五次作业答案,交大网院计算机第三次作业分析.docx
  5. (原創) 如何对array或struct做初始化? (memset()) (C/C++) (C)
  6. java诺基亚nba,HMD 签约NBA 新秀劳里·马尔卡宁 为诺基亚手机品牌大使
  7. X86 register
  8. .net 启动mysql数据库连接,ASP.NET实战002:MySQL数据库连接
  9. laravel sql多个orWhere条件时数据查询错误
  10. 教你成为全栈工程师(Full Stack Developer) 一-各显神通总结八大类编程语言的区别...
  11. (操作系统)系统调用
  12. MongoDB与Tokyo Tyrant性能比较(2):并发写入操作
  13. 手机电脑投屏软件_手机投屏电脑,电脑控制手机,推荐这款良心免费的软件
  14. java即时通讯源码 IM即时通讯源码 IM源码 安卓苹果原生APP源码 带音视频无标题】
  15. Find the maximum and minimum value in tensor array
  16. Python——requests模块详解
  17. 人到五十岁以后做什么生意最好?
  18. 银行提供了整数整存整取定期储蓄业务,其存期分为一年,两年,三年,五年,到期凭存单支取本息,编写一个程序,输入存入的本金数目,计算假设存一年,两年,三年,五年,到期取款时,银行应支付多少本息分别是多少
  19. 最大公因数等于 K 的子数组数目求解全过程
  20. 如何搭建web服务器

热门文章

  1. 指数分布族(Exponential Family)相关公式推导及在变分推断中的应用
  2. 带你了解物联网控制APP的几种模式
  3. UE4地编基础-入门
  4. 使用 Python 模块 bluepy 玩转 BLE
  5. Unity 使用柏林噪声(Perlin Noise)生成网格地图
  6. 川农《水力学(本科)》21年12月作业考核
  7. 【数据分析与挖掘系列】基于基站定位数据的商圈分析(全数据集和代码)
  8. 软件工程 张秋余等著 第八章课后习题部分答案
  9. C语言酒店入住管理系统课设
  10. 用橡皮泥做了个青龙偃月刀