Typo && Spacing

There was an extraneous space. I also updated functions syntax to follow the style guide referenced in other parts of this document. These functions could potentially be updated to es6 as well.
This commit is contained in:
Ryan Busby
2018-12-11 13:58:19 -08:00
committed by GitHub
parent bbafab92ed
commit d6d0d36203

View File

@ -2,7 +2,7 @@
### One Paragraph Explainer
We all know how checking arguments and failing fast is important to avoid hidden bugs (see anti-pattern code example below). If not, read about explicit programming and defensive programming. In reality, we tend to avoid it due to the annoyance of coding it (e.g. think of validating hierarchical JSON object with fields like email and dates) libraries like Joi and Validator turn this tedious task into a breeze.
We all know how checking arguments and failing fast is important to avoid hidden bugs (see anti-pattern code example below). If not, read about explicit programming and defensive programming. In reality, we tend to avoid it due to the annoyance of coding it (e.g. think of validating hierarchical JSON object with fields like email and dates) libraries like Joi and Validator turn this tedious task into a breeze.
### Wikipedia: Defensive Programming
@ -17,8 +17,7 @@ var memberSchema = Joi.object().keys({
email: Joi.string().email()
});
function addNewMember(newMember)
{
function addNewMember(newMember) {
// assertions come first
Joi.assert(newMember, memberSchema); //throws if validation fails
// other logic here
@ -29,11 +28,11 @@ function addNewMember(newMember)
### Anti-pattern: no validation yields nasty bugs
```javascript
// if the discount is positive let's then redirect the user to pring his discount coupons
function redirectToPrintDiscount(httpResponse, member, discount)
{
if(discount != 0)
// if the discount is positive let's then redirect the user to print his discount coupons
function redirectToPrintDiscount(httpResponse, member, discount)
if (discount != 0) {
httpResponse.redirect(`/discountPrintView/${member.id}`);
}
}
redirectToPrintDiscount(httpResponse, someMember);