Slide 1

Slide 1 text

AI Coding assistants Rajesh Lingappa / Michael Isvy PLEASE SCAN !!! 1

Slide 2

Slide 2 text

Who we are ● Rajesh Lingappa ○ Former Digital Ecosystems Platform Head at DBS Bank ○ Over 2 decades of product delivery; over a decade of AI ● Michael Isvy ○ VP of Engineering at cynapse.ai (Computer Vision) ○ 17 years of Java/Spring, 3 years of AI 2

Slide 3

Slide 3 text

Agenda ● Introduction to AI Assistants ● Cursor deep-dive ● Supervised coding ○ Michael: generating Java/Spring code ● Unsupervised coding ○ Rajesh: building a full stack application with minimum supervision 3

Slide 4

Slide 4 text

AI for Software Engineering 4

Slide 5

Slide 5 text

AI Assisted Coding - a new paradigm “It is our job to create computing technology such that nobody has to program. And that the programming language is human,” … “Everybody in the world is now a programmer. This is the miracle of artificial intelligence.” Jensen Huang at World Government Summit in Dubai. Feb 2024 “SaaS is Dead” Satya Nadella. Dec 2024 5

Slide 6

Slide 6 text

1. Code Completion, Explanation and Generation 2. Automated Testing 3. Code Review Automation 4. Refactoring large codebases 5. Documentation . . . AI for Software Engineering 6

Slide 7

Slide 7 text

1. Increased Developer Productivity 2. Better Test Coverage 3. Personalized Developer Assistance 4. Improved Decision Making 5. Code Exploration and Familiarization Benefits of AI for Software Engineering 7

Slide 8

Slide 8 text

1. Evolving Standards, Models and Tools in flux 2. Overestimating AI’s capabilities 3. Complexity in Integrating AI tools 4. Potential performance overhead 5. Potential security Risks in generated code Gotchas of AI for Software Engineering 8

Slide 9

Slide 9 text

Cursor deep-dive Code-samples in Java 9

Slide 10

Slide 10 text

Prelude: state of AI coding assistants in IntelliJ ● IntelliJ is Java developers’ solution of choice ○ Great reputation among Java developers Source: Baeldung's 2024 Survey 10

Slide 11

Slide 11 text

IntelliJ support ● AI support is limited ● Our bet: Jetbrains is preparing a major update IntelliJ + Copilot VSCode + Copilot Cursor (based on VSCode) In-editor Chat ✅ ✅ ✅ Code gen with diff ❌ ✅ ✅ Code gen as you type ❌ 😐 ✅ Community and Doc 😐 😐 ✅ Misc. (terminal, git messages…) ❌ ✅ ✅ 11 Disclaimer: These might change by the time this talk is over :) demo: GreetingService IntelliJ

Slide 12

Slide 12 text

Cursor: the new kid in the block? ● Has taken the dev community by storm in only 3 months ○ Now used by over 100,000 developers ○ Windsurf and Copilot are catching up fast ● Super-focused on developer experience ● Still a young company ○ Only 20 people at the time of writing! ● https://www.cursor.com/ 12

Slide 13

Slide 13 text

Cursor implementation ● Fork of VSCode with embedded AI capabilities ○ Still compatible with all VSCode plugins ● No support yet for other IDEs ○ IntelliJ, Pycharm, GoLand, Visual Studio, etc https://forum.cursor.com/t/please-consider-a-jetbrains-plugin/17042/31 13

Slide 14

Slide 14 text

Let’s code! 14

Slide 15

Slide 15 text

Service class Springifying an application JUnit test 15 @Service public class StudentService { private final StudentRepo studentRepo; public StudentService(StudentRepo studentRepo){ this.studentRepo = studentRepo; } } @SpringBootTest public class StudentServiceTest { @Autowired private final StudentService studentService; @Test public void shouldFindStudentById() { } } demo: GreetingService part 1

Slide 16

Slide 16 text

Constructor Injection Quiz: which type of Injection in a Spring bean? Field Injection Setter Injection 16 @Service public class StudentService { private final StudentRepo studentRepo; /* No @Autowired */ public StudentService(StudentRepo studentRepo){ this.studentRepo = studentRepo; } } @Service public class StudentService { @Autowired private StudentRepository studentRepo; } @Service public class StudentService { private StudentRepository studentRepo; @Autowired public void setStudentRepo( StudentRepo studentRepo) { this.studentRepo = studentRepo; } }

Slide 17

Slide 17 text

Field Injection Quiz: which type of Injection in a Spring test? Constructor Injection 17 @SpringBootTest public class StudentServiceTest { private final StudentService studentService; @Autowired public StudentServiceTest( StudentService studentServ) { this.studentService = studentServ; } @Test public void shouldFindStudentById() { } } @SpringBootTest public class StudentServiceTest { @Autowired private StudentService studentService; @Test public void shouldFindStudentById() { } } demo: GreetingService part 2

Slide 18

Slide 18 text

● Most annotations may be omitted using conventions over configuration JPA: Class-Table mapping @Entity @Table(name = "student") public class Student { @Id @GeneratedValue @Column(name = "id") private Integer id; @Column(name = "name") private String name; //… } id fname 1 John 2 Sam Table: student 18 demo: VisitService part 1

Slide 19

Slide 19 text

@Transactional inside a SpringBootTest ● Keep your test database clean so it’s ready for the next test! @SpringBootTest public class StudentServiceTest { @Autowired private StudentService studentService; @BeforeEach public void initialiseStudent() { this.studentService.save(new Student(null, "Sam", "Smith")); } @Test @Transactional public void shouldFindStudentById() { var student = this.studentService.findById(1); assertThat(student.getId()).isEqualTo(1); } } BEGIN ROLLBACK 19 demo: VisitService part 2

Slide 20

Slide 20 text

Tab completion ● Cursor: name came from the fact that it can autocomplete next to your cursor ○ Still compatible with all VSCode plugins ○ Uses Tab feature (used to be called Copilot++) 20 demo: LoggerTest

Slide 21

Slide 21 text

Conclusion on Cursor and Java dev ● Cursor is a great AI coding assistant ● Java developers are facing a dilemma ○ Give up on IntelliJ or use limited AI assistant ○ Most likely it will improve in a few weeks https://forum.cursor.com/t/please-consider-a-jetbrains-plugin/17042/31 21

Slide 22

Slide 22 text

Unsupervised coding 22

Slide 23

Slide 23 text

We shall use Cursor to build a very simple pet service / API. What are we going to do? 23 In Scope pets-service order-service storefront notifications

Slide 24

Slide 24 text

● Initial prompt: Let the tool build everything 24 1. Generate a NodeJs / Express / Typescript REST API implementation for a Resource Pet with the following attributes: a. id (number) b. name (string, min=3, max=20) c. tag (string , min=3, max=20, optional) 2. Ensure input fields are validated 3. Add tests with test coverage and ensure coverage is above 80% 4. Generate necessary steps to run and test the service

Slide 25

Slide 25 text

We will be more specific about what we want 25 ● New prompt: You are a senior nodejs developer. implement the following requirement in full. Go through every step below and follow the instructions accurately. 1. write an express / typescript based REST API implementation for the openapi spec @pets_api_v0.1.yaml 2. use the structure shown below: … … 3. add pagination semantics with optional page and limit query params. default the limit to 1 and page to 0 4. add contract testing with coverage information. the test coverage must be a minimum of 80%. also, write through tests covering all api endpoints and scenarios 5. add necessary logging using winston 6. create necessary package.json and tsconfig.json 7. the api service will run on Nodejs 22

Slide 26

Slide 26 text

Let’s code! 26

Slide 27

Slide 27 text

We think it is generally went well. How did it go? 27 However, it is worth considering the following; 1. Keep an eye on (large scale) code changes (+/-) in short order 2. Go with incremental instructions / build 3. Look out for possible hallucinations - eg. including/omitting certain attributes from API resource, deleting test cases that errors out. 4. Don’t let the AI fix simpler issues - Cursor, for example can fix simple issues fairly well locally with its `Tab completion` feature 5. You own the code and the AI tools are assisting. So, make sure the code meets the requirements on security, quality, maintainability, scalability, etc

Slide 28

Slide 28 text

We barely scratched the surface of what AI could do for software engineering. There are several possible next steps - 1. Add security (ex: JWT) 2. Add observability 3. Integrate other frameworks / tools 4. Use AI in other parts of the workflow - Code Review, for example 5. Use of enterprise-wide policies to govern what AI generates 6. Documentation 7. Deploy the generated code according to enterprise standards ... Possible next steps.. 28

Slide 29

Slide 29 text

Conclusion 29

Slide 30

Slide 30 text

Supervised versus Unsupervised generation ● Cursor is a productivity tool for developers ○ Still needs to be supervised and improved ● If you’re using VSCode already, just jump into AI coding assistants! ● If you’re using Java or C#: it’s time to explore, things will improve fast 30 Be aware that AI tools are assistants, not replacements. Always validate AI-generated code and designs within the context of your project.

Slide 31

Slide 31 text

Our resources ● Java/Cursor demo: https://github.com/michaelisvy/cursor-spring ● builder.io Cursor vs Copilot comparison: https://www.builder.io/blog/cursor-vs-github-copilot 31

Slide 32

Slide 32 text

Thank you! 32