Is it efficient solving problems using Immutabilit...
# getting-started
c
Is it efficient solving problems using Immutability? Also is it possible to solve all the problem using Functional Style 🙂
t
Immutability has nothing to do with efficiency but with readability and removing side effects because your objects can’t (or let’s say it’s at least very hard) mutate. So the intention of the object gets clearer Function style programming is just a >style< of programming which fits for some issues, but not necessarily easily for all. I am using functional programming where ever i can, because (1) it’s more efficient generally speaking, and (2) it’s easier to understand and read for most devs.
👍 1
c
Immutability has nothing to do with efficiency
Is val and var are compiler specific tor runtime specific?
t
I’m not an expert in the actual byte code generated by Kotlin, but i actually assume, that the compiler will just bring up a private field, backed by a Getter and a Setter for
var
and only a Getter for
val
. So in both cases you are having - more or less the same object, but in one occasion only with a getter, in the other with getter and setter. But generally speaking - if you are bothering with performance issues from programming language perspective, you should checkout your algorithms, it’s more likely that they are the bottleneck and not the language. (Surely depending on your field or business)
c
I'm still learning Kotlin , how do you analyze performance for a problem of O(2^N) or O(N!) ?
t
Well first of all on paper - typically speaking i’m just going through my algorithm in an old fashioned way and just checking whether i have any issues in the algorithm (theoretically) itself. Can you explain what you issue actually looks currently?
c
By Algo you analyze performance but how do you differentiate with languages? For simple scenario let takes , generate permutation of
{1,2,3...N}
t
Typically i do not. I’m choosing the language for the problem - if I require something for e.g. Data Science i would use Python, for a brute-force recursion problem (which has to be performant) i would use Prolog, for general purpose, where i don’t have to care about the performance I choose Kotlin, for a high available service I would choose Go and so on. So i’m not measuring the performance of a language itself