Home

CS 478 HW 2 Reflection

Node

Keep track of any changes you made to your back end as you implemented your front end. What changes did you need to make and why? If you could go back in time, is there anything you would change about the way you approached making your back end for HW1?

Some changes I made to the back end involved updating the validation to ensure that the form data to create an author or book is not empty. This was necessary because initially when I submitted the form to create a book or author it was allowing me to create books with empty titles, and authors with empty names. I also had to add some logic that parses integers from the request body, because apparently, you can only send numbers over http as a string, and then they need to be converted back to a number on the server side. I also added routers to make adding the `/api` to the start of the API route a little bit easier. If I could go back in time, I would have added these changes before building the UI.

When adding books and authors, did you only use server-side validation, or did you also use client-side validation? What are the pros/cons of making either choice?

I only used server side validation, as in this case it was sufficient on it's own. The pros of making client-side validation is that it puts less load on the server, because invalid requests are filtered before even being sent to the API. The con to client-side validation is that it's insufficient on it's own, because someone could always just hit the API directly using curl or postman, and the client-side validation would be rendered useless. The pro of server-side validation is that it always stops bad data from reaching the database even if the user uses curl or postman to circumvent the API. In this way, client-side validation is optional, however server-side validation is not.

React

What was your general experience using React? What did you struggle with? What did you enjoy?

I enjoyed using React. I found the process of creating components and screens easy to work with. I found it satisfying being able to have a reusable header (as opposed to copy and pasting one for a vanilla HTML website). I also found routing to be intuitive. One thing I struggled with was complying with typing. When I recieved a response from the database, and stored it to state, I had to create an interfacing matching the expected data format received from the database and explicitly define it in the `useState` declaration or else React would assume I was working with a `never` type because the state starts off as an empty array.

Compare and contrast writing React versus writing plain JS DOM manipulation code as you did in CS375. How was your experience different? Which do you prefer and why?

Writing React was much more succinct and overall a much better experience. As mentioned before, I really enjoyed the ability to reuse the header component so that I didn't need to copy and paste as much. I also found that managing state was initially a little harder because of the need to use a setter function, but all in all, I know that when the app's codebase gets bigger it will save more headache in the long-run. I definately prefer writing React.

What was your experience using types with the front-end? Did they catch any bugs? Did you struggle to type things correctly? Did they feel helpful, useless, tedious?

Types were definately useful, but they were annoying at times. Like I mentioned before, when recieving data from the API, I needed to create custom datatypes to outline what the expected data would look like. The most annoying thing was that useState kept assuming any state that starts with a value of `[]` is of type `never[]`. I guess it makes sense because React can't know from that initial value what the underlying array type is, it just would've made my life easier if it defaulted to `any[]` instead, though I also understand why React choses not to do that, as to not let me (the programmer) be lazy about types. Other than that minor annoyance though, I didn't struggle with typing.

LLMs

Did you use LLMs to help you write your code? If yes, explain how you used them.

No

If you used LLMs, reflect on how they changed your experience of coding. Did they make it more or less fun? Did they save you time? How do you think they affected what you learned from this assignment?

N/A