Tags

,

Here, I start the Curiosities series, that will show curious data about languages, databases and everything cool and relevant. On this post: difference on the return of the methods.

You may have wondered: “And the other programming language? How It Works? How is that on this language?”
Well, let’s start …

Java, C# and most programming languages

  • On Java, C# and most programming languages, there’s a “return” statement that returns a value or an object. (Java Example)

Java_Return

Visual Basic (VB)

  • On VB, the return is passed to a variable with the name of the function

VB6

Python and Lua

  • Follow the Java model, but it is also possible to return more than one parameter (Python Example)

Python_Return

Or

Python_Return2

Ruby, Groovy and Scala

On these languages, the last line is the return. Thus, the use of “return” is optional, but is not commonly used. (Ruby Example)

Ruby_Return

Ruby, Groovy and Scala also can return more than one value.

PHP

The PHP also follows Java model, but PHP 7 joined a new model where the return type of the method is defined in the end of function definition.

PHP_Return

GO

As PHP 7, the Go language (Golang) also features the return type of the method in the end of function definition, but as Lua and Python, can return more than one parameter.

Go_Return

Javascript

Javascript also follows the Java model, but has a very different particularity and, particularly, I think very cool: Javascript can return a function. That’s right, a function. Example below:

Javascript_Return

Python also can return a function.

That’s it. Do you have any language that you know that has a different type in return? Let me know in the comments.

Advertisements