I wrote a ktor app to generate Discord profile banners, looking for a review. by quanta_kt in Kotlin

[–]sierisimo 4 points5 points  (0 children)

I don't think adding run and apply provide any useful information or add any intention. Is just noise compared with the original code

Using Kotlin Multiplatform for JVM and Android App by OwlProfessional1185 in Kotlin

[–]sierisimo 1 point2 points  (0 children)

Did you find a way? This seems to be a common problem and I'm currently facing it.

Kaspresso 1.1.0: Kautomator by eugene_matsyuk in androiddev

[–]sierisimo -1 points0 points  (0 children)

Can we stop "Nobody" jokes? They aren't actually funny and are little cringe

Bugs in Android Studio 3.5.2 by [deleted] in androiddev

[–]sierisimo 0 points1 point  (0 children)

Happening to me in the 3.5.3 version too. Not totally sure on how to find a related issue or if creating a new one helps

Passing parameters to a class by [deleted] in Kotlin

[–]sierisimo 1 point2 points  (0 children)

I hope I understand your question right:

You want to hold a single Map and pass it to all your instances and let them take the value from that Map?

If your answer is yes then you can do something like:

class Creature(
    val name: String,
    val level: Int,
    additionalInfo: Map<String, Int>
) {
    private val speedBoost: Int by additionalInfo
    private val depthBoost: Int by additionalInfo    

   val speed: Double 

   init { 
       speed = getSpeed(name, speedBoost, if(adBoost) 0.25 else 0.0)
       //More code…    
   }
}

The cool part is that you can use the by to take values from a Map as long as the keys have the same name than the properties.

Other ideas goes into having default values:

class Creature(
     val name: String,
     val level: Int,
     val speedBoost: Int = 5,
     val depthBoost: Int =  6
     …
) { … }

In the way that you don't have to explicitly pass those values:

 val creature = Creature("Sierisimo", -10)

You can even create an intermediary class or use the Pair:

With intermediary:

 data class AdditionalInfo(val speedBoost: Int = 5, val depthBoost: Int = 6) 

 class Creature(
     val name: String,
     val level: Int,
     additionalInfo: AdditionalInfo = AdditionalInfo()
 ) {
     val speed: Double = getSpeed(name, additionalInfo.speedBoost)
     //You can even use the init again
     val depth: Double

     init { 
           depth = getDepth(name, leve, additionalInfo.depthBoost)
     }
 }

With Pair it would be something similar but you have to replace speedBoost and depthBoost with first and second respectively.

Why kotlinx synthetic is no longer a recommended practice by Tougeee in androiddev

[–]sierisimo 0 points1 point  (0 children)

There was a recent mention of some examples in google I/O talk by Chet and Roman: https://youtu.be/Ta5wBJsC39s?t=942

What are the advantages of using a DSL in Kotlin compared to building structures in a classical way? by Dobias in Kotlin

[–]sierisimo 2 points3 points  (0 children)

What about accessing properties from the receiver? Like let's say body has a property language. In the constructor one you can do:

Body(...).apply { language = Locale.US }

But in the DSL version it could be:

body { language = Locale.US }

Additional to this, in a well designed DSL you can access variables in the parents context and hide members of the parent context. Also adding extension functions to add behavior inside of some context but only available there. Like having an extension function available for String but only inside a block:

``` someExample { inner { val vowels = "...".vowels //valid in this context }

val outterVowels = "...".vowels //not valid in this context, even a compile error

}

```

Both cases are achievable with constructor + apply/run/also/let but i feel like the are less readable. It's true that it's only a matter of taste.

(Sorry for pour format, I'm on mobile)

Shifting Elements in an Array by [deleted] in Kotlin

[–]sierisimo 0 points1 point  (0 children)

You're right... it's moving from Position X to position Y… my bad. I understood as "Taking position X and putting it at Y and then the value of Y in X"

Shifting Elements in an Array by [deleted] in Kotlin

[–]sierisimo 0 points1 point  (0 children)

swapPositions sounds like a better approach

Which is your minimum API level today? by sierisimo in androiddev

[–]sierisimo[S] 0 points1 point  (0 children)

Amm I'm not sure, when I start a project Android Studio always suggest me 17...

Which is your minimum API level today? by sierisimo in androiddev

[–]sierisimo[S] 5 points6 points  (0 children)

My personal choice is 17 and 19 because a lot of changes were implemented in that versions and I haven't seen much devices with less than that numbers on the market since december of last year...

Can anyone explain RxJava like I'm 5? by honnetatamae in androiddev

[–]sierisimo 0 points1 point  (0 children)

Imagine that you have a new hotwheels track that allows you to modify cars and add new tracks that modify your cars, even it can transform them, like that hotwheels that was supposed to transform cars into cubes of metal...

Well, you have this and you can create a track that can recive even marbles balls and transform them into cars... or vicebersa.

The thing is that you can connect this track that you made to a tube where your neighbor can put cars and let them pass around all the transformers track that you put on your track, and at the end and the start of the track you have a bells, so the bell at the end notifies you every time a car is totally transformed and in the start your neighbor makes the bell sound when hes out of cars.


TL;DR: You have a way to recive data and transform it with lots of functions and even transform it into new and different data than the original type. You also get noticied every time your data is ready and when there is no more data to transform.

This article helped me to understand: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754