Python is widely regarded as an easy language for beginners. But did you know that there’s a much easier language, one that has far greater capabilities? It’s called Pharo, a modern variant of Smalltalk. Let’s compare the two…

Simplicity, Conciseness, and Elegance

Pharo is much, much simpler than Python. It has all of six reserved words. The complete syntax fits on a post card!

You sure as hell can’t do that with Python!

You can learn the entire language in 15 minutes: Learn Smalltalk with ProfStef. You sure as hell can’t do that with Python!

Pharo is astonishingly concise and elegant. Here’s a sampling of wonderful one-liners:

"Compute difference in days between two dates"
('2014-07-01' asDate - '2013/2/1' asDate) days
"Set up an HTTP server that returns the current timestamp"
(ZnServer startDefaultOn: 8080) 
  onRequestRespond: [ :request | 
    ZnResponse ok: (ZnEntity with: DateAndTime now printString) ]
"Split a string on dashes, reverse the order of the elements and join them using slashes"
$/ join: ($- split: '1969-07-20') reverse
"Sum of the primes up to 64"
(Integer primesUpTo: 64) sum
"Extract a Unix format timestamp from the 5th to 8th byte of a byte array given in hex"
DateAndTime fromUnixTime:
  ((ByteArray readHexFrom: 'CAFEBABE4422334400FF') 
      copyFrom: 5 to: 8) asInteger
"Return the weekday of a date"
'2013/5/7' asDate dayOfWeekName
"Save the HTML source of a web page to a file"
'http://www.pharo.org' asUrl saveContentsToFile: 'page.html'
"Count the number of, or show the leap years between two years"
(1914 to: 1945) count: [ :each | Year isLeapYear: each ].
(1895 to: 1915) select: [ :each | Year isLeapYear: each ].
"Encode the same string using Latin1, UTF-8 and UTF-16"
#(latin1 utf8 utf16) collect: [ :each | 
  (ZnCharacterEncoder newForEncoding: each)
    encodeString: 'Les élèves Français' ]

In Python, it’s almost impossible to do anything in one line.

Off-side Rule

Python’s use of indentation as syntax is highly controversial. It’s the main reason why so many developers hate Python. One issue is that an accidental misalignment of code can cause a very subtle and difficult-to-find bug. Who can claim that accidents never happen?

Pharo doesn’t suffer from this malady.

Object-oriented Programming

Pharo is purely object-oriented from top to bottom. Its clarity and consistency in this regard are unmatched by any other language.

Python, on the other hand, has a makeshift implementation of OOP that feels bolted on. For example, there is no true encapsulation in Python: instance variables and methods are “hidden” or made “private” by prefixing their names with underscores. This is extremely kludgy.

Python requires you to explicitly pass “self” as the first argument to all instance methods. This is unbelievably hokey.

Python objects don’t always have the attribute that you expect. For example, the length property is almost always an external function called len().

Functional Programming

Pharo has a lovely implementation of lambdas in its “blocks.” This provides Pharo with a nice functional programming capability. In fact, Pharo’s class library contains many functional constructs.

Python can also do functional programming after a fashion. However, its lambdas are restricted to a single expression, rather than allowing for multiple lines of code. No other programming language in the world has this restriction! I hesitate to call this hokey and kludgy. (Okay, I lied: it’s hokey and kludgy.)

IDE (integrated development environment)

Pharo has a lovely built-in live coding IDE that’s every bit as simple and easy to use as the language itself. Live coding allows you to inspect and modify the code and data in your program while it’s running! This powerful technique practically eliminates the traditional edit-compile-test-debug cycle that has hampered developers for over half a century. This is the main reason why Pharo (Smalltalk) is the most productive general-purpose programming language in the world, according to a study conducted by Namcook Analytics.

Python’s best IDE is PyCharm. While it’s a nice IDE to be sure, there’s no question that it’s much, much larger and more complex than Pharo’s IDE. It would take a long time to master this program.

And PyCharm doesn’t support live coding.

Productivity and Ease of Development

Python has a reputation for being productive. Namcook Analytics tell us that Pharo (Smalltalk) is twice as productive as Python. This is on average. In many cases, Pharo will be much more productive, sometimes by a factor of five!

Plain and simple, Pharo is just much easier to use for programming. The language and its development environment present virtually no cognitive load on the developer.

Ecosystem

Python has an enviable ecosystem of libraries. This is a weak point for Pharo. Despite this, Pharo is incredibly versatile. It’s used for many different kinds of applications. For example, Pharo is very good for web development, thanks to the Seaside web framework and the Teapot micro framework.

Pharo is very good for front-end development, thanks to Amber and PharoJS.

Pharo is good for data science, thanks to PolyMath and Roassal.

Pharo is good for virtual reality:

Pharo is good for Internet of Things and embedded programming. See Learn How To Program.

Pharo is used to script the Unreal game engine:

Pharo is being used to fight Ebola!

Pharo is used in wide-scale data visualization for medicines in 16 countries.

Pharo is used for natural language processing.

Pharo is used for machine learning and neural network processing.

Smalltalk, in general, is versatile. The U.S. joint military used Smalltalk to write a million-line battle simulator called JWARS. It actually outperformed a simular program called STORM written in C++ by the U.S. Air Force. Whoa! That’s mind-blowing!

Smalltalk was used by JP Morgan to write their massive financial risk management system called Kapital.

Orient Overseas Container Lines used Smalltalk to develop their IRIS-2 shipping management system.

If Pharo is disadvantaged by its ecosystem, it certainly doesn’t seem to slow it down. In fact, I think it’s fair to say that Pharo is more versatile than Python.

Multithreading

Both Pharo and Python can do multithreading, but Python is hampered by the GIL (global interpreter lock), long a complaint of most programmers.

(First published at Code.)

#python

Python vs Pharo
32.30 GEEK