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!
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.
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.
W, no bullshit, no annoying stuff, straight forward, not only clean code, also clean video
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.
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.
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.
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.
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
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.
This video is so good. So many gold nuggets that you don't learn in traditional coding bootcamps or tutorials.
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.
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.
my hero who just jump into the topic with no delay and smalltalk ❤
🎯 Key points for quick navigation: 00:00 🌐 Avoid unnecessary nesting and branching to improve code readability and maintainability. 02:16 📝 Clarify ambiguous code by using descriptive names and function names that reflect their behavior. 04:09 🔍 Use comments sparingly and effectively to explain complex logic rather than reiterating what the code does. 05:32 🛠️ Maintain consistent code formatting for readability and reduce potential errors. 07:25 🔄 Apply the DRY principle to eliminate code duplication and enhance maintainability. 08:50 ⚡ Fail fast and early in functions to minimize unnecessary processing and enhance code efficiency. 09:47 🎩 Replace magic numbers or values with named constants to improve code readability and maintainability. 11:27 🔧 Ensure functions adhere to the Single Responsibility Principle to enhance clarity and maintainability. 12:08 🔄 Prefer clear and readable code over overly clever solutions for better maintainability and understanding. 14:08 ⏳ Avoid premature optimization; optimize code when necessary based on actual performance bottlenecks. Made with HARPA AI
i get all the points you made, that means my javascript studying has been going great. Excellent video my friend straight to the point no bullshit . NICE
For those on a tight schedule, his 10 principles start at 0:00
@euqinuykcaj