Clean Code: SOLID – Beau teaches JavaScript



Learn the best practices of how to write clean code in JS. This video tutorial is over the S.O.L.I.D. principles of clean code programming:
S – Single Responsibility Principle
O – Open-Closed Principle
L – Liskov Substitution Principle
I – Interface Segregation Principle
D – Dependency Inversion Principle

Learn what these mean and how to implement them in JavaScript!

The full Clean Code playlist: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkK24EaPurzMq0-kw5U9pJh

Code: http://codepen.io/beaucarnes/pen/gmowZd?editors=0010

Ryan McDermott’s original article: https://github.com/ryanmcdermott/clean-code-javascript

Other resource on SOLID: http://thefullstack.xyz/solid-javascript/

Beau Carnes on Twitter: https://twitter.com/carnesbeau

⭐JavaScript Playlists⭐
▶JavaScript Basics: https://www.youtube.com/playlist?list=PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5
▶ES6: https://www.youtube.com/playlist?list=PLWKjhJtqVAbljtmmeS0c-CEl2LdE-eR_F
▶Design Patterns: https://www.youtube.com/playlist?list=PLWKjhJtqVAbnZtkAI3BqcYxKnfWn_C704
▶Data Structures and Algorithms: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkso-IbgiiP48n-O-JQA9PJ


We’re busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.

Join our community at https://freecodecamp.com
Read our Medium publication at https://medium.freecodecamp.com/

source

This Post Has 21 Comments

  1. Hungry Mind

    No man , examples are not to the point and technically incorrect.It is old video but should have replace this with the better one.

  2. crazylegs85

    From what I understand, dependency injection is more about not having 'hidden' dependencies within the function that is being called, but rather explicitly state what dependencies are used. This helps with testability (mocking/stubbing). By injecting the dependency or class you can easily create an object that will give you the behavior or state that is being tested. In the example in the video, the function call is changed to determine the type of protocol used to perform the request. However, you still use different classes in the function that's being called without the ability to mock them and hence only test the actual logic behind your request. Another side benefit of injection is speed. Your tests will run faster if they have a 'canned' answer ready rather than use the actual service (implementation).

  3. saharis sheme

    You gave a bad example for the Liskov Sibstitution principle, the goal is to sibstitute the Parent class with child class but it needs to work on the reverse direction also, and it is not going to work

  4. Carnaru Valentin

    With "push" you are modify reference so "close" from close to be modified is not respected.

  5. Bootstrapper

    SOLID seems like an antipattern. Lol is this just super old fashioned? if you did this you would end up with thousands of classes.

  6. Bakaoug4 G4

    Uncle Bob said this representatiof square and rectangle is wrong in his video

  7. JS Stallone

    Strange only 33K views, it seems nobody wishes to write clean code and instead prefer "Spaghetti"

  8. sdsdsdfsdf

    At 6:30 you say that Im able to substitute squares and rectangles? How is it possible if square no longer extends rectangle?

  9. Fredddy

    Отлично объяснил. Спасибо большое!

  10. movax20h

    There are few problems with this video.

    First these are PRINCIPLES, not RULES. As such you can't label things as BAD and GOOD. More like BETTER and WORSE. Or RECOMMENDED and DISCOURAGED. There are always situations where you need to ignore some principles, or say stop, and know at which point to say stop to making everything to adhere to principles to every last details. The problem with following some of these principles, is that the code and setup on a caller side is bigger than in your "BAD" examples, as such it can be actually BAD. One of the examples would be cryptographic libraries. You often want to restrict extensibility or dependency injection abilities, because it makes it easier to mess things up leading to unsecure system. There are many other situations in general code.

    Also, you can make Square be a child class of Rectangle, as long as you put only read only properties / actions into interface, and the modifiable ones into constructor. There are few other options that will still adhear to the L principle, without creation of Shape interface.

  11. Anthony L

    Sorry Beau, that's not a good example of Open/Closed. What if I want to add the ability to delete flavors? O/C is more about extending functionality, not data manipulation.

  12. Forgoroe

    I think I'd rather have the good way of doing things first, then the bad. I'm afraid my brain will somehow stick with the bad just cause it was explained first. Scumbag brain

Leave a Reply