# Danny Preussler

Stories by Danny Preussler on Medium

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Software craftsmanship in the age of agentic coding

DevFeed: [Software craftsmanship in the age of agentic coding](<https://devfeed.tech/articles/software-craftsmanship-in-the-age-of-agentic-coding-101119.md>)

Original publisher: [Read original article](<https://dpreussler.medium.com/software-craftsmanship-in-the-age-of-agentic-coding-54e2b85f740c?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2026-10-26T14:10:12Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [agentic-coding](<https://devfeed.tech/topics/agentic-coding.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Developer experience](<https://devfeed.tech/topics/developer-experience.md>), [developer-productivity](<https://devfeed.tech/topics/developer-productivity.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>)

Tags: [agentic](<https://devfeed.tech/tags/agentic.md>), [agentic-coding](<https://devfeed.tech/tags/agentic-coding.md>), [ai](<https://devfeed.tech/tags/ai.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [craftsmanship](<https://devfeed.tech/tags/craftsmanship.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [productivity](<https://devfeed.tech/tags/productivity.md>), [software](<https://devfeed.tech/tags/software.md>), [software-craftsmanship](<https://devfeed.tech/tags/software-craftsmanship.md>), [software-development](<https://devfeed.tech/tags/software-development.md>), [tdd](<https://devfeed.tech/tags/tdd.md>), [testing](<https://devfeed.tech/tags/testing.md>), [value](<https://devfeed.tech/tags/value.md>), [work](<https://devfeed.tech/tags/work.md>)

### AI overview

The excerpt presents software craftsmanship as shifting from pride in implementation mechanics toward delivering user value and exercising sound judgment. It argues that classic TDD's red-green-refactor micro-cycles fit agentic coding poorly, while test-first work--humans specify and agents implement--can still help, though agents may alter tests and can generate unit tests themselves. The author notes that AI-assisted work has not yet shown clear productivity gains in user value or revenue, and that agent friction can disrupt mob programming; teams without much AI use may remain competitive while code review and quality gates are unresolved. The proposed role for engineers is a safety net, supported by harnesses, linters, test suites, and experienced judgment, analogous to pilots overseeing autonomous aircraft. The account closes with optimism grounded in collaboration and human connection.

### Source excerpt

What does software craftsmanship mean in the age of agentic coding? I went looking for answers and left with more questions, along with a surprising amount of optimism. Source: https://bsky.app/profile/socrates-crete.org AI is transforming our field. Contrary to the apocalyptic predictions from six months ago, most of us haven't lost our jobs. In fact, companies are still struggling to measure any real productivity boost, at least in terms of user value or revenue. Yet, how we work is fundamentally changing, and that shift can feel unsettling. As I felt similarly, it was time to step out of my bubble. Nearly ten years ago, I used to attend Software Crafters events across Europe. I remembered meeting deeply knowledgeable engineers, not the "rockstars" dominating LinkedIn feeds, but people who cared about their craft. So it was time again to reconnect with them. Therefore, I booked a flight to Greece for SoCraTes Crete, which took place in a seaside resort: no stages, no pre-packaged slides, just attendees sharing experience, questions, and conversation. It was naive to expect the future to be mapped out neatly over a weekend. Actually, everyone arrived with similar questions. At times, it felt like group therapy for programmers who don't get to program anymore, trying to answer: How do we keep the joy of our work? As someone who still enjoys his work, I realized the answer to that question depends on where you take the joy from. Are you proud of the what (the value delivered to users), or the how (the elegance of the implementation)? When your pride is tied to the mechanics of the how, today's shift feels existential. Which brings us to the core issue: what craftsmanship actually means now? As part of that, in one of my sessions I asked: Is TDD dead (again)? For the classic red-green-refactor micro-cycles, it probably is dead; we had to agree. Trying to force an agent into small, incremental loops just is no fun, for the agent nor us. If we think as "test-first," whe

## Interpreting voice results for Android media apps in cars

DevFeed: [Interpreting voice results for Android media apps in cars](<https://devfeed.tech/articles/interpreting-voice-results-for-android-media-apps-in-cars-25891.md>)

Original publisher: [Read original article](<https://proandroiddev.com/interpreting-voice-results-for-android-media-apps-in-cars-f36d7bdb26e1?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2022-01-10T21:33:42Z

Content type: tutorial

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Android Auto](<https://devfeed.tech/topics/android-auto.md>), [Android](<https://devfeed.tech/topics/android.md>), [media3](<https://devfeed.tech/topics/media3.md>), [Android Testing](<https://devfeed.tech/topics/android-testing.md>)

Tags: [actions](<https://devfeed.tech/tags/actions.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [android-auto](<https://devfeed.tech/tags/android-auto.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [cars](<https://devfeed.tech/tags/cars.md>), [google-assistant](<https://devfeed.tech/tags/google-assistant.md>), [integration](<https://devfeed.tech/tags/integration.md>), [media](<https://devfeed.tech/tags/media.md>), [voice](<https://devfeed.tech/tags/voice.md>)

### AI overview

For Android Auto media searches, the excerpt reports that Assistant calls `MediaSessionCompat.Callback.onPlayFromSearch()` with the remaining query, but the documented `MediaStore.EXTRA_MEDIA_FOCUS` check does not distinguish artist, album, or track: it says the received focus is always `vnd.android.cursor.item/*`. The suggested workaround is to read the non-null `EXTRA_MEDIA_ARTIST`, `EXTRA_MEDIA_ALBUM`, and `EXTRA_MEDIA_TITLE` values from the callback bundle to identify the requested entities. The author notes the cause is unclear and recommends testing the implementation, since documented behavior may not match reality.

### Source excerpt

When working on the Android Auto integration for SoundCloud, I stumbled upon an interesting issue. When it comes to implementing voice actions, things you read in the documentation might differ a bit from reality. Voice commands are very critical while driving a car. You want the driver to keep looking at the street, keep his hands on the steering wheel, instead of interacting with any screen. This is why when building for Android Auto, Automotive OS, and Assistant Driving Mode you have to support basic voice searches. For a music app like ours, the idea is simple. A user can say something like: "Play Moderat on SoundCloud" Under the hood The Assistant will break down our sentence for interpretation: "<Play> <Moderat> <on SoundCloud>" The verb (Play) and the app (SoundCloud) in the above command were meant for the system. It will then wake up the app mentioned (if it declared auto support via manifest) and, as we asked for verb "Play", the method MediaSessionCompat.Callback.onPlayFromSearch() will be called with the remaining query ("Moderat") as the argument. This query of "what to play" can still mean different things though. How do you know if Moderat is a band or a song? Don't worry, the Assistant will help us also here. It already got some idea what our query could mean, if we asked for an artist, an album, or a specific track. But be aware, it behaves slightly differently than officially documented. According to documentation we are supposed to write code like this: val mediaFocus = extras?.getString(MediaStore.EXTRA_MEDIA_FOCUS) if (mediaFocus == MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) { isArtistFocus = true artist = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST) We are suppose to check for a bundle entry with the key MediaStore.EXTRA_MEDIA_FOCUS . This will give us a hint on how best to interpret the query. The value of the constant MediaStore.EXTRA_MEDIA_ARTIST checked above is vnd.android.cursor.item/artist and there are similar constants related to

## Using the Kotlin standard library in Java

DevFeed: [Using the Kotlin standard library in Java](<https://devfeed.tech/articles/using-the-kotlin-standard-library-in-java-25888.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/using-the-kotlin-standard-library-in-java-ea0766deac10?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-06-14T19:01:08Z

Content type: tutorial

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Java](<https://devfeed.tech/topics/java.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [collections](<https://devfeed.tech/tags/collections.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-beginners](<https://devfeed.tech/tags/kotlin-beginners.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

### AI overview

This tutorial explains how Java code can use Kotlin standard-library functions through static imports. It covers list creation, Kotlin free functions compiled into classes, and extension functions exposed to Java with the receiver as the first argument.

### Source excerpt

Using the Kotlin standard library from Javagiphy.com If you work with Kotlin on a daily basis you probably love the language and don't want to go back to Java. Though, many of us work on a codebase that isn't purely Kotlin. Our Android codebase at SoundCloud still has a fair amount of code written in Java. This percentage gets smaller over time but there is no urgent need for mass migration of the remains right now. Therefore, every once in a while, I find myself, changing Java files. In those cases, I miss some of the Kotlin functions I'm used to; I can easily think of string manipulation or handling collections as examples. Of course, Java has powerful utility libraries such as Googles Guava or Apache Commons, libraries many of which we used to work with in the world before Kotlin. But when writing Kotlin code all day, remembering those "older" APIs is sometimes hard. It is a complete context switch. It would be much easier to use what we use in Kotlin. And you should! Let me show you! Let's assume we want to create a list of items. In Kotlin, we would write: val items = listOf( items1, item2, item3 ) In Java, I would write it as: List<Item> items = Arrays.asList(item1, item2, items3); Usage is pretty much the same but you still need to remember the name of the function. Wouldn't it be easier to just use: List<Item> items = listOf(item1, item2, items3); And yes you can! All you need to do is to static importthat function! This works aslistOf, like many of our daily Kotlin utility functions, are simply static functions you can use from Java. And even better, as your project already uses Kotlin, you already got those dependencies included anyway, no additional library needed. A closer look If you would click on the details of listOf from Kotlin, you would end up in a file called Collections.kt and the definition looks like this: public fun <T> listOf(vararg elements: T): List<T> It is a free function, not bound to any class. But from a Java perspective this looks so

## The modifier that shouldn't be there

DevFeed: [The modifier that shouldn't be there](<https://devfeed.tech/articles/the-modifier-that-shouldn-t-be-there-25894.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-modifier-that-shouldnt-be-there-77ff941f0529?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-05-31T14:15:00Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>)

Tags: [android-studio](<https://devfeed.tech/tags/android-studio.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [call](<https://devfeed.tech/tags/call.md>), [class](<https://devfeed.tech/tags/class.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [example](<https://devfeed.tech/tags/example.md>), [extend](<https://devfeed.tech/tags/extend.md>), [fields](<https://devfeed.tech/tags/fields.md>), [interface](<https://devfeed.tech/tags/interface.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [open](<https://devfeed.tech/tags/open.md>), [open-class](<https://devfeed.tech/tags/open-class.md>), [override](<https://devfeed.tech/tags/override.md>), [programming](<https://devfeed.tech/tags/programming.md>), [properties](<https://devfeed.tech/tags/properties.md>), [property](<https://devfeed.tech/tags/property.md>), [type](<https://devfeed.tech/tags/type.md>), [val](<https://devfeed.tech/tags/val.md>)

### AI overview

Kotlin properties are final by default, but an interface property implemented with `override val` is open unless marked `final`. The excerpt's original case came from `@OpenForTesting`, which a compiler plugin uses to open the class and its fields for mocking. Overriding such a property can cause a constructor hazard: the parent initializer calls the child getter before the child backing field is initialized, producing `null`. The author advises avoiding access to non-final fields from constructors and suggests considering Mockito's inline mock maker or using fewer mocks.

### Source excerpt

The Kotlin modifier that shouldn't be therePhoto by Belinda Fewings on Unsplash Most Kotlin developers would agree that a val property is equivalent to a final property in Java. What if I tell you that this is not completely true and sometimes you might need a final val? Opposite to Java, Kotlin properties are final by default unless they are explicitly marked as open! This would mean there is no need for the final keyword, right? Let's Google that: As the internet confirmed our hypothesis, I was quite surprised when Android Studio told me to addfinal to a val: and indeed adding final would fix that: So there is a final keyword for properties but why and when should we make a val final? Let's look at this behavior using a simple example: class FinalBlog { val someProperty: String = "some" init { print(someProperty + "thing") } } "Everything works as expected here and the code will print "something" when the class is instantiated. Let's modify everything to be open: open class FinalBlog { open val someProperty: String = "some" init { print(someProperty + "thing") } } This will trigger the same type of warning I got before. This is very obvious when you think about it. The class can be subclassed and our property might be overridden. This could lead to unexpected side effects (which we will look into at the end of this post.). We can fix this simply by removing theopen modifier from the field. So, althought the warning has the same cause, it's not the exact same scenario my Android Studio was warning me on, there is no way I could add final here: non open already means final! Let's try something else: interface BlogTopic { val someProperty: String } open class FinalBlog: BlogTopic { override val someProperty: String = "some" init { print(someProperty + "thing") } } If the property is inherited from an interface, then it's open by default! Again, we will get the warning, we were looking for: And this time adding the final modifier will fix it: open class FinalBlog: Blo

## Avoid backing properties for LiveData and StateFlow

DevFeed: [Avoid backing properties for LiveData and StateFlow](<https://devfeed.tech/articles/avoid-backing-properties-for-livedata-and-stateflow-25886.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/avoid-backing-properties-for-livedata-and-stateflow-706006c9867e?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-01-12T14:03:52Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [class](<https://devfeed.tech/topics/class.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [abstract-class](<https://devfeed.tech/tags/abstract-class.md>), [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [clean-code](<https://devfeed.tech/tags/clean-code.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-flow](<https://devfeed.tech/tags/kotlin-flow.md>), [language](<https://devfeed.tech/tags/language.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [properties](<https://devfeed.tech/tags/properties.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

The article recommends exposing `LiveData` and `StateFlow` through an interface or abstract ViewModel instead of maintaining paired public read-only and private mutable properties. The backing-property pattern duplicates names and accessors; an abstract property can declare the public type while an implementation overrides it with a more specific mutable type, allowing internal updates such as `loading.value = true`. The author argues that concrete implementations should be created through dependency injection or a ViewModel factory, so callers normally use the abstract API. For Jetpack ViewModels, the excerpt says Koin can bind the abstract type to its implementation directly; Ktx delegates may need a custom provider or factory, and Dagger binding adds setup code. The proposed tradeoff is less ViewModel duplication and a clearer API for some additional dependency-injection configuration.

### Source excerpt

https://unsplash.com/photos/OopPIi_A428 If you have ever worked with LiveData you probably have written code similar to this: class MyViewModel: ViewModel() { val loading: LiveData<Boolean> get() = _loading private val _loading = MutableLiveData<Boolean>()} This seems nowadays the typical way developers would expose some immutable LiveData, while being able to have a mutable version inside the implementation we would write data into. Every time I saw, or even had to write, this kind of code something cringed inside me. As I quoted in one of my talks this feeling in our brain is for real: social missteps activate regions in the brain, [..] that have been previously associated with physical pain. As developers, we know something is wrong with this code, right? It also feels like we are writing manual getters and setters here. What's wrong? We could start with the prefix we use for the backing field, although we fought hard for a long time to get rid of prefixes, we accept it here! It is even made it into the official coding conventions. But even if we rename it, it still cringes: class MyViewModel: ViewModel() { val loading: LiveData<Boolean> get() = mutableLoading private val mutableLoading = MutableLiveData<Boolean>()} This duplication feels unneeded! Especially if you write something like a ViewModel that exposed many of these, you get lost in reading the code just by all these duplications. But it's just LiveData? You might think it's just a specialty of LiveData and the future of that construct might be a more limited one. And you would not have this issue with primitives. The language supports this out of the box with a private setter: var secret: String = "Secret" private set But there is a new kid in town: StateFlow needs the same thing! Look at this snippet from the official Jetbrains blog: class DownloadingModel { private val _state = MutableStateFlow<DownloadStatus>(DownloadStatus.NOT_REQUESTED) val state: StateFlow<DownloadStatus> get() = _state This probl

## When "Compat" libraries won't save you

DevFeed: [When "Compat" libraries won't save you](<https://devfeed.tech/articles/when-compat-libraries-won-t-save-you-25895.md>)

Original publisher: [Read original article](<https://proandroiddev.com/when-compat-libraries-do-not-save-you-dc55f16b4160?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-01-04T19:34:03Z

Content type: opinion

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Jetpack](<https://devfeed.tech/topics/jetpack.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [app](<https://devfeed.tech/tags/app.md>), [channel](<https://devfeed.tech/tags/channel.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [example](<https://devfeed.tech/tags/example.md>), [features](<https://devfeed.tech/tags/features.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [fragmentation](<https://devfeed.tech/tags/fragmentation.md>), [google](<https://devfeed.tech/tags/google.md>), [google-i-o](<https://devfeed.tech/tags/google-i-o.md>), [groups](<https://devfeed.tech/tags/groups.md>), [introduced](<https://devfeed.tech/tags/introduced.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [latest](<https://devfeed.tech/tags/latest.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [linter](<https://devfeed.tech/tags/linter.md>), [notification](<https://devfeed.tech/tags/notification.md>), [operating-system](<https://devfeed.tech/tags/operating-system.md>), [os](<https://devfeed.tech/tags/os.md>)

### AI overview

Compat APIs do not all provide copied, lower-version-safe types: some bridge to platform APIs, while others return platform classes after checking the OS version. In the example, NotificationManagerCompat returns an empty list of notification channel groups below API 26, but callers still receive platform NotificationChannelGroup objects. Suppressing NewApi warnings around code that uses them can hide a later API-level error: filtering with isBlocked, introduced in API 28, can crash on older versions. The article recommends avoiding broad NewApi suppression and putting higher-level API calls in small, focused methods, so adding an unsupported call triggers a warning. It also suggests direct SDK checks and using RequiresApi annotations to make callers handle requirements; the excerpt notes the linter may not recognize some check patterns. It mentions an alpha of NotificationCompat planned to include compat versions of NotificationChannel and NotificationChannelGroup.

### Source excerpt

And why you should avoid using the "NewApi" suppression! https://unsplash.com/photos/EgGIPA68Nwo The idea of "Compat" libraries was probably one of the key aspects of Android dominating the mobile space. Other than with iOS, Android users often could not update their operating system after a new version launch, simply as their phones won't allow them to, the Android problem of fragmentation. But developers still wanted to use the latest features to compete. The solution was simple: instead of adding new APIs to the operating system, you shipped those directly with your app by using a "backport" version Google gave you. It all started with ActionBar Sherlock by Jake Wharton then got adopted by Google with in their "support libraries". Later on, this was mirrored as AndroidX under the Jetpack umbrella. Same but different Under the hood, not all of those "compat"-APIs are made the same way. Some, like the ones for Fragments, are complete copies of the code. You either use android.app.Fragment from the OS (actually deprecated) or androidx.fragment.app.Fragment. Both don't share any code or have a common base class (which is why we also have two versions of the FragmentManager). On the other handAppCompatActivity for example, simply extends the original Activity. AlsoAppCompatImageButton still is an ImageButton! We can see that sometimes these "Compat"-classes are just a "bridge" to add missing functionalities and sometimes they are complete duplicates. Let's look at another example! One area that changed a lot over time is the notification API from Android. There was a time where every Google I/O introduced a new API change. Good that we have NotificationManagerCompat to save us!? If, for example, we need to get the notification channel groups: val groups = notificationManagerCompat.notificationChannelGroups We don't need to worry about the groups being supported on all OS versions, as it is handled under the hood for us: public List<NotificationChannelGroup> getNotific

## When LiveData and Kotlin don't play well together

DevFeed: [When LiveData and Kotlin don't play well together](<https://devfeed.tech/articles/when-livedata-and-kotlin-don-t-play-well-together-25889.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/when-livedata-and-kotlin-dont-play-hand-in-hand-30149aa794ec?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-12-15T13:38:10Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Null-Safety](<https://devfeed.tech/topics/null-safety.md>), [RxJava](<https://devfeed.tech/topics/rxjava.md>), [Publish-subscribe pattern](<https://devfeed.tech/topics/pubsub.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [crash](<https://devfeed.tech/tags/crash.md>), [error](<https://devfeed.tech/tags/error.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [null](<https://devfeed.tech/tags/null.md>), [observable](<https://devfeed.tech/tags/observable.md>), [pattern](<https://devfeed.tech/tags/pattern.md>), [reactive](<https://devfeed.tech/tags/reactive.md>), [reactive-streams](<https://devfeed.tech/tags/reactive-streams.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>), [sticky](<https://devfeed.tech/tags/sticky.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

LiveData replays its latest value to new observers, which is useful for state but can repeat one-off errors after events such as device rotation. The excerpt presents SingleLiveEvent as one option for one-off events, then considers clearing an error from LiveData to retain sticky results without replaying the error. Setting the value to null can crash when Kotlin code treats the observed value as non-null: LiveData is implemented in Java, so Kotlin's compiler cannot prevent a null from reaching that observer. The excerpt also notes that Java generic type information and compile-time nullability annotations do not resolve this mismatch. It ends before giving a complete alternative implementation.

### Source excerpt

When LiveData and Kotlin don't play well togetherPlaying well together The idea of LiveData was an interesting one. Based on the idea of reactive streams, that was on the peak at that time with RxJava plus adding automatic lifecycle handling -- a problem on Android. LiveData had bad timing though. It arrived just before Kotlin made its impact in the Android community and sometimes both don't play that nice together. Let's explore why and what can happen! The good and the bad The idea of LiveData was pretty simple: a lifecycle-aware implementation of the Observable pattern. In addition, if you resubscribe, you will get the last emitted value again. It could be compared to a typed version of an EventBus with sticky messages. This is one of the core features of LiveData. But very soon after developers, including the authors, figured, you don't always want that behavior. Let's say you have an error value. Then you probably don't want to show that error value again after resubscribing, like after rotation of a device -- for instance. One way to solve this is SingleLiveEvent and it's a good choice for one-off events like errors. Both worlds But what if you want a bit of both? You want to have the last value "sticky" plus not showing potential errors multiple times! In that case, it would be good to remove our error value from LiveData after they have been consumed, right? Let's look at the implementation ofLiveData: The current value is saved on a field: private volatile Object mData; Initially, it is set to NOT_SET which. static final Object NOT_SET = new Object(); Unfortunately, is not public otherwise, we could use it to reset the value. What now? If you search for this problem, one of the most suggested solutions is simply setting it to null. Let's explore this: viewModel.results.observe(lifecycleOwner) { result -> when (result) { SomeResult.Error -> { handleError() viewModel.results.reset() } SomeResult.Result -> { handleResult(result) } } } where the ViewModel's imple

## Swift's Guard Statement for Kotlin

DevFeed: [Swift's Guard Statement for Kotlin](<https://devfeed.tech/articles/swift-s-guard-statement-for-kotlin-25890.md>)

Original publisher: [Read original article](<https://medium.com/swlh/swifts-guard-statement-for-kotlin-967ba580443f?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-12-07T21:55:37Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [statement](<https://devfeed.tech/tags/statement.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

Swift's `guard` exits early when a condition fails, keeping subsequent code outside nested checks. The excerpt shows Kotlin alternatives: use `toIntOrNull()` with `?: run` or an `if`/`else` that returns from the function; both work when a function return is available. For reusable guarded blocks, it proposes throwing a custom exception from `otherwise` and catching it in an inline `guarded` wrapper, with `Nothing` indicating that `otherwise` does not return. A later variant makes the failure action optional and uses an extension `guard` to check a Boolean while returning the original value. The author notes that these are approximations built from Kotlin features, not an official language keyword, and that the optional failure action differs from Swift's required `else`.

### Source excerpt

https://unsplash.com/photos/znMu0Enj_Gw Even if you live on the Kotlin side of things maybe once in a while you also check Swift code. If you do, you probably noticed how similar both languages are. To me, Kotlin looks more concise but I'm also biased as I work with Kotlin daily. On the other hand, Swift has some great features too. One is the guard keyword, a really nice tool Swift developers have that we are missing. Can we bring it to Kotlin? What is guard? guard is used to exit a block of code early, if a given condition is not met. This way all the code following the guarded variable can be safely executed. Let's look at an example where we do some calculation but only if the given input can be converted into an integer: func printResultFor(input: String) -> Void { guard let result = Int(input) else { println("input was not an integer") return } // function continues with valid int print("result: ", 100 * result)} Of course, simple code like this could be written with the standard if/else statements! But the power of guard becomes apparent when many of these statements are used in succession. Written in a traditional way this can easily lead to a hell of nested ifs where you make sure everything is safe in the innermost block when all the if are true. Take a simple sign up flow for example, where the customer needs to enter user, password, and their age for validation. We have to make sure those are not nil or empty and check for a valid age. func submit(usernameText: String?, passwordText: String?, ageText: String?) { guard let username = usernameText, !username.isEmpty else { print("username is not set or blank") return } guard let password = passwordText, !password.isEmpty else { print("password is not set or blank") return } guard let ageString = ageText else { print("age is not set") return } guard let age = Int(ageString), age > 18 else { print("age not valid") return } // all values are checked and valid here register(username, password, age)} Here the r

## The hidden pitfalls of the Elvis operator

DevFeed: [The hidden pitfalls of the Elvis operator](<https://devfeed.tech/articles/the-hidden-pitfalls-of-the-elvis-operator-25887.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/the-hidden-pitfalls-of-the-elvis-operator-da536ba68161?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-07-28T08:05:18Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Safe-Call Operator](<https://devfeed.tech/topics/safe-call-operator.md>), [if expression](<https://devfeed.tech/topics/if-expression.md>)

Tags: [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

Kotlin's Elvis operator evaluates its entire left-hand expression before deciding whether to run the right-hand side, so it is not always equivalent to an if/else. In a chain such as `data?.let { updateData(data) } ?: run { showLoadingSpinner() }`, the fallback depends on the value returned by `updateData` as well as whether `data` is null. If that call returns null, both the update and loading spinner can run. The excerpt recommends making the intended either-or behavior explicit; it also notes that Kotlin expressions, including `let` and `run` blocks, return values.

### Source excerpt

Hidden pitfalls when using Elvis operator I guess many of us love Elvis, both the artist and the operator in Kotlin. But it can lead to some hidden pitfalls if you are not aware of how it works. https://unsplash.com/photos/1LCzr14Ah5U I only realized recently when Vladimir Zdravkovic put some code on twitter and ask us to guess what it's printing: https://twitter.com/vlazdra/status/1287366531987406848?s=20 I assumed a hidden puzzle but I could not see the issue. I could not see any reason why this would print anything but it does! After thinking about the issue (Vladimir wrote an article about it) I found more and more cases where this could go wrong. But let me show you some code: Kotlin's null safety I think most of us love the way we can easily write null safe code with Kotlin like this: presenter?.onDestroy() or data?.let{ updateData(data) } And it is super easy to add an alternative case: data?.let{ updateData(data) } ?: run { showLoadingSpinner() }Let me ask you something Do you think the following code is basically the same as the above? if (data != null) { updateData(data) } else { showLoadingSpinner() } I'm sure most of us do think they are equivalent. But what if I told you, it's not? The if/else is totally binary, it's either-or. But with the Elvis operator, it might be both! To understand why we have to look closer to how it works. Other than the else that belongs explicit to an if , the Elvis operator is not tied to a single ?. Remember, we can chain them: someVariable?.someField?.doSomething() if we now add the Elvis operator here, it will get executed depending on the expression to its left side: someVariable?.someField?.doSomething() ?: run { doSomethingElse() } so if any expression in there is null, the Elvis block will get called. It will finish evaluating everything on the left before checking if the operator is needed. This includes the last expression. So this is depending on whatever doSomething() returns! If it is null, then the right side wil

## Keep your interfaces simple

DevFeed: [Keep your interfaces simple](<https://devfeed.tech/articles/keep-your-interfaces-simple-25892.md>)

Original publisher: [Read original article](<https://proandroiddev.com/keep-your-interfaces-simple-e025d515e3b9?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-07-16T07:56:26Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [extension property](<https://devfeed.tech/topics/extension-property.md>), [interface](<https://devfeed.tech/topics/interface.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [hashCode](<https://devfeed.tech/topics/hashcode.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [api](<https://devfeed.tech/tags/api.md>), [avoid](<https://devfeed.tech/tags/avoid.md>), [extension](<https://devfeed.tech/tags/extension.md>), [feature-flags](<https://devfeed.tech/tags/feature-flags.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [simple](<https://devfeed.tech/tags/simple.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

Convenience methods can create hidden contracts that every implementation must honor. The article illustrates this with `isEnabled` and `isDisabled`: adding both to `AppFeatures` makes their opposite results a contract that mocks may not enforce, so switching methods can break tests even when behavior was meant to stay the same. A default interface implementation of `isDisabled` does not solve this for Mockito Kotlin, because the mock may return the default `false` instead of running that implementation. The proposed alternative is a Kotlin extension function, `AppFeatures.isDisabled(feature) = isEnabled(feature).not()`: it keeps the interface small, derives the result from the existing method, and requires no added implementation from fakes or mocks. The excerpt also cites the `equals`/`hashCode` contract as another example of coupled API methods.

### Source excerpt

Avoiding implicit connections and learn how extension functions can help you writing good APIshttps://unsplash.com/photos/xxeAftHHq6E Writing your classes with a good API is hard but important. As the writer is trying to make it easy for the user, we sometimes tend to repeat ourselves by adding convenient methods. Think about the List interface in Java. To check if there are no elements in the list we could check list.getLength() == 0 or we simply ask for isEmpty(). The 2nd one reads much better. But it also adds a duplication and implicit connection between the two: If the list is empty, it can't contain any elements! This must be respected by every implementer of the interface! We can easily think of many other methods with implicit dependencies. Think about how hashCode and equals have a connection. This is stated in the Javadocs: Note that it is generally necessary to override the hashCode method whenever equals is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes. This is a pitfall that can be difficult to avoid and can lead to issues elsewhere that are difficult to track down and fix. Nowadays we have tools to validate this contract, or even better, to generate the implementation. Another example: feature flags A lot of developers work with features flags. These enable us to release continuously without the need for long-lived feature branches. Let's say we have an interface like this: interface AppFeatures { fun isEnabled(feature: Feature): Boolean } When using this I realized I often write code like: if (!isEnabled(Feature.SomeFeature)) "not is enabled" does not read nicely though. But I want the reader to understand my code without thinking too much. Therefore my initial thought was to add another method to the interface fun isDisabled(feature: Feature): Boolean But I realized, doing this might break a lot of tests that simply mock the interface: val appFeatures = mock<AppF

## The forgotten art of construction

DevFeed: [The forgotten art of construction](<https://devfeed.tech/articles/the-forgotten-art-of-construction-25893.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-forgotten-art-of-construction-cfedc368e67f?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-06-22T17:39:16Z

Content type: article

Language: en

Sources: [Danny Preussler](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [class](<https://devfeed.tech/topics/class.md>), [adapter pattern](<https://devfeed.tech/topics/adapter-pattern.md>)

Tags: [analytics](<https://devfeed.tech/tags/analytics.md>), [android](<https://devfeed.tech/tags/android.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [clean-architecture](<https://devfeed.tech/tags/clean-architecture.md>), [clean-code](<https://devfeed.tech/tags/clean-code.md>), [code-smell](<https://devfeed.tech/tags/code-smell.md>), [code-smells](<https://devfeed.tech/tags/code-smells.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [koin](<https://devfeed.tech/tags/koin.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [spring](<https://devfeed.tech/tags/spring.md>)

### AI overview

The excerpt argues that dependency injection tools can hide "Constructor Over Injection": classes with many dependencies are harder to understand and test, and may signal a violation of the Single Responsibility Principle. It suggests keeping constructor arguments below four as a rule of thumb, while treating that as guidance rather than a hard rule. To reduce dependencies, group related items such as schedulers, hide implementation details behind focused facades or interfaces, and use use cases to expose operations that combine unrelated repositories. If remaining dependencies point to different responsibilities, split the class. Builders or parameter objects may reduce the visible argument list without reducing the underlying complexity. The article recommends checking constructors and responsibilities regularly as classes grow.

### Source excerpt

How tools made us forget how to write sane constructors https://unsplash.com/photos/qvBYnMuNJ9A In an ideal world, developers get smarter every day. The code we write this year should be better than the code we wrote 10 years ago, which in turn should be better than the code 20 years ago. Today we have better tools, more modern languages, and better practices. But as often in life, we realize we are not living in that ideal world. In nearly every codebase I see today, there are things that would shock a developer two decades ago. I am speaking of what Mark Seemann called "Constructor Over Injection". We've all learned to inject our dependencies into constructors. And ideally use a tool for that like Spring or Dagger. If you look at some random classes from your codebase, how many fields are you injecting? Three? Five? More? I'm pretty sure you easily can find classes with even more, like this one: class ProfilePresenter @Inject constructor( @MainThreadScheduler private val mainScheduler: Scheduler, @IOScheduler private val ioScheduler: Scheduler, private val profileApi: ProfileApi, private val userRepository: UserRepository, private val analytics: Analytics, private val errorReporter: ErrorReporter private val referrerTracker: ReferrerTracker, private val shareTracker: ShareTracker, private val tracksRepository: TracksRepository, private val playlistRepository: PlaylistRepository ) If you would show this constructor to a developer from 20 years ago they would probably look at you as if you would be crazy. No one would want to call this constructor and provide all these parameters. But these days we don't care. We don't have to. We have a tool that will provide us with all those parameters, right? This does not make it right though! The proof If you would use some manual injection code or a service locator like Koin, you would notice more what's going on because you would need to write code like this: ProfilePresenter(get(), get(), get(), get(), get(), get(), get(),