From d6d0d36203f808e4f130e35fc52d96ed17bb1b5c Mon Sep 17 00:00:00 2001 From: Ryan Busby Date: Tue, 11 Dec 2018 13:58:19 -0800 Subject: [PATCH] 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. --- sections/errorhandling/failfast.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sections/errorhandling/failfast.md b/sections/errorhandling/failfast.md index 90ddbbb1..2fbe30c5 100644 --- a/sections/errorhandling/failfast.md +++ b/sections/errorhandling/failfast.md @@ -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);