How to Identify and Fix Code Smells in Kotlin

AI-powered code review tools are revolutionizing how teams maintain code quality. For Kotlin developers, these tools can automatically catch bugs, style issues, and even subtle code smells that hurt maintainability. By automating mundane review tasks, Panto’s AI lets your team ship features faster while still enforcing best practices.
In this tutorial we’ll define code smells, see common examples in Kotlin, and show how Panto’s GitHub-integrated AI review can spot and fix them in a real project.
What Are Code Smells and Why They Matter
Code smells are patterns in code that signal deeper design or maintenance problems. They aren’t bugs in the sense of breaking functionality, but they reduce code quality and make future changes harder. For example, a code smell might be an overly long function or duplicated logic. As one source puts it, a smell is “a piece of code that works now but may generate problems… because the code is difficult to understand, modify, or test.” Left unchecked, smells accumulate and create technical debt, slowing down development and increasing bugs down the road.
In practice, catching code smells early is key to maintainability. Simple refactorings suggested by tools can enhance maintainability and reduce technical debt. For example, automatically extracting duplicate code into a function improves readability and reuse. Automated reviews like Panto’s can pinpoint these issues immediately, so you fix them before they spread.
Common Code Smells in Kotlin
Kotlin brings its own best practices, but many familiar smells still apply. Common examples include:
- Long functions or classes (“Long Method/Class”): doing too much in one place. Very long blocks of code are hard to read and test.
- Duplicate code: copying similar logic in multiple places. This violation of DRY means a bug might need fixing in several spots.
- Tight coupling: classes or modules that depend too heavily on each other, making changes ripple through the code.
- Primitive obsession: overusing basic types (e.g. many String or Int parameters) instead of richer domain types or enums.
- Magic numbers and literals: scattering unexplained constants in code instead of named variables or enums.
Beyond these, Kotlin-specific issues often show up:
- Null-safety problems (for example, unnecessary null checks or use of the unsafe
!!
operator) can make code fragile. Some Kotlin experts consider heavy use of nullable types itself a code smell. - Overly generic types: for instance, a function returning
Any
(or a rawList<Any>
) obscures intent and type safety. - Business logic in data classes: Kotlin’s data classes should hold data, not behavior. Putting business logic into a data class mixes concerns and makes testing harder. It’s better to separate them into dedicated classes or functions.
Each of these smells increases complexity or risk. For example, adding optional properties or logic to a core data class violates separation of responsibility. Similarly, ignoring null safety can invite NullPointerExceptions at runtime. By contrast, idiomatic Kotlin constructs (like the safe-call ?.
, Elvis operator ?:
, listOfNotNull()
, etc.) help avoid these issues.
Panto’s AI review is trained to flag these smells in your Kotlin code, making your codebase more robust over time.
Integrating Panto AI into GitHub
Setting up Panto for code reviews is simple. First, on the repository (just a few clicks). Once installed, Panto can be invoked on any PR. For example, commenting /review
on a pull request triggers an instant AI analysis. (You can also enable automatic reviews so that every PR gets checked.) The AI model then reads the code changes, flags smells, and suggests fixes in comments on the PR.
- Install Panto on GitHub: Go to the GitHub marketplace link in Panto’s docs and add Panto to your organization or repo.
- Trigger a review: In a PR conversation, add a comment
/review
. Panto’s bot will reply with an analysis shortly.
With Panto active, let’s inspect the code smells it found.
Panto Review: Before-and-After Fixes
In one pull request, Panto identified several smells in the Kotlin code and suggested concrete fixes. Below are a couple of examples demonstrating the before-and-after code. (// ...
indicates omitted code for brevity.)
Null-safety and idiomatic Kotlin
In one function, the original code used explicit null checks on parameters:
Panto recommended using Kotlin’s safe-call (?.) and Elvis (?:) operator to simplify this. The refactored code combines the checks into one expression:
This version is shorter and handles nulls cleanly. Null-safety features catch potential null issues at compile time, making code safer and more maintainable. Using ?: "guest"
ensures that if user
or user.name
is null, we default to "guest" without a crash. This change addresses the code smell of manual null handling – Panto even flags excessive nullability as a smell.
Simplifying list operations
Another common pattern is merging two nullable lists. The original code had:
Panto suggested leveraging Kotlin’s built-in collection functions. The improved version uses listOfNotNull
and flatten
to handle nulls elegantly:
Here listOfNotNull(a, b)
creates a list containing a
and b
if they’re non-null, and flatten()
concatenates them. This single expression replaces many lines of checks. Using functions like listOfNotNull
and filterNotNull
is a clean way to deal with nullable collections. This fix removes boilerplate logic and prevents a null-safety smell.
In other parts of the PR, Panto also pointed out a long function doing too many tasks. For example, if a function was both parsing input and printing output, Panto would recommend breaking it into smaller functions or extracting logic into helper methods. This enforces the single-responsibility principle, making each function easier to test and maintain.
Overall, Panto’s suggestions focused on stronger typing and clearer responsibilities. For instance, if a function used very generic types (Any?
) or had unclear return types, Panto would advise giving them explicit, specific types. This makes the code self-documenting. In our examples above, switching to List<String>
and using Kotlin operators improved both safety and readability.
How AI Tools Boost Productivity and Code Quality
Using an AI code reviewer like Panto gives broad benefits. By catching code smells automatically, Panto helps standardize code quality and prevent technical debt. Its refactoring suggestions (like combining duplicate code) immediately reduce boilerplate and duplication, which enhances maintainability.
More generally, studies show that AI-assisted reviews let developers complete tasks significantly faster – for example, one report found a 26% speedup with AI support. Panto also frees developers from repetitive checks, so teams can focus on high-impact work. AI can handle the time-consuming and often inconsistent parts of review, and in doing so it enables the team to concentrate on architecture or features.
Furthermore, AI reviews like Panto’s work around the clock, ensuring no PR falls through the cracks. They enforce consistent standards regardless of who is on the team. In practice, this means spotting forgotten TODOs, insecure code, or outdated patterns early. All of this adds up: higher code quality and less manual effort. Panto’s own benchmarks categorize its feedback as aimed at catching bugs, improving design, and optimizing performance – exactly the kind of insights teams need.
What’s Next: Improving Your Kotlin Workflow with Panto
Panto is easy to adopt in your Kotlin projects. Try installing the Panto GitHub App on your own repo (just 2–3 clicks), and then comment /review
on a pull request to see instant feedback. As you’ve seen, Panto will call out null-safety improvements, encourage more functional Kotlin idioms, and highlight any large methods or data-class misuse. Over time, this keeps your codebase clean and maintainable.
In summary, AI code reviews give you the best of both worlds: speed and depth. They speed up reviews while enforcing code quality. By catching code smells automatically, Panto helps prevent bugs and technical debt before they hurt your project.
Give Panto a try on your next Kotlin PR – your future self (and fellow developers) will thank you.
Your AI code Review Agent
Wall of Defense | Aligning business context with code | Never let bad code reach production
No Credit Card
No Strings Attached


