When comparing Python vs Ruby, the Slant community recommends Python for most people. In the question“What is the best programming language to learn first?” Python is ranked 1st while Ruby is ranked 10th. The most important reason people chose Python is:
Python's popularity and beginner friendliness has led to a wealth of tutorials and example code on the internet. This means that when beginners have questions, they're very likely to be able to find an answer on their own just by searching. This is an advantage over some languages that are not as popular or covered as in-depth by its users.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Lots of tutorials
Python's popularity and beginner friendliness has led to a wealth of tutorials and example code on the internet. This means that when beginners have questions, they're very likely to be able to find an answer on their own just by searching. This is an advantage over some languages that are not as popular or covered as in-depth by its users.
Pro Active and helpful community
Python has an active and helpful community, such as the comp.lang.python Google Groups, StackOverflow, reddit, etc.
Pro Easy to get started
On top of the wealth of tutorials and documentation, and the fact that it ships with a sizeable standard library, Python also ships with both an IDE (Integrated Development Environment: A graphical environment for editing running and debugging your code); as well as a text-based live interpreter. Both help users to get started trying out code immediately, and give users immediate feedback that aids learning.
Pro Comes with extensive libraries
Python ships with a large standard library, including modules for everything from writing graphical applications, running servers, and doing unit testing. This means that beginners won't need to spend time searching for tools and libraries just to get started on their projects.
Pro Can be used in many domains
Python can be used across virtually all domains: scientific, network, games, graphics, animation, web development, machine learning, and data science.
Pro Clear syntax
Python's syntax is very clear and readable, making it excellent for beginners. The lack of extra characters like semicolons and curly braces reduces distractions, letting beginners focus on the meaning of the code. Significant whitespace also means that all code is properly and consistently indented.
The language also uses natural english words such as 'and' and 'or', meaning that beginners need to learn fewer obscure symbols. On top of this, Python's dynamic type system means that code isn't cluttered with type information, which would further distract beginners from what the code is doing.
Pro Cross-platform
Installs and works on every major operating systems if not already installed by default (Linux, macOS).
Pro Has many libraries for scientific computing, data mining and machine learning
Python is commonly used in data science and has many libraries for scientific computing, such as numpy, pandas, matplotlib, etc.
Pro Good documentation
The Python community has put a lot of work into creating excellent documentation filled with plain english describing functionality. Contrast this with other languages, such as Java, where documentation often contains a dry enumeration of the API.
As a random example, consider GUI toolkit documentation - the tkinter documentation reads almost like a blog article, answering questions such as 'How do I...', whereas Java's Swing documentation contains dry descriptions that effectively reiterate the implementation code. On top of this, most functions contain 'Doc Strings', which mean that documentation is often immediately available, without even the need to search the internet.
Pro Very similar to pseudo-code
When learning Computer Science concepts such as algorithms and data structures, many texts use pseudo-code. Having a language such as Python whose syntax is very similar to pseudo-code is an obvious advantage that makes learning easier.
Pro It's really simple
It's very simple for understanding how programming works. If you don't like programming in Python, you probably won't like programming. It is a good way to find out with little investment. If you like, it is a great language. I wouldn't look for a language that has everything you eventually need to know in programming, such as static typing, in my first language. It should be easy to learn. You can pick up the hard stuff later if you tackle C or C++ or assembler. It will make learning them much easier. If you start with them, you might quit programming due to the difficulty of learning.
Pro Easy to find jobs
Python's popularity also means that it's commonly in use in production at many companies - it's even one of the primary languages in use at Google. Furthermore, as a concise scripting language, it's very commonly used for smaller tasks, as an alternative to shell scripts.
Python was also designed to make it easy to interface with other languages such as C, and so it is often used as 'glue code' between components written in other languages.
Pro Advanced community projects
There are outstanding projects being actively developed in Python. Projects such as the following to name a random four:
- Django: a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
- iPython: a rich architecture for interactive computing with shells, a notebook and which is embeddable as well as wrapping and able to wrap libraries written in other languages.
- Mercurial: a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface.
- PyPy: a fast, compliant alternative implementation of the Python language (2.7.3 and 3.2.3) with several advantages and distinct features including a Just-in-Time compiler for speed, reduced memory use, sandboxing, micro-threads for massive concurrency, ...
When you move on from being a learner you can still stay with Python for those advanced tasks.
Pro Supports various programming paradigms
Python supports three 'styles' of programming:
- Procedural programming.
- Object orientated programming.
- Functional programming.
All three styles can be seamlessly interchanged and can be learnt in harmony in Python rather than being forced into one point of view, which is helpful for easing confusion over the debate amongst programmers over which programming paradigm is best, as developers will get the chance to try all of them.
Pro Good introduction to data structures
Python's built-in support and syntax for common collections such as lists, dictionaries, and sets, as well as supporting features like list comprehensions, foreach loops, map, filter, and others, makes their use much easier to get into for beginners. Python's support for Object Orient Programming, but with dynamic typing, also makes the topic of Data Structures much more accessible, as it takes the focus off of more tedious aspects, such as type casting and explicitly defined interfaces.
Python's convention of only hiding methods through prefacing them with underscores further takes the focus off of details such as Access Modifiers common in languages such as Java and C++, allowing beginners to focus on the core concepts, without much worry for language specific implementation details.
Pro One right way to do things
One of the Guiding Principles of Python is that there should be only one obvious way to do things. This is helpful for beginners because it means that there is likely a best answer for questions about how things should be done.
Pro Easy to learn, More to Go
It is very easy to learn and it has community support and many categories available.
Pro Mobile versions
Mobile versions are available but can be difficult to find. Examples for android are pydroid and qpython
Pro Interpreters for JS, Microtontrollers, .Net , Java & others
Python is not limited to just be cross platform. It goes far beyond all high level languages since it can run on top of several other frameworks & architectures :
Examples of interpreters:
- Standard (PC Win/Lin/Mac, ARM, Raspberry, Smartphones): CPython usually, but some more specialized for smartphones: Kyvi, QPython, ...
- Web Browser JS : Brython, PyJS,
- .Net : IronPython
- Java: Jython
- Microcontrollers with WiFi like ESP8266 or ESP32: MicroPython
- Can be statically compiled (instead of interpreted) with Cython. (Do not mix up with cPython)
With python, you're sure your code can run (almost) everywhere, from 2€ computers to the most expensives.
So, for instance, with Jython you can access the Java libraries with Python language.
Pro Static typing via mypy
Python's syntax supports optional type annotations for use with a third-party static type checker, which can catch a certain class of bugs at compile time. This also makes it easier for beginners to gradually transition to statically typed languages instead of wrestling with the compiler from the start.
Pro Has features of both high and low level language
It is somewhere between C and Java.
Pro Best chances of earning most money
According to Quartz, Python programming skills on average earn $100,000 per year. Closely followed by Java, C++, JavaScript, C, and R with $90,000 per year and above.
Pro Easy for new users and experienced programmers
(If you can get over whitespace formatting)
Pro Import Turtle
Do something visually interesting in minutes by using the turtle standard library package.
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an import turtle, give it the command turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.right(25), and it rotates in-place 25 degrees clockwise.
Turtle can draw intricate shapes using programs that repeat simple moves.
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
Pro Includes pygame library
Want to start game development? No problem! Using pygame open-source library you can fast begin creating games without worrying about pointers or undefined behaviors which they exists in C/C++.
Pro Widely used
Ruby is one of the most popular languages for developing web sites. As a result, there's an abundant amount of documentation, sample code, and libraries available for learning the language and getting your project up and running. The most popular features are just 'gem install' away. Additionally, it is easier to find Ruby jobs because of this.
Pro Clean syntax
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters.
presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"]
for ss in 0...presidents.length
print ss, ": ", presidents[presidents.length - ss - 1], "\n";
end
Pro A large ecosystem of tools & libraries
Ruby has a large ecosystem of tools and libraries for just about every use. Such as ORMs (Active Record, DatabMapper), Web Application Frameworks(Rails, Sinatra, Volt), Virtualization Orchestration(docker-api, drelict), CLI tools(Thor, Commando), GUI Frameworks(Shoes, FXRuby) and the list goes on. If you can think of it, there is probably a gem for that ( and if not you can create your own and share with the community).
Pro Newbie-friendly community
Pro Essential algorithmic features
The Ruby language is equipped with the necessary features to learn the essence of algorithms.
In online playground environments like ideone.com, measures have been taken to prevent beginners from going astray by restricting the use of external libraries such as Python's NumPy and SymPy.
Even in such constrained Ruby execution environments, the required features for learning algorithms are fully available.
Many of the algorithms that should be learned are documented in the book "Hello Ruby: Adventures in Coding." For example, the cake serving problem in the book leads to topological sorting, which is a graph theory concept useful in project management for creating Gantt charts.
To evaluate the effectiveness of algorithms with a level of complexity comparable to topological sorting,
it is necessary to be able to solve mathematical computation problems up to the high school level easily.
As shown in the table below, using only Ruby's standard library, it is possible to solve high school-level math problems effortlessly.
However, other programming languages may not be able to perform such computations in online playground environments.
To experience the superior performance of algorithms, it is important to challenge oneself by reimplementing good algorithms. Ruby's standard library includes implementations of excellent algorithms. For instance, the algorithm for solving linear equations, which has been widely known since the era of Fortran, is used within the code of SolvingLinearEquations through the "/" operator. Reimplementing code from Ruby's standard library serves as an excellent learning resource with high reusability and efficiency.
The SolvingLinearEquations function mentioned above demonstrates the benefits of duck typing and forced type conversion between objects of different types in arithmetic operations. While Rust also has features like duck typing, the implementation of "forced type conversion" is still far from being realized.
Mathematical Problem Type | Ruby Standard Library | Python Standard Library |
---|---|---|
Long Integer and Fraction | ✓ | ✓ |
Long Integer and Complex Fraction | ✓ | ✖ |
Operations on Matrices with Multiple-Digit Numbers as Coefficients | ✓ | ✖ |
Solution of Integer Coefficient Systems of Equations | ✓ | ✖ |
Solution of Systems of Equations with Long Integer and Complex Fraction Coefficients | ✓ | ✖ |
Solutions of Linear Equations with Real, Fraction, Complex, and Complex Fraction Coefficients | ✓ | ✖ |
# Title: "(1) Cake Serving Procedure Problem"
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end
puts 'Tasks'
task_names = {
'A' => 'Arrange the plates.',
'B' => 'Set the spoons.',
'C' => 'Place the birthday cake on the table.',
'D' => 'Spread the tablecloth.'
}
p task_names
puts 'Preceding Tasks'
preceding_tasks = {
'A' => ['D'],
'B' => ['C', 'A'],
'C' => ['A', 'D'],
'D' => []
}
steps = preceding_tasks.strongly_connected_components
puts 'The appropriate steps are as follows:'
steps.each do |task_candidates|
p task_candidates.map { |task| [task, task_names[task]] }
end
p "#(2) Equation Solving Rule"
def SolvingLinearEquations(y, a, b)
x = (y - b) / a
end
p "(2-1) Real Solution", SolvingLinearEquations(1.0, 5, 0.5)
# => 0.1
p "(2-2) Fraction Solution", SolvingLinearEquations(Rational(1, 1), Rational(5, 1), Rational(1, 2))
# => (1/10)
p "(2-3) Imaginary Solution", SolvingLinearEquations(1 + 1i, 5, 1.0 / (2 + 2i))
# => (0.15+0.25i)
p "(2-4) Complex & Fraction Solution", SolvingLinearEquations(Rational(1 + 1i, 1), Rational(5, 1), Rational(1, 2 + 2i))
# => ((3/20)+(1/4)*i)
p "(2-5) Matrix Solution with Large Integers",
SolvingLinearEquations(Matrix[[Rational(1234567890123456789890, 1), Rational(0, 1)]],
Matrix[[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 2, 1)],
[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 3, 1)]],
Matrix[[Rational(1234567890, 1), Rational(123456789, 1)]] )
# => Matrix[[(3703703670366790122789/1234567890123456789890), (-2469135780244567900789/1234567890123456789890)]]
p "(2-7) Matrix Solution with Large Integers, Complex Numbers, and Fractions",
SolvingLinearEquations(Matrix[[Rational(1234567890123456789890, 1i), Rational(0, 1)]],
Matrix[[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 2, 1i)],
[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 3, 1i)]],
Matrix[[1234567890, 0 + 1i]] )
# => Matrix[[((-3703703671/1234567890123456789890)-(3/1)*i), ((2469135781/1234567890123456789890)+(2/1)*i)]]
Pro Ruby on Rails
Lays out an easy to follow and opinionated MVC pattern that teaches best practices through necessity.
Pro Test Driven Development, #1
It's the fore-runner and trend setter for TDD.
Pro Hugely object oriented
Object oriented programming is one of the most important concepts in programming.
Pro Meta-programming
Meta-programming provides efficiency and freedom.
Pro No indentation
No indentation increase development efficiency.
Pro Pry
Cons
Con Not good for mobile development
You can use frameworks like Kivy, but if your ultimate goal is to write mobile apps Python may not be the best first choice.
Con Inelegant and messy language design
The first impression given by well-chosen Python sample code is quite attractive. However, very soon a lack of unifying philosophy / theory behind the language starts to show more and more. This includes issues with OOP such as lack of consistency in the use of object methods vs. functions (e.g., is it x.sort() or sorted(x), or both for lists?), made worse by too many functions in global name space. Method names via mangling and the init(self) look and feel like features just bolted on an existing simpler language.
Con Language fragmentation (this is finally starting to go away)
A large subset of the Python community still uses / relies upon Python 2, which is considered a legacy implementation by the Python authors. Some libraries still have varying degrees of support depending on which version of Python you use. There are syntactical differences between the versions.
Con Worst language design ever
Instead of sticking to a certain paradigm, the original writer of the language couldn't make up his mind, and took something from everywhere, but messing it up as he went by. This is possibly one of the worst balanced languages ever. People who pollute their mind with Python and think it's the next best thing after sliced bread, will have to un-learn a lot of garbage 'pythonesque' habits to actually learn how to program. It's not because the academic world uses it a lot, that it's a good language. It says something about the inability of the academic world to write decent code, actually.
Con Hard to debug other people's code
As the structure of Python code is based on conventions many developers are not following them and so it is difficult to follow/extract the design of not trivial application from the code. While this is a con, I see it in other languages as well. It seems to depend on the programmer. Most people don't learn conventions first, they just start programming. Unless you work for someone who insists you follow the conventions, you will probably go with what you like. You might never look at the conventions.
Con Multi-threading can introduce unwanted complexity
Although the principals of multi-threading in Python are good, the simplicity can be deceptive and multi-threaded applications are not always easy to create when multiple additional factors are accounted for. Multi-thread processes have to be explicitly created manually.
Con The process of shipping/distributing software is reatively complicated
Once you have you program the process of having a way to send it to others to use is fragile and fragmented. Python is still looking for the right solution for this with still differences in opinion. These differences are a huge counter to Python's mantra of "There should be one-- and preferably only one --obvious way to do it."
Con Limited support for functional programming
While Python imports some very useful and elegant bits and pieces from FP (such as list comprehensions, higher-order functions such as map and filter), the language's support for FP falls short of the expectations raised by included features. For example, no tail call optimisation or proper lambdas. Referential transparency can be destroyed in unexpected ways even when it seems to be guaranteed. Function composition is not built into the core language. Etc.
Con Unflexible userbase
You will be expected to rigidly stick to the coding practices and to do everything by-the-numbers. One of the most common complaints I heard from people who left Plone, which is Python based, to Drupal, which is PHP based, is the community is more like a frat house than a community. If you look for help, make sure you follow the rules of whatever type of group you are requesting help from.
Con Too opinionated for a general-purpose programming language
While it's a good language to learn and use after you have mastered a couple of other less rigid programming languages, it's definitely not good for first-time learners. Both the language itself and its community have made it quite clear that you should do everything the "Pythonic way" to get the best results, that it feels more like an opinionated framework instead of a general-purpose programming language, which means if you are a first-time learner and getting too "tuned" to the "Pythonic way" it will be much harder for you to learn other less-opinionated languages compared to the other way around. Like any programming languages and/or frameworks, I'd recommend first-time learners to learn less opinionated ones first to open up your mind, then learn some of the more opinionated ones to increase productivity for specific fields of works.
After all, programming languages are just some utilities for the human mind to interface with the computers, and there are more suitable tools for different tasks, and you should master the "Pythonic way" (after you already have adequate experience in computer programming) instead of locking your mind too close to the "Pythonic way" as a first-time learner.
Con Abstraction to the point of hinderance
Python is abstracted far enough that if it's your first language, it will be harder to pick up lower level languages later versus going the other direction.
Con Does not teach you about data types
Since Python is a dynamically typed language, you don't have to learn about data types if you start using Python as your first language. Data types being one of the most important concepts in programming. This also will cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Might not be very future-proof
Lots of features that will probably be crucial as time goes (good support for parallelism for example) are missing or are not that well-supported in Python. Since 2.x and 3.x still exist, be prepared to switch if something makes 3.x take off in the future.
Con Significant whitespace
While proper formatting is essential for any programmer, beginners often have trouble understanding the need and lack the discipline to do it. Add to that all those editors that randomly convert N spaces (usually 8) to tabs and you get an instant disaster. You may need to find yourself an editor/IDE you like and carry it with you on a thumb drive, which isn't a bad idea anyway.
Con It is best suited for scripting, but so are many other languages
i.e. running js as a script in a node is trivial. Even languages that were not meant to run as a script are easy to use as a scripting language with just a .sh file.
Con Version Confusion with V2.x and V3.x
Con Bad for games
Python has a lot of frameworks like pygame, but exporting the game is hard and building files like .exe gets very large and have a bad performance on bad computers.
Con Not a serious coding language
If you consider it your first language, better pick Julia!
Con Fails in comparison to Nim
Everywhere that counts, Nim is superior, according their people. Nim should be standing where Python is. It is only cruel fate and the maneuvers of the cabal that Nim is not standing over Python in victory.
Con Multi-threaded programs are too slow
Because of the GIL, multi-threaded programs run too slow, in an already slow interpreted language.
Con Moving large blocks of code in whitespace sensitive languages is scary
Quoting inventor of the V language: "V's syntax is cleaner with fewer rules. Lack of significant whitespace improves readability and maintainability of large code bases and makes generating code much easier. From my experience of working with a huge Python code base, moving large blocks of code in whitespace sensitive languages is scary."
Con Assignment
Heavily relies on assignment, with no distinction between defining the variable and assigning the value. This makes it necessary to introduce rather complex environmental model of computation.
Con Monkeypatching
Requiring a library can change the rules of the language. This is very confusing for beginners.
Con Its ecosystem is limited outside of web development
If you're looking to host, generate, manipulate or secure a website, Ruby is your language. There's also some great support here for infrastructure as code work via Chef. However, it just doesn't have the depth and breadth that Python does. Things like native UI development, high performance math, and embedded / small footprint environments are barely supported at all in Ruby-space.
Con Arcane grammar based on Perl
Ruby is too complicated for beginners:
- arcane Perlisms;
- semi-significant whitespace;
- parentheses are not necessary around method arguments, except for sometimes they are;
- control constructs could be elegantly implemented with block like Smalltalk (Instead they're baked into the grammar.);
- verbose block syntax, unless it happens to be the last argument. (proc lambda).
- There are too many exceptional cases and arcane precedence rules.
Con Meta-programming causes confusion for new developers
The ability for libraries to open classes and augment them leads to confusion for new developers since it is not clear who injected the functionality into some standard class.
In other words, if two modules decide to modify the same function on the same class can introduce a number of issues. Mainly, the order in which the modules are included matters. Since you more or less can't tell what kind of "helper" functions a module might write into any class, or for that matter, where the helper function was included from, you may sometimes wonder why class X can do Y sometimes but not at other times.
Con No docstrings
It's hard to access Ruby's documentation from the REPL (irb), unlike Python, Lisp, and Smalltalk which let you ask functions how to use them, which is a great benefit to the beginner, and which also encourages you to document your program as you code it.
Con More than one way to do it
A problem inspired by Perl. The core API interfaces are bloated. There's at least four different ways to define methods. More is not always better. Sometimes it's just more.
Con Does not teach you about data types
Since Ruby is a dynamically typed language, you don't have to learn about data types if you start using Ruby as your first language. Data types being one of the most important concepts in programming. This also will cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Dynamic type system
Majority of bugs could be resolved with types.
Con Viewed as a web development language
Despite its flexibility and performance, Ruby is often seen as being unsuitable for other tasks by those who are not familiar with it. As such, a lot of discussion about it centers around Rails, which is not at all relevant if you're using Ruby for something else, such as game development.
Con Focus on Object-Oriented Programming (OOP)
Focussing on OOP in a beginner stage is an easy and popular plan, but not the best one.