Hey, guys. We’re going to reconsider our system de...
# announcements
u
Hey, guys. We’re going to reconsider our system design. Can you point some C++ vs. Kotlin comparisons, benchmarks? Probably including some project management aspects like “coding time” (amount of time required to implement the same functionality), developers costs (average salary), learning curve, etc. Thanks in advance
c
It's like comparing tractors to pickup trucks. Yeah, both are machines, and both can tow things, but they're very different beasts. Which is best for your project depends on your project and resources available to you (as in developers).
1
u
Both agree and disagree. From TPM’s point of view it’s just ecosystem that helps solve some technical task. Not sure that are too different as you mentioned. For example Kotlin/Native can compile kotlin code into binaries (not JVM bytecode) so they are pretty comparable
What i’m trying to do is to find measurable advantages over C++ ecosystem
m
If you do find a study like this, the entire programming community would want to see it. Unless you’re willing to hire two teams, give them the exact same assignment and complete isolation, there’s no way to know… No two projects are exactly the same. No two teams are exactly the same. Too many variables.
👆 1
For performance, I’m sure you can find comparisons between C++ and Java/JVM. Kotlin compiles to Java bytecode, so that should be sufficient. For team development time, good luck. For average salaries, there are several resources for looking at salaries. If you’re lucky, someone will have gathered this, and might be willing to share…
u
Yeah, i can clearly see your point. However if it’s possible at all i’d like to learn existing findings to demonstrate reasonable advantages of Kotlin ecosystem
I believe every TPM have to do it before investing into some solution if choosing between C++ and Kotlin
and probably other solutions
m
C++ and Kotlin are very different, so I doubt there are too many teams choosing between the 2. If they’re already C++, they’ll likely stick as it’s always expensive to change languages. Kotlin will mostly come from Android dev and existing JVM teams. If you’re truly starting from scratch, then I can completely see where you’re coming from. But a lot of decisions are more ‘gut feel’, or ‘emotional’ because of a lack of objective measures and studies.
u
I think i can share some details on our current system design. It’s JS wrapped into C++ (and embedded V8), wrapped into Java (over JNI) and used in Android. We can see clear limits of such approach because of disk footprint (V8 size) and memory consumption (too small opportunities for improvements in JS). So i’d say we start from scratch but having some experience in domain and technical implementation (language agnostic). So we’re really choosing between rewriting everything in C++ or Kotlin (and we’re taking into account possibility to compile to binary with Kotlin/Native and to JVM bytecode with Kotlin JVM)
c
I see now why you believe Kotlin has advantages here. I think the main one is removing all that indirection you've specified. The problem though is that your team will have to learn a new technology, which is always a drag on the project. It may be advantages long-term, but I doubt that you'll feel any benefit short-term. Or just get another team which is Java/Kotlin from the start.
m
Wow! That’s quite the tech stack there. If the end target is Android, why not just Kotlin? Or is the code too shared and performance is that critical? Doesn’t sound like you have a typical problem space that you’re dealing with. If you’re targeting Android, Kotlin (IMO) is a much better choice than Java. And especially if you also have iOS as Swift and Kotlin are more similar then Swift and Java. And what Alexander said.
u
it’s performance and memory-critical. We have lot’s os strings and most likely migrating to some memory-efficient data structures like trie (probably even marisa trie). Also as Alexander mentioned, we’e like to get rid of that wrappers chain because it causes lot’s of troubles: it’s 3 languages, different set of skills, tools and peoples working on it. The target goal is to use it in both large C++ code (Chromium fork) and android apps (as library).
Yeah, we will need people - for both C++ and Kotlin. So learning curve and hiring possibilities also matters
Also it would be good to suggest me some videos on experts opinions on the subject, like

https://www.youtube.com/watch?v=Pz-4co8IaI8&list=LLmdEPb5geNqn_WSbq7J6FPw&index=43&t=0s

