2010년 4월 12일 월요일

Comparing Python to Other Languages(Python과 다른 언어와의 비교)

Disclaimer: This essay was written sometime in 1997. It shows its age. It is retained here merely as a historical artifact. --Guido van Rossum

Python is often compared to other interpreted languages such as Java, JavaScript, Perl, Tcl, or Smalltalk. Comparisons to C++, Common Lisp and Scheme can also be enlightening. In this section I will briefly compare Python to each of these languages. These comparisons concentrate on language issues only. In practice, the choice of a programming language is often dictated by other real-world constraints such as cost, availability, training, and prior investment, or even emotional attachment. Since these aspects are highly variable, it seems a waste of time to consider them much for this comparison.

Java
Python programs are generally expected to run slower than Java programs, but they also take much less time to develop. Python programs are typically 3-5 times shorter than equivalent Java programs. This difference can be attributed to Python's built-in high-level data types and its dynamic typing. For example, a Python programmer wastes no time declaring the types of arguments or variables, and Python's powerful polymorphic list and dictionary types, for which rich syntactic support is built straight into the language, find a use in almost every Python program. Because of the run-time typing, Python's run time must work harder than Java's. For example, when evaluating the expression a+b, it must first inspect the objects a and b to find out their type, which is not known at compile time. It then invokes the appropriate addition operation, which may be an overloaded user-defined method. Java, on the other hand, can perform an efficient integer or floating point addition, but requires variable declarations for a and b, and does not allow overloading of the + operator for instances of user-defined classes.

