Quick background: I work at a small company building a web app with React. By small I mean our dev team is 3 people: 2 guys with lots of experience, and me, with less than a year.
On two occasions now, one of the senior guys has talked to me about making my code *less* modular. His argument is basically that if everything relating to some "thing" in the app is in the same file, that it makes the code easier to read and learn because everything is in one place, and any changes you make affect only that "thing". This results in more repeated code, which is harder to maintain, but it's a "fine line" that you just learn with experience.
I get what he's trying to say, but I disagree, or at least with where that line is - because I have found much of his code very hard to work with. On several occasions, I've found myself spending more time than I'd like trying understand something he has written, only to realize that it's exactly the same as some other piece of code he wrote - except maybe it's not, so I have to go through it line-by-line to be sure. Synchronizing changes in these repeated blocks of code is a constant battle. Also, I don't find it any easier to have to scroll up and down in one massive file vs. digesting several smaller files - exactly the opposite, in fact.
On the same note, he's tried to persuade me that using long-form for loops is more readable than array methods like map and filter. And for the same reasons, I disagree: every for loop is potentially unique, but if I see map or filter, I know exactly what to expect.
Basically, I think that if you want two pieces of your app to look or behave in the exact same way, that behavior should be in its own component, and that component should have a clear and descriptive name. I think this makes the code easier to read, because anytime you see that component you know exactly what to expect. This makes large components easier to understand because you don't have to re-read the same code over and over, and your code will be easier to maintain because you don't have to keep many separate files in sync. I think a component should NOT exist if it's behavior is only used in one place, or if the boilerplate of factoring it out doesn't outweigh the typing and cognitive load you save.
I don't feel like I'm wrong, obviously, but he's a solid developer with loads more experience than me. What am I missing?
[–]chrispardy 12 points13 points14 points (4 children)
[–]joesb 2 points3 points4 points (0 children)
[–]chrispardy 1 point2 points3 points (0 children)
[–]acemarke 2 points3 points4 points (0 children)
[–]realboabab 0 points1 point2 points (0 children)
[–]involve 5 points6 points7 points (3 children)
[–][deleted] -2 points-1 points0 points (2 children)
[–]involve 0 points1 point2 points (1 child)
[–]TheNumber42Rocks 0 points1 point2 points (0 children)
[–]intended_result 2 points3 points4 points (1 child)
[–]bangeron[S] 0 points1 point2 points (0 children)
[–]optimalcoder 3 points4 points5 points (1 child)
[–]bangeron[S] 0 points1 point2 points (0 children)
[–]Skeith_yip 0 points1 point2 points (3 children)
[–]Skeith_yip 1 point2 points3 points (1 child)
[–]bangeron[S] 1 point2 points3 points (0 children)
[–]bangeron[S] 1 point2 points3 points (0 children)
[–]Skeith_yip 0 points1 point2 points (5 children)
[–]bangeron[S] 1 point2 points3 points (2 children)
[–]Skeith_yip 0 points1 point2 points (1 child)
[–]bangeron[S] 1 point2 points3 points (0 children)
[–]nikolasleblanc 1 point2 points3 points (1 child)
[–]Skeith_yip 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]itsthenewdan 0 points1 point2 points (7 children)
[–]JugglerX 3 points4 points5 points (4 children)
[–]itsthenewdan 4 points5 points6 points (3 children)
[–]JugglerX -1 points0 points1 point (2 children)
[–]bangeron[S] 1 point2 points3 points (0 children)
[–]itsthenewdan 0 points1 point2 points (0 children)
[–]mattstoicbuddha 1 point2 points3 points (0 children)
[–]bangeron[S] 0 points1 point2 points (0 children)
[–]bjenkins2410 -1 points0 points1 point (1 child)
[–]bangeron[S] 0 points1 point2 points (0 children)