The first 2 minutes made so much sense - pure logic, clean organization and anyone can immediately see how readable and easy to follow the code is after refactoring! Excellent work!
0:00 1. Eliminate if/else branching; early termination 2:16 2. Ambiguous definitions: ‘is’ function prefix to denote boolean return 4:05 3. Self documenting code: avoid belaboured comments 5:37 4. Consistent formatting. Use Eslint + Prettier to automate code style 7:14 5. DRY business logic. Look for opportunities to refactor. Make sure to test! 8:37 6. Fail or exit functions fast. Related to 1. 9:28 7. Avoid magic values - declare and use CONSTANTS instead. 10:41 8. Avoid violating single responsibility. Prefer to use pure functions (no side effects) 11:57 9. Overly clever code (code golf). Leads to impenetrable single liners (have to rewrite in order to debug) 14:00 10. Premature optimisations.
This video is an excellent example of what uncle Bob mentioned in his book about being pragmatic with your own clean practices. All your tips are in the book, and the tips you don’t judge it to be good you just don’t have to use. People flame uncle Bob with the “functions shall be short” tip, but they forget the pragmatism mentioned by Bob in the introduction of the book.
W, no bullshit, no annoying stuff, straight forward, not only clean code, also clean video
The isPrime example, you use Math.sqrt in the condition, this will in many languages, including js, cause the sqrt to be calculated on each pass of the loop so you should break that out to a variable and the comment can then be added to the creation of the variable, this will make it even more clear that the comment is for why we use Math.Sqrt and improve performance and reduce line complexity since the loop conditional will be a simple i <= maxDivisor or similar.
This might be the first YouTube video I've seen in well over a decade where the content actually starts at 0:00 Subscribed
You made me realise that my JavaScript code was complete doodoo and made me redo it all again. This time I actually understood what I was trying to do. Thank you.
His habit of clean code shows in his way of doing a video. Clean and crisp
Though of skipping the video, but it immediately got my attention due to how objective it is. Thanks for the content.
I have been coding since 1969 and constantly learning. With ober 13 Lang under my best (1st love is assembly on a mainframe) I always agonize over "is it readable?" If not them clean it up! I write with the intention that someone else may have to maintain this. I also never take code personally, as I have seen many coders do. Instead I will show my code to others and ask them "is this easy to understand?" If the answer is no, I need to fix it. On each function, I place "function notes block" which are a block of comments, right before the function definition. It describes why the function is used, all the variables used, along with global variables, and in the case of assembly, what registers are touched or referenced. I used to run the code through a custom print program to output all these "function note blocks" to be used along any documentation I have. It shows the functions sorted alphabetically, the module they are in along with the line number where they are defined. Comes in very handy when something goes wrong
A common mistake about dry is that people think it's about the same code. I love that you add for the same purpose. Many people even seniors, overlook this. The reason is that same code with different purpose will likely not mutate the same. And you might break one usage because you change the other.
3:39 these prefixes are called “auxiliary verbs” and include: is, does, was, will, should, can, and more. Great video! 👍
Just a small addition on the example of DRY; what's covered here is to replace three functions that do the same thing with one function that can do anything. If you want to enforce the passed-in value is always one of a specific set of strings, it should still be fine to use these other three functions. They can cover an abstraction, enforcing the passed "action" to be a specific value. Such as "return logAction("logged in")" in the first example function.
you just properly clarified what side-effects and pure functions are for me. I don't know why your phrasing is what finally got it to click, but I think I actually get it now.
For those on a tight schedule, his 10 principles start at 0:00
13:28 Good example at #9. I trying always read other people code before explanation, and, man, this reduce is insane complex expression that doing very simple thing. This one requires at least comment. And in other hand very simple and clean 'filter' and then 'map' expression that I can understand in 1 second.
This video is so good. So many gold nuggets that you don't learn in traditional coding bootcamps or tutorials.
clear info Conner, easy-to-understand. I've been making games for a few years (self-taught), and what a hell of experience because of my bad habits. I'm trying to become a real/better programmer now. You're video was a good start. Thanks.
Over commenting. I’m in university and I have to comment everything line for line and have a massive comment block on the top explaining how it works overall. Why is this taught if that many comments is actually a bad thing?
@euqinuykcaj