TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How can I prove to my coworker that his code is complex?

32 pointsby filipedeschampsabout 10 years ago
Currently, I think the code of my coworker really complex, but for now, this is just an opinion only.<p>Is there any metric that will transform my opinion on a proven fact?

34 comments

bontoJRabout 10 years ago
It&#x27;s a nontrivial task, I wouldn&#x27;t waste too much time in trying to prove that someone&#x27;s code is complex. I tried in the past with the result of being appointed as &quot;lazy&quot; or &quot;basic&quot; developer. I heard arguments like: &quot;if you think this is complex then you are not so good&quot; or other very unnecessary arguments.<p>Don&#x27;t prove he&#x27;s writing complex code, it would be interpreted as &quot;being wrong&quot;, but instead prove that you can come up with easier and cleaner solution. Write your own, test it and then propose it to the original author, see if he can admit that your solution is cleaner, easier to understand and easier to handle. I did this few times with very good results on feedbacks.
评论 #9492451 未加载
kazinatorabout 10 years ago
You mean <i>unnecessarily</i> complex, of course. That might appear self-evident, but it is better to articulate it in situations like this.<p>Why is it unnecessarily complex? Is it because it is handling cases which you think do not occur? Or is it implementing requirements that you think need not exist (i.e. implementing a more complex, undocumented version of the <i>specification</i> than the one that is actually documented?) Or is it implementing the right specification, but without an effective program design that would reduce code and process duplication, or without the effective use of existing code, of the programming language, of libraries and of tools?<p>You need a more specific argument than &quot;your code is too complex&quot;.
rwallaceabout 10 years ago
No. (<i>I</i> don&#x27;t believe cyclomatic complexity is meaningful, so it&#x27;s not likely your coworker will believe it :))<p>The following assumes you&#x27;ve already politely expressed your opinion to your coworker and he&#x27;s disregarded it.<p>It&#x27;s important to understand what you&#x27;re proposing to do here. You want to think of it in terms of fact, but what you are actually proposing to do is start a political fight.<p>Now, I don&#x27;t know whether you&#x27;re right or wrong. I also don&#x27;t know whether it would be a good idea for you to start a political fight over the issue. I do know three things that are relevant to this situation, however:<p>1. Whether you&#x27;re right and whether it&#x27;s a good idea for you to start a fight are separate questions. It&#x27;s important not to assume an answer to one automatically implies an answer to the other.<p>2. It&#x27;s practically never a good idea to start a fight without carefully thinking through the costs and benefits - all of them, not just the immediate ones - and how you plan to win it.<p>3. In the modern environment, the usual outcome of a fight is that both parties lose.
评论 #9492735 未加载
评论 #9492311 未加载
5habout 10 years ago
I&#x27;ve come up against this many times over. When it stems from over-enthusiasm for using recently discovered features or concepts I&#x27;ve reliably changed a trend-toward-complexity by picking a small section &amp; re-writing it in a simpler&#x2F;more elegant fashion, then proposing to the author something along the lines of &quot;can we make it _all_ that simple&quot;? The subtle (or not so subtle) creation of a challenge towards simplicity has worked well with coders near the beginning of their career.
评论 #9492253 未加载
hamidpaloabout 10 years ago
You&#x27;re thinking about it wrong. It&#x27;s not about the complexity of code or any measure thereof, but a simple communication issue.<p>Telling someone that their code is too complex can very easily be interpreted as a personal affront, especially by more junior developers. It can very easily communicate that they are a shitty developer and don&#x27;t know what they are doing. When that happens you will get nowhere.<p>In that situation, the other person feels that they have to defend themselves. They get myopic and unable to see whatever argument you present. They simply will not accept it, or if they do they will resent you for it.<p>The best way to go about it is to acknowledge their efforts and validate their thinking. Look at why the code is the way it is, and try and understand why it&#x27;s written that way. Approach the situation not as &quot;I am right, you are wrong&quot; but as &quot;I don&#x27;t understand this part, can you explain it to me.&quot; When they explain and you think it&#x27;s complex say something like &quot;Ah, yes! That&#x27;s what I thought it did. It seemed a bit complex so I was wondering if it did anything else. Have you considered x or y?&quot;<p>The more opportunities you allow to the other person to save face, and the more you value their efforts and work the further you will get.
sdeglerabout 10 years ago
The simplest way is to provide an alternative implementation that is more correct, more succinct, and is easier to read.<p>+1 rich hickey talk<p>Of course that is not the least resource intensive solution. Code reviews may help.
评论 #9492399 未加载
Sealyabout 10 years ago
How did you come to the conclusion in the first place that his code is complex?<p>The answer to this question may provide your answer to your coworker. Ultimately if its only an opinion, then you don&#x27;t have much to go off...
jerfabout 10 years ago
To be honest, the technical aspects raised by the question pale in comparison to the human aspects. Even from a position of authority over a coder it can be very difficult to solve the problem of &quot;excessively complicated&quot; code. To &quot;solve&quot; this from a peer position, unless your coworker is an extraordinarily humble person, is going to be quite the trick. It is likely that the cost&#x2F;benefit analysis (and in engineering you are never more than a few minutes away from a cost&#x2F;benefit analysis, even here in the &quot;fuzzy human stuff&quot; domain) is unlikely to work out in your favor with any sort of strong approach. You are unlikely to experience any positive outcomes, what ones you could are fairly minimal, and the negative outcomes (w.r.t. your employment) are almost unbounded, including the ability to outright work your way into losing your job.<p>All you can really do is write good code yourself, keep learning how to write better code, and use this as an opportunity to learn how to deal with complicated code because goodness knows you&#x27;ll never stop encountering overcomplicated code, unless this industry changes a lot.<p>If that sounds a bit defeatist... well... it&#x27;s hard to express my true feelings in text here. I&#x27;ve been doing this for just shy of 20 years now and have no intention of stopping, so it&#x27;s not like I&#x27;m burned out or anything. Yet... you can not escape the fact that you shall always be working with people whom you wish would code better. I find it helpful to remember that A: among the set of people I really wish would code better is my past self, at times even as recently as last week and B: there are certainly plenty of other people who wish that I would code better, for their personal definition of &quot;better&quot;. In fact, I know that even as my code tends towards the &quot;simple&quot; side and I find some people&#x27;s overcomplicated, they consider my code oversimple. (I mean, I&#x27;m still on my side and can defend it, but, well, insert any well-known saying about opinions here, right?) A certain amount of zen and a certain amount of humility is called for here in the long term, I think.
评论 #9492459 未加载
grandalfabout 10 years ago
Often times people who are good at dealing with complex code become programmers, and they themselves write complex code.<p>Since so many projects contain a mess of complex code, programmers like these will always find jobs and you may end up with one as a coworker. It&#x27;s not a bad thing but ideally they have enough of an aesthetic sense about code readability to use their powers for good.
grandalfabout 10 years ago
Chapter 1 of the below book is all about coupling in systems, and illustrates how coupling leads to significantly more system complexity:<p><a href="http:&#x2F;&#x2F;www.amazon.com&#x2F;Event-Based-Programming-Taking-Events-Limit&#x2F;dp&#x2F;1590596439&#x2F;ref=sr_1_1?ie=UTF8&amp;qid=1430830310&amp;sr=8-1&amp;keywords=event+based+programming" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Event-Based-Programming-Taking-Events-...</a><p>Get it free here:<p><a href="http:&#x2F;&#x2F;en.bookfi.org&#x2F;s&#x2F;?q=taking+events+to+the+limit&amp;t=0" rel="nofollow">http:&#x2F;&#x2F;en.bookfi.org&#x2F;s&#x2F;?q=taking+events+to+the+limit&amp;t=0</a>
kaydevabout 10 years ago
Hi all,<p>there are some complexity KPIs that have proven to reflect the complexity of your source code. Code in nesting level N and the cyclomatic complexity (aka. McCabe complexity) [<a href="http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cyclomatic_complexity" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cyclomatic_complexity</a>] are two of them.<p>Especially &quot;nesting level complexity&quot;, that is the amount of code in nesting level N+ (e.g. the amount of code in nesting level 7+), is a complexity KPI that can reflect unnecessary complexity in your code.<p>However, just having the &quot;numbers&quot; is not enough to convince your co-workers (I talk my own experiences here ;)). What you need is a visualization of these complexity KPIs. I used the following online-platform (<a href="https:&#x2F;&#x2F;tp.softwarediagnostics.com" rel="nofollow">https:&#x2F;&#x2F;tp.softwarediagnostics.com</a>) to discuss issues like yours with my co-workers in an objective and transparent manner. They provide a freemium version of the platform that lets you analyze and visualize the nesting level complexity of your source code in a convenient way. Maybe it can help you in the discussion with your co-workers.
rachbelaidabout 10 years ago
(IMHO) Complex code is difficult to test so if the code can be tested easily without over using factory or tight coupled setup required then maybe the code is not so complex and maybe it&#x27;s just an hard problem. Writing test can help to highlight an over complex code and an alternative code will have much simpler tests. It&#x27;s not a metric but it&#x27;s probably easier to agree on clean test
fslothabout 10 years ago
Code is written for humans. I don&#x27;t think there is any proven metric for elegance.<p>When I was a junior dev I made a god awful complex thingamajic for basically calling a dozens of functions with different input parameters. Our lead just said &quot;o god, not like this <i>just call the functions</i> &quot; and he was correct.<p>Unless you are in a senior&#x2F;junior position trying to prove your colleague wrong will likely result of him thinking you are arrogant and will make efforts to improve things in years to come difficult.<p>Communication usually fails. If you say &quot;your code is too complex&quot; despite your best efforts to be polite he might hear &quot;I am an arrogant twat and just want to put you down for the fun of it&quot;.<p>Some times best people lead by example. If you can write your stuff elegantly and show it to him he may appreciate the more simple approach. Or not.<p>Unless it&#x27;s an obvious antipattern like coupling of code and data we are, up to a point, discussing aesthetics. Experienced programmers often grow to appreciate simplicity if only of the categories of bugs code eliminates by just being simple. But this takes time.
评论 #9492373 未加载
dferlemannabout 10 years ago
No one wants to hear that they are wrong, even if you proved it unless you already have their respect, or you are their boss. All programmer will hear is that &quot;you are not doing good enough job,&quot; but the &quot;good&quot; is vague and graded, and lazy. Instead, show him how you would have done it. You know, as a learning opportunity.
mselloutabout 10 years ago
First you need to define what you mean by &quot;complex&quot; as that could refer to many things. A useful definition for the term will be focused on informing a decision. Why did you ask the question?<p>Further, definitions that rely on one or many observable phenomena are more useful than definitions which rely on subjective experiences.
JoeAltmaierabout 10 years ago
Maybe you don&#x27;t understand the problem she&#x27;s solving? Or maybe the co-worker designs in a way different from your comfort zone. How about trying to learn a few new design patterns. Then that &#x27;complex&#x27; code will become familiar.
an_koabout 10 years ago
I do this by reading the code&#x27;s logic aloud, and while doing so, noting the <i>things that I have to remember</i> to understand it. This includes things like &quot;what was the name of that variable&quot;, &quot;what does this function do&quot;, &quot;has the parser read a comma&quot;, etc. Complex code results in larger &quot;mental stacks&quot;, simple code smaller ones.<p>This isn&#x27;t really &quot;proof&quot;, but in my experience, such a demonstration is easy to understand and leads to constructive conversations and good results.
swalshabout 10 years ago
Good code should be no more complex then the problem it&#x27;s solving. Though sometimes easy problems prove themselves to be complex. If you can think of a simpler way to accomplish the same task while achieving the same thing, introduce the idea.<p>Chances are though, you don&#x27;t have time to fix it, unless its young code, and you have some room in your schedule (which you don&#x27;t, no one ever does). I&#x27;d just make sure the code review process is fixed so we can catch it earlier.
nimblegorillaabout 10 years ago
Every developer has a different idea of what complex code means. Cyclomatic complexity is one metric, but vastly different code could have the same score. Sometimes we have to trade simplicity for flexibility, speed, or other goals.<p>The idea that you can prove code complexity shows that you are a newer developer. I&#x27;m not sure what goal you want to achieve by proving someone else wrote complex code. There are probably better ways to achieve that goal.
starkmikeabout 10 years ago
Readability should be paramount above complexity. Write code for future you, and future developers that will be working on the project. You might understand the complexity now, but what about after not working on it for 6 months or more.<p>I don&#x27;t know of any metric for code readability, but it should be as simple as possible. Readable code is WAY better than complex code anyday. Great programmers know this.
TimSchumannabout 10 years ago
Have you considered the possibility that you&#x27;re asking the wrong question?
frou_dhabout 10 years ago
Both watch Rich Hickey&#x27;s excellent presentation on the matter and establish whether you agree on the definitions.<p><a href="http:&#x2F;&#x2F;www.infoq.com&#x2F;presentations&#x2F;Simple-Made-Easy" rel="nofollow">http:&#x2F;&#x2F;www.infoq.com&#x2F;presentations&#x2F;Simple-Made-Easy</a>
drKarlabout 10 years ago
Yes, there&#x27;s a metric for that, and it&#x27;s called Cyclomatic Complexity. Depending on the programming language there may or may not be tools to perform an anylisis on Cyclomatic Complexity on your code. I know for Java there are some tools.
评论 #9491993 未加载
tremolsabout 10 years ago
Complexity is not a problem if something is achieved with it. That said, a complex problem will often require a complex solution and sometimes the simplest solution is the most appreciated, efficient or elegant.<p>Poor maintainability &#x2F;extensibility &#x2F; modularity &#x2F;scalability, bad encapsulation, abundance of side effects, spaguetti and raviolli code - among others - are perhaps the real problem you&#x27;re seeing behind your coworker&#x27;s complex design.<p>It is not a war that can be easily won though, you can see how in the java ecosystem unnecessary complexity is the norm. And outside java too we see unnecessarily complex frameworks or libraries gaining heavy traction.
dragonwriterabout 10 years ago
There are all kinds of complexity metrics that exist that you could use to quantify the complexity of the code at issue, and for many of those metrics there are also commonly-cited standards for levels of complexity that are sources of concern.<p>But its still, ultimately, a matter of opinion that the particular measure and standard are really too complex for the purpose the particular code is serving in the particular project, so while you can get some facts, the <i>relevant</i> bit still boils down to a matter of opinion.<p>OTOH, the best proof that code is too complex is to demonstrate simpler code that does the same thing.
brudgersabout 10 years ago
If it&#x27;s someone else&#x27;s code, there are bigger challenges in the workplace than code complexity. The idea that it matters to whom something about the code is proved is a symptom of them.
christophersleeabout 10 years ago
Software is all about tradeoffs, and there are so many ways a single problem could be solved. What works for me is to show them an alternative way that the code could be written.<p>Then you can have a practical discussion about the differences and what the differences are. Maybe their code is complex because they are considering more scenarios.<p>Sometimes, (not always), complex code is difficult to test. When I hear &quot;the test is hard to write&quot;, it&#x27;s a small to me that the code might be too complex.
评论 #9492408 未加载
mkageniusabout 10 years ago
I have been on the other side of table where a coworker told me that my code was complex.<p>But at doing that he appreciated the code that it worked as expected and how quickly I made it work, he taught me that in long run though, how a complex code would lead to various bugs.<p>Show him examples, show him how to refactor that and convert the same code into a beautiful code.<p>So, my advice would be to give something back to the developer in case you want him to listen to you.
soldergenieabout 10 years ago
Sure, you can prove it is complex by measuring cyclomatic complexity. But, the harder part is to prove that complexity matters. (I don&#x27;t think it does myself).<p>Have you considered that maybe it doesn&#x27;t matter? Is his code well tested, easily maintainable, ships with few bugs, and is produced on time? If so, who cares about complexity?
interdriftabout 10 years ago
You got two options :<p>1.Give him a better solution and prove that it can be done better 2.Let him drown and drag you in too.
评论 #9492219 未加载
piercebotabout 10 years ago
Code Climate has a scoring algorithm that looks at the quality of your code, including its complexity.<p><a href="https:&#x2F;&#x2F;codeclimate.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;codeclimate.com&#x2F;</a>
btbuildemabout 10 years ago
Do you mean &quot;too complex for what it&#x27;s trying to solve?&quot; - you can prove that with a simpler, cleaner solution to compare against.
a3nabout 10 years ago
Don&#x27;t bother, it&#x27;s just an argument with no useful outcome likely.<p>Do good work. Improve yourself. Don&#x27;t worry, none of it really matters.
gorbachevabout 10 years ago
Ask him to change it in some meaningful way and document the struggle.