Live data from Hacker News

Please do not attempt to simplify this code

github.com

271–280 of 327 posts

Re: Please do not attempt to simplify this code

#271

Earlier quoted context omitted.

Known bug. The SRR (software readiness review) process happened after development but prior to certification for launch. Most of the bugs were found here and were found to have existed in the code since the beginning of the program. These were overwhelmingly low severity discrepancy reports. If I recall correctly, there was a time when they were finding lots of bugs through SRR, so the main development team started t…

> This made the SRR people angry because they were finding fewer bugs and felt the development team was focusing on competition over bug numbers rather than the code itself. This reminds me of the Quality culture, at my last job, which was a famous Japanese optical corporation. It was deliberately set up, so there was an adversarial relationship between QA, and Development, with QA holding the aces. As a Development…

Reasons why I might not think twice when buying anything built in Japan. I know they care about quality.

I rather it be built right, than quickly. I wish we held quality to higher standards in the software industry.

Re: Please do not attempt to simplify this code

#272

Earlier quoted context omitted.

> This made the SRR people angry because they were finding fewer bugs and felt the development team was focusing on competition over bug numbers rather than the code itself. This reminds me of the Quality culture, at my last job, which was a famous Japanese optical corporation. It was deliberately set up, so there was an adversarial relationship between QA, and Development, with QA holding the aces. As a Development…

Reasons why I might not think twice when buying anything built in Japan. I know they care about quality. I rather it be built right, than quickly. I wish we held quality to higher standards in the software industry.

Japans cultivate this through their entire culture - starting from young children. We, the Westerns, are already at least 2 decades behind, sometimes even 4-5 decades ...

Re: Please do not attempt to simplify this code

#273
post #16

> // 1. Every 'if' statement has a matching 'else' (exception: simple error > // checks for a client API call) > // 2. Things that may seem obvious are commented explicitly Honest question: Why invent "safety" practices and ignore every documented software engineering best practice? 2,000 line long modules and 200-line methods with 3-4 if-levels are considered harmful. Comments that say what the code does instead of…

Splitting a 200 line method into 20, 10-line methods rarely improves readability, it just tricks you into thinking those 200 lines are simpler than they actually are.

Furthermore, how to split 200 lines into methods is context dependent. Looking through the lens of memory, optimality, simplicity, different flows of concern, and you'll want to split those 200 lines up differently.

The problem space is complex, hiding that fact doesn't get rid of that fact.

Re: Please do not attempt to simplify this code

#274
post #272

Earlier quoted context omitted.

Reasons why I might not think twice when buying anything built in Japan. I know they care about quality. I rather it be built right, than quickly. I wish we held quality to higher standards in the software industry.

Japans cultivate this through their entire culture - starting from young children. We, the Westerns, are already at least 2 decades behind, sometimes even 4-5 decades ...

I liked an NPR article about how Mayans let their young do chores whilst young, when in contrast we tell them to go away and hand them an iPad. I read it before having a kid, and now that I do, if my daughter can help with a chore in any way, I let her, and encourage her for helping. She is so overjoyed for helping out.

Re: Please do not attempt to simplify this code

#275

Earlier quoted context omitted.

I agree to a point, but I would separate explicit code from excessive commenting. Explicit code is good because it lets you explain to the reader what you're actually trying to do. Excessive comments (or even comments in general) is less so because compiler cannot check them for correctness, if someone simply forgets to update a comment or writes it incorrectly then the only thing to potentially catch it is a code re…

Do you consider this example as "excessive commenting"?

I haven't looked close enough at it to really know for sure. I'm not saying it's _always_ bad, comments are helpful, but the problem is that unlike code they are not required to actually match reality.

In this case, I see several `if`s with no corresponding `else` even when the `if` section does not throw/return at the end, and that's largely my point. If the "space shuttle code" requirement is not actually rigorously followed, then why go on at length about it? And if it really is that important, then the comment about it is not good enough.

Rather than a comment about it that can be ignored, they should set up a static analyzer to enforce it at build time. That way you're forced to follow the convention and not relying on code reviewers that probably don't even see that comment during their review.