How AI Is Reinventing Developer Onboarding — And Why Every Engineering Leader Should Care
Let’s be honest: onboarding new developers is hard. You want them to hit the ground running, but you also need them to write secure, maintainable code. And in today’s world, “getting up to speed” means more than just learning the codebase. It means understanding business goals, security protocols, and how to collaborate across teams. If you’re an engineering leader, you know the pain points. According to a recent survey by Stripe, nearly 75% of CTOs say that onboarding is their biggest bottleneck to productivity. Meanwhile, McKinsey reports that companies with strong onboarding processes see 2.5x faster ramp-up for new hires. The message is clear: invest in onboarding, and you’ll see real returns. But here’s the twist: traditional onboarding just isn’t cutting it anymore.
Jun 12, 2025

Aligning Code with Business Goals: The Critical Role of Contextual Code Reviews
As a CTO, VP of Engineering, or Engineering Manager, you understand that code quality is not just about catching bugs; it’s about ensuring that every line of code delivers real business value. In today’s fast-paced development environments, traditional code reviews often fall short. Teams need a smarter approach: one that embeds business logic, security, and performance considerations directly into the review process.
Jun 11, 2025

Zero Code Retention: Protecting Code Privacy in AI Code Reviews
As CTOs and engineering leaders, you know that source code is your crown jewels — it embodies your IP, contains customer data, and reflects years of design decisions. When we built Panto as an AI code-review platform, we treated code with that level of trust: our guiding rule has been never to store or expose customer code beyond the moment of analysis. In this post I’ll explain why zero code retention is critical for AI-powered code reviews, how our architecture enforces it, and what it means in practice (for example, one customer cut PR merge times in half without sacrificing privacy). We’ll also cover how a privacy-first design meshes with industry standards like SOC 2, ISO 27001, and GDPR.
Jun 10, 2025

From Mundane to Meaningful: How AI Tools Boost Developer Productivity
Ask any high-performing developer what gets them excited about work, and you’ll rarely hear “writing unit tests,” “checking for input sanitization,” or “rewriting a poorly structured PR description.” Yet, this is exactly where so many engineers spend a chunk of their day. **77% of developers say they spend half or more of their time on repetitive tasks that could be automated,** according to GitHub Next & Wakefield Research, 2023. As a founder and former engineer, I’ve seen it firsthand: we hire people for their creativity and problem-solving ability, then bury them under mechanical, repetitive work. It’s no wonder developer satisfaction and retention are ongoing challenges for teams everywhere. So why does this happen? And more importantly, how do we stop it?
Jun 10, 2025

Build vs. Buy: Panto’s Take on AI Code Reviews and Code Security
As we talk to CTOs and engineering leaders, a common refrain we hear is, “We could just build this ourselves.” The idea of a custom, home-grown AI code review or code security tool can be tempting. It offers promises of full control, perfect fit to internal processes, and no subscription fees. It sounds great on paper: “Our engineers can tailor every feature” and “we keep everything in-house”. But from Panto’s perspective, that choice comes with hidden complexity. In this post, I’ll walk through why developing your own AI code tools—with layers of GenAI, compliance logic, and developer workflows—turns out to be far more challenging (and expensive) than most teams expect. I’ll also share how Panto has evolved its agent to solve these problems out of the box, and why many fast-moving teams find it smarter to buy rather than build.
Jun 02, 2025

Why SCA Should Be Part of Code Review Checks
Panto introduces its new Software Composition Analysis (SCA) module for real-time visibility into open-source dependencies. As part of Panto’s unified security platform (including SAST, IaC, and secrets scanning), the SCA module delivers severity-based vulnerability alerts, SBOM insights, license risk reporting, and developer-friendly dashboards. Learn how Panto SCA empowers teams to secure code fast without slowing delivery.
May 27, 2025