Learning a New Programming Language Part 3: Syntax Differences - Defining Functions
(Page 4 of 7 )
Declaring functions is yet another thing that varies from language to language. In Python the keyword "def" is used.
Python functions also have a unique feature called a "doc string" that is the first thing defined in a function.
"""this function returns a number"""
Doc strings are triple quoted and can be used as a property of the function (in Python functions are objects just like everything else). This allows Python IDEs, for instance, to use the doc string for context sensitive help.
Ruby does not have functions, just methods. The syntax is not that dissimilar to functions in other languages.
Objective C Message Passing
Objective C is an object oriented subset of the C language. It was originated by the NEXT computer company as part of their Nextstep and Openstep operating systems. NEXT was bought by Apple, who made Objective C the foundation of it's cocoa programming environment. There is also a multi-platform open source implementation of Objective C called GNUStep.
There are just as many concepts to learn about Objective C as any other object oriented language, but it does have a unique syntax for calling methods that will take some getting used to. Objective C code does not so much call methods as send messages to objects. A message is contained in square brackets.
int result = [myObject mymethod:myvalue:myothervalue];
Inside the brackets is the name of the object we are sending the message to, then the name of the method. After the method name is a colon, followed by an argument to the method, and in this example, another colon and argument.
Finally, Objective C, unlike most compiled languages, has some control over code execution at run time similar to interpreted languages.
More Web Hosting How-Tos Articles
More By Chris Root