开发过程中大家是不是都遇到过这样的场景:上一个开发者没有写注释!程序代码几经转手,到你这已经是不知本意?今天意外的遇到了这样一个工具,能够在一定程度上帮助我们解决这些问题,它就是Denigma Alpha。
官网地址:https://denigma.app/(上不去时候记得科学一下)
进入官网首页,可以直观的看到它的介绍:
理解不熟悉的编程结构
帮助开发者破解代码之谜
用通俗易懂的英语解释代码。由机器学习提供支持。
绿色的按钮是可以在线进行尝试,并且无需进行注册。再向下进行浏览可以看到官方提供的例子 ,可以看到能够提供支持的语言是比较全面的。
点击显示解释,可以看到官方对这段代码的解释
从例子来看,解释的还是比较易懂和贴切,让我们自己用代码去试试,看看能否一定程度上解决我们工作的痛点。切换到尝试页面,小贴士映入眼帘
- 裁剪代码以帮助 Denigma 专注于重要部分。更少的代码有时可以带来更好的解释。
- 对误导性变量名称进行重命名或将他们替换为“foo”或“bar”。
- 删除多余的评论。
写了一段常用的获取浏览器Cookie的代码,交给AI进行解释
- The code starts by declaring a variable called cookieValue.
- The code then checks if the document.cookie exists and, if it does, splits the cookies into an array of strings with ";".
- For each string in the array, it checks to see if there is a substring that matches cookieName (the name of the cookie).
- If so, it gets the value from that string and returns it.- The first line declares a variable called cookieValue which will hold all of our cookies' values when we check them later on in this function.
- Next comes checking for whether or not document.cookie exists and splitting up any cookies found into an array with ";" as its delimiter character:
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = cookies[i];
- if (cookie == 'name=value') { //This means that we have found a match! }
- else { break; }
–
- The code is used to get the value of a cookie.
从结果来看,确实是通俗易懂了,尤其是最后一句“The code is used to get the value of a cookie.”也对这部分的代码用途下了一个定义,虽然是英文的。写到这,我发现是不是可以用这个直接生成代码注释,稍加修改,方便后来人进行阅读。
最后,网站对隐私方面的问题进行了说明,同时,他还有VSCode的插件版本提供。
这个功能推荐给大家进行使用,希望能够多多少少解决大家的一些问题。
Tips:该写注释的地方还是要写注释的,别成为你当初厌恶的人!