Re: Please do not attempt to simplify this code

#276
post #166

Earlier quoted context omitted.

> Just like updating the tests when code is changed, update the comment when the code is changed. Well, yeah. But the point is that tests can be run in a pipeline that can fail if the tests fail. Comments going out of date has to get caught by a human, and humans make mistakes.

> humans make mistakes All software is built by humans in some way. All software has mistakes. Perfection is an impossible goal.

Yeah but there's a fundamental difference between something like tests that can be checked automatically and comments, that have to be checked manually. Because of this, it can be assumed that comments will eventually go out of date.

Re: Please do not attempt to simplify this code

#277
post #276

Earlier quoted context omitted.

> humans make mistakes All software is built by humans in some way. All software has mistakes. Perfection is an impossible goal.

Yeah but there's a fundamental difference between something like tests that can be checked automatically and comments, that have to be checked manually. Because of this, it can be assumed that comments will eventually go out of date.

Good PR review from a skilled and more senior developer catches these things, most of the time.

Just like how tests catch functionality issues , most of the time — bugs still exist in tested software, because people make incorrect assumptions about how/what to test, or implement the test wrong.

> it can be assumed that comments will eventually go out of date.

Don’t make assumptions. That’s just a lazy excuse for not trying.

The same thing could be said for tests

> it can be assumed that tests will eventually go out of date

So why should we bother updating tests? They’re just going to go out of date?!!

Because it makes the codebase easier to work with for someone brand new.

Same as comments.

Pay down the debt for the next person. The next person could even be you in a year’s time after working in a completely different project for 9 months.

Re: Please do not attempt to simplify this code

#278

Earlier quoted context omitted.

> I strongly prefer the explicitness I have a rule for my teams: "Don't write clever code". I try to constantly reinforce that we don't write code for ourselves, we write it for the next person. We should be doing everything in our power to decrease their cognitive load. I try to envision the person that comes after me (who may be me in months or years!) and imagine that they are having a Bad Day and they have to mak…

Your Elixir feedback is strange. I find it very explicit. Can you give some examples what you find clever / implicit about it?

I think it's super subjective, and I'm sure it's just my mental block from 30 years of C style languages.

I have trouble with the equals sign being "pattern matching". There are other syntax things like that, where it seems like too much is being done in odd (to me) ways that are hard to grok.

I know a lot of people love it, and I really did try, but for whatever reason the syntax just doesn't work for me.

Re: Please do not attempt to simplify this code

#279
post #126

Earlier quoted context omitted.

A simple example for anyone who might not appreciate why this can be so nice. In languages where if is a statement (aka returns no value), you'd write code like int value; if(condition) { value = 5; } else { value = 10; } Instead of just int value = if(condition) {5} else {10} Some languages leave ifs as statements but add trinary as a way to get the same effect which is an acceptable workaround, but at least for me…

How would this work if I need to update multiple variables? int value1 = 0; int value2 = 0; if (condition) { value1 = 8; value2 = 16; } else { value1 = 128; value2 = 256; } Would I have to repeat the if expression twice? int value1 = if (condition) { 8 } else { 128 }; int value2 = if (condition) { 16 } else { 256 };

.. save yourself an else :

int value1 = 128;

int value2 = 256;

if (condition) {

    value1 = 8;

    value2 = 16;

  }

Re: Please do not attempt to simplify this code

#280

Earlier quoted context omitted.

It’s actually so painful to go back to languages without destructuring and pattern matching.

As someone who writes a fair bit of c# making switch and if's into expressions and adding Discriminated Unions (which they are actually working on) are my biggest "please give me this." Plus side I dabble in f# which is so much more expressive.

Same for me in the Scala vs. Java world, it's hard once you get used to how awesome expressions over statements and algebraic data types/case enums/"discriminated unions" are. But I haven't done much C# (yet) myself, could you clarify for me: does C# have discriminated unions? I didn't think the language supported that (only F# has them)?
Post reply on HN