问题描述
我想在以下这些工具上获得一些反馈:
I would like to get some feedback on these tools on :
- 功能;
- 适应性;
- 易用性和学习曲线.
推荐答案
好吧,我有点好奇,所以我在问了问题之后才对3进行了测试;-)
Well, I am a bit curious, so I just tested the 3 myself right after asking the question ;-)
好的,这不是一个很严肃的评论,但这是我可以说的:
Ok, this is not a very serious review but here is what I can say :
我在以下脚本上尝试了使用默认设置的工具(这很重要,因为您几乎可以选择检查规则):
I tried the tools with the default settings (it's important because you can pretty much choose your check rules) on the following script :
#!/usr/local/bin/python
# by Daniel Rosengren modified by e-satis
import sys, time
stdout = sys.stdout
BAILOUT = 16
MAX_ITERATIONS = 1000
class Iterator(object) :
def __init__(self):
print 'Rendering...'
for y in xrange(-39, 39):
stdout.write('\n')
for x in xrange(-39, 39):
if self.mandelbrot(x/40.0, y/40.0) :
stdout.write(' ')
else:
stdout.write('*')
def mandelbrot(self, x, y):
cr = y - 0.5
ci = x
zi = 0.0
zr = 0.0
for i in xrange(MAX_ITERATIONS) :
temp = zr * zi
zr2 = zr * zr
zi2 = zi * zi
zr = zr2 - zi2 + cr
zi = temp + temp + ci
if zi2 + zr2 > BAILOUT:
return i
return 0
t = time.time()
Iterator()
print '\nPython Elapsed %.02f' % (time.time() - t)
结果:
-
PyChecker
很麻烦,因为它会编译模块以对其进行分析.如果您不希望代码运行(例如,它执行SQL查询),那就不好了. -
PyFlakes
应该是精简版.确实,它决定代码是完美的.我正在寻找很严重的东西,所以我认为我不会去做. -
PyLint
一直很健谈,并且对代码的评分为3/10(天哪,我是一个肮脏的编码器!).
PyChecker
is troublesome because it compiles the module to analyze it. If you don't want your code to run (e.g, it performs a SQL query), that's bad.PyFlakes
is supposed to be lite. Indeed, it decided that the code was perfect. I am looking for something quite severe so I don't think I'll go for it.PyLint
has been very talkative and rated the code 3/10 (OMG, I'm a dirty coder !).
PyLint
的要点:
Strongs points of PyLint
:
- 非常准确和描述性的报告.
- 检测一些代码气味.在这里,它告诉我放弃类来编写带有函数的内容,因为在这种特定情况下,OO方法没有用.我知道些什么,但从没想到会有电脑告诉我:-p
- 经过完全校正的代码运行速度更快(没有类,没有引用绑定...).
- 由法国队制造.好的,这不是每个人的优点,但我喜欢它;-)
PyLint
的缺点:
Cons of PyLint
:
- 某些规则非常严格.我知道您可以更改它,并且默认值是匹配PEP8,但是写"for x in seq"是否构成犯罪?显然可以,因为您不能用少于3个字母写一个变量名.我会改变的.
- 非常健谈.准备好使用眼睛.
更正的脚本(带有惰性doc字符串和变量名):
Corrected script (with lazy doc strings and variable names) :
#!/usr/local/bin/python
# by Daniel Rosengren, modified by e-satis
"""
Module doctring
"""
import time
from sys import stdout
BAILOUT = 16
MAX_ITERATIONS = 1000
def mandelbrot(dim_1, dim_2):
"""
function doc string
"""
cr1 = dim_1 - 0.5
ci1 = dim_2
zi1 = 0.0
zr1 = 0.0
for i in xrange(MAX_ITERATIONS) :
temp = zr1 * zi1
zr2 = zr1 * zr1
zi2 = zi1 * zi1
zr1 = zr2 - zi2 + cr1
zi1 = temp + temp + ci1
if zi2 + zr2 > BAILOUT:
return i
return 0
def execute() :
"""
func doc string
"""
print 'Rendering...'
for dim_1 in xrange(-39, 39):
stdout.write('\n')
for dim_2 in xrange(-39, 39):
if mandelbrot(dim_1/40.0, dim_2/40.0) :
stdout.write(' ')
else:
stdout.write('*')
START_TIME = time.time()
execute()
print '\nPython Elapsed %.02f' % (time.time() - START_TIME)
多亏了Rudiger Wolf,我发现了pep8
确实符合其名称的含义:匹配PEP8.它发现了PyLint没有的一些语法禁忌.但是PyLint
发现的内容与PEP8没有特别的联系,但很有趣.两种工具都很有趣且互补.
Thanks to Rudiger Wolf, I discovered pep8
that does exactly what its name suggests: matching PEP8. It has found several syntax no-nos that PyLint did not. But PyLint
found stuff that was not specifically linked to PEP8 but interesting. Both tools are interesting and complementary.
最终我将同时使用这两种方法,因为它们真的很容易安装(通过软件包或setuptools),并且输出文本也很容易链接.
Eventually I will use both since there are really easy to install (via packages or setuptools) and the output text is so easy to chain.
让您对它们的输出有一些了解:
To give you a little idea of their output:
pep8 :
./python_mandelbrot.py:4:11: E401 multiple imports on one line
./python_mandelbrot.py:10:1: E302 expected 2 blank lines, found 1
./python_mandelbrot.py:10:23: E203 whitespace before ':'
./python_mandelbrot.py:15:80: E501 line too long (108 characters)
./python_mandelbrot.py:23:1: W291 trailing whitespace
./python_mandelbrot.py:41:5: E301 expected 1 blank line, found 3
PyLint :
************* Module python_mandelbrot
C: 15: Line too long (108/80)
C: 61: Line too long (85/80)
C: 1: Missing docstring
C: 5: Invalid name "stdout" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 10:Iterator: Missing docstring
C: 15:Iterator.__init__: Invalid name "y" (should match [a-z_][a-z0-9_]{2,30}$)
C: 17:Iterator.__init__: Invalid name "x" (should match [a-z_][a-z0-9_]{2,30}$)
[...] and a very long report with useful stats like :
Duplication
-----------
+-------------------------+------+---------+-----------+
| |now |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines |0 |0 |= |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |0.000 |= |
+-------------------------+------+---------+-----------+
这篇关于PyLint,PyChecker或PyFlakes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!