Java OOP与Python OOP的区别

For a Java guy Python is an anarchic playgound where anyone can grab a club and start mauling your head.

对于Java的忠实粉丝来说,Python就像是一个无政府主义的游乐场,任何人都可以随手拿起一根棍子敲你的头。

For a Python guy Java is a an Orwellian universe where you are constantly shackled to someone else`s diminishing view of how the universe tick.

而对于Python的支持者,Java就像奥威尔的宇宙(Orwellian一词可以释义为“受严格统治而失去人性的社会”,转译为“严格控制的”),在其中你无时无刻不受到他人的严格管控。

The truth is anything you can do in one language you can do in the other just as cleanly. However there are important difference in both community as to what clean means.

实际上,任何你使用某一门语言能够做到的事情,都可以用另一门语言干净利落的完成。不过,对于Python和Java来说,“干净利落”的定义是不一样的。

Java way : A clean system is one that does what is meant to and nothing else, it will not allow extensions or modifications that go against the nature of the intended purpose and will attempt to enforce these as much as possible through the compiler. Flexibility is obtained through careful crafting of simple interfaces within strict structures. In Java one`s sand box should always be clearly bounded and overstepping these met with swift feedback from the compiler. Java provides means to statically define object structures and create dynamic interactions from instances of them. When I work in Java I try to cleverly create basic building blocks towards a brain dead solution. I mostly work bottom-up once I have a working theory on how to tackle the problem.(#Request For Better Translation)

Java风格:一个干净的系统只专注于做自己分内的事情,它不允许违背预期目的的扩展或者修改,并且尽可能的通过编译器强化这一点。灵活性通过结构严谨,精心设计的简单接口实现。在Java中,沙盒总是具有清晰的边界,任何试图逾越这种边界的行为会得到编译器的快速反馈。Java提供了静态地定义对象结构,并从它们的实例中创建动态的交互的方法。我在使用Java时,会努力巧妙地创建基本的构建模块,朝着一个脑残的解决方案。一旦我有一个解决问题的工作理论,我总会自底向上的去做。

Java will tend to produce large software that can span large teams and provides tools and means to keep the flock in check(#Request For Better Translation). If kept unchecked this will lead to very detached teams working independently towards an ever more unclear goal. Eventually each team becomes it`s own "raison d'être" and the system as a whole becomes diluted driving astray the main project. These can lead to extreme cost overruns and huge software systems that perform and maintain poorly.

Java倾向于用来制造可以跨越大型团队并提供项目管理工具与方法的大型软件。如果缺乏管理,会导致团队合作分崩离析,各个小组的目标不明确。最终每个团队各自为战,而系统作为一个整体会变得涣散最终使得整个项目走上歧途。这些会导致巨大的项目超支,并使得大型软件系统的性能和维护变得非常糟糕。

There is almost never a small quick and easy way to do things in Java, but the IDE and the tooling are there to make painful tasks a mere few clicks away.

在Java中几乎从来没有小巧快速而又简单的解决问题的方法,但是有了IDE和工具的帮助,痛苦的任务只需要点几次鼠标就可以完成。

Python way: Clean means concise and easily readable. A good python system is designed to let you get right to the heart of it and exposes it`s innermost secrets in a way that you can understand from the code the intended use and purpose of it. It will also allow you to design your own solution around by extending and/or encapsulating the original design so that it will go exactly in your direction. Python provides means to create object templates from which you can dynamically change the instance to fit the needs at hand. In python I tend to tackle the problem right away and then spread the code in a logical structure such that the final solution remains as simple and readable as can be. In python I tend to work top-down and manage the increase complexities through a divide-and-conquer approach. 

Python风格:干净意味着简洁与易读。一个好的python系统被设计用来帮助你直达问题的核心,并且将它最深处的秘密以一种你可以理解的方式从代码中暴露出来,帮助你了解代码的用途和意图。它也允许你通过扩展和/或对原始的设计做封装来设计你自己的解决方案,使其能够按照自己的想法行事。Python提供了创建对象模板的方法,从中你可以动态地改变实例以适配当前的需要。在python中我倾向于直截了当地解决问题,然后再把代码扩展成一种逻辑的结构,以至于最终的解决方案尽可能的简单和易读。在python中我倾向于自顶向下的工作,并且使用一种分治的方法来管理逐渐增加的复杂性。

Python teams will tend to produce light systems and be very fast in delivering a working solution. They will tend to be a close knit bunch working interchangeably on any part of the system validating each other's solution every chance they get. They feed on each other creating a synergy that is quite exhilarating. However this creates teams that are difficult to scale to larger systems and often hit a sort of glass ceiling. Introducing new members in the team will help but it will take some time for the knowledge to spread around enough for the extra productivity to be felt. The team then becomes divided and the constant overview over the whole system dilutes as does the atmosphere of the early days. This can lead to overly convoluted code to what once was a simple problem, extreme cost overruns and systems that perform and maintain poorly.

Python团队倾向于构建轻量级的系统,并且在交付解决方案时十分的迅速。他们倾向于以一种互相交叉的方式在系统的任何部分交替地进行工作,并且一有机会就会互相验证彼此的解决方案。他们从彼此的协作中获得动力。然而,这样的团队难以扩展成大型的系统,并且经常会遇到某种“玻璃天花板”。向团队中引入新成员会有帮助,但这需要花费一些时间来让新成员融入团队,进而使得团队获得额外的生产力。进而团队会被分割,随之而来的频繁的对整个系统的回顾会使得团队早期的氛围遭到稀释。这可能导致原来很简单的问题变得复杂化,项目成本超支,系统难以维护。

There is almost always a quick and easy way to do things with Python but complexity can be harder to keep in check once the system reach a certain threshold.

几乎总是能够使用Python找到一个迅速而容易的解决问题的方法,但是当系统的规模达到某种阈值时,其复杂性会变得难以控制。

In short, both have a dark side and both have clear strength. However, when prodding along both communities you will find that the strength of one leads to the dark side of the other and vice versa.

简而言之,各有利弊。然而,在这两种语言的粉丝眼中,自己所钟爱的语言的缺点也变成了优点。

原文链接:http://programmers.stackexchange.com/questions/62994/differences-between-java-oop-and-pythonic-oop

本文链接:http://bookshadow.com/weblog/2014/11/26/differences-between-java-oop-and-pythonic-oop/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码

Pingbacks已关闭。

暂无评论

张贴您的评论