How to Increase Code Writing Speed: AI, Code Generation, and Plugins

How to Increase Code Writing Speed: AI, Code Generation, and Plugins

15:07, 26.05.2023

Article Content
arrow

  • Code Generation
  • Java Annotation Processing (APT)
  • Gradle Plugin
  • Kotlin Compiler Plugins
  • IDE
  • Code Completion
  • Live Templates
  • Plugins
  • Android Studio Templates
  • Geminio by HH
  • AI Code Completion
  • Conclusion

Developers often find themselves writing a significant amount of code and are constantly seeking ways to improve their code writing speed. This article explores various tools and techniques that can help accelerate code writing, including the use of AI, code generation, and plugins.

Code Generation

One effective approach to reducing the amount of code written is through code generation. By minimizing the code written directly in an application, its stability can be improved, and the occurrence of bugs can be reduced.

Java Annotation Processing (APT)

A well-known method for code generation is Java Annotation Processing (APT), which is commonly utilized in libraries like Dagger, Hilt, and Room. However, APT has certain drawbacks, such as increased build time and limitations on modifying existing Java classes.

To make APT work in Kotlin projects, KAPT (Kotlin Annotation Processing Tool) is used, which generates Java stubs that are then processed by the annotation processor. Although APT avoids using reflection and can be optimized further, it introduces additional complexity and impact on build time.

Kotlin Symbol Processing (KSP) is an alternative to APT specifically designed for Kotlin code. It eliminates the need for additional steps like KAPT and promises faster code generation compared to APT. KSP is built on top of Kotlin compiler plugins, which allows for potential optimization in future versions.

Gradle Plugin

In addition to building projects, Gradle can be utilized to incorporate code generation functionality. Various plugins like ViewBinding, DataBinding, Apollo GraphQL, protobuf, and SQLDelight can assist in code generation from non-Kotlin/Java sources, such as Android XML resources or SQL queries.

Kotlin Compiler Plugins

Kotlin compiler plugins offer unique capabilities for code generation. Examples of plugins include Kotlin Serialization, KSP, and Jetpack Compose. These plugins enable additional features and modifications to the code that go beyond what's specified in the original code.

IDE

The Integrated Development Environment (IDE) plays a crucial role in code writing speed. Android Studio or IDEA, the primary IDEs for Android development, offer numerous built-in features. Furthermore, the IDE's functionality can be extended through the use of plugins.

Code Completion

Code completion, provided by IDEs, significantly enhances code writing speed. It eliminates the need to remember specific class names or search for documentation. Autocomplete suggests appropriate classes or methods based on the context, making coding faster and more efficient.

Live Templates

IDEs, like IDEA and Android Studio, offer a feature called Live Templates. These templates allow developers to use abbreviations or shortcuts to generate commonly used code constructs quickly. Custom live templates can be created based on existing ones or from scratch, saving time in writing repetitive code.

Plugins

IDEs can be expanded through plugins, which provide additional code generation and modification capabilities. However, developing and maintaining plugins can be complex, requiring compatibility with multiple API versions. Writing plugins for IDEA is facilitated by referring to the source code of the IDEA Community Edition.

Android Studio Templates

Android Studio provides its own mechanism for generating code through templates. Although it offers various features and is regularly updated with new templates, adding custom templates is currently not supported. However, this limitation may change with future updates.

Geminio by HH

Geminio, developed by HH, is a notable solution for code generation. It allows the generation of code templates, known as recipes, which can span multiple files and even generate Gradle modules. Geminio offers the advantage of storing templates within the project, enabling versioning and code review.

AI Code Completion

With the prevalence of AI in various domains, including mobile OSs and hardware acceleration, it's time to consider leveraging AI for code writing. Google's subsidiary has even showcased AlphaCode, a neural network that excelled in Codeforces tasks, combining critical thinking, logic, algorithms, coding, and natural language understanding. 

But now we would rather explore AI technologies designed to assist in code writing rather than replace a regular programmer. 

GitHub Copilot is an AI code companion trained on GitHub projects. Although Kotlin support isn't official, it still works well. However, it learns from unrelated code, making relevant results challenging. Also, it requires an internet connection and sends your code to the server, raising concerns about privacy.

TabNine is another solution worth mentioning. While it only operates online, it can be self-hosted, allowing you to train the model on your codebase. This appeals to companies focused on data integrity and security.

Although coding with AI can be faster, it's important to note that services don't guarantee code quality, and they may suggest deprecated or flawed code. For this reason, what actually may happen is that one day we transition from software engineers to code quality engineers.

Conclusion

In the article above, we’ve presented some great tools that can facilitate writing code for you. As you have seen, they can provide great help in accelerating code writing by using different approaches. In particular, AI-code writing has a potential of overtaking more of the programmers work. However, for now, no approach can provide us with flawless code that doesn’t need to be reviewed, so competence in the field of coding is a necessary quality to really benefit from the tools discussed.

.



views 4m, 11s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

How to modify hosts file
How to modify hosts file
cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.