For these reasons, Python is much better suited as a "glue" language, while Java is better characterized as a low-level implementation language. In fact, the two together make an excellent combination. Components can be developed in Java and combined to form applications in Python; Python can also be used to prototype components until their design can be "hardened" in a Java implementation. To support this type of development, a Python implementation written in Java is under development, which allows calling Python code from Java and vice versa. In this implementation, Python source code is translated to Java bytecode (with help from a run-time library to support Python's dynamic semantics).

Javascript
Python's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and unlike Java), Python supports a programming style that uses simple functions and variables without engaging in class definitions. However, for JavaScript, that's all there is. Python, on the other hand, supports writing much larger programs and better code reuse through a true object-oriented programming style, where classes and inheritance play an important role.

Perl
Python and Perl come from a similar background (Unix scripting, which both have long outgrown), and sport many similar features, but have a different philosophy. Perl emphasizes support for common application-oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but rarely beats it in its original application domain; however Python has an applicability well beyond Perl's niche.

Tcl
Like Python, Tcl is usable as an application extension language, as well as a stand-alone programming language. However, Tcl, which traditionally stores all data as strings, is weak on data structures, and executes typical code much slower than Python. Tcl also lacks features needed for writing large programs, such as modular namespaces. Thus, while a "typical" large application using Tcl usually contains Tcl extensions written in C or C++ that are specific to that application, an equivalent Python application can often be written in "pure Python". Of course, pure Python development is much quicker than having to write and debug a C or C++ component. It has been said that Tcl's one redeeming quality is the Tk toolkit. Python has adopted an interface to Tk as its standard GUI component library.

Tcl 8.0 addresses the speed issuse by providing a bytecode compiler with limited data type support, and adds namespaces. However, it is still a much more cumbersome programming language.

Smalltalk
Perhaps the biggest difference between Python and Smalltalk is Python's more "mainstream" syntax, which gives it a leg up on programmer training. Like Smalltalk, Python has dynamic typing and binding, and everything in Python is an object. However, Python distinguishes built-in object types from user-defined classes, and currently doesn't allow inheritance from built-in types. Smalltalk's standard library of collection data types is more refined, while Python's library has more facilities for dealing with Internet and WWW realities such as email, HTML and FTP.

Python has a different philosophy regarding the development environment and distribution of code. Where Smalltalk traditionally has a monolithic "system image" which comprises both the environment and the user's program, Python stores both standard modules and user modules in individual files which can easily be rearranged or distributed outside the system. One consequence is that there is more than one option for attaching a Graphical User Interface (GUI) to a Python program, since the GUI is not built into the system.

C++
Almost everything said for Java also applies for C++, just more so: where Python code is typically 3-5 times shorter than equivalent Java code, it is often 5-10 times shorter than equivalent C++ code! Anecdotal evidence suggests that one Python programmer can finish in two months what two C++ programmers can't complete in a year. Python shines as a glue language, used to combine components written in C++.

Common Lisp and Scheme
These languages are close to Python in their dynamic semantics, but so different in their approach to syntax that a comparison becomes almost a religious argument: is Lisp's lack of syntax an advantage or a disadvantage? It should be noted that Python has introspective capabilities similar to those of Lisp, and Python programs can construct and execute program fragments on the fly. Usually, real-world properties are decisive: Common Lisp is big (in every sense), and the Scheme world is fragmented between many incompatible versions, where Python has a single, free, compact implementation.



--Guido van Rossum저. (이강성 역)

Java (자바)
Javascript (자바스크립트)
Perl (펄)
Tcl (티클)
Smalltalk (스몰톡)
C++
Common Lisp and Scheme


--------------------------------------------------------------------------------
Python은 흔히 Java, JavaScript, Perl, Tcl 또는 Samlltalk와 같은 인터프리터 언어와 비교된다. C++, Common Lisp 그리고 Scheme과 같은 비교되 부각된다. 이 절에서 난 이들 언어를 간단히 비교할 것이다. 이 비교는 언어적인 측면에서만 다룬다. 실제적으로, 프로그래밍 언어의 선택은 다른 실세계 제약(비용, 유용성, 학습 그리고 선행 투자비용 혹은 감성적인 친근감까지도)에 의해 자주 언급되기도 한다. 이러한 면들은 아주 가변적이고, 이러한 면으로 비교를 한다는 것은 시간 낭비에 가깝다.

Java (자바)
일반적으로 Python 프로그램은 Java 프로그램 보다는 느리게 수행된다. 하지만 Python 프로그램은 개발하는 시간이 훨씬 적게 걸린다. Python 프로그램은 Java 프로그램보다도 3-5배 정도 코드가 짧다. 이 차이는 Python의 내장 고수준 데이터 형과 동적인 형결정 기능에서 기인한다고 생각한다. 예를 들면, Python 프로그래머는 인수나 변수의 형을 선언하는데 시간을 허비하지 않고, 구문적인 지원이 언어안에 내장되어 있는 Python의 강력한 다형질의 리스트(polymorphic list)와 사전 형은 거의 모든 Python 프로그램에서 유용하게 활용되고 있다. 실행시간 형결정으로 인해서 Python의 실행시간에 Java가 하는 것보다 좀더 많은 일을 한다. 예를 들면, a+b와 같은 식을 계산할 때, 먼저 컴파일시에 알려지지 않은 a와 b 객체를 검사하여 그들의 형을 알아내야 한다. 그리고 나서 적절한 덧셈 연산을 호출한다. 그 덧셈 연산은 객체에 따라 사용자에 의해 오버로드(overloaded)된 것일 수 있다. 반면에, Java는 효과적인 정수형, 실수형 덧셈을 한다. 하지만 a와 b의 변수선언을 요구하고, + 연산자에 대한 사용자 정의 연산자 오버로딩을 허용하지 않는다.

이러한 이유들로, Python은 '접착' 언어로서 아주 적당한 반면, Java는 저수준 구현 언어로 특성화 지을 수 있다. 사실 이 두 언어는 아주 훌륭한 조합을 이룬다. Java에서 개발된 요소(components)들이 Python에서 활용된다; Python 역시 Java로 구현되기 전에 그 프로토타입을 정하는데 활용된다. 이러한 형의 개발을 지원하기 위해, Java로 쓰여진 Python 구현(implementation)이 개발중이다. 이것은 Java에서 Python을 호출하고 그 반대도 가능하게 해준다. 이 구현으로, Python 소스코드는 Java 바이트코드로 (Python의 동적 의미를 지원하기 위한 실행시간 라이브러리의 도움으로)번역된다.

Javascript (자바스크립트)
Python의 '객체기반' 부분 집합이 대략 JavaScript와 동일하다. JavaScript와 같이 (그러나 Java와는 다르게), Python은 클래스안에 정의하지 않아도 되는, 단순한 함수와 변수를 사용하는 프로그래밍 스타일을 지원한다. 하지만 JavaScript는 이것이 지원하는 전부이다. Python은, 반면에, 훨씬 큰 프로그램을 클래스와 상속이 중요한 역할을 하는 진정한 객체 지향 프로그래밍 스타일을 통하여 더 좋은 코드 재사용을 하도록 지원한다.

Perl (펄)
Python과 Perl은 비슷한 배경에서 개발되었다(유닉스 스크립트언어에서 성장했다). 그리고 많은 비슷한 기능을 지원한다. 그러나 철학은 다르다. Perl은 보편적인 응용지향 태스크를 지원하는데 중심을 두었지만 (예:내장 정규식 표현, 파일 스캐닝과 보고서 생성 기능들), Python은 보편적인 프로그래밍 방법론 (자료구조 설계 및 객체지향 프로그래밍)을 지원한다. 그리고 프로그래머가 우와하고(elegant) 암호같지 않은 코드를 통해 일기 쉽고 관리하기 쉽도록 한다. 결과적으로, Python이 Perl과 가깝지만 그 원래 응용 영역을 침범하는 일은 많지 않다. 하지만 Python은 Perl의 적합한 응용분야 외에 많은 부분에서 적용성을 갖는다.

Tcl (티클)
Python과 같이 Tcl은 독립적인 프로그래밍 언어 분 아니라, 응용 확장언어(extension language)로도 사용된다. 하지만, 전통적으로 모든 데이터를 문자열로 처리하는 Tcl은 자료구조에 약하고 Python 보다 실행에 시간이 많이 걸린다. Tcl은 또한 모듈러 이름영역(name space)와 같은, 큰 프로그램을 쓰기에 적합한 특징들을 가지고 있지 않다. 따라서 Tcl을 사용하는 전형적인 큰 응용 프로그램은 특별히 그 응용에 필요한 C나 C++로 확장된 부분을 갖는다. 이에 반해서 Python 응용 프로그램은 '순수한 Python'으로만 흔히 기술된다. 물론 순수한 Python을 이용한 개발은 C나 C++부분을 쓰고 디버깅하는 것보다도 훨씬 빠르다. Tcl의 결점을 매우는 부분이 Tk 툴킷이다. Python은 Tk을 표준 GUI 라이브러리로 쓰도록 적용했다.

Tcl 8.0은 바이트코드를 도입하여 빠른 처리를 했고, 제한된 데이터 형 지원과 이름영역을 지원한다고 하지만 여전히 거추장스러운 프로그래밍 언어이다.

Smalltalk (스몰톡)
아마도 Python과 Smalltalk의 가장큰 차이는 Python이 보다 더 '주류(mainstream)' 구문을 가진다는 것이다. Python은 Smalltalk과 같이 동적인 형결정과 결합(binding)을 한다. Python의 모든 것은 객체이다. 하지만, Python은 내장 객체 형과 사용자 정의 클래스를 구별하고, 내장 형으로부터의 상속은 현재로서 허용하지 않는다. Smalltalk의 데어터 타입의 표준 라이브러리 모음은 훨씬 섬세한 반면, Python의 라이브러리는 인터넷과 WWW 세계 (email, HTML, FTP등) 에 적응하기 좋은 많은 기능을 제공한다.

Python은 개발환경과 코드 배포에 있어서 다른 철학을 갖는다. Smalltalk이 환경과 사용자 프로그램을 포함하는 통일된 '시스템 이미지'를 갖는데 반해, Python은 표준 모듈과 사용자 모듈을 다른 파일에 저장하여 쉽게 재배열되고 시스템 밖으로 배포될 수 있다. 한 결과를 예를 들면, GUI가 시스템 안에서 설계된 것이 아니므로, GUI를 붙이기 위한 한가지 이상의 선택이 Python 프로그램에 있다.

C++
Java에 대해서 이야기 한 대부분이 C++에도 적용된다. Python코드가 Java 코드보다 3-5배 짧으며, C++코드에 비해 5-10배 짧다!! 일 예로 한명의 Python 프로그래머는 C++프로그래머 두 명이 1년에 끝낼 수 없는 일을 두달만에 끝낼 수 있다. Python은 C++로 쓰여진 코드를 사용하는 접착 언어로 빛을 발한다.

Common Lisp and Scheme
이들 언어는 동적인 의미해석에서 Python에 가깝다. 그러나 구문해석 접근은 너무 달라서 매우 심한 논쟁거리가 될 만한 비교가 된다: Lisp의 구문적인 부족함이 장점일까 단점일까? Python은 Lisp과 같은 내성적인 능력(capabilities)이 있고, Python 프로그램은 아주 쉽게 프로그램 부분을 구성해서 실행할 수 있다는 것을 밝혀야겠다. 일반적으로, 실세계 실체가 결정적이다: Common Lisp은 크다(어떠한 관점에서도 그렇다). Scheme 세계는 많은 어울리지 않는 버전들로 나누어져있다. 그에 반해서 Python은 하나이고, 무료이고, 작게 구현되었다. 더 자세한 Scheme와의 비교에 관해선 Moshe Zadka가 쓴 Python vs. Scheme을 보라.

댓글 없음:

댓글 쓰기