{"id":274,"date":"2025-03-09T14:27:43","date_gmt":"2025-03-09T14:27:43","guid":{"rendered":"https:\/\/ajaykumar.co.in\/?p=274"},"modified":"2025-03-24T15:33:14","modified_gmt":"2025-03-24T15:33:14","slug":"ai-powered-coding-a-game-changer-or-a-trap","status":"publish","type":"post","link":"https:\/\/ajaykumar.co.in\/?p=274","title":{"rendered":"AI-Powered Coding: A Game Changer or a Trap?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What&#8217;s Covereted<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>AI Generated Code Current State<\/li>\n\n\n\n<li>AI Generated Code Anti-pattern<\/li>\n\n\n\n<li>Example of prompts for high quality code Generation<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co.webp\" alt=\"\" class=\"wp-image-295\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co.webp 1024w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co-300x300.webp 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co-150x150.webp 150w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co-768x768.webp 768w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-09-19.55.02-A-futuristic-AI-powered-coding-environment-with-a-developer-sitting-at-a-workstation.-The-AI-assistant-a-glowing-holographic-entity-is-suggesting-co-750x750.webp 750w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Okay, so you&#8217;ve decided to start using AI to generate code. The tool could be Windsurf, Copilot, Cline, Cursor\u2014any of these. By the time this post is published, there might be even more options available. So don\u2019t stress over which tool to use. Every day, we see flashy demos claiming their &#8220;Hello World&#8221; is the next big production-ready application. But the reality is far more complex. Production-grade applications are intricate and require careful craftsmanship on top of the code generated by LLMs.<\/p>\n\n\n\n<p>As the AI world evolves rapidly, a significant portion of coding tasks can now be offloaded to LLM-based coders. It\u2019s crucial to leverage them fully to boost productivity. Remember the quote from Andrew Ng: <em>AI will not replace human jobs, but humans with AI skills will replace those without them.<\/em> The future belongs to <strong>HI (Human Intelligence) + AI (Artificial Intelligence).<\/strong> While low-level tasks will get offloaded to LLMs, you need to level up your skills to thrive in the next-gen tech world. If a production issue arises, you must be able to fix it\u2014with or without AI. So, while generating code with LLMs is beneficial, maintaining control over the process is equally important to ensure the reliability of production deployments.<\/p>\n\n\n\n<p>We&#8217;ve been using these LLMs extensively and have observed both improvements and challenges in AI-generated code. Keeping control doesn\u2019t just mean selecting what to generate but also ensuring its quality. Best practices around design, architecture, maintainability, performance, and scalability must still be followed. <strong>Code craftsmanship matters.<\/strong> Design patterns play a key role\u2014they are proven solutions to recurring problems. Recognizing and applying them can lead to well-structured, maintainable applications. For example, the <strong>Bulkhead pattern<\/strong> is commonly used to contain failures within a specific area of an application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Danger of Anti-Patterns in AI-Generated Code<\/h2>\n\n\n\n<p>However, alongside patterns, there are <strong>anti-patterns<\/strong>\u2014practices that seem beneficial initially but cause long-term problems. These bad practices often appear to solve an issue quickly but lead to inefficiencies and maintenance nightmares down the road. The tricky part? They can feel like the correct approach at first.<\/p>\n\n\n\n<p>Let\u2019s examine some <strong>anti-patterns in AI-generated code.<\/strong> When using an LLM, the first generated solution might seem like the best one\u2014but in the long run, it could create more issues than it solves. Below, we\u2019ll discuss some common AI-related anti-patterns and how to defend against them.<\/p>\n\n\n\n<p>1. <strong>Blackbox Code Mentality (Cargo Cult Programming)<\/strong><\/p>\n\n\n\n<p><strong>Anti-pattern:<\/strong> Blindly accepting AI-generated code without understanding its inner workings.<\/p>\n\n\n\n<p><strong>Defense:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Conduct thorough code reviews with experienced developers.<\/li>\n\n\n\n<li>Use step-by-step debugging to trace the code\u2019s execution.<\/li>\n\n\n\n<li>Require AI to provide explanations or documentation alongside the code.<\/li>\n<\/ul>\n\n\n\n<p><strong>2. Lack of Maintainability<\/strong><\/p>\n\n\n\n<p><strong>Anti-pattern:<\/strong> AI generates code that is difficult to modify or extend.<\/p>\n\n\n\n<p><strong>Defense:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Enforce coding standards and style guides.<\/li>\n\n\n\n<li>Ensure AI-generated code is well-documented and modular.<\/li>\n\n\n\n<li>Regularly refactor AI-generated code to improve its structure.<\/li>\n<\/ul>\n\n\n\n<p><strong>3. Dependency Hell<\/strong><\/p>\n\n\n\n<p><strong>Anti-pattern:<\/strong> AI introduces excessive or conflicting dependencies.<\/p>\n\n\n\n<p><strong>Defense:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use version control and dependency management tools.<\/li>\n\n\n\n<li>Regularly review and remove unnecessary dependencies.<\/li>\n\n\n\n<li>Limit AI-generated code to well-defined modules to prevent bloated dependency trees.<\/li>\n<\/ul>\n\n\n\n<p><strong>4. Inefficient Code &amp; Unoptimized Algorithms<\/strong><\/p>\n\n\n\n<p><strong>Anti-pattern:<\/strong> AI may generate inefficient loops, recursive functions, or brute-force approaches.<\/p>\n\n\n\n<p><strong>Defense:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Perform benchmarking &amp; profiling to detect performance bottlenecks.<\/li>\n\n\n\n<li>Use Big-O analysis to assess algorithmic efficiency.<\/li>\n\n\n\n<li>Manually refactor AI-generated logic when necessary.<\/li>\n<\/ul>\n\n\n\n<p><strong>5. Over-Reliance on AI &amp; Skill Atrophy<\/strong><\/p>\n\n\n\n<p><strong>Anti-pattern:<\/strong> Developers become overly dependent on AI, leading to a decline in their coding skills.<\/p>\n\n\n\n<p><strong>Defense:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use AI as a tool to <strong>augment<\/strong>, not <strong>replace<\/strong>, human developers.<\/li>\n\n\n\n<li>Encourage continuous practice and skill improvement.<\/li>\n\n\n\n<li>Treat AI-generated code as a learning resource to understand different coding patterns better.<\/li>\n<\/ul>\n\n\n\n<p>By recognizing these <strong>anti-patterns<\/strong> and applying <strong>defensive strategies<\/strong>, developers can <strong>harness AI\u2019s power while maintaining code quality and security.<\/strong> AI-generated code can accelerate development, but blind trust in its output is a <strong>major risk<\/strong>. The best practice is to <strong>use AI as an assistant, not a replacement for human judgment.<\/strong><\/p>\n\n\n\n<p>Now, let\u2019s look at some <strong>prompting strategies and generated code examples.<\/strong> <em>(I\u2019m using Claude 3.5 Sonet Preview in GitHub Copilot.)<\/em><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Basic Prompt<\/p>\n<cite>Generate an ASP.NET Web API endpoint to save user data to a SQL database.<\/cite><\/blockquote>\n\n\n\n<p><strong>Generated Code<\/strong><\/p>\n\n\n\n<pre title=\"Model\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using System.ComponentModel.DataAnnotations;\n\nnamespace YourNamespace.Models\n{\n    public class User\n    {\n        public int Id { get; set; }\n\n        [Required]\n        [MaxLength(100)]\n        public string Name { get; set; }\n\n        [Required]\n        [EmailAddress]\n        public string Email { get; set; }\n\n        [Phone]\n        public string PhoneNumber { get; set; }\n    }\n}<\/code><\/pre>\n\n\n\n<pre title=\"DBContext\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using Microsoft.EntityFrameworkCore;\nusing YourNamespace.Models;\n\nnamespace YourNamespace.Data\n{\n    public class ApplicationDbContext : DbContext\n    {\n        public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)\n            : base(options)\n        {\n        }\n\n        public DbSet&lt;User&gt; Users { get; set; }\n    }\n}<\/code><\/pre>\n\n\n\n<pre title=\"API Controller\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using Microsoft.AspNetCore.Mvc;\nusing Microsoft.EntityFrameworkCore;\nusing YourNamespace.Data;\nusing YourNamespace.Models;\n\nnamespace YourNamespace.Controllers\n{\n    [ApiController]\n    [Route(&quot;api\/[controller]&quot;)]\n    public class UsersController : ControllerBase\n    {\n        private readonly ApplicationDbContext _context;\n\n        public UsersController(ApplicationDbContext context)\n        {\n            _context = context;\n        }\n\n        [HttpPost]\n        public async Task&lt;ActionResult&lt;User&gt;&gt; CreateUser(User user)\n        {\n            if (!ModelState.IsValid)\n                return BadRequest(ModelState);\n\n            _context.Users.Add(user);\n            await _context.SaveChangesAsync();\n\n            return CreatedAtAction(nameof(GetUser), new { id = user.Id }, user);\n        }\n\n        [HttpGet(&quot;{id}&quot;)]\n        public async Task&lt;ActionResult&lt;User&gt;&gt; GetUser(int id)\n        {\n            var user = await _context.Users.FindAsync(id);\n\n            if (user == null)\n                return NotFound();\n\n            return user;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Many more I removed for bravety. However, below are the issues with this code. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No validation&nbsp;of input (User&nbsp;model).<\/li>\n\n\n\n<li>No Proper Logging<\/li>\n\n\n\n<li>No API Documentation<\/li>\n\n\n\n<li>And many more more&#8230;..<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Improved Prompt<\/p>\n<cite><em>Generate an ASP.NET Web API endpoint to save user data to a SQL database using Entity Framework Core. Include input validation, asynchronous operations, dependency injection for the DbContext, proper error handling, and Swagger documentation. Explain the security measures used.<\/em><\/cite><\/blockquote>\n\n\n\n<p>Generated Code<\/p>\n\n\n\n<pre title=\"Model\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using System.ComponentModel.DataAnnotations;\n\nnamespace YourApi.Models\n{\n    public class User\n    {\n        public int Id { get; set; }\n\n        [Required]\n        [MaxLength(100)]\n        public string Name { get; set; } = string.Empty;\n\n        [Required]\n        [EmailAddress]\n        public string Email { get; set; } = string.Empty;\n\n        [Phone]\n        public string? PhoneNumber { get; set; }\n\n        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;\n        \n        public DateTime? LastModifiedAt { get; set; }\n    }\n}<\/code><\/pre>\n\n\n\n<p>DTO Added<\/p>\n\n\n\n<pre title=\"DTO\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">namespace YourApi.Models.DTOs\n{\n    public class CreateUserDto\n    {\n        public string Name { get; set; } = string.Empty;\n        public string Email { get; set; } = string.Empty;\n        public string? PhoneNumber { get; set; }\n    }\n}<\/code><\/pre>\n\n\n\n<p>DTO Validation Added \ud83d\ude42<\/p>\n\n\n\n<pre title=\"DTO Validation\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using FluentValidation;\nusing YourApi.Models.DTOs;\n\nnamespace YourApi.Validators\n{\n    public class CreateUserDtoValidator : AbstractValidator&lt;CreateUserDto&gt;\n    {\n        public CreateUserDtoValidator()\n        {\n            RuleFor(x =&gt; x.Name)\n                .NotEmpty()\n                .MaximumLength(100)\n                .Matches(&quot;^[a-zA-Z ]*$&quot;).WithMessage(&quot;Name can only contain letters and spaces&quot;);\n\n            RuleFor(x =&gt; x.Email)\n                .NotEmpty()\n                .EmailAddress()\n                .MaximumLength(255);\n\n            RuleFor(x =&gt; x.PhoneNumber)\n                .Matches(@&quot;^\\+?[1-9]\\d{1,14}$&quot;).When(x =&gt; !string.IsNullOrEmpty(x.PhoneNumber))\n                .WithMessage(&quot;Invalid phone number format&quot;);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Audit Details added. You may have asked for more details.<\/p>\n\n\n\n<pre title=\"Db Context with Audit field \" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using Microsoft.EntityFrameworkCore;\nusing YourApi.Models;\n\nnamespace YourApi.Data\n{\n    public class ApplicationDbContext : DbContext\n    {\n        public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)\n            : base(options)\n        {\n        }\n\n        public DbSet&lt;User&gt; Users =&gt; Set&lt;User&gt;();\n\n        public override Task&lt;int&gt; SaveChangesAsync(CancellationToken cancellationToken = default)\n        {\n            var entries = ChangeTracker\n                .Entries()\n                .Where(e =&gt; e.Entity is User &amp;&amp; e.State is EntityState.Modified);\n\n            foreach (var entry in entries)\n            {\n                ((User)entry.Entity).LastModifiedAt = DateTime.UtcNow;\n            }\n\n            return base.SaveChangesAsync(cancellationToken);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Controller Details<\/p>\n\n\n\n<pre title=\"Swagger Doc and many more \" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using Microsoft.AspNetCore.Mvc;\nusing Microsoft.EntityFrameworkCore;\nusing YourApi.Data;\nusing YourApi.Models;\nusing YourApi.Models.DTOs;\n\nnamespace YourApi.Controllers\n{\n    [ApiController]\n    [Route(&quot;api\/[controller]&quot;)]\n    [Produces(&quot;application\/json&quot;)]\n    public class UsersController : ControllerBase\n    {\n        private readonly ApplicationDbContext _context;\n        private readonly ILogger&lt;UsersController&gt; _logger;\n\n        public UsersController(ApplicationDbContext context, ILogger&lt;UsersController&gt; logger)\n        {\n            _context = context;\n            _logger = logger;\n        }\n\n        \/\/\/ &lt;summary&gt;\n        \/\/\/ Creates a new user.\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=&quot;userDto&quot;&gt;The user data.&lt;\/param&gt;\n        \/\/\/ &lt;response code=&quot;201&quot;&gt;Returns the newly created user&lt;\/response&gt;\n        \/\/\/ &lt;response code=&quot;400&quot;&gt;If the user data is invalid&lt;\/response&gt;\n        [HttpPost]\n        [ProducesResponseType(StatusCodes.Status201Created)]\n        [ProducesResponseType(StatusCodes.Status400BadRequest)]\n        public async Task&lt;ActionResult&lt;User&gt;&gt; CreateUser(CreateUserDto userDto)\n        {\n            try\n            {\n                var user = new User\n                {\n                    Name = userDto.Name,\n                    Email = userDto.Email,\n                    PhoneNumber = userDto.PhoneNumber\n                };\n\n                _context.Users.Add(user);\n                await _context.SaveChangesAsync();\n\n                _logger.LogInformation(&quot;User created successfully: {UserId}&quot;, user.Id);\n\n                return CreatedAtAction(nameof(GetUser), new { id = user.Id }, user);\n            }\n            catch (Exception ex)\n            {\n                _logger.LogError(ex, &quot;Error creating user&quot;);\n                return StatusCode(500, &quot;An error occurred while creating the user&quot;);\n            }\n        }\n\n        \/\/\/ &lt;summary&gt;\n        \/\/\/ Retrieves a specific user by ID.\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=&quot;id&quot;&gt;The user ID&lt;\/param&gt;\n        \/\/\/ &lt;response code=&quot;200&quot;&gt;Returns the requested user&lt;\/response&gt;\n        \/\/\/ &lt;response code=&quot;404&quot;&gt;If the user is not found&lt;\/response&gt;\n        [HttpGet(&quot;{id}&quot;)]\n        [ProducesResponseType(StatusCodes.Status200OK)]\n        [ProducesResponseType(StatusCodes.Status404NotFound)]\n        public async Task&lt;ActionResult&lt;User&gt;&gt; GetUser(int id)\n        {\n            var user = await _context.Users.FindAsync(id);\n\n            if (user == null)\n            {\n                _logger.LogWarning(&quot;User not found: {UserId}&quot;, id);\n                return NotFound();\n            }\n\n            return user;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Middleware added<\/p>\n\n\n\n<pre title=\"Application Builder\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">using FluentValidation;\nusing FluentValidation.AspNetCore;\nusing Microsoft.EntityFrameworkCore;\nusing YourApi.Data;\nusing YourApi.Models.DTOs;\nusing YourApi.Validators;\n\nvar builder = WebApplication.CreateBuilder(args);\n\n\/\/ Add services to the container\nbuilder.Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;\n    options.UseSqlServer(builder.Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));\n\nbuilder.Services.AddControllers();\nbuilder.Services.AddFluentValidationAutoValidation();\nbuilder.Services.AddValidatorsFromAssemblyContaining&lt;CreateUserDtoValidator&gt;();\n\nbuilder.Services.AddEndpointsApiExplorer();\nbuilder.Services.AddSwaggerGen(c =&gt;\n{\n    c.SwaggerDoc(&quot;v1&quot;, new() { Title = &quot;User Management API&quot;, Version = &quot;v1&quot; });\n    \n    \/\/ Include XML comments for Swagger documentation\n    var filePath = Path.Combine(AppContext.BaseDirectory, &quot;YourApi.xml&quot;);\n    c.IncludeXmlComments(filePath);\n});\n\n\/\/ ...existing code...<\/code><\/pre>\n\n\n\n<pre title=\"Security Header Middleware\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">namespace YourApi.Middleware\n{\n    public class SecurityHeadersMiddleware\n    {\n        private readonly RequestDelegate _next;\n\n        public SecurityHeadersMiddleware(RequestDelegate next)\n        {\n            _next = next;\n        }\n\n        public async Task InvokeAsync(HttpContext context)\n        {\n            context.Response.Headers.Add(&quot;X-Content-Type-Options&quot;, &quot;nosniff&quot;);\n            context.Response.Headers.Add(&quot;X-Frame-Options&quot;, &quot;DENY&quot;);\n            context.Response.Headers.Add(&quot;X-XSS-Protection&quot;, &quot;1; mode=block&quot;);\n            context.Response.Headers.Add(&quot;Referrer-Policy&quot;, &quot;strict-origin-origin-when-cross-origin&quot;);\n            context.Response.Headers.Add(&quot;Content-Security-Policy&quot;, &quot;default-src &#039;self&#039;&quot;);\n\n            await _next(context);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Improved Areas<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Input Validation:<\/em><\/li>\n\n\n\n<li><em>Security Headers:<\/em><\/li>\n\n\n\n<li><em>Audit Trail:<\/em><\/li>\n\n\n\n<li><em>Error Handling:<\/em><\/li>\n\n\n\n<li><em>API Documentation:<\/em><\/li>\n\n\n\n<li>&#8230;.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Next Prompt<\/p>\n<cite>Explain why you used AddAsync instead of Add, and how SaveChangesAsync avoids thread pool starvation.<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Generated Output<\/p>\n<cite>Let me explain the key differences and benefits of using async methods in Entity Framework Core:<br><code>AddAsync<\/code>\u00a0vs\u00a0<code>Add<\/code><br>Actually, in my previous response, we should stick with\u00a0<code>Add<\/code>\u00a0instead of\u00a0<code>AddAsync<\/code>. Here&#8217;s why:<br><code>AddAsync<\/code>\u00a0is only useful when using identity columns that need to get their value from a database sequence or\u00a0<code>HiLo<\/code>\u00a0patterns<br>For normal entity tracking operations,\u00a0<code>Add<\/code>\u00a0is sufficient since it&#8217;s a synchronous operation that just marks the entity for insertion<br>Microsoft&#8217;s documentation specifically notes that\u00a0<code>AddAsync<\/code>\u00a0provides no benefits for normal scenarios<br>Here&#8217;s the corrected controller code:<\/cite><\/blockquote>\n\n\n\n<p>You can see the what&#8217;s going on here \ud83d\ude42<\/p>\n\n\n\n<pre title=\"Example of proper Sync hanlding\" class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">public async Task&lt;ActionResult&lt;User&gt;&gt; CreateUser(CreateUserDto userDto)\n{\n    try \n    {\n        var user = new User\n        {\n            Name = userDto.Name,\n            Email = userDto.Email,\n            PhoneNumber = userDto.PhoneNumber\n        };\n\n        _context.Users.Add(user);\n        \n        \/\/ Use ConfigureAwait(false) since we don&#039;t need context after the save\n        await _context.SaveChangesAsync().ConfigureAwait(false);\n        \n        _logger.LogInformation(&quot;User created successfully: {UserId}&quot;, user.Id);\n        \n        return CreatedAtAction(nameof(GetUser), new { id = user.Id }, user);\n    }\n    catch (Exception ex)\n    {\n        _logger.LogError(ex, &quot;Error creating user&quot;);\n        return StatusCode(500, &quot;An error occurred while creating the user&quot;);\n    }\n}<\/code><\/pre>\n\n\n\n<p>You can see we are able to generate better designed code using prompts here on what are we looking for than fully relying on LLM to generate code for you. \ud83d\ude42 It means we need to keep upgrading ourself on fundamentals very well.<\/p>\n\n\n\n<p>Please comment\u00a0 how much percentage of code you have been able to generate which was put in the production. I would like to understand how is evolution is going for you.<\/p>\n\n\n\n<p>Happy AI Coding to you&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s Covereted Introduction Okay, so you&#8217;ve decided to start using AI to generate code. The tool could be Windsurf, Copilot, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":295,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[24],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=274"}],"version-history":[{"count":22,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/274\/revisions\/297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/media\/295"}],"wp:attachment":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}