(re)Creating a Ktor DSL

My mission at the moment is to understand the JetBrains Ktor HTTP library. So last week I wrote some tests for one of the example projects (https://ktor.io/docs/server-create-http-apis.html), with a view to comparing Ktor with http4k, the server-as-a-function alternative.

To be a fair comparison I want to make sure that I run the same tests against Ktor and http4k. This is something of a problem, as they have a quite different approach to in-memory testing.

This week then I’ll look at reimplementing part of Ktor’s domain specific language to target http4k, so that the same tests can be used to ensure that we implement the same behaviours. On the way we’ll learn how to implement a cheap and cheerful DSL in Kotlin.

In this episode

00:00:52 Reviewing our tests 00:02:13 I have a cunning plan 00:02:38 Substitute our DSL entry point 00:03:03 Change the receiver of the DSL body block 00:04:07 Add the properties we require in the DSL block 00:04:33 Adapt http4k HttpHandler to look like Ktor HttpClient 00:06:04 We can extend assertions to avoid other conversions 00:07:37 Rinse and repeat for other operations 00:08:27 Nesting DSLs 00:09:12 Add another context for the nesting 00:14:14 That turns out to compile 00:14:29 and our test source is unchanged 00:15:33 Review

This video is in a playlist of Ktor episodes (https://www.youtube.com/playlist?list=PL1ssMPpyqochUiQEM9PZ_P-9CbV1Il81B) and http4k (https://www.youtube.com/playlist?list=PL1ssMPpyqocg5TKqmiGWlvi3O5L8XPe8Q)

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It’s about far more than just the syntax differences between the languages – it shows how to upgrade your thinking to a more functional style.

submitted by /u/dmcg
[link] [comments]

Continue Reading(re)Creating a Ktor DSL

Exploring Data Analysis with Kotlin, Part I

Hey there, Kotlin enthusiasts! Excited about delving into data manipulation and visualization? A new article has just been released, diving into the world of Kotlin DataFrame and Kandy libraries.

——> Tutorial

https://preview.redd.it/agksfl17pswc1.jpg?width=1214&format=pjpg&auto=webp&s=69a8ffe07252967f2a6d1e0783b84d54a9aa111c

📝 Overview:

The latest piece is tailored for regular Kotlin developers, offering insights into data manipulation without requiring prior data expertise.

In this article, you’ll find:

1️⃣ Importing data from CSV files to create DataFrames.

2️⃣ Common data tasks made easy.

3️⃣ Effortless presentation of findings.

💡 Kotlin Notebook Convenience:

Discover the convenience of Kotlin Notebook for a smooth learning experience, applicable to Gradle-based projects too!

🌐 Real-Life Insights:

Explore data about top Stack Overflow answerers, unraveling exciting trends.

📥 Access the Data:

Head to the StackExchange Data Explorer for sample data downloads.

Ready to explore Kotlin’s data analysis capabilities? Dive into the new article and embark on a journey of discovery!

View Poll

submitted by /u/NetHairy4282
[link] [comments]

Continue ReadingExploring Data Analysis with Kotlin, Part I

New book! Kotlin in Action, Second Edition

Hello,

I’m sorry for blatant advertising, but we have just released this book that I wanted to share with the community. Please remove this post if you don’t think it’s for the benefit of the community.

Written by core Kotlin language developers and Kotlin team members, “Kotlin in Action, Second Edition” by Sebastian Aigner, Roman Elizarov, Svetlana Isakova, and Dmitry Jemerov, teaches you Kotlin techniques that you can use for almost any application type, from enterprise services to Android apps. This new second edition is fully updated to include the latest innovations, and it adds new chapters dedicated to coroutines, flows, and concurrency.

You can find the book here. LiveBook should have enough free content to get you started.

Hope you find it useful.

Thank you.

Cheers,

submitted by /u/ManningBooks
[link] [comments]

Continue ReadingNew book! Kotlin in Action, Second Edition

Have you tried to generate Kotlin code using AI? Share your feedback with us!

Have you ever used AI to generate Kotlin code? Perhaps you’ve used AI to ask questions about Kotlin? Was AI helpful in these cases?

We want to learn more about your use cases and also assess the quality and effectiveness of these interactions. Your feedback will help us improve AI tools, making your work with Kotlin simpler and more productive.

Take our survey and share your experience! ➡️ https://kotl.in/ai-tool-ux-reddit

submitted by /u/daria-voronina
[link] [comments]

Continue ReadingHave you tried to generate Kotlin code using AI? Share your feedback with us!

Should I stay with Kotlin?

Hi guys! I work in a Supply Chain company, so I do not have a good understanding of what is going on in the IT area.

During my life I have completed a couple of programming courses and got some certificates in Python and Oracle SQL. I would like to make programming as my hobby to slowly but consistently improve my understanding of the area and try building some apps/tools. I have been trying C# recently and like it so much. I also tried Kotlin and Java with Android studio. Though Kotlin looks simple and convenient to use, Android studio gave me a bad experience due to its slow response.

Could you please give me some advice before I went too far in the wrong direction? If I want to try building some applications but I am an iPhone user and am not sure whether I want to work with mobile apps only, should I continue with Java/Kotlin or should I choose something like Python or JavaScript? Whether it is beneficial to start with Java/Kotlin now when there is a big chance that in a couple of weeks I decide to move to a WEB dev or something I cannot now even understand I would need and like.

submitted by /u/SanJunipero2033
[link] [comments]

Continue ReadingShould I stay with Kotlin?

Ktor serialization question

I have a data class that models a response from Firebase on user sign in. It looks like the following:

@Serializable data class SignInResponse( val kind: String? = null, val localId: String? = null, val email: String? = null, val displayName: String? = null, val idToken: String? = null, val registered: Boolean? = null, val error: ErrorResponse? = null } 

On my httpClient I have set it up like so:

val httpClient = HttpClient(CIO) { install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } // other config here... } 

I am using kotlinx.serialization

I have another class FirebaseAuthenticationClient that uses that httpClient to make requests into Firebase.

My question is, is there a way to not have to mark all properties in the SignInResponse class nullable and give a default value of null? I would prefer it if the serializer handled this automatically and if a property on the response wasn’t present, it nulled it by default without me having to explicity mark it as so. As it stands, an exception is thrown every time I remove ?. I thought that was the purpose of ignoreUnknownKeys, but that does not seem to be the case.

Coming from C# this seems very weird to me as this would be handled automatically and here I’m trying to avoid having to mark all properties as nullable across all my response objects.

submitted by /u/genericprogrammer
[link] [comments]

Continue ReadingKtor serialization question

Would changing my language make a difference?

I am currently in the process of learning to become a programmer and looking for work as well as i currently have zero working experience. My programming logic is really bad at the moment and i have been trying to build it. Java has been my main language for a while and its through java i learned the fundamentals of programming. However, and i’ve heard this sentiment from others too that, java might be holding me back a little or at least making my experience not so good. While i don’t dislike using it, i just feel like i keep trying everyday to polish my skills but i end up learning nothing. Its become a routine now for me to open up leetcode and hackerrank and trying solving the problems(mostly easy ones) and i end up having to look them up after giving each problem like an hour and a half. I am most likely the one at fault here as it would imply my fundamentals are not correct and the language isn’t to blame which i would totally agree with. But i have gone through those fundamentals probably like 20 times and yet it still isn’t helping me. So thus why i wanted to ask will changing my language make even a slight difference? Kotlin was the one that many recommended to me as its supposed to be similar to java but have more features and is easier to read and write. Mind you i don’t plan on ever quitting java for good. I still like it, i just feel trying to out something else as everything i possibly could do with it i have done with my current set of skills and i need to do something else now to further progress my programming career.

submitted by /u/Ggordon27
[link] [comments]

Continue ReadingWould changing my language make a difference?

End of content

No more pages to load