ویرگول
ورودثبت نام
snehacynixit
snehacynixit
snehacynixit
snehacynixit
خواندن ۱۲ دقیقه·۵ سال پیش

Ruby vs Python [Infographic + Updated for 2020]

Python and Ruby are two of the best examples of the new generation of high-level languages which focus on simplicity and giving the programmer the ability to get things done fast, rather than syntax correctness and strict hierarchy (insert cough that sounds like “Java!” here).

First the similarities. Both are high-level, object-oriented languages. Both provide an interactive shell, standard libraries, multiplatform support across Linux, Unix, Windows and other operating systems, as well as persistence support. ruby on rails online training for more skills and techniques.

They are also both excellent for web development, more so when you take advantage of each language’s purpose-built web frameworks – Django for Python and Rails for Ruby. That said, Ruby on Rails is somewhat more popular as a web development tool than Django-Python. Python is favored more in the academic and scientific arenas.

But beyond that they also have some major differences. They also, surprisingly, have their passionate adherents and equally passionate detractors, which has resulted in more than one flame war that’s degenerated into insults and ad hominem attacks, and even into Godwin’s law. None of that here; we’ll delve into objective assessments and stick to what each language can or cannot do.

1. Ruby

Ruby was created in 1995 by the renowned Yukihiro “Matz” Matsumoto and was influenced by C, Perl, Java and C++. It is unabashedly object-oriented; in Ruby everything is an object. Some famous sites built using Ruby (on Rails) are Twitter, Hulu, Shopify, and Groupon.

From the very beginning, Ruby’s ethos has always been expressiveness, power and elegance. Its dedicated followers love it for its ‘principle of least astonishment’ - the belief that a language’s code should always cause as little confusion as possible for the developer.

This guiding principle naturally leads to Ruby’s inheritance of the Perl philosophy of having more than one way to do the same thing. This is the main difference between it and Python, as we’ll see later. This in turn means that a method can have multiple names, and this could lead to confusion for newbies.

2. Python

Python was created in 1991 by Guido van Rossum, inspired by a multitude of languages – C/C++, java, Lisp, Perl and ICON. Some famous Python-built websites are Google, Dropbox, Reddit, and Youtube.

Unlike Ruby with its daring, somewhat adventurous nature, Python is somewhat conservative. Python abhors Ruby’s ‘many ways of doing something’ school of thought, which Ruby has in common with languages like Perl and PHP; instead Python has always stressed that there is only one best way to do something, and the language should do it that way. This results in a language strict on layout and indentation and even the amount of whitespace to use (!), which of course feels stifling to Ruby proponents. However, this regimented philosophy results in Python being supremely readable and easy to learn – in fact a good number of schools and colleges use Python as a teaching aid. Its syntax is very simple, there is little to remember, and it is thus great for beginners.

Python also boasts extensive libraries and an OO nature, though this is not as ‘pure’ as Ruby’s and is similar to object orientation in C++. Some more features in which Python is superior to Ruby are listed below.

  • Better namespace handling and use of modules
  • Central use of iterators
  • Internal functions
  • A richer set of data structures

3. Web Apps: Ruby Has The Edge

Web development remains one of the chief arenas in which Ruby and Python compete. Sure, there is server scripting, enterprise apps, mobile apps, and now machine learning, but the traditional user of these languages was the web developer. In the web applications arena, for better or for worse, Ruby has been the much more dominant player, thanks to Ruby On Rails.

Ruby’s flexibility, fully promoted by its philosophy that allows multiple ways of getting the same thing accomplished, is a boon to web developers. It’s tempting to think that one simple way of doing things will work for everyone, but when the use cases that web developers diverge as widely as they do, it’s only practical to let multiple approaches flourish. In this case, the success of Ruby is reminiscent of that of C++, a much-maligned language that has succeeded so widely because it lets any team pick whichever particular subset of the language they want to use.

Ruby On Rails is like Ruby on steroids, complete with extensive behind the scenes code generation and server-side metaprogramming that would make coders in a more staid language community raise eyebrows. Indeed this was the case when Django, over in Python land, emulated the Rails MVC approach and immediately faced pushback from Pythonistas who thought the framework was doing too much and getting too complex, out of line with the Pythonic emphasis on readability. Where Python programmers, and Django, went with simplicity, Ruby On Rails went with power and flexibility. True, it can get complex, but the flexibility has proven valuable for web developers. This has led to Rails being almost a rite of passage for “cutting edge” startups especially those developing B2C platforms, with a plethora of big successes such as Airbnb, Twitter, Github, and others too many to count. Rails development is insanely fast, hyper productive, and allows an early stage startup to iterate flexibly with next to no technical staff beyond a couple of core ROR developers. Ruby has also done well in devops, with tools like Chef taking full advantage of the expressive power of the scripting language.

4. Ruby Vs Python: Open Source Community

In numbers, Python has a stunning edge, but that’s to be expected given how versatile Python is as a general-purpose programming language. Its simplicity and beginner-friendly semantics has seen it make deep inroads into just about any area of computing imaginable. The numbers speak for themselves. Python has an estimated 8.2 million developers around the world, nearly four times the estimated 1.8 million developers that Ruby has. Python’s community dwarfs Ruby in this respect.

