I would like some relatively simple QoL improvements for libraries. First: I miss configurable string interpolation. I want to write a wrapper around JDBC, but without proper string interpolation it doesn’t make sense. Formatting should be built-in too, using String.format isn’t good solution. So something like "${a.b:.2f}, where part before :
is kotlin value and part after :
is passed to some function which will perform an actual formatting (for SQL it could be ${s:varchar}
, for example, because JDBC sometimes requires actual DB type with parameter value).
Another improvement would be something like __FILE__
, __LINE__
, __function__
in C. Some kind of compiler magical value: fun logDebug(message: String, file: String = currentFile, line: Int = currentLine)
. Compiler has this information when it compiles file and it’ll be inlined with 0-cost. Retrieving this information in run-time using stack trace is slow and discouraged in release builds. So you can’t have this information in your production logs now, but you could have it with this feature.
And, yes, using nullable private var
now isn’t nice. Something should be done about it. I often encounter this situation when I have to create a local variable just to work with this value. It looks like bad code. May be just allow it for private fields and add something like volatile
to explicitly mark field as unsafe. Compiler could introduce local variable under the hood, if I use this field, that’s OK for me, I just don’t want to see it in my code.