Evaluations
Evaluate our pet service CRUD application.
Qualities
The project has some qualities:
Some thought has gone into organizing the code, and the file names give us a pretty good idea of what’s contained within, even if
helpers
andlib
could be more helpful.There are few dependencies, resulting in good performance.It’s quite easy to add a new type of animal as long as no new special behavior is required. Storing information with or without a counter only requires the creation of a new class and routes.
Right now, the code isn’t overly complicated (but this is also due to its being a mere example).
Now, what are the specific issues with this project, and what does that tell us about other projects written in a similar style?
The first issue involves the passing of request
, response
, and next
parameters, something express seems to have made popular in the Node ecosystem. For example:
function queryParamValidation(request, response, next) {if (!request.query) {next();} else {try {// validatenext();} catch (e) {return response.sendStatus(400);}}}
Code issues
Despite its popularity, this approach includes disadvantages. Most important among them is that a lot of code becomes aware of what framework we’re using. So, if we decide to switch to a framework that doesn’t inject parameters, we must change a large part of our codebase. Due to the dynamic nature of JavaScript, changing to a similar but different framework presents additional difficulties. Small differences might cause subtle bugs that slip by our tests and manual verifications, particularly because we’ll probably be mocking those three parameters in most tests.
Speaking of tests, if the framework infects more of our code, we have to do more mocking, making our test code more complex and less predictable. A simple function that checks whether an incoming request contains an ID should produce a return value that we can verify. With an express-like framework, we have to check the response parameter instead.
Among the more ...