7 ms·
Detekt – A static code analyzer for Kotlin
- synesso 1y agoI've been using detekt for years. Why is this suddenly the top article on HN?
- collinvandyck76 1y agoThere's a ton of reasons why that may happen. One of which being that someone may not have known about it and wanted to share.
- TheWiggles 1y agoYes, this is exactly why I posted it. I'm learning Kotlin but thought others would find it useful.
- synesso 1y agoThank you. I wondered if there was something new. Enjoy your Kotlin journey!
- TheWiggles 1y agoThank you, I appreciate it. :)
- self_awareness 1y agoRandom trend, that's all. Sometimes people post the same link to HN for weeks, and nothing happens. Suddenly after 10th try, trend catches up, and the same link is on the main page.
- stefs 1y agohttps://xkcd.com/1053/ https://xkcd.com/1053/
- smokel 1y agoOut of curiosity, how many of you are using Kotlin for backend development? It seems that Java has caught up a bit, and the advantages of Kotlin (extension methods, better syntax, better null-checking) might not be enough to justify the risk of lock- in? Personally, I quite like Kotlin, but I haven't been able to convince most of my greybeard colleagues to make the leap.
- glasskaar 1y agoMy workplace of ~3k employees has Kotlin as the golden path for our backend services. We previously mainly used Java, but I think it's been Kotlin for almost every new service since 2018. I think it works great for us.
- Traubenfuchs 1y agoOne of our ex developers was a big kotlin fan and enabled it in every java/maven project he touched -that is actually quite easy and interoperability between java and kotlin is fine. He also refactored every class he touched to kotlin. After he left, no one else was really into continuing his work. Our mobile devs use kotlin though and they are happy. I'd say it's nice and I would actually start every new (spring/java) project I do in kotlin now. But for existing projects, I actually see no value. It does not magically make code easier to understand and it doesn't reduce bugs, it's just a bit more fun and challenging to write and pads your resume... We did have one issue where upgrading the kotlin version from 1.x to 2.x in a project broke all depending projects due to a classfile version issue though. I deferred it by just forcing the version back to 1.x. That's the kind of annoyance you can encounter.
- simon_void 1y agoI know one of these developers as well! It's me :D
- Tmpod 1y agoI think those features are quite good on their own, but Kotlin has many more worthy features, such as sealed hierarchies, import aliases, delegation, operator overloading, default arguments, named arguments, reified generics, inline value classes (though somewhat limited by JVM features still), a very nice stdlib (in part augmenting Java's stdlib), etc. Even newer stuff like context parameters are really interesting and have useful applications. The language ends up being more complex, but I find it a joy to use; going "back" to Java projects always leaving me wishing I could use Kotlin instead :P Yet it's true, Java has improved quite a lot in the last decade. It is ahead of Kotlin in a few things, like pattern matching (though not incredible, it's still better than the nigh nonexistent support in Kotlin).
- robch 1y agoI have been using detekt for work and personal projects for years now. Writing advanced lint rules that take advantage type resolution makes it the best linter for Kotlin. I just hope they get k2 support soon.
- jascha_eng 1y agoThe worst thing about kotlin is the intellij lock in. VSCode support is exceptionally poor and that makes using modern AI tooling (like cursor) a pain.
- PaulHoule 1y agoJava has also improved greatly since JDK 7 so the need for JDK languages that are Java, but just a little better, is less than it was.
- smith7018 1y agoKotlin is much better than "Java, but just a little better."
- c03 1y agoKotlin has everything. A language isn't better just because it has more. Its great for DSLs though.
- PaulHoule 1y agoJava is pretty good for DSLs too.
- ohdeargodno 1y agoLanguage.Builder().getOh().getYes().getJava().getIsSoNice().setFor(() -> { return "DSLs";}); No trailing lambdas, no infix operators, no @DslMarkers, no top level functions, and an infinite list of examples of Java verbosity making even the smallest thing look like an ancient greek epic. Java is utterly terrible for DSLs.
- vips7L 1y agoLanguage { oh { yes { Java { isSoNice } } } You can contrive awfulness in any language.
- LennyWhiteJr 1y agoI love Detekt! It's particularly good for enforcing project conventions that can't be covered with standard linters. With access to the full AST, you can basically enforce any kind of rule you want with custom analyzers. And LLMs take out 90% of the effort for creating new analyzers.
- esafak 1y agoDo you use it in CI? Do you have a template or something to share?
- LennyWhiteJr 1y agoYeah, it's included as one of the gradle scripts which fails the build in CI if the rules don't pass. No template, as it's specific to my team's project, but one example is that we enforce that classes within our core domain don't import types from outside the project. You could accomplish this with separate projects, but that comes with its own complexities. This rule basically says "any domain type shall not import a non-domain type".
- rileymichael 1y agothere's an official template here: https://github.com/detekt/detekt-custom-rule-template/tree/main https://github.com/detekt/detekt-custom-rule-template/tree/m... and here's the diff for a 'real world' rule I implemented: https://github.com/michaelbull/kotlin-result/compare/master...rileymichael:kotlin-result:feat/detekt-ruleset https://github.com/michaelbull/kotlin-result/compare/master....
- cruz101 1y agocurious why this is being shared? Ive been using detekt for kotlin backend projects. It gets the the job done. Is there some new release or feature?