Code learning tools

news2024/11/27 18:48:37

这里写目录标题

  • 1. Code learning tools
    • 1.1. Chrome Sourcegraph plugin
    • 1.2. Print statements never go out of style
    • 1.3. When in doubt, PANIC
    • 1.4. Visit the past with GitHub blame

1. Code learning tools

I know what you are thinking. Brad, you are new to Kube and Go and you quickly learned all this. You must be a genius! Well, sadly I have a list of Twitter followers who would be more than happy to jump in with solid concrete evidence that would easily refute that statement. But through the help of others I have identified several tools and techniques that can really help accelerate your ability to learn the Kubernetes source code. In this section I describe my favorite techniques: use of the Chrome Sourcegraph plugin, properly formatted print statements, the use of a Go panic to get desperately needed stack traces, and GitHub blame to travel back in time.

1.1. Chrome Sourcegraph plugin

Morgan Bauer introduced me to one of the coolest tools I have seen for learning Kubernetes code. The Chrome Sourcegraph plugin provides several advanced IDE features that make it dramatically easier to understand Kubernetes Go code when browsing GitHub repositories. Here is an example of how it can help. When I first started looking at Kubernetes code I found the following code snippet absolutely depressing to parse through and understand. It had a ton of functions and it was just overwhelming.
在这里插入图片描述

Screen capture of code section I found bewildering and depressing when new to Go and Kubernetes programming styles

When looking at this same piece of code in a Chrome browser with the Sourcegraph extension installed you can hover the mouse over each function and quickly get a description of the function, what is passed into the function and what it returns. This is a huge time saver as you can avoid having to grep the code base to understand where a function is defined and what it does. An example of this is shown in the figure below.
在这里插入图片描述

Screen capture of Sourcegraph hover view, which makes it obvious that ContinueOnError operates on a Builder object and returns a Builder object and describes what the function does

The Chrome Sourcegraph extension also has an advanced view that provides the ability to peek into the function that is being invoked. This extremely useful capability is shown here.
在这里插入图片描述

Screen capture of Chrome Sourcegraph advanced view that provides the ability to peek into the function that is being invoked

One issue I noticed with Chrome Sourcegraph is that sometimes it hangs and fails to pop up the code details. My experience has been that this is easily fixed by simply hitting the refresh button on the browser.

1.2. Print statements never go out of style

Adding print statements as I have shown throughout this article is a huge help to validating that the code is executing in fashion that matches how you are interpreting it. The %#v formatting option shown below typically provides the best debugging information. Don’t forget that you may have to add "fmt"to your list of imports if it is not already included in the module.

fmt.Println("\n createAndRefresh Info = %#v", info)

1.3. When in doubt, PANIC

I was having a very difficult time determining how the createAndRefresh function in Create.go was invoked. Finally, I decided to throw in a panic into the code to force a stack trace to be generated and printed to the screen. The code below shows how I added a panic to the function. This was a huge help as it helped me to determine which type of Visitor was actually being used to invoke the createAndRefresh function.

func createAndRefresh(info *resource.Info) error {
  fmt.Println("\n createAndRefresh Info = %#v", info)
  panic("Want Stack Trace")
  obj, err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, info.Object)
  if err != nil {
    return err
  }
  info.Refresh(obj, true)
  return nil
}

1.4. Visit the past with GitHub blame

Sometimes you look at some lines of source code and you think to yourself, what was the person thinking when they committed those lines of code. Thankfully, the GitHub browser interface has a blame option available as a button on the user interface. The figure below shows the location of the blame button.
在这里插入图片描述

Screen capture of blame button on the GitHub browser interface

When you push the blame button, you are given a view of the code that has the commits responsible for each line of code in the source file. This allows you to go back in time and look at the commit that added a particular line of code and determine what the developer was trying to accomplish when that line of code was added. The figure below illustrates the use of the blame option and on the left hand side all the commits are listed.
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/42140.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

有哪些电容笔值得推荐?值得买的电容笔测评

和苹果原装的电容笔不同,普通电容笔没有苹果电容笔的独特重力压感,只是给人一种倾斜的压感。不过,如果你对画画没有什么特别的需求,也不必买昂贵的Apple Pencil,平替电容笔就足够我们使用了。接下来,我会给…

全球133种语言自动翻译mishop大米外贸商城系统

提示:133种语言自动翻译,开源无加密。 文章目录介绍安装方法部分代码展示学习资料下载地址成品效果图片展示介绍 提示:这里可以添加本文要记录的大概内容: 大米外贸商城系统 简称mishop 完全开源版,只需做一种语言一…

JXcore 打包在企业级项目里的合理运用和模块系统以及网络的配置详解【node.js】

文章目录 JXcore 打包模块系统netJXcore 打包 node.Js是面向服务器端和网络应用程序的开源跨平台运行环境。 JXcore是一个支持多线程的节点。对于js发行版,您可以在多个线程中安全运行,而无需对现有代码进行任何更改。 安装命令如下: $ curl https://raw.githubusercontent.…

Java语言学习全笔记保姆级学习

目录 文章目录一、Java基础篇1.接口和抽象类的区别2.重载和重写的区别3.和equals的区别4.异常处理机制5.HashMap原理6.想要线程安全的HashMap怎么办?7.ConcurrentHashMap原如何保证的线程安全?8.HashTable与HashMap的区别9.ArrayList和LinkedList的区别1…

Tauri 入门教程

