Office Hours — Today, November 17

Saturday, November 14

Nov 17
8:25 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Kai H.
has entered the room
Kai H.
Hello
Mark M.
hello, Kai!
how can I help you today?
8:30 AM
Kai H.
I wanted to ask a question, but something just came up :(
Mark M.
sorry!
I'll be here for an hour if you get a chance to ask
Kai H.
I hope so :)
8:55 AM
Kai H.
I actually have a Java question :D
Mark M.
OK
Kai H.
I have a class named Constants.java with some public static final int A_CONSTANT = 123; and one function.
Now I import and use the class in another class and A_CONSTANT is 0. Until I call the function, after that it's 123.
Any idea how that could come about?
Mark M.
off the top of my head, no
Kai H.
I tried the almighty google but couldn't find a satisfying explantion.
explanation
Mark M.
it's possible multidex could have a role here, if those classes wound up in different DEX files
9:00 AM
Mark M.
but I would have expected the Java compiler to inline the constant value at the use sites
Kai H.
So would I and all the ppl I talked to :)
Mark M.
anything unusual in where the Constants.java file is located, such as being in a separate module?
Kai H.
I think it's just a different package but same module (I am not so firm on modules)
Mark M.
do you use Android Studio?
Kai H.
Yes, ofc :) It rocks.
Mark M.
the boldface entries off of the project root in the Project tree are the modules
Kai H.
Same module then.
Mark M.
or, if you are using the Android view for the Project tab, then the boldface root entries are the modules
then, other than something funky with multidex, I cannot think of a reason for that behavior
Kai H.
It's good to have some lead on any explanation at all :)
9:05 AM
Kai H.
You told me last time that I should think about moving to Kotlin in 2021.
Mark M.
yes
Kai H.
I wondered today if Java interoperability in Kotlin is going to stay.
Mark M.
since the Android framework classes are in Java, yes
and even if that were not enough reason for JetBrains, some of their other work, such as Jetpack Compose for Desktop, require Java interop
so, that ain't going away any time soon
Kai H.
So the transition to Kotlin can be a somewhat slow, on a "as needed" basis.
Mark M.
yes
just class-by-class can work, though there may be some cases where you elect to convert a cluster of tightly-coupled classes
Kai H.
cool :)
I was thinking new classes in Kotlin first, with the occasional refactoring or rewriting of Java into Kotlin ones.
Mark M.
that too can work
Kai H.
We still have TONS of AsyncTask based logic that eventually will have to go over, for example.
9:10 AM
Mark M.
that has other reasons for being reworked, such as AsyncTask being deprecated
Kai H.
will have = I think should
That's gonna be a major thing, as the AsyncTasks used right now are not easy to understand.
Mark M.
yet another reason to rework them :-)
Kai H.
Also a hard task though
Mark M.
no argument there
Kai H.
Do you prefer Kotlin over Java?
Mark M.
as a developer, yes -- as an instructor, it's a mixed bag
Kai H.
That's an unexpected answer.
Mark M.
well-written Kotlin can be very readable, but it is also possible to write Kotlin that is difficult to read
Kai H.
I restarted learning it a week ago or so and it's not easy.
9:15 AM
Mark M.
it takes some getting used to
and not everybody picks up new programming languages at the same pace, just as not everybody picks up new spoken languages at the same pace
my primary concern with Kotlin, when it came out, was whether people would have the discipline to write readable Kotlin for public stuff (docs, posts, presentations, etc.)
there was a period where that was a problem, but more recently that seems to have gotten better
and the fact that more and more stuff will only get written about using Kotlin examples is one of the reasons why I recommend developers get up to speed on it sooner rather than later
Kai H.
Did it become better because of changes in Kotlin?
So I am on the right track if I continue :D
Mark M.
I'd say people published more-readable Kotlin after they became more comfortable with Kotlin and had a better sense of what is and is not necessarily a good idea
a lot of Kotlin syntax exists in part to make Kotlin itself, and to make libraries that have a very slick API
9:20 AM
Mark M.
however, that mean that a lot of Kotlin syntax is not the sort of thing that ordinary developers will be encountering all that much
Kai H.
Makes it quite hard for newbies though.
Mark M.
er, "that means"
that's part of the reason I wrote *Elements of Kotlin* -- I wanted to focus on the portion of the syntax that matters
Kai H.
So it's _element_ary Kotlin?
Mark M.
sorta, I suppose
your "power users" of the language will use more of the esoteric syntax; ordinary developers can get by with a smaller subset
and I wanted to draw that distinction
Kai H.
Cool
I am currently working my way through the Kotlin Koans, I think your Klassbook is gonna be next.
Mark M.
sounds reasonable
9:25 AM
Kai H.
Btw, in the Klassbook, why isn't the code editable from the beginning?
Mark M.
to encourage people to run the unedited version
the Klassbook looks similar to some of the stuff that JetBrains runs
however, under the covers, the implementations are fairly different, owing in large part to the fact that JetBrains is a lot bigger firm than is CommonsWare
Kai H.
Ok
Mark M.
the Klassbook takes the Kotlin in the editor pane and sends it to a server of mine
that server converts the Kotlin into JavaScript and sends the JavaScript back
Kai H.
I usually run the unedited version, but always forget to press "edit" and am somewhat annoyed if I have to do that.
Mark M.
the JavaScript is then run in the browser
Kai H.
How does JetBrains do it?
Mark M.
the Kotlin->JavaScript conversion isn't the fastest thing
they actually run your Kotlin directly on their server and stream back the results
they are also in better position to deal with script kiddies who might use that to run unfortunate code on their server
Kai H.
I was thinking how you deal with it.
And that it can be quite a nightmare.
Mark M.
I went the route that I did to get the actual code to run in the browser, not on the server
but, my rented server is weak
so the Kotlin->JavaScript conversion is slow
so I cache the results
that's why when you run an unedited Klassbook entry, you get the results right away
Kai H.
I see.
Mark M.
if you edit it, it takes a few seconds
Kai H.
So I'll just have to learn to press the edit button if I want to try something out
Mark M.
yes, if you want to start with one of the examples
9:30 AM
Mark M.
the "Scratch Pad" button gives you an editor for free-form Kotlin
Kai H.
I usually want to modify just a small thing in the example code.
Mark M.
then, yes, you will need to click the Edit button
it annoys me too sometimes
Kai H.
Haha
Mark M.
on the whole, I'm still comfortable with my decision
though I have toyed with changing editor theme between read-only and read-write to better distinguish the modes
Kai H.
Where do you take the time. Amazing.
Or you're really fast or quite structured.
Mark M.
well, it's a third-party editor component
IIRC, changing themes on the fly wasn't working for me, but I haven't updated that editor in a while, so perhaps there are more options
Kai H.
But still, between publishing newsletters, editing books, doing office hours and having a full time client.
Mark M.
yes, well, it's not the easiest thing
and, it's why I need to cap these office hours... such as, right about now :-)
Kai H.
:D
Mark M.
the next one is Thursday at 7:30pm US Eastern
Kai H.
Thanks and have a good time.
Mark M.
you too!
Kai H.
has left the room
Mark M.
turned off guest access

Saturday, November 14

 

Office Hours

People in this transcript

  • Kai H.
  • Mark Murphy