This is also wrong: “The return type is not specif...
# announcements
d
This is also wrong: “The return type is not specified, which means that the function returns nothing.” — Examples https://play.kotlinlang.org/byExample/01_introduction/01_Hello%20world cause it returns Unit — https://pl.kotl.in/-E3uqRzER
n
it probably is wrong technically but this is more of a simplification for beginners
than being meaningfully wrong
t
You're technically right. However, for practical purposes, not returning anything is the same as returning Unit and Unit is not something you really work with directly. It's what you use if there is no (semantic) return value/type. I don't think that's a distinction you have to make on litterally the first, simple introduction example in form of a little Hello World program. You could rephrase it to be technically accurate, but that would confuse people more than it would help. I'm actually suprised they went into it in the very next example.
n
Unit doesn't care any useful information, being a monostate type
It's the same as python, in python functions that have no return statements still return None
but when you're just starting out, you tell beginners look, no return statement, so the function doesn't return anything 🤷
btw, the reason for things like Unit is a very clever lesson learned from the failures of Java and C++. Both of these language have a real notion of returning nothing (
void
), it turns out this concept buys you nothing, and makes generic programming a lot more painful sometimes
d
I’m 50/50 here. What if a beginner reads about “Nothing” https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html
n
Nothing is not really something a beginner needs to worry about
a
nothing is neither written as Nothing or under a highlight
Nothing
there shouldn't be any confusion. For beginner, I don't think introducing it to singletons or things like that will work any better.