工具帮助开发人员更快地阅读类层次结构 [英] Tools to help developers reading class hierarchy faster

查看:188
本文介绍了工具帮助开发人员更快地阅读类层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大多在我的日常工作中花时间在Python / Django和Objective-C / CocoaTouch和js / jQuery。

I mostly spend time on Python/Django and Objective-C/CocoaTouch and js/jQuery in the course of my daily work.

我的编辑器是<对于Objective-C / CocoaTouch,code> vim 用于Python / Django和js / jQuery和 xcode

My editor of choice is vim for Python/Django and js/jQuery and xcode for Objective-C/CocoaTouch.

我的开发速度的瓶颈之一是我读取现有代码的速度,特别是我使用的开源库。

One of the bottlenecks on my development speed is the pace at which I read existing code, particularly open source libraries which I use.

Python / Django例如,当我遇到一些由django开发人员介绍的新功能时,我很好奇,并开始手动探索代码库。例如,当基于类的视图从django 1.3开始引用时,引用 - https://docs.djangoproject.com/en/dev/topics/class-based-views/ - 我将查看显示的示例代码:

In Python/Django for example, when I encounter some new features introduced by django developers, I get curious and begin exploring the code base manually. For example, when class-based views were introduced from django 1.3 onwards, reference - https://docs.djangoproject.com/en/dev/topics/class-based-views/ - I will check out the example code shown:

from django.views.generic import TemplateView

class AboutView(TemplateView):
    template_name = "about.html"

并尝试我的一个项目。更重要的是,我很想知道幕后的情况,所以我将深入到源代码 -

And try it out on one of my projects. More importantly, I am curious about what goes on behind the scenes, so I will dig into the source code -

# django/views/generic/__init__.py file

from django.views.generic.base import View, TemplateView, RedirectView
from django.views.generic.dates import (ArchiveIndexView, YearArchiveView, MonthArchiveView,
                                     WeekArchiveView, DayArchiveView, TodayArchiveView,
                                     DateDetailView)
from django.views.generic.detail import DetailView
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView


class GenericViewError(Exception):
    """A problem in a generic view."""
    pass

从这里,我将跟踪到django / views / generic / base .py文件,并确定 TemplateView 类确实是什么: -

From here, I will trace it backwards to the django/views/generic/base.py file and find out exactly what TemplateView class does:-

class TemplateView(TemplateResponseMixin, View):
    """
    A view that renders a template.
    """
    def get_context_data(self, **kwargs):
        return {
            'params': kwargs
        }

    def get(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)
        return self.render_to_response(context)

此处显示 TemplateView 类继承自 TemplateResponseMixin 查看类...并继续进一步挖掘......等等...

And here's it shows that TemplateView class inherits from TemplateResponseMixin and View classes... and I continue digging further... and so on...

问题是,这是一个非常低效和缓慢的过程(手动跟随类hierachies并打开每个文件)。

所以问题是 - 是否有一个简单的方法/ UI工具(或其他视觉解决方案)解析特定项目中的Python代码,并可视化类层次结构,然后我可以通过点击特定类我有兴趣了解一下?

So the question is - is there an easy way/UI tool (or other visual solution) that parses Python code in a particular project and visualize class hierarchies which I can then inspect easily by "clicking" on a specific class I am interested to read about?

注意,我知道IPython shell,但似乎不像用户友好的视觉显示工具。

Note that I am aware of IPython shell but that doesn't seem as user-friendly as a visual display tool.

例如,在Objective-C / iOS / Mac编程世界中有 F- Script 它不仅提供了一个shell(很像python或IPython shell),但是为开发人员提供了一种直观的方式来介绍类hierachies。

For example, there's F-Script in the world of Objective-C/iOS/Mac programming, which not only provides a shell (much like python or IPython shell), but provides a visual way for developers to introspect class hierachies.

参考截图: -

所以有一个类层次的可视化工具(特别是Python,但更好,如果它是通用的,可以用于不同的语言)在阅读开放源代码时,您如何有效提高速度?

So is there a class-hierarchy visualization tool (for Python specifically, but even better if it's generic and can be used for different languages)??? What are your methods of getting up to speed efficiently when reading open source source code???

UPDATED

根据下面的建议,我尝试了 ctags 和vim插件 taglist 使用:TlistOpen 在vim中打开一个边缓冲区: -

Per advice below, I tried out ctags and vim plugin taglist and I was able to use :TlistOpen to open up a side buffer in vim like this:-

这看起来很酷,因为: TlistOpen 现在基本上显示了我当前打开的缓冲区上可用的所有类和函数。

This looks really cool as :TlistOpen now essentially shows me all the classes and functions that are available on my currently open buffer.

我的问题是,当我尝试当我的光标位于 TemplateView 上时,我会收到以下错误: -

My problem now is that when I attempt to do Ctrl] while my cursor is on TemplateView, I get the following error:-

>

我做错了什么?是因为我的django源代码是在 virtualenv ?还是有一些具体的我需要做的使 django源代码? ctags / taglist 感知 / p>

What am I doing wrong? Is it because my django source code is in a virtualenv? Or is there something specific I have to do to make ctags/taglist "aware" of the django source code?

推荐答案

标签是一个很好的开始。 (在它上面有太多的东西,所以我只需要提供一个额外的关键字来搜索:ctags。)

Tags are a very good start indeed. (There's too much stuff all over the place on it, so I'll just provide you with one extra keyword to search with: ctags.)

在Vim中,在 Ctrl +] 中转到类/函数定义,使用 Ctrl + T 返回

In Vim, it ends up (in the basic case) with Ctrl+] to go to a class/function definition and Ctrl+T to return.

这篇关于工具帮助开发人员更快地阅读类层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