📝 My Assignment Reflection

Thoughts and lessons learned from this assignment

Coding

Time spent
I spent roughly 6-8 hours on this assignment.

Main focus
My primary focus was first ensuring that I could correctly retrieve and insert data into the database. Once that was working, I concentrated on writing suitable tests for my backend to verify that everything functioned as intended.

Biggest struggles
The biggest challenge I faced was realizing that if the database tables were not correctly initialized or reset, leftover data from previous runs could interfere with new data. This often caused unexpected issues when testing, highlighting the importance of proper database setup and cleanup.

TypeScript

Bugs caught
TypeScript was especially helpful in catching type errors, including situations where I passed arguments of the wrong type to functions or tried to access properties that were not defined on objects.

Bugs missed
It didn’t catch logic errors, such as incorrectly querying the database or accidentally using stale data.

Typing challenges
For this first assignment, I didn’t encounter any significant difficulties with TypeScript. The types required were relatively straightforward, and I was able to define interfaces and function types with ease. Overall, TypeScript worked seamlessly and helped me write safer, more predictable code, providing confidence that my functions and data structures behaved as expected.

Testing

Experience
Honestly, testing feels more like a sanity check for me, since I can’t be certain I’ve made a mistake unless I verify each function. Writing tests has become a habit, and in this assignment it felt particularly rewarding because the tests helped me uncover and fix some bugs in my code. Additionally, testing helped me understand how Vitest runs tests in parallel. At first, I wanted to create separate test files for authors.ts and books.ts, but when I ran both tests together, I realized that the data could overwrite each other, causing both tests to fail. This was an important lesson and something to keep in mind for future testing.

Bugs found
I actually found two bugs thanks to testing. The first was that I forgot to initialize the database when starting the server, which caused all database calls to report errors. The second bug was in the database setup: the id field required manual input, but when I wrote the insert statements, I expected it to be generated automatically. This mismatch caused errors during testing and highlighted the importance of carefully aligning database setup with my code.

Future improvements
For future improvements, I think it would be better to find a smarter way to separate the tests for authors and books into different files. To do this, I may need to learn a more efficient way to manipulate the database or simply create a fresh table each time I run tests. For now, I’ll leave this as a note for future me to address.

LLMs

Usage
I used ChatGPT when I noticed that my tests for authors and books were overwriting each other’s data. Before using an LLM, I had tried resetting and re-initializing the database each time a test function was called, but it still didn’t work. After about 30 minutes, I decided to ask ChatGPT for guidance and learned how Vitest runs tests in parallel. Based on that, I decided to combine those tests into a single file so the data would no longer overwrite.

Reflection
ChatGPT and other LLMs are powerful tools for gathering information. Before using LLMs, I had to search on Google and sift through multiple pages, which could sometimes take hours just to find a solution that worked for my problem. With ChatGPT, I can find relevant information in just a few minutes and select the best solution for my needs, which saves a lot of time. However, LLMs are not perfect. They can sometimes generate incorrect answers (hallucinate). Overall, LLMs are useful tools, but they require the user to have some understanding of the problem in order to evaluate whether the information provided is accurate, much like using a Google search.