It’s All the Same! 96 of 100 Days of…
I went to submit my solution on codewars and found something pretty cool
Recently I talked about the conclusion to the Keep Hydrated codingkata on codewars. I built a fully functioning command line app, but I still needed to upload my solution.
For more on this, watch the video at the bottom of the page. You can find the source code for the Kotlin version here, and the Java version here.
When I went to the codewars website, I noticed something familiar about the function provided.
This one had a return type in the function header!
I haven’t covered this yet, but I knew exactly what I was looking at. The codingkata provided an empty function which returned a value of type Int. I updated my solution using this new information.
In my version, I created a function which returned a Double instead. After this update, I wanted to see a side by side comparison with a Java program. My next move was to recreate this same program in Java
Doing this in Java helped me better analyze Kotlin syntax for functions. I even noticed a pattern with how colons are used in Kotlin. Typically there’s a variable or something which returns a value, followed by a colon, and the datatype. The format usually follows:
Now I know how to set return types for functions in Kotlin. I’ve said it before, coding challenges are a great way to learn about a language. Even the simplest ones can take you far.
Join the mailing list to see updates like this every week!
Coding Fanatic