Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do dynamic languages like Ruby and Python not have the concept of interfaces like in Java or C#?

To my surprise as I am developing more interest towards dynamic languages like Ruby and Python. The claim is that they are 100% object oriented but as I read on several basic concepts like interfaces, method overloading, operator overloading are missing. Is it somehow in-built under the cover or do these languages just not need it? If the latter is true are, they 100% object oriented?

EDIT: Based on some answers I see that overloading is available in both Python and Ruby, is it the case in Ruby 1.8.6 and Python 2.5.2 ??

like image 556
Perpetualcoder Avatar asked Apr 03 '09 20:04

Perpetualcoder


People also ask

Why does Python not have interfaces?

Python does not have interfaces, but the same functionality can be achieved with the help of abstract base classes and multiple inheritance. The reason for not having interfaces is that Python does not use static typing, so there's no compile-time type checking.

What are the advantages of Ruby over Python?

Advantages of RubyRuby has a clean and easy syntax, which allows a new developer to learn very quickly and easily. Just like Python, it's open source. Ruby language was developed to make the developer's work faster, and it gives freedom to developers to develop any size of the web app in shorter time duration.

Why is Ruby better than Python?

Python is generally better for educational use or for people who want to build quick programs rather than work as developers, while Ruby is better for commercial web applications. There are more specific differences when comparing Ruby versus Python, and they have in common that there are many ways to learn both.


1 Answers

Thanks to late binding, they do not need it. In Java/C#, interfaces are used to declare that some class has certain methods and it is checked during compile time; in Python, whether a method exists is checked during runtime.

Method overloading in Python does work:

>>> class A:
...  def foo(self):
...    return "A"
...
>>> class B(A):
...  def foo(self):
...    return "B"
...
>>> B().foo()
'B'

Are they object-oriented? I'd say yes. It's more of an approach thing rather than if any concrete language has feature X or feature Y.

like image 100
andri Avatar answered Sep 21 '22 10:09

andri