#Kotlin: changing job, moving from java. What senior guy should know about kotlin, besides syntax? =)

1 messages · Page 1 of 1 (latest)

edgy tide
#

While being a junior java backend developer, got an offer for a senior one.

I'm pretty ok with java, but haven't ever touched kotlin, thus a little scared.
Besides basic syntax, what an average senior guy is expected to know with this language? Must have kotlin-only libs/frameworks? (I know it reuses a lot of java ones, and I'm comfortable with java infrastructure)

I have ~ok level of understanding of system design concepts and stuff, so question is purely on kotlin language

hollow prismBOT
#

<@&1008423204219531294> please have a look, thanks.

hollow prismBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

glad sinew
#

and probably another month + practice to get into the kotlin style of writing code

#

so that u stop writing java code in disguise

#

kotlin has excellent tutorials on their website for all their fancy stuff

#

so they will cover u

#

there are some good books that help getting into the kotlin mindset

#

for example Effective Kotlin

#

u can start reading from here

#

and then go through the topics on the left

#

since ur coming from java, one of the first things ull notice is that kotlin dumped the concept of static

#

and replaced it by utility classes

#

which they call object, instead of class

#

and sth that is very frequently used in kotlin-style code are the scoped functions

#

let, run, with, apply, also

#

which let u write code in a fluent-chain

#

sometimes very elegant

#

lambdas look a tad different in kotlin as well, since they introduced them before java did

#

and there is a shorthand that looks strange at first

#

if u have a method that takes a lambda as the last argument, u call the method in the following style:

#
foo(...) {
  ... // lambda body
}
#

instead of foo(..., lambda)

#

thats a concept thats super prominent

#

especially bc the scope functions also use that

#
Person().apply {
  name = "John"
  age = 25
}.let {
  saveToDatabase(it)
}.also {
  log(it)
}
#

it is a shorthand for the first parameter in the lambda

#

so u dont have to name it explicitly

#

like in java x -> foo(x)

#

the last line in a lambda is implicitly return ...

#

so u dont have to write that either

#

another very prominent concept in kotlin are extension functions

#

they allow u to add methods to existing classes

#

for example:

#
fun String.printMe() {
  println(this)
}
#
"huhu".printMe()
#

this idea is heavily made use of to extend the existing java code base with new stuff

#

and u can use it as well (but dont overdo it)

#

in fact, a lot of things that look like magic use it

#
for (i in 1..3) {
  ...
}
#

this for example uses an infix-extension on Int

#
infix fun Int.'..'(other : Int) =
  Range(this, other)
#

looks sth like this

#

so its a method added to Int, that wants another Int as parameter, and it returns a Range as result

#

which is iterable

#

and hence u can iterate over it

#

and bc of infix, u can write the function as x foo y instead of x.foo(y)

#

like an operator

#

sth else thats important is that kotlins collections are all immutable by default

#

List cant be changed

#

MutableList can

#

one extends the other though, so u can switch easily

#

when is used a lot as well

#

its a mix between switch and if-else

#

its quite powerful

#

since u can write arbitrary expressions in it

#

and not just fix cases like in java

#

enjoy ur journey. kotlin feels like java 2.0

#

it tries to get rid of all issues that annoy java devs

edgy tide
#

Thanks for such a detailed list, but I've already learned all these as part of "basic syntax" thing, and it feels, like there should be many more other concepts?
Things, that you can learn with the experience, like certain practices, that aren't mentioned in these guides. Like how in Java we don't like using inheritance for reusing complex behaviour, or using null for business logic (yes, I know that kotlin handles nulls in special, and a really nice way) This is just an example of what is allowed by language itself, but is considered a bad practice amongst developers

edgy tide
# glad sinew enjoy ur journey. kotlin feels like java 2.0

Yeah, kotlin feels really really nice and neat. Also feels like one of these modern languages, with clean and accessible documentation and code guidelines. (c++ flashbacks, where there are 50 insane ways to write any single thing)

glad sinew
#

if u just write java code in kotlin-syntax, u will end up with java code in disguise

#

the kotlin mindset is different

#

revolving around what i mentioned mostly

#

u will see a lot of scoped functions and extension functions

edgy tide
glad sinew
#

if u know modern java, u probably know Optional

#

kotlins nullability stuff is similar like that, just more extreme

#

foo?.bar()

edgy tide
glad sinew
#

foo ?: 5

#

and so on

edgy tide
#

I guess I got the Idea. You outlined most important concepts, for which I'm grateful, and the rest would come with experience

glad sinew
#

yeah. u will adapt very quick after u converted a few classes

edgy tide
glad sinew
#

its automatic, thanks 👍