Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Objective-C doesn't support method overloading?

Objective-C doesn't support methods overloading.
Why?
Is it doable but Apple decided not implement it? or it is not doable due the dynamic nature of Objective-C?

I have the impression that method overloading can be done on compiled languages (Java, C#) and can't be done on interpreted languages (Ruby, Python).
Holds some true?

like image 619
Chiron Avatar asked Dec 14 '10 22:12

Chiron


1 Answers

The distinction that's relevant here is not between compiled and interpreted languages, but between statically typed (Java, C#) and dynamically typed (Ruby, Python, Objective-C). In a dynamically typed language, type information is very often not known until runtime. At runtime, all objects are statically typed as id in Objective-C.

Additionally, a core idea in dynamically typed OO languages is that you should not care what type an object is as long as it responds to the messages you want to send. So overloading based on type would fly right in the face of that.

like image 159
Chuck Avatar answered Oct 08 '22 18:10

Chuck