Why use the "is" variable beginning in Kotlin?

3

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

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

    get(){
        return height == width
    }
}
    
asked by anonymous 26.11.2017 / 17:06

1 answer

7

This has nothing to do with Kotlin or any other language, it is just a convention that is used to indicate that the variable is Boolean, is to give readability by showing the semantics of it.

It has little to do with set , although it can be used on it.

Some consider it a disguised form of Hungarian notation , others consider it not because it shows the real meaning of the variable. If you remove this prefix you can not tell what it is, if you put something else it can get bigger and still not be suitable.

Of course, is is just an example that tells you if something is or is in a certain state. has is also used to indicate if it has something. But you can use several other ways to prefix a noun and adjectivize its meaning, such as can to indicate if you have that ability, just to cite one more example.

Some people use it in Portuguese, which may be better to indicate if it is a "transient" state ( está ) or "permanent" ( é ).

I'll tell you more about this in another answer .

    
26.11.2017 / 17:15