ChatGPT — Bard: The comparison in automatically generating code – Medium
Sign in
Sign in
Ronnienguyen (Thien-Phuc Nguyen-Dinh)
Follow
—
Listen
Share
As developers, irrespective of our geographical location or industry, staying abreast of advancements in AI models is essential for enhancing technology and boosting efficiency across various domains. In today’s article, we’re immersing ourselves in a detailed comparison between Bard and ChatGPT, exploring how these cutting-edge AI models contribute to technological innovation, efficiency, and productivity in their respective applications.
In November 2022, the launch of OpenAI’s ChatGPT took the internet by storm, swiftly capturing widespread attention. Following suit, Google entered the arena with its own AI-powered chatbot, setting the stage for a compelling showdown between these tech behemoths. Both implementations leverage generative AI, a technology that dynamically produces content in response to user queries. This content spans a spectrum, encompassing text, images, and videos, all autonomously generated by machine learning models. In this evolving landscape, the clash between these two giants unfolds not just as a competition but as a pivotal moment in the progression of generative AI technology.
While popular AI-generated content for ChatGPT includes only text-generated answers, Bard has announced many kinds of different answers, including text, images, songs, and videos.
While the services of ChatGPT and Bard share similarities, they differ significantly in their data access capabilities. Bard is equipped to continuously draw information from the internet, ensuring that it stays abreast of the latest developments through real-time access to the most recent research and information. In contrast, ChatGPT’s sources are capped with data up to 2021, indicating a limitation to information available only until that point. However, intriguingly, as we explore in this article, it appears that ChatGPT has extended its reach beyond the officially announced data limitations. Despite its apparent constraints, ChatGPT seems to have surpassed expectations, showcasing a capacity for assimilating information beyond the initially declared boundaries set by its company.
As a developer, it’s increasingly evident that in the coming year, leveraging AI for code generation will become a pivotal aspect of our workflow. The integration of AI in code writing holds immense potential to expedite the development process, allowing us to efficiently translate complex business requirements into functional code. Beyond the time-saving advantage, this approach facilitates a quicker and more precise analysis of diverse business needs. In the current economic landscape, where agility is paramount, the market favors those who can swiftly adapt and innovate. Embracing AI for code generation positions developers as frontrunners in this race, enabling them to outpace competitors and respond promptly to evolving business demands.
ChatGPT is widely employed for generating diverse content types, showcasing its versatility across various domains. Notable applications include the automatic generation of written code, crafting compelling product descriptions, producing engaging blog posts, drafting email content, summarizing transcripts, capturing the essence of meetings and podcasts, and facilitating seamless translations. This broad spectrum of AI-generated content underscores the adaptability of ChatGPT, making it a valuable tool for a myriad of tasks spanning coding, marketing, content creation, communication, and language translation.
Selecting Java for your testing is a strategic choice, given its widespread popularity and extensive history in the field of backend development. With a legacy spanning over 25 years, Java has proven its reliability, scalability, and versatility in powering backend systems. As one of the most preferred programming languages for backend development, Java offers a robust foundation for building enterprise-level applications.
By choosing Java as your testing ground, you align with a language that not only boasts a vast ecosystem of libraries and frameworks but also has a strong community support. The mature and stable nature of Java makes it an ideal candidate for assessing the capabilities of AI models, ensuring compatibility and effectiveness in real-world scenarios, especially in the context of backend development. This strategic decision reflects a focus on industry-standard technologies, emphasizing the importance of stability and longevity in the development landscape.
Create a repository interface named “ExpenseRepository”, extends with MongoRepository, simplify the code base with local setup in MongoDB, provides a number of methods for interacting with a MongoDB database, you can try with another RDBMS such as: MySQL, PostgreSQL, Oracle.
The optional function findByName use to query the information with the name parameter input.
Create ExpenseService class, it provides methods for adding, updating, getting, and deleting expenses. The methods use the ExpenseRepository
to interact with the MongoDB database.
Create ExpenseController file, this controller provides the following RESTful endpoints:
First, we’ll take a look at how each system analyzes the structure of the code, as well as defines the functions within this file.
When using Bard, the outcomes often leave me feeling uneasy as they tend to align with a complexity that doesn’t align well with my specific requirements. The tool, while powerful, appears to introduce a level of intricacy that doesn’t meet the simplicity and clarity I seek for my particular needs:
I subjected Bard to a task involving my Java code, requesting it to autonomously generate unit tests. Here, I’ll break down the outcome for a more in-depth understanding.
In the code, I implement a manual check to determine the existence of a customer. This involves using an ‘if’ statement to verify if the customer object is not null. Subsequently, I proceed to update the customer information, ensuring that the password has been appropriately encoded using a PasswordEncoder
.
Let's talk about the strengths.
The unit tests exhibit several strengths that contribute to their effectiveness in validating the updateCustomerInformation
method. Firstly, the test methods are well-structured, each meticulously focusing on a specific scenario. This organization enhances the clarity of the overall test suite, making it both comprehensible and easily maintainable. Additionally, the strategic use of mocking, facilitated by Mockito, ensures proper isolation and controlled testing of dependencies such as CustomerRepository
and PasswordEncoder
. This approach fosters a controlled testing environment, crucial for accurate evaluation of the targeted functionality. The assertions employed in the tests serve as clear checkpoints, systematically verifying the expected outcomes and asserting the correctness of the tested functionality. Lastly, the inclusion of behavior verification using verify
further strengthens the test suite by ensuring that the requisite methods on mocked objects are invoked as anticipated, contributing to a robust and comprehensive testing approach.
It appears to be highly comprehensive, addressing all possible test cases across various scenarios with clarity.
Otherwise, there are some areas of concern we can look into it.
The current unit tests for updateCustomerInformation
exhibit strengths, but areas like code duplication and undefined null password behavior can be improved. To boost robustness, consider extracting common customer setup into shared methods or utilizing test data builders. This simplifies maintenance and avoids redundancy.
Furthermore, ensure null password handling aligns with app requirements. Explicit checks or documenting the expected behavior are crucial. Remember, resilient tests adapt to changes, so understand the implementation and design adaptable tests using dependency injection and mocking for isolation. Expanding coverage to include input validation, error handling, and integration tests further strengthens your testing suite. By addressing these points, you can create robust, comprehensive tests that solidify the quality and reliability of CustomerService
.
I find ChatGPT quite impressive, particularly in terms of its speed and the clarity that defines its responses as the focal point. The answers provided by ChatGPT are notably straightforward, making it easy for users to comprehend and implement the guidance offered. The efficiency with which ChatGPT delivers concise and clear responses contributes to a positive user experience. However, there are instances where ChatGPT falls short, especially when it comes to delving into specific details of a query. For example, in a test using the same code mentioned earlier, ChatGPT may not provide the level of detailed information that some users might seek for a more nuanced understanding. Despite this limitation, the overall swiftness and user-friendly nature of ChatGPT’s responses remain noteworthy.
The answer is very clear and have some strengths.
The test exhibits several notable strengths in its design and execution. Notably, it demonstrates a high level of proficiency in employing Mockito for effective mocking of dependencies such as CustomerRepository and PasswordEncoder. By doing so, the test adeptly isolates the behavior of CustomerService during testing, safeguarding against external factors that might otherwise influence results and bolstering confidence in the internal logic of the service.
Furthermore, the test follows a well-structured approach, adhering to the widely recognized AAA (Arrange, Act, Assert) pattern. This meticulous structuring enhances code readability and clarity, providing a clear sequence of events — from the setup of test data to the verification of the expected outcome.
A commendable aspect of the test lies in its thorough validation of method calls. It diligently examines the frequency and parameters of calls made to the mocked dependencies, ensuring that CustomerService interacts with them as intended. This not only offers valuable insights into the service’s collaboration with other components but also contributes to a more robust understanding of its behavior.
Lastly, the test includes a well-crafted confirmation of success by checking the method’s return value. This step ensures that the test appropriately verifies the correct indication of success in the event of a successful update. Such a confirmation serves as a fundamental assurance that the intended functionality is indeed fulfilled. Overall, these strengths collectively contribute to the test’s reliability and effectiveness in validating the functionality of the CustomerService.
However, there are notable areas for improvement that would enhance the overall robustness and effectiveness of the testing strategy.
Firstly, the test’s limited scope is evident in its focus on the happy path, neglecting critical scenarios such as updating non-existent customers, handling invalid input data, managing potential exceptions like repository failures, and defining expectations for null or empty passwords. To bolster the reliability of the service, it is crucial to introduce additional test cases that explore these edge scenarios and ensure comprehensive error handling.
Another area of concern is the potential for code duplication as more test cases are added. The current approach involves manual creation of customer objects, which may become cumbersome and prone to redundancy. A recommended improvement is to consider refactoring common steps into shared methods or employing test data builders. This not only enhances maintainability but also reduces duplication, ensuring consistency across tests.
Furthermore, the focus on internal variables, such as assertions related to the updated password within the existingUser object, raises concerns about the test’s independence and resilience. Shifting the emphasis towards the service’s observable behavior, such as return values and interactions with other components, would lead to more robust and reliable tests that are less reliant on internal state.
Expanding the test coverage to include integration tests for the actual repository and password encoder is another avenue for improvement. While unit tests are effective in isolating internal logic, integration tests would provide a more comprehensive validation of the system’s overall functionality and data persistence, offering a more complete assessment of the service.
Lastly, the encouragement of automation is pivotal for efficiency and consistency. Integrating the tests into a testing framework and automation pipeline streamlines execution and reporting, ensuring continuous coverage as the code evolves. This automated approach not only facilitates swift identification of issues during development but also contributes to the overall reliability of the testing process. Embracing automation aligns with best practices in software development, promoting a robust and efficient testing lifecycle.
In my experience, ChatGPT stands out for its simplicity and effectiveness in delivering answers with clarity. I appreciate its user-centric approach, making information accessible and easily understandable. On the other hand, while Bard is a valuable tool, it might be perceived as overrated and overly complex in the realm of artificial intelligence. The emphasis on complexity by Bard’s creators might overshadow its inherent educational value, especially for beginners learning to code.
For those starting their coding journey, Bard offers a comprehensive exploration of various problem scenarios. It aids in developing analytical skills and a deeper understanding of code. It’s a great resource for juniors, helping them leverage their abilities and progressively enhance their coding comprehension.
However, as one advances in their career, there’s a noticeable shift in preference among seniors and team leaders. The focus tends to lean towards simplicity and efficiency. Leaders often prioritize clear, straightforward solutions that enhance team productivity and expedite business scalability. The aversion to complex or legacy code stems from its potential hindrance to progress. Leaders take on the responsibility of steering the team away from unnecessary complexity, ensuring that code remains transparent and conducive to efficient collaboration.
In summary, while Bard serves as an excellent learning tool for beginners, the preference among seasoned professionals tends to favor solutions that are not only efficient but also straightforward, fostering productivity and preventing the accumulation of unnecessary complexity in the codebase.
If you have any concerns or contributions to enhance this article, please feel free to reach out via email at ndtphuclqd1306@gmail.com. Your feedback is valuable, and I look forward to collaborating to improve the content.
—
—
Be brave enough to knock on the door !!
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams