Homework 1 Reflection

Coding

Total Time for Assignment

I spent roughly 5-6 hours in total over the course of 3 different days.

Time Spent Most On

I spent the most time designing my API, figuring out TypeScript, and fixing configurations. I spent a good chunk of time understanding how I wanted the author and book schemas to look like, using Zod to validate their schemas. I also had some issues trying to understand what type was needed or what type TypeScript was expecting, especially regarding a genre list for valid genres. That took me a while to understand and demonstrates typescript's benefit as it ensured that for a genre exactly matches my genre list. Lastly, I had some issues with npm run dev where my server would stop working after I made too many changes. After using Node version 20, the server seemed to become more stable.

What Did You Struggle With the Most?

I struggled most with the types and understanding what TypeScript is expecting. It is still a bit confusing from time to time reading all the types and having to add types. I do understand and see the benefits of typescript and it has assisted in catching errors earlier on. However, I still have lingering confusion and need more adjustment to the language. My experience for this assignment has been good. I don't have any suggestions for improvement as of now.

TypeScript

TypeScript Helped Me Catch

An array mismatch db.all<BookDB>() vs db.all<BookDB[]>() which would've been an issue if I tried to use result.title afterward. It ensured I would only be using valid genres from the genreList.

TypeScript Did Not Help Me Catch

The author's bio field is optional, and TypeScript cannot prevent users from sending bio: null which is not the equivalent of omitting the field. When deleting authors, TypeScript was not aware of foreign key constraints, causing some tests to fail.

Confusing TypeScript Topics

Optional vs nullable for Zod, as const used on lists, and creating the type for a list and type checking were all confusing topics. I had some confusion between what I could pass in for optional, and passed in "null" as a value to the field. However, that was incorrect, and the correct and more accurate representation is omitting the field which is what I would like users to be able to do. In addition, I had to take extra time to understand what as const does and how it changed the type.

Testing

Experience Writing Tests

Writing tests is rewarding knowing that your tests pass or that your code is working to some degree. They helped me understand what I should look out for in my code, such as when it comes to validation. I still tend to have habit of writing code before writing tests as I feel it helps me understand the problem and what test I need. Additionally, I have a hard time visuallizing what I need for the test before I write it. However, I would like to improve my test writing process next time by writing tests first for a change.

Did Your Tests Help You Find Any Bugs?

I discovered that if I insert an empty string for an optional text field such as genre, that would pass validation and become "" instead of null, making my database inconsistent. I had to add code to turn "" into null. I also learned that inserting null to test my validation doesn't work. I would be omitting passing in anything when I make something optional.

How Would You Structure Your Testing Differently in the Future?

I would structure my testing by major features and validation that I want to ensure I get correct in my code. I learned that testing is an easier method to exhaustively test features rather than trying to do so hands on, especially since there is no UI to test with.

LLMs

Did You Use LLMs to Help You Write Your Code?

I used LLMs to create a gitignore file, create inserts for books and authors for my database, write some repetitive tests, and explain certain types.

How LLMs Changed My Coding Experience

LLMs made my experience of coding less grueling by streamlining simpler tasks such as creating simple files like gitignore and writing the inserts for book and author items. Insert lines for the database are very repetitive and take away from the main task at hand. Having it assist in writing tests also saved time, as test writing starts to become a repetitive process after a while to check all cases. Using LLMs helped me get more time to learn about TypeScript, as I did not have to spend extra time on other tasks. I usually would spend less time looking at resources that aren't absolutely necessary and keep my code simple enough. However, I felt that I had more time to spend understanding my assignment, such as reading up on Zod and studying up on TypeScript.