👍 1
(who bets to Java if choosing between C++ and Java)
m
I don’t have experience with performance/memory critical apps. Everything I’ve read tends to indicate the JVM can be very good at this, but like all things, may require some tweaking and full understanding of the library data structures etc. As far as language, I strongly lean to Kotlin. I was doing some Java, and although it’s a great language, it still felt like death by a thousand cuts in comparison to writing/reading Kotlin code. And the teams I’m working with feel the same way.
u
Thanks for your feedback, Mike! I personally enjoy Kotlin too. However in order to prove to my TPM that Kotlin is better than C++ in terms of language syntax i think we should demonstrate some measurable advantage, not just words
That’s why i’m looking for some articles, findings, comparisons, etc
m
As I said, unfortunately too many decisions are made by gut feel because objective studies/measures that are actually valuable are very tough to find/do. I don’t have anything concrete because I’ve never had the opportunity to do A/B comparison as that’s obviously significantly more expensive than just choosing one, even if it’s a little bit worse. I suspect the bottom-line is more about the team, what they’re comfortable with, and what they’re willing to learn. Any change of language will have a cost associated with it, and is likely quite hard to recoup the costs on… We’re all still waiting for the perfect language 😉
💯 1
u
Right 😀 Thanks! However, anyone - feel free to share anything helpful here
d
My experience limited experience with C++ is that people choose for “performance” dogmatic rather than pragmatic reasons-- they typically have no benchmarks, they just think they know it’s going to be necessary ahead of time. I think, depending on the problem you are trying to solve, you may be able to demonstrate that the performance between C++ and Kotlin is not significantly different with a small prototype or something to that effect. Although depending on the role of Javascript in the project you might still have problems because you’d probably be stuck running it through a WebView or something on Android.
u
Thanks for your input on that, Derek. Yeah, good point with small prototype. I’ve already started with prototype on Kotlin and i was able to do it really fast, though i’m not C++ expert (J2ee background instead). You’re right aobut Android, but we solved it with embedding of V8 and added huge paint as binary V8 required wich adds 15mb to the app
d
Ouch at the binary V8. I’ve been on another project which embedded the Rhino JS engine for our javascript-scripting needs, which is about 1MB in size, but it impacts startup time, and Rhino was very slow because it couldn’t use a JIT on Android.
c
I would start with these: https://yosefk.com/c++fqa/ 🙂 C++ is very easy to get wrong, Kotlin much less so.
👍 1
Kotlin is demonstrably more consistent, easier to learn and better designed (although the latter is arguable). If we are comparing languages. Eco-system is whole another matter. Kotlin eco-system is not very mature, that said it piggy backs on JVM one which is one of the most mature eco-systems out there. On the other hand Kotlin native is not ready for prime time, IMHO.
u
Yeah, agree completely. But i’d say it’s our feelings and overall impression and it’s pretty difficult to prove that to TPM. I’d really appreciate some experts opinions or measurable comparisons. However even “mature” C++ vs “still experimental” K/M already shows the difference 😉
k
i. and others in my org, have spent time looking at Kotlin Multiplatform vs. C++ for cross platform development
I've found both to be satisfactory from a purely language and productivity perspective, as there are good tools for C++ for autogenerating necessary bindings.
The real issue, IMO, comes from finding 3rd party libraries that can be easily consumed on iOS and Android, because you end up having to cross compile with 2 different toolchains and multiple ABIs
u
agree, libraries matter too
k
with Kotlin/native you've already got some useful tools that are supported (Ktor, kotlinx.serialization). But the Kotlin common stdlib is smaller than the Koitlin JVM stdlib
i see significant momentum behind Kotlin Multiplatform, though. The project is just in its infancy.
u
what makes you think so? BTW do you mean Kotlin/Native compiler pr K/Multiplatform as approach in general?
k
Jetbrains is investing heavily there. There were a number of multiplatform talks at KotlinConf (and also the year before)
you can easily see they want Kotlin to be used everywhere
Google is the other major member of the Kotlin Foundation, and they're also pursuing multiplatform (Flutter)
also, I've heard we're using Duktape as a lightweight embedded JS engine
IIRC, they said it's around 1 MB
u
yeah, we’ve tried Ducktape and it really suxx in terms of memory consumption (~4 times worse in our use case)
k
Gotcha
In my mind it's not an either/or proposition. We intend to use the right framework for any given project.
u
@Kris Wong Can you please explain why you think K/M (or K/N) is not mature enough?
k
Well, it's still experimental for one
It's not even released
There's less documentation and online conversation about issues and what not, because a lot of people are just getting started with it
r
IMO, it’s important to understand what experimental means in this context. Experimental does not indicate instability or unreadiness for “prime time”. I’m just going off the historical example of coroutines here, so forgive me if this is an incorrect conclusion. Experimental simply means that the API might have breaking changes in the future. As long as the benefits outweigh the risk of eating that potential cost, it’s a viable solution (and maybe even preferred).
I haven’t touched C++ in around 5 years, so I’m a touch unfamiliar with what’s available, but you might look at model constructs and standard extensions that would massively simplify current patterns in your existing code base. A really good (but Java-focused) example of this, would be Jake Wharton’s various intro-to-kotlin style talks he was giving non-stop about a year or two ago.
Here’s an example of a shorter one:

https://www.youtube.com/watch?v=0sPzDwS55wM

💯 1
t
Hi @4ntoine This is a well timed discussion as I am also looking into considering Kotlin for replacing a C++ project for support of multiple platforms (web/Windows desktop). It seems like a great language, but it seems like this would be an "all in" approach, and I would like to setup small "experiments" in order to learn from mistakes and "fail fast" if need me. Does anyone know of a way to ease Kotlin development in with C++ for developing a C++ native library used by Windows applications?
k
Kotlin/Native integrates nicely with C. Unfortunately not C++.
but you can easily develop independent modules in whatever language you like and bring them together into one app
to clarify my first statement, you can reference a C library from Kotlin code, but not C++. You can use a Kotlin library compiled with Kotlin/Native from either C or C++.
👍 1
s
Is C++ interop planned?
t
Thanks, @Kris Wong for that insight. So if compiling with Kotlin Native, I would have access to C standard libraries? That would provide a limited form of experimentation. I am also considering using Haxe since, in theory, that would allow me to generate C++ code that could compile with my existing C++ library. If there is a way to do something similar in Kotlin, that would make a nice POC as well.
k
certainly. that's the main point of Kotlin/Native
u
@Terry Gruenewald Yeah, my intention was also to do some poc projects. We will also need to use kotlin compiled code from C++. Afaik Kotlin and C++ interop for some reason isn’t supported (correct me) Objective-C glue layer isn’t desired for us. @Kris Wong any examples of accessing of compiled kotlin code from C++?
👍 1
k
it compiles to C headers/binary. you can easily use C from C++.
u
@Kris Wong Could you please explain it or reference to some sample code/project?
t
Thanks @Kris Wong
🍻 1
u
@Kris Wong I haven’t found any project example written in C++ using Kotlin code. I guess Kotlin code should be compiled to static or shared library with K/N and then reused in C++ project. However it’s unclear how to use it in C++ project. I believe it can expose only C interface, not C++ (correct me) and that’s disappointing disadvantage again. Any examples are still appreciated.
k
you are correct