
Ask HN: Using Kotlin for web application back end - backslash_16
Hi HN,<p>The quick version of my question is: What are the pros and cons of creating a web application in Kotlin and if you had your choice of languages would you use Kotlin for that purpose?<p>The long version:
I just started a side project which will be your average web application. Users, authenticaiton, authorization, CRUD actions, your usual things. One of my goals is to learn a new language.<p>I&#x27;ve used statically typed languages for the backend for the majority of my dev career (C#, C++, just a little F#). I tried out Python and while I really like it for small projects, parsing data files, and practicing data structures and algorithms I really miss being able to lean on static typing when refactoring. I also miss the strong IDE integration I get with that category of languages.<p>I checked out mypy with Python and it&#x27;s really cool but unless I configured it wrong it doesn&#x27;t apply its type checking across files well.<p>All of this led to me to look at Java and then Kotlin. I love how you only need to type one side of your declarations like I&#x27;m using C#&#x27;s var. The idea of data classes is fantastic as well.<p>Because Kotlin is on the JVM and can interop with Java I&#x27;m hoping I can leverage those libraries and frameworks when needed. For some commentary on the tools, IntelliJ is a great IDE and I&#x27;m not sure how I feel about gradle yet.<p>With all that said, have any of you used Kotlin to build a webapp? What did you like about it, what didn&#x27;t you like? What other statically typed language would you use?
======
imauld
> tried out Python and while I really like it for small projects, parsing data
> files, and practicing data structures and algorithms I really miss being
> able to lean on static typing when refactoring. I also miss the strong IDE
> integration I get with that category of languages.

PyCharm has excellent integration with the language. It can give you expected
return types and check types of parameters if you sue type hints or if you
give functions and methods doc strings. I've used Java along with IntelliJ and
I would say the difference is pretty minimal. There is a metric ton more
boiler plate to write in Java so it's more needed. If you write Python like
you write Java you're going to have a bad time no matter what.

I would suggest Go. You get static typing,less verbosity, and a much easier to
use concurrency model. Depends on what you are making though. ORM's are not
really all that popular in the Go community so if you'll be needing one you
may want to look for something else. That being said, writing SQL isn't the
end of the world and there are a lot of upsides to using it.

~~~
backslash_16
It's possible I'm not writing Python in the best way, I've tried to embrace
duck typing and trusting my call sources & targets.

What I missed is the easy assurance from adding parameters to method calls,
changing function/method/class names.

I learned a lot about dynamic languages from a cool book - 99 Bottles of OOP

------
testb
Our backend is currently 50% Kotlin with hopefully 100% when we do a full
migration. I think you're already aware of the benefits such as data classes
which remove the cruft of normal POJOs. What Kotlin doesn't gift you is a
magically better architecture. There's still verbosity in querying a db,
serializing JSON, mapping SQL results. Those things by themselves are of
course not difficult but add in different layers and abstractions and suddenly
the language itself doesn't help that much when your overall flow is just as
complicated.

I'm not sure what is necessarily better right now - I am pretty happy with
Kotlin (using Dropwizard) and the type safety that comes with it.

~~~
backslash_16
Agreed, I feel like I always add a ton of code to communicate with the DB/data
storage system. If I go with Kotlin I think data classes will keep the number
of lines of code down at the very least.

For a side note about language influencing architecture, when I wrote Python I
felt some of the jobs you mentioned (serializing & deserializing JSON, mapping
SQL results to objects) were smaller and simpler, probably because I tried to
embrace duck typing and forget about types and checking somewhat. I'm not sure
if that's a great long term solution but it was an interesting feeling and
data point.

------
kjksf
If you want to learn a new language, then pick a project that has a known (to
you) scope, like porting an existing application you wrote.

If you want to complete a new project, stick to what you know.

Risk multiples.

If you want to pick a backend language, then pick one of: Go/Ruby (On
Rails)/Python/node.js/PHP. If you don't know which, then pick one of them
randomly.

Those languages were used to ship tens of thousand web applications.

Anything outside of that is an adventure. Remember: risk multiplies.

Kotlin is a fine language and you'll probably be fine but I would still pick
Go/Ruby/Python/node.js/PHP.

~~~
backslash_16
You're right, if I used C# I could knock out the project in a fraction of the
time it will (most likely) take me to learn:

    
    
      - IntelliJ (or VS Code with the Kotlin plugin)
      - gradle
      - Kotlin
      - A Kotlin applicable web framework and ORM
    

Thanks for the very applicable advice!

------
muzani
I love Kotlin, but JavaScript/node/typescript already gives a lot of the back
end hacker buzz.

Kotlin works great for large projects, because of the way components go
together. It would be nice to see it in a full web framework.

------
romanovcode
If you are proficient in C# I don't really see the point in going into Kotlin
at all given that you can use .NET Core.

------
smt88
I've done back ends in TypeScript/Node. The TypeScript part is great; the rest
is still Node and has awful, frustrating downsides. Package management remains
a disaster.

I haven't tried them yet, but Rust and Kotlin are next on my list. I really
can't stand working without static typing anymore.

~~~
backslash_16
Same here, I've worked on projects without static typing and it's more painful
without the safety of the compiler. Rust is also on my list.

I do think that programming in Python got me comfortable with passing
functions around and a few things that were easier in dynamic languages so I'm
always glad about that.

You use TypeScript instead of JS for Node? Interesting...

~~~
smt88
> _" You use TypeScript instead of JS for Node? Interesting..."_

I'm actually flabbergasted that anyone can write a large, complex Node back-
end without TypeScript. Even with fantastic IDE support from WebStorm,
jslint/hint, and great discipline, there is just way too much ambiguity, doc-
reading, and simple mistakes.

------
vram22
Is Kotlin somewhat stable, or changing fast like I think I've read Rust is?
Sorry if my impression on Rust is wrong or out of date, I think I read at
least somewhat recently that it is still changing fast.