Tauri入门教程1 简介2 创建Tauri项目(页面基于Vue)2.1 环境准备2.2 创建工程3 Tauri 工程目录介绍4 页面调用rust方法5 事件系统6 HTTP请求7 文件系统8 对话框9 窗口配置10 打包1 简介 Tauri:构建跨平台的快速、安全、前端隔离应用。Tauri 是一个相对较新的框架,允…

Apollo 应用与源码分析:Monitor监控-硬件监控-CAN监控

目录 基本概念 CAN Card CAN - 原始套接字 ESD CAN 监控分析 Socket Can监控分析 基本概念 CAN Card 首先需要直到CAN的一些基本的概念。 CAN 是Controller Area Network 的缩写(以下称为CAN),是ISO国际标准化的串行通信协议。在汽车产…

Elastic Stack 环境配置与框架简介

目录 简介 什么是Elastic Stack Elasticasearch Logstash Kibana Beats 框架图 下载 配置 一、安装java环境 启动 Elasticsearch Kibana FileBeat Logstash 测验 简介 什么是Elastic Stack Elastic Stack缩写为elk,它由三个软件组成:E…

唯品会:高利润,慢增长?

配图来自Canva可画 近日,阿里、京东等互联网大厂纷纷发布了新一季度的财报,从其财报不难看出,国内头部电商平台已经告别了一路狂奔的时代,开始愈发稳健起来。唯品会虽然在体量和规模上都还不能和这两家巨头相比,但自其…

36、Java——吃货联盟订餐系统(JDBC+MySQL+Apache DBUtils)

✅作者简介:热爱国学的Java后端开发者,修心和技术同步精进。 🍎个人主页:Java Fans的博客 🍊个人信条:不迁怒,不贰过。小知识,大智慧。 💞当前专栏:Java案例分…

关于物联网你需要知道的一切

如果你想要一个更像 wiki (维基百科)的定义「什么是物联网?」,我们可以将其视为连接到 Internet 的全球对象网络,这些对象能够在没有人为干预的情况下,相互交互和交换数据。符合这一的一般定义的解决方案&a…

Java项目:基于jsp+sevlet+mysql日记系统

作者主页:源码空间站2022 简介:Java领域优质创作者、Java项目、学习资料、技术互助 文末获取源码 项目介绍 本项目主要功能有: 写日记 查看日记 日记删除 日记修改 日记类别添加 日记类别修改 日记类别删除 个人信息查看 个人信息修改 分页…

java刷题day 05

一. 单选题: 解析: 5 >> 2 相当于 5除于2两次,等于1>>> 表示无符号右移,高位用 0 填充,0001右移两位 0000,所以选A解析:作对这道题的关键是要理解Java的值传递,关于值…

婚纱租赁系统毕业设计,婚纱租赁管理系统设计与实现,论文毕设作品参考

功能清单 【后台管理员功能】 广告管理:设置小程序首页轮播图广告和链接 留言列表:所有用户留言信息列表,支持删除 会员列表:查看所有注册会员信息,支持删除 资讯分类:录入、修改、查看、删除资讯分类 录入…

【Milvus的以文搜图】

0. 介绍 以文搜图指的是,根据文本描述,从图像数据库中检索与文本内容相似的图像数据并返回。通过在CSDN中搜索以文搜图,找到了如下两篇文章: 从零到一,教你搭建「以文搜图」搜索服务(一)_Zill…

Linux “挂载” 的概念

0、前言 截至到写这个稿子,始终对挂载的概念有点模糊,到底是硬盘挂载到目录?还是目录挂载到硬盘呢?今天终于从《鸟哥的Linux私房菜》中推断出了答案,而且也恍然大悟地理解了之前书中一句晦涩难懂的话。 1、挂载的概念…

基于Web的Markdown编辑器HedgeDoc

什么是 HedgeDoc ? HedgeDoc 是一个开源的、基于 web 的、自托管的、协作的markdown编辑器。您可以使用它轻松地在笔记、图形甚至演示文稿上进行实时协作。用户需要做的就是将你的笔记链接分享给同事,他们就可以开始使用了。 不想自己搭建可以试试官方的…

基于有偏距离权值双线性插值原理(Weighted bilinear with warping)的图像超分辨重构研究-附Matlab程序

⭕⭕ 目 录 ⭕⭕✳️ 一、图像超分辨率重构原理✳️ 二、双线性插值重构理论与实验分析✳️ 2.1 双线性插值理论与实验验证✳️ 2.2 有偏距离双线性插值重构理论与实验验证✳️ 2.3 权重双线性插值理论与实验验证✳️ 2.4 有偏距离权值双线性插值理论与实验验证✳️ 三、参考文…

frps内网穿透

1 原理讲解 frp工作原理 服务端运行,监听一个主端口,等待客户端的连接; 客户端连接到服务端的主端口,同时告诉服务端要监听的端口和转发类型;服务端fork新的进程监听客户端指定的端口; 外网用户连接到客户…

2012-2020中国地区银行多指标数据

1、数据来源:bankscope 2、时间跨度:2012-2020-3季度 3、区域范围:中国 4、指标说明: 包含以下数据: 资产负债表,利润表,流动性表,资本充足率表,财务比率 global s…

java 高级面试题(借鉴)

谈谈ConcurrentHashMap的扩容机制 1.7版本 1. 1.7版本的ConcurrentHashMap是基于Segment分段实现的 2. 每个Segment相对于⼀个⼩型的HashMap 3. 每个Segment内部会进⾏扩容,和HashMap的扩容逻辑类似 4. 先⽣成新的数组,然后转移元素到新数组中 5. 扩容的…