Hearted Youtube comments on Kantan Coding (@kantancoding) channel.
-
3200
-
2200
-
2100
-
827
-
625
-
531
-
305
-
281
-
277
-
268
-
218
-
217
-
166
-
162
-
147
-
146
-
127
-
as a lead dev, I can only say that you never want to debug such code, which contains 10 small functions, because someone decided to split everything. It is a huge pain to debug such code, because you have to switch context a lot. You have to switch between function, classes, files.
Sometimes it is much better just to have one bigger method instead of 5-10 small. Sometimes it is always better to not create an abstraction for every single potential change, because many of them will never happen.
For example, it doesn't make sense to create an abstraction for delimiter, because delimiter may never change. But sometimes it makes sense to create such abstraction, haha...that's the hardest part of programming - to find a good balance and write readable not overcomplex code.
It is not hard to create overcomplicated code with many abstractions, but the real problem is to create easy readable code for complex solutions.
114
-
111
-
108
-
99
-
93
-
73
-
72
-
71
-
69
-
68
-
67
-
67
-
66
-
65
-
64
-
58
-
58
-
55
-
53
-
50
-
48
-
47
-
47
-
47
-
46
-
45
-
I really dislike the common wisdom about "self-documenting code" as it is proven again and again by examples that are the simplest of simple code.
I think it all starts somewhere different. And that's the distribution of logic into multiple methods when it does not need to be that way.
When ever something gets so big that you might add in a comment, someone will say "just split it into descriptive methods", and yes, in the spirit of uncle bob you can split that 30 lines method into 10 simple methods. And instead of reading the code from lines 30 to line 60, the dev now has to scroll around trying to memorize 10 methods and what they do and build a mental model of how they are called. And after splitting one method into 10 methods, it's suddenly too much work to put a doc header of them, so we don't do it because we don't like tying shit after we just split that shit up for no reason.
Three steps back. Lets not split up code if there's no reusing of the methods. Let's keep the code local, in context.
Complex code exists, because complicated tasks exist.
So you got complex code. Your coworker asks "what dos that do?"
What do say? Do you go line by line saying things like "so this line checks if the first parameter is null" and so on? Of course not. Your coworker can read. Human language can is great to explain the concept of something. You will probably be able to formulate one sentence that can explain a complex block of code. Well, if you understand that code you should.
And that's a good comment. Because three years later, someone will search for a bug and will find that block of code and ONE GOOD LINE may explain it better than anything else.
"So what if the comments lie?"
Comments are written with the assumption that code does what it is meant to do. Comments may "lie" when the code does not what it is meant to do, but in that case, the bug is the discrepancy between intended and actual behavior. You got two versions now, one telling you what it does, and one what it is supposed to do. You can now check if the assumptions where wrong from the beginning or if it's an implementation error and the fix is going to make the code do what the comment tells.
That's my experience in working with complicated code.
44
-
44
-
44
-
44
-
41
-
40
-
39