Just a minor irritation but it would be useful IMO if the set of escape sequences supported by Kotlin could be extended to include the NUL or zero character.
I’ve written some programs recently where I was filling CharArrays which, of course, use NUL as their default element value. When testing whether a particular element was initialized, I’ve then had to use code such as:
if (array[x] == '\u0000') doSomething()
which is a bit long-winded as is the alternative of
0.toChar(). Since there is no implicit conversion between Int and Char, one can’t just use
0 as you would in Java.
What I’ve tended to do when a lot of NULs are used in a program is to define a global compile time constant:
const val NUL = '\u0000'
which is not too bad.
Most C-based languages use ‘\0’ to represent NUL though as Kotlin doesn’t support octal escape sequences this isn’t available either. Perhaps ‘\z’ would be a better choice though it would be a breaking change - albeit a very minor one.
A shorter notation for NUL might also be useful in Kotlin Native when one is dealing with null terminated C string buffers and the like.
What do others think - worth adding something or not?