Hearted Youtube comments on Kantan Coding (@kantancoding) channel.

  1. 9
  2. 9
  3. 9
  4. 8
  5.  @kantancoding  What I was saying is that comments provide "a" layer of guidance and confirmation, not "the" confirmation. Yes certainly, there should be test cases. But in practical terms, the struggles around not knowing which is wrong, the code or the comments/tests is still valid in both paradigms, whether you're taking about comments or tests cases. Either way, when the bug report comes in, someone has to find the bug. When reading that code and wondering "hmm is this < supposed to be a <=", or "is this parentheses misplaced", or "is this parameter wrong", its much, much easier to read the nearby comments and gather the intent than to flip back and forth to another file elsewhere (like a test case) to try to figure out what the commentless "self documenting" code was supposed to do. The part about "self documenting code can eliminate the need for most comments" is the fallacy. Sure, when you're the one writing the code, your own comments can look somewhat redundant. But that's cognitive bias coming from already understanding the code and whatever idea it was implementing. To someone else debugging that code their first time, those comments can be valuable. The bandwagon of "self documenting code" and pressure to comment less seems to keep coming up as if its an answer, but it isn't. It's part of the problem, and its bad. Just like a dev who doesn't update comments is bad. I don't make excuses for either of them. You are right in that comments can be poorly written. Writing good comments is a skill, just like coding itself is a skill. But someone else's poorly written comments aren't a validation to this movement of discouraging comments in the name of "self documentation".
    8
  6. 8
  7. 8
  8. 8
  9. 8
  10. 8
  11. 8
  12. 8
  13. 8
  14. 8
  15. 7
  16. 7
  17. 7
  18. 7
  19. 7
  20. 7
  21. 7
  22. 7
  23. 7
  24. 7
  25. 7
  26. 7
  27. 7
  28. 7
  29. 7
  30. 7
  31. 6
  32. 6
  33. 6
  34. I really need to say this. The advice to never nest your code has been repeated for years now, it's the same thing that I was told 8 years ago when I was reading about how to write VB code in highschool and it is a good concept, but It's important to note something. In the provided example, yes, I think the code is easier to read, but it does not change the conditions you need to keep in your head. If you are doing more complex logic that then relies on the state of those conditions, you still need to know that those conditions are not true for example. Take authentication. If you have middleware the runs in an endpoint, or your function verifies that the user is authenticated before running, you still need to know that condition has been met, otherwise you will end up writing redundant code in your actual logic to ensure that the user is authenticated. Whether your nest or don't nest the condition, you need to be aware of the state your app can be in at that point in the code, and both ways require you to have this awareness. I agree that in most cases, early returns are better, but just wait until you have a function that has a structure like this and tell me it isn't confusing AF if (A) return // logic if (B) return if (C) return // logic if (D) { //logic } else { //logic } if (E) return //logic The code looks readable, but damn, it can get confusing, especially if the code I put as "//logic" can potentially return, therefore adding conditions that aren't even ovbious. Sometimes the real solution in my opinion is to double up your conditions just for understandings sake, or in a complex case, abstract where necessary. The idea of code inversion is very primitive and does not always apply
    6
  35. 6
  36. 6
  37. 6
  38. 6
  39. 6
  40. 6
  41. 6
  42. 6
  43. 6
  44. 6
  45. 6
  46. 6
  47. 6
  48. 6
  49. 6
  50. 6