cool. Is this preferable? ```fun sql(colb : Int?) ...
# getting-started
n
cool. Is this preferable?
Copy code
fun sql(colb : Int?) = "SELECT * FROM TABLE WHERE A=3 ${colb?.let {" AND B=$it"}.orEmpty()}"
v
Preferable in what sense? IMO including the last bit inside a string literal is an unnecessary complication
n
The point of templates seems to me that you don't need to use string concatenation. Your example was using a '+' in theory this could create more than one stringbuilder
v
Do you think that would be a bottle neck of your program?
The point of templates IMHO is increase readability in simple cases
BTW, @nikolaymetchev, I just checked the byte code that kotlinc generates, and it uses a
StringBuilder
in place of
+
operations on strings
So feel free to use
+
and string templates however you like and allow the compiler to do the optimizations 😄
n
Sorry about the slow response. The java compiler generates a StringBuilder also for + operations. My original point was that the code could in theory generated more than one StringBuilder for the whole expression instead of just the one. I realise it is not going to be a major bottleneck and I don't think performance should be a consideration in this example. However it feels to me that the whole point of templates was to get rid of the use of + as it is less readable.