문제

편집: 이 질문은 물을 많이 개선에서 일어난 표준 Python 과학 라이브러리(는 대상 영역).예를 들어 numpy 프로젝트는 큰 노력을 개선하 docstrings.하이 여전히 존재한다고 주장하는 경우가 있었을 것이 가능한 이러한 문제를 해결하기 위해 지속적으로 오른쪽에서 시작합니다.


이는 다소 이단 질문:왜 그렇게 많은 Python 라이브러리가 지저분한 코드고 따르지 않 표준의 모범 사례?또는 당신이 생각하는 것이 관측은 절대적 사실인가요?어떻게 상황을 비교를 다른 언어로 사용할 수 있습니까?나에 관심을니다.

몇 가지 이유가 있는 인상 품질이 부족:

  • 이 docstrings 은 종종 완전히 누락되었거나 불완전한,심지어 공개 API.그것은 고통스러운 방법이 걸립 *args**kwargs 그러나지 않는 문서 값을 지정할 수 있습니다.

  • 나쁜 Python 코딩 방식 같은 추가하는 새로운 외부의 특성 __init__.이 같은 것들을 만드시 읽기(또는 유지하).

  • 거의 모든 라이브러리에 따라 PEP8 다.때로는 규칙은 심지어 일관성에서 단일 파일입니다.

  • 전체적인 디자인이 지저분하고,명확한 API 를 사용합니다.그것은 것 같지 않은 거의 충분한 리팩터링을 수행합니다.

  • 가난한 unittest 에 대한 여러 커버합니다.

Don't get me wrong, 나는 절대적으로 사랑하는 파이썬 및 에코시스템.도 고생으로 이러한 라이브러리 그들은 일반적으로 일을 끝내고 난 그것에 대해 감사.그러나 나는 생각 끝에 톤의 개발 시간을 낭비 때문에 이러한 문제를 해결합니다.어쩌면 그 때문입 파이썬은 당신이 그렇게 많은 자유는 그것은 매우 쉽게 쓰는 잘못된 코드.

도움이 되었습니까?

해결책

에 관한 문서를,그것은 단지 Python.이 있는 경우 하나의 단일 요인하는 것을 방해하는 더 넓은 채택 보다는,이 문서를 작성하는 진정으로운 수준의 문서 대부분의 OS 프로젝트입니다.이에서 시작하는 코드 수준을 확장하여 사용자 문서.할 수 있습니 그냥 말하면 누구나 작업에서는 OS:

a)코멘트는 코드!같은 것은 없으로 자기 문서화합니다.

b)최소한 25%의 프로젝트의 시간에 예산에서 최종 사용자 설명서입니다.

고 막연하게 무슨 얘기-나는 몇 가지의 OS 프로젝트의 내 자신,내가에 기여하는 여러 가지 다른 사람을 내가 사용하는 OS 를 거의 독점적으로 이용한다.어제 내가 지출 4 시간 이상을 구축을 위해 노력하고 주요 OSS 프로젝트(이름이 없는,아무 팩 드릴),그리고 실패했기 때문에 시시하다,자기 모순 문서입니다.

다른 팁

대신 저자들은 각자 자신의 영광스러운 협약을 따르는 것 같습니다. 때로는 규칙이 도서관의 동일한 파일과 일치하지 않습니다.

현실 세계의 멋진 코드에 오신 것을 환영합니다!

내가 만난 FWIW Python 코드는 다른 언어보다 더 나쁘거나 나쁘지 않습니다.

(음, 평균 PHP 프로젝트보다 낫지 만 분명히 공정하지는 않습니다.)

가장 먼저 깨달아야 할 것은 파이썬이 버전 2.X 주위의 Guido 헤드에서 완전히 형성되지 않았다는 것입니다. 지난 20 년 동안 성장했습니다.

실제로, 당신이 언급 한 많은 것들 (예 : Unittest, Pep-8)은 일부 표준 라이브러리가 처음 작성되었을 때도 존재하지 않았습니다.

아마도 당신이보고있는 도서관이 오래 될수록, 그들이 현재 "모범 사례"와 차이가있을 가능성이 높아질 것입니다. 보다 최근의 라이브러리는 현재 관행을 준수 할 가능성이 높습니다.

또한 때로는 종종 좋은 이유가 있습니다. ~ 아니다 최신 정보를 제공합니다. 현재 Python 라이브러리에 대해 수만 줄의 코드가 작성되었다고 상상해보십시오. 이제 해당 라이브러리 중 하나의 관리자는 클래스 및 기능 이름이 PEP-8을 준수하도록 라이브러리를 변경하기로 결정합니다. 이제 작업 코드가있는 모든 사람은 크게 상당한 금액을 다시 방문해야합니다.

그것은 파이썬 라이브러리에서 개선 할 수있는 것들이 없다고 말하는 것은 아닙니다. 그러나 완벽 함과 일을 끝내는 사이에는 항상 상충 관계가 있습니다. 그것이 그들이 "실용성이 순결을 능가한다"고 말하는 이유 중 하나입니다.

This is because Python is not backed up by the corporate world like Java or .Net .

If I want my Java library to be promoted by Sun I will follow their guidelines. This is not the case with Python. I write my code, people find it better and it has to evolve on its own.

Also most Python developers are from C++, C, Java,.Net etc. And they start writing production code right from the first day. Thanks to easiness of Python. And the vicious cycle continues.

Even it took me a month to come to PEP8 and refactor my code.

PEP 8 has changed over time. Some modules follow older recommendations. You can see that with PIL, which uses modules like "Image" where the module contains a single main class, instead of the recommended lowercase for module names, and in C extensions which use the "c" prefix, rather than the more modern "_" prefix.

Some of the libraries are developed by people who are strongly influenced by traditions in other fields, like Java and C++. These people more often use CamelCase instead of the PEP 8 recommended lowercase_with_underscores.

The answers here wouldn't be complete without reference to Sturgeon's Law: "Ninety percent of everything is crap."

Ninety percent of [python libraries] are crud, but ninety percent of everything is crud

-- Sturgeons law (paraphrased)

It sounds like you have come to find that code quality does not meet the expectations you were set up to expect. Perhaps from school, or best practices books or senior developers.

After having worked at several companies, I found myself regularly advised to do unit tests, document code, use version/source control (all good advice that I have taken) then finding that the givers of that advice rarely follow the advice themselves.

I would say that you do have the right impression that sometimes the code quality is low, but only based on your expectations. Certainly numpy and others are quite useful packages, even if not coded to the standard you were set up to expect.

Standards are opinions, and if you are of the opinion that standards are low, then you can try to help make those standards better by contributing, or accept them as they are and be sure to write code that serves as an example to the juniors you will find yourself in charge of one day.

As for matplotlib, there is project to improve it's "pythoness" - http://www.scipy.org/PyLab

The thing about scientific libraries, is that they are written by scientist, no by professional software developers. Moveover, those scientist are used to write Fortran. The question is -- would you rather have working code or beautiful code?

PEP8 is a style guide, not a style requirement. It even states that you should "know when to be inconsistent". Personally, I don't like some of the guidelines in it. I prefer camelCase to snake_case since I'm more used to that.

And I don't often look at the source code of libraries I'm using unless it's absolutely necessary (such as debugging). I'd much prefer the documentation for said library to be adequate enough that I never have to look at the source.

Seriously, why do you really care what the source code for matplotlib looks like, as long as it does what it is intended to do?

I agree with you on the missing docstrings (assuming they're public elements rather than internal ones) but that's not the only way to document a library.

I believe that Python suffers from being hoisted too eagerly on people who are not programmers (by schooling or trade) as a solution for "need some programming done? Here, try this easy and mature tool".

Similarly to how PHP became such a huge success and with so many libraries with abysmal code quality (even if, granted, the average Python code quality is better then for PHP) - the average PHP user similarly to the average Python user has not much programming experience or skills and very little incentive to improve themselves in this regard - they set out to achieve something, and maybe they thought it is worthy enough to be shared with the community in the form of a library, but most often once the job is done they have no interest to better the code or better themselves (in programming skills, I mean).

The solution might be for Python library repositories (such as PyPI) to have stricter rules about accepting contributed packages - handle this with a review process whose purpose is to ensure quality - the same way that major Linux distributions have a review process before adding a package to their repositories.

PEP8 is just that, a convention, not a requirement. It would be really sad if all python programmers had to adhere to a common set of rules, we lose enthusiasm over the slightest of issues.

As far as missing docstrings are concerned - yes, they can help when using interactive help - but I generally don't mind as long as there's some documentation. I try not to read the source code of the libraries I use, I tend to start modifying (rewriting) them.

Regarding comparison with other languages, I think that language design plays a big part here. For example, in a strong-typed language like Java, even if the library is missing good documentation, you can still deduce much of the functionality from the method signatures. No *args to contend with.

How about a collection of examples of good software doc ?
Good examples might lead to overall improvement a bit faster than random walk.
The collection could be split into categories such as:
inline doc / help page / tutorial / reference manual, web page / paper, pictures / none.
Each entry should have a few words on why the reviewer finds it good.
(Where: a corner of stackoverflow ?)

nikow: I can only answer for myself, most of my Python (and PHP or Ruby, all dynamic "scripting" languages) work is done just for me - but I always release it on my personal site if anyone else finds it useful, but I never go through any documentation or QA process because as long as it works for me I'm happy.

Well, they are open source. As such they will also evolve over time, if they are good enough.

That's one of the many beauties of open source.

Often there is little sense in writing lot of documentation and "good" code if you don't know whether the project will live on. That would just be a waste of time.

Edit: Of course writing good code would never hurt the first time around though... But maybe just "getting the job done" is good enough in many cases. I think that otherwise we wouldn't enjoy the vast amount of options when it comes to OSS.

I think that if enough people act a specific way there might be some explanation to it. They are not just randomly doing so to offend you.

Quality of code * number of comments * time = constant

Pick two !

I never had any problem using matplotlib; can't say I looked at the code much - it is a fine library. Does what it is supposed to do (for free !)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top