BRIEFS logo BRIEFS

Lines of code !== Complexity

02/15/2021 , 2m, 54s

https://twitter.com/DavidKPiano/status/1361353521648590853?s=19

What up folks Happy President's Day for those in the US I wanted to talk about this tweet that I saw from David K. Piano that's his Twitter handle his last name is Korshid and the tweet is can we stop with the myth that more code means more complexity? Sometimes less code means more edge casings ignored which means willfully and dangerously ignoring complexity not reducing it.

And he gives some a sample of some simple code that just awaits fetch from API and then returns the data and it's saying here are some of the ignored.Complexity error handling data validation timeout handling cancellation interruption, etc. I super duper agree with David here and I very often will have people ask me about the complexity of some code because there's a lot of it.

And the code that they're talking about is maybe some class name for tailwind, you know, a tailwind has tons of class names or maybe they're talking about inline styles with the CSS prop or sorry CSS and JS or like maybe they're talking about.JSX and this component just has like 200 lines of JSX or something.

Whatever the case may be the number of lines of code is maybe correlated but not necessarily correlated even with the amount of complexity. You could have a list of all the countries in the United States. And now that would be that would be represented by a lot of lines of code.

Sorry, did I say all the countries? I meant, like all the cities in the United States. That would be a lot of code but it would not be complex.At all. So the there's a very subtle if any relationship between the amount of code and the complexity thereof and I think that it's an important thing to to keep in mind.

So just because there's a lot of code doesn't mean that this is going to be a maintainability nightmare or it's going to be complex. I actually find that prematurely abstracting some of that stuff because you think it's complex can make things even more complex, for example, if you have a I don't know some like tons of.

TSS or something like that CSS like class names or something you try to abstract that away with some fancy higher order component or something then that would be even worse. Or if you like have a bunch of JSX and then you wind up trying to like extract these into little components then now you have to worry about passing props and everything and that just increases the complexity.

Now, I'm not saying that's always the case but just keep that in mind. There's not necessarily relationship between the amount of code and how complex that code is. I hope that's helpful. I have an awesome day. Goodbye.