I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.
the one problem with default parameters in a function is that it only works if the parameter is undefined.
If the parameter is null, then the default parameter isn't applied; Default parameters don't strictly behave as a truthy check.
e.g.
function plusSome(num, some = 1) {
return num + some;
}
plusSome(1, null); // returns 1. Because null passed in, coerced to 0
plusSome('1', null); // returns '1null'
So, even with default parameters, you still have to be careful
Of course, I'm only pointing out the negatives and none of the many positives...
You made a big no-no with some of your functions by NOT naming them as VERBS. "newBurger" is NOT a good function name. What? Are you "newing" it??? How about, "createBurger"? NOW that IS a VERB -- much better!
Also, it is a good thing to implement METHOD CHAINING in your CLASSES, but I see chains used TOO MUCH. My rule, if it's a void return then it should instead return this. However, your example above for total chains .map & .reduce. Instead, you should have 2 variables: prices (mapped) & total (reduced). That way, when more functionality around pricing is added, another [Jr] dev doesn't come along and write var prices = items.map( ({ price }) => price ) -- adding another full iteration to the operation. It's also more informative when we're "reducing prices" rather than "reducing [structure]".
Moreover, JavaScript is both Functional AND OOP, and if you're not using both you're just not going to write good code. Why encourage only Functional? Jr devs automatically, naturally gravitate toward writing Functional code, why not encourage more OOP? That would probably benefit a dev much more.
I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.
I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.
I always love the opportunity to create useful solutions. I'm passionate about my projects, believer of team work and communication and find joy creating things that people will really use.
How can I even begin to thank you, man, speechless on the quality of your post. My gratitude and I would like to share with my team the knowledge learned here.
I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.
I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.
I really like this series
Thank you very much!
I have already thought up to 6 parts for it!
I do not want to extend too much in the series but I want to see the beauty of clean code.
A greeting!
Would really love to see more!
Love it how you keep it precise and illustrate with examples :-)
the one problem with default parameters in a function is that it only works if the parameter is
undefined.If the parameter is
null, then the default parameter isn't applied; Default parameters don't strictly behave as a truthy check.e.g.
So, even with default parameters, you still have to be careful
I agree in part, because generally speaking you shouldn't pass null as param, and functions shouldn't return null
Of course, I'm only pointing out the negatives and none of the many positives...
You made a big no-no with some of your functions by NOT naming them as VERBS. "newBurger" is NOT a good function name. What? Are you "newing" it??? How about, "createBurger"? NOW that IS a VERB -- much better!
Also, it is a good thing to implement METHOD CHAINING in your CLASSES, but I see chains used TOO MUCH. My rule, if it's a void return then it should instead return
this. However, your example above fortotalchains.map&.reduce. Instead, you should have 2 variables:prices(mapped) &total(reduced). That way, when more functionality around pricing is added, another [Jr] dev doesn't come along and writevar prices = items.map( ({ price }) => price )-- adding another full iteration to the operation. It's also more informative when we're "reducing prices" rather than "reducing [structure]".Moreover, JavaScript is both Functional AND OOP, and if you're not using both you're just not going to write good code. Why encourage only Functional? Jr devs automatically, naturally gravitate toward writing Functional code, why not encourage more OOP? That would probably benefit a dev much more.
Wow ok. This is indeed a great series, I will also share it with my team. How the hell did I miss the ES6 default arguments thingy...
Thanks for the article, it's really useful.
Thanks!!
This is a post series about my experience develop using JavaScript.
Pretty impressed with the quality of this post.
With your permission, I'm sharing it with my team, tocayo :)
It is a great honor for me to share my content :-).
Hopefully we can devirtualize in some event, some day!
Cheers!
A simple thank you can't express my gratitude. Bring more
How can I even begin to thank you, man, speechless on the quality of your post. My gratitude and I would like to share with my team the knowledge learned here.
Thanks! 🔥🔥
Congratulations Carlos!
Really good article that resumes the core points of the Clean Code book!
The tips you describe here are pretty big deal for newcomers and even for the senior developers!
Thanks! 💪💪
"Without wanting to enter into debate between programming paradigms"
Boldly enters into debate between programming paradigms...