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)
Visual Basic (VB)
- On VB, the return is passed to a variable with the name of the function
Python and Lua
- Follow the Java model, but it is also possible to return more than one parameter (Python Example)
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, Groovy and Scala also can return more than one value.
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.
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.
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.