Why use "is" at variable start in Kotlin?

Asked

Viewed 83 times

3

What is the reason for using the is in front of the variable. Example source code. I know it has something to do with the set.

class Rectangle( val height: Int, val width:Int)
{
    val IsSquare: Boolean

    get(){
        return height == width
    }
}
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

8


This has nothing to do with Kotlin or another language, it’s just a convention that is used to indicate that the variable is boolean, it’s to give legibility showing its semantics.

It has nothing to do with set, although it can be used in it.

Some consider a disguised form of hungarian notation, others consider that it does not already show the real meaning of the variable. If you take out that prefix you can’t tell what it is, if you put something else it might get bigger and still not be suitable.

Of course the is is just an example of whether something is or is in a certain state. The has is also widely used to indicate if you have something. But you can use several other ways to prefix a noun and adjective its meaning, such as can to indicate whether it has that capacity, just to quote one more example.

There are those who use in Portuguese, which may be better for indicating whether it is a "transitory state" (está) or "permanent" (é).

I talk more about it in another answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.