Day in the Life of a Developer With Google’s Gemini Code Assist: Part 1
Explore Gemini Code Assist, its usage, and its impact beyond basic code generation for phases like bootstrapping, development, testing, deployment, and more.
Join the DZone community and get the full member experience.
Join For FreeI started evaluating Google's Gemini Code Assist development in December 2023, almost about its launch time. The aim of this article is to cover its usage and impact beyond basic code generation on all the activities that a developer is supposed to do in his daily life (especially with additional responsibilities entrusted to developers these days with the advent of "Shift-Left" and full stack development roles).
Gemini Code Assist
Gemini Code Assist can be tried at no cost until November 2024.
These are the core features it offered at the time of carrying out this exercise:
- AI code assistance
- Natural language chat
- AI-powered smart actions
- Enterprise security and privacy
Refer to the link for more details and pricing: Gemini Code Assist.
Note
- Gemini Code Assist was formerly known as Duet AI.
- The entire content of the study has been divided into two separate articles. Interested readers should go through both of them in sequential order. The second part will be linked following its publication.
- This review expresses a personal view specific to Gemini Code Assist only. As intelligent code assist is an evolving field, the review points are valid based on features available at the time of carrying out this study.
Gemini Code Assist Capabilities: What’s Covered in the Study as per Features Availability
Gemini Pro | Code Customization |
Code transformations
|
---|---|---|
✓ Available for all users | ✓ Local Context from Relevant files in local folder | x Use Natural Language to modify existing code e.g java 8 to Java 21 |
✓ Chat | × Remote Context from private codebases | |
✓ Improve Code Generations | ||
✓ Smart Actions | ||
Note: 1. Items marked with x will be available in future releases of Gemini Code Assist. 2. Code Transformations is not released publicly and is in preview at the time of writing. |
Technical Tools
Below are technical tools used for different focus areas during the exercise. The study is done on the specified tools, languages, and frameworks below, but the results can be applicable to other similar modern languages and frameworks with minor variations.
Focus Areas | Tools |
---|---|
Language and Framework |
Java 11 & 17; Spring Boot 2.2.3 & 3.2.5 |
Database | Postgres |
Testing | Junit, Mockito |
IDE and Plugins |
VS Studio Code with extensions:
|
Cloud Platform |
GCP with Gemini API Enabled on a project (Pre-requisite) Docker Cloud SQL (Postgres) Cloud Run |
Development Lifecycle Stages and Activities
For simplicity, the entire development lifecycle has been divided into different stages (below) encompassing different sets of activities that developers would normally do. For each lifecycle stage, some activities were selected and tried out in VS Code Editor using Gemini Code Assist.
S.No# | stage | Activities |
---|---|---|
1 | Bootstrapping |
|
2 | Build and Augment |
|
3 | Testing and Documentation |
|
4 | Troubleshoot | Invalid/No Responses or application errors |
5 | Deployment | Deploy Services to GCP Stack: Cloud Run/GKE/App Engine, Cloud SQL |
6 | Operate | Get assistance modifying/upgrading existing application code and ensuring smooth operations |
Requirements
Let's now consider a fictitious enterprise whose background and some functional requirements are given below. We will see to what extent Gemini Code Assist can help in fulfilling them.
Background | Functional Requirements |
---|---|
A fictitious enterprise that moved to the cloud or adopted “cloud-native” a few years back:
Grappling with multi-fold technical challenges:
|
Rules: A product will belong to a single category and a category may have many products. |
Let's Start with Stage 1, Bootstrapping, to gain deeper domain understanding.
1. Bootstrapping
During this phase, developers will:
- Need more understanding of domain (i.e., e-commerce, in this case) from Enterprise Knowledge Management (Confluence, Git, Jira, etc.).
- Get more details about specific services that will need to be created.
- Get a viewpoint on the choice of tech stack (i.e., Java and Spring Boot) with steps to follow to develop new services.
Let’s see how Gemini Code Assist can help in this regard and to what extent.
- Prompt: "I want to create microservices for an e-commerce company. What are typical domains and services that need to be created for this business domain"
Note: Responses above by Gemini Code Assist: Chat are based on information retrieved from public online/web sources on which it is trained, and not retrieved from the enterprise’s own knowledge sources, such as Confluence. Though helpful, this is generic e-commerce information. In the future when Gemini Code Assist provides information more contextual to the enterprise, it will be more effective.
Let’s now try to generate some scaffolding code for the catalog and recommendation service first as suggested by Code Assist. First, we will build a Catalog Service through Gemini Code Assist.
A total of 7 steps along with code snippets were generated. Relevant endpoints for REST API methods to test the service are also provided once the service is up. Let's begin with the first recommended step, "Create a new Spring Boot project."
Building Catalog Service, Step 1
- Generate project through Spring Initializr:
Note: Based on user prompts, Gemini Code Assist generates code and instructions to follow in textual form. Direct generation of files and artifacts is not supported yet. Generated code needs to be copied to files at the appropriate location.
Building Catalog Service, Steps 2 and 3
- Add dependency for JPA, and define
Product
andCategory
entities:
Building Catalog Service, Step 4
- Create
Repository
interfaces:
Building Catalog Service, Step 5
- Update
Service
layer:
Building Catalog Service, Steps 6 and 7
- Update the
Controller
and run the application:
Building Catalog Service, Additional Step: Postgres Database Specific
This step was not initially provided by Gemini Code Assist, but is part of an extended conversation/prompt by the developer. Some idiosyncrasies — for example, the Postgres database name — can not contain hyphens and had to be corrected before using the generated scripts.
Building Through Gemini Code Assist vs Code Generators
A counterargument to using Gemini Code Assist can be that a seasoned developer without Gemini Code Assist may be able to generate scaffolding code with JPAEntities quickly based on his past experience and familiarity with existing codebase using tools such as Spring Roo, JHipster, etc. However, there may be a learning curve, configuration, or approvals required before such tools can be used in an enterprise setup. The ease of use of Gemini Code Assist and the flexibility to cater to diverse use cases across domains makes it a viable option even for a seasoned developer, and it can, in fact, complement code-gen tools and be leveraged as the next step to initial scaffolding.
2. Build and Augment
Now let's move to the second stage, Build and Augment, and evolve the product catalog service further by adding, updating, and deleting products generated through prompts.
Generate a method to save the product by specifying comments at the service
layer:
Along similar lines to the product-catalog service, we created a Recommendation
service.
Each of the steps can be drilled down further as we did during the product-catalog service creation.
Now, let's add some business logic by adding a comment and using Gemini Code Assist Smart Actions to generate code. Code suggestions can be generated not only by comment, but Gemini Code Assist is also intelligent enough to provide suggestions dynamically based on developer keyboard inputs and intent.
Re-clicking Smart Actions can give multiple options for code.
Another interactive option to generate code is the Gemini Code Assist Chat Feature.
Let’s now try to change existing business logic. Say we want to return a map of successful and failed product lists instead of a single list to discern which products were processed successfully and which ones failed.
Let's try to improve the existing method by an async implementation using Gemini Code Assist.
Next, let's try to refactor an existing code by applying a strategy pattern through Gemini Code Assist.
Note: The suggested code builds PricingStrategy
for Shops
; e.g., RandomPricing
and ProductLength
pricing. But, still, this is too much boilerplate code, so a developer, based on his experience, should probe further with prompts to reduce the boilerplate code.
Let's try to reduce boilerplate code through Gemini Code Assist.
Note: Based on the input prompt, the suggestion is to modify the constructor of the shop
class to accept an additional function parameter for pricingstrategy
using Lambdas. Dynamic behavior can be passed during the instantiation of Shop
class objects.
3. Testing and Documentation
Now, let's move to stage 3, testing and documentation, and probe Gemini Code Assist on how to test the endpoint.
As per the response, Postman, curl, unit tests, and integration tests are some options for testing provided by Gemini Code Assist. Now, let's generate the payload from Gemini Code Assist to test the /bulk
endpoint via Postman.
Let's see how effective Gemini Code Assist generated payloads are by hitting the /bulk
endpoint.
Let's see if we can fix it with Gemini Code Assist so that invalid category IDs can be handled using product creation.
Next, let's generate Open AI Specifications for our microservices using Gemini Code Assist.
Note: Documenting APIs so that it becomes easy for API consumers to call and integrate these API(s) in their applications is a common requirement in microservices projects. However, it is often a time-consuming activity for developers. Swagger/Open API Specs is a common format followed to document REST APIs. Gemini Code Assist generated Open API Specs that matched the expectations in this regard.
Next, we are generating unit test cases at the Controller
layer. Following a similar approach, unit test cases can be generated at other layers; i.e., service
and repository
, too.
Next, we ran the generated unit test cases and checked if we encountered any errors.
4. Troubleshooting
While running this application, we encountered an error on table
and an entity
name mismatch, which we were able to rectify with Gemini Code Assist help.
Next, we encountered empty results on the get products
call when data existed in the products
table.
To overcome this issue, we included Lombok dependencies for missing getters and setters.
Debugging: An Old Friend to the Developer’s Rescue
The debugging skill of the developer will be handy, as there would be situations where results may not be as expected for generated code, resulting in hallucinations.
We noted that a developer needs to be aware of concepts such as marshalling, unmarshalling, and annotations such as @RequestBody
to troubleshoot such issues and then get more relevant answers from Gemini Code Assist. This is where a sound development background will come in handy. An interesting exploration in this area could be whether Code Assist tools can learn and be trained on issues that other developers in an enterprise have encountered during the development while implementing similar coding patterns.
The API call to create a new product finally worked after incorporating the suggestion of adding @RequestBody
.
Handling exceptions in a consistent manner is a standard requirement for all enterprise projects. Create a new package for exceptions, a base class to extend, and other steps to implement custom exceptions. Gemini Code Assist does a good job of meeting this requirement.
Handling specific exceptions such as "ProductNotFound
":
Part 1 Conclusion
This concludes Part 1 of the article. In Part 2, I will cover the impact of Gemini Code Assist on the remainder of the lifecycle stages, Deployment and Operate; also, productivity improvements in different development lifecycle stages, and the next steps prescribed thereof.
Opinions expressed by DZone contributors are their own.
Comments