However, it’s good to be aware of how passionate the Ruby community is. This counts for a lot more than it would seem on the surface. In technical circles, the mere size of a community can be dwarfed by the passion of the community. Languages with unique features that are valued by their niche communities can have very passionate devotees.The functional family of languages like Haskell, O’Caml, and Elixir are good examples. They have tiny communities, and have had for years, but these languages have not disappeared, or their communities grown disenchanted with them. Rather, whether at Wall Street banks doing esoteric derivatives computations or in academia, their adherents have dug in even deeper and there is a lot of dynamism in these much smaller communities. Ruby’s community looks a lot like them in this respect.

5. Machine Learning: Python Has The Edge

Data science and machine learning are just coming into their own, but, the world is now realizing the portent power of data science, spanning all the way from big data to artificial intelligence (AI), and deep learning. Data science, and machine learning in particular, allows machines to make human-like decisions and “learn” from data to get better over time at solving a dizzyingly wide assortment of problems. A lot of value has been unlocked and, naturally, businesses from tech giants like Google to small scrappy startups, are gearing up and making strides in this lucrative field. This has proven to be Python’s most portent area of accomplishment. ruby on rails online course from industrial experts.

A machine learning comparison is a nightmare scenario for just about any language when matched up against Python. Indeed, in data science circles, especially those in academia, the comparison between Ruby and Python in this sphere would not warrant much beyond a cursory dismissal of Ruby.

6. Ruby Vs Python: Frameworks And Libraries

As open source programming languages with particularly vibrant communities, both Ruby and Python have stunningly complete ecosystems, with libraries that showcase the power of the open source ethos. Just about anything you can imagine can be accomplished with freely available open source packages in either programming language.

Other software distribution systems to complement these exist, and there’s excellent tooling on both sides. This is a commonality between Ruby and Python that makes the communities, so different in many ways, much closer in their approach to open source.

Here’s a look at some of the top libraries in the Ruby ecosystem:

  • Web App Frameworks - rails, sinatra, rack
  • Web servers - puma, unicorn
  • Database adapters - pg, mysql2
  • Ruby core extensions - activesupport, hashie
  • Concurrent processing - eventmachine, concurrent-ruby
  • Testing tools - rspec, capybara, minitest

For Python, a who’s who of top libraries showcases the broader areas of focus where the Python programming language has made serious inroads, with a pronounced focus on areas related to data science:

  • Django (web framework)
  • Numpy (data science)
  • Pandas (data science)
  • Matplotlib (data science)
  • Scipy (data science)
  • Flask (web framework)
  • Keras (machine learning, deep learning)
  • Theano (data science)
  • TensorFlow (machine learning, neural networks)
  • Scikit-learn (machine learning)
  • PyQT (graphical user interface, GUI development)
  • wxPython (GUI development)
  • Pygame (video game development)
  • Tkinter (GUI package)

Python’s vast data science footprint continues to grow, and its data science libraries, in many ways the leading libraries in that respect, are growing in user adoption among Python developers.

7. Ruby Vs Python: Code Side By Side

Ruby code and Python code has a lot in common, but there are subtler differences, especially in coding idioms driven largely by philosophical differences. Both are dynamic, interpreted languages. Both use white space and don’t have the braces made popular by C, C++, and Java, among other languages. These languages are truly versatile, however, as revealed by the paradigms they support: procedural, imperative, functional, and object-oriented. Yes, certain super functional-style code is far easier to write in Ruby than in Python, but Python, despite its drive for simplicity, can be used in ways rather similar to Ruby. Ruby, however, tends to be more expressive, and strikes a bit closer to functional languages like Lisp or Scheme than Python. Syntactically, and in many other ways, Ruby code looks a lot more like Python.

Here is a simple example that illustrates how close these two really are, while being far from the clones they might look like on the surface:

Fibonacci function in Ruby

def fib(n)

n < 2 ? n : fib(n-1) + fib(n-2)

end

alias :fibonacci :fib

Fibonacci function in Python

def fib(n):

if n < 2:

return n

else:

return fib(n-1) + fib(n-2)

The Python code is just a tad simpler, while the Ruby code prefers power over simplicity. Still, both of these are much closer than would be examples in Java, C++, and other languages. What this means is that if your team ever has to switch language, moving from Ruby to Python or vice versa, while often considered inconceivable by deep enthusiasts in either software development camp, the sky would not exactly fall down. The learning curve is much easier to scale for developers and teams moving from one to the other, than it would be to move to a language such as C, C#, or even Erlang.

8. Conclusion

Despite the noisy arguments from both languages’ camps, it is impossible to say whether one language is overall ‘better’ than the other. It’s clear that each has some areas it is better suited to, because of its features and support from other users in the same area. ruby on rails training for more effective learning.

For Ruby this is web development via the Rails framework, and for Python it is scientific and academic programming. And each has some features or capabilities that the other does not have or does not do well.

۰
۰
snehacynixit
snehacynixit
شاید از این پست‌ها خوشتان بیاید