394451 (3) [Avatar] Offline
#1
In Chapter 2, page 19, you write:

This section shows you how to declare variables in Kotlin. In Java you start a variable
declaration with a type. This wouldn’t work for Kotlin, because it allows to omit the
types from many variable declarations. Thus in Kotlin you start with a keyword, and you
may (or may not) put the type after the variable name. Let’s declare two variables:
EXPRESSION BODIES
fun max(a: Int, b: Int): Int = if (a > b) a else b
fun max(a: Int, b: Int) = if (a > b) a else b
2.1.4 Variables
val question =
"The Ultimate Question of Life, the Universe and Everything"
val answer = 42

This is a small issue, but one I would consider "fixing": The term variable is used repeatedly here, and then your illustration uses a "constant" (val).

Of course, it is the word "variable" that is the challenge.

I would change it because people new to programming will absorb all this, and they will misunderstand the types val and var. It matters. Well, it would matter to me if I had written this. (If the reader is not new to programming, she will just have that sinking feeling, if she paid for the book. This is a programming book. Detail matters, I say.)

(And while I am being silly about the words we write, why would you type "answer" as a val? Surely, most often an answer has to be computed and then assigned, and so if it is declared earlier, it should be a var? Is there only one answer to your question? )

PS I have read further, and now will "keep quiet" unless I find something that is just plain "won't work". I began C++ programming in 1994, having worked (without achieving anything much, I admit) in assembler before that. I learned Java from version 1.1. Clearly your book is meant to be a "light touch" across programming using Kotlin, and the responsibility is upon the reader to "learn a bit more" after starting to use the language.

I apologise for my noise, here.
Dmitry Jemerov (39) [Avatar] Offline
#2
Just as an update (better late than never), we've considered this and decided to stick with the term "variable" to describe both "var" and "val". There are not many alternatives: the term "value" is typically used to refer to the contents of the variable, rather than the variable itself, and the term "constant" has a more specific meaning in Kotlin (a "const val").
408399 (15) [Avatar] Offline
#3
I agree, Dmitry. I have seen the term "symbol" in other languages, but I always find it awkward and mentally translate to "variable". The term "name" would be too general, and "container" (rightly or wrongly) seems to imply some type of collection or grouping. And "field" is already taken.