Live data from Hacker News

Please do not attempt to simplify this code

github.com

31–40 of 327 posts

Re: Please do not attempt to simplify this code

#31
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…

Because sometimes, there's "No Other Way(TM)".

Arbitrary line limits tend to unnecessary fragmentation. Add includes, licenses, glue code and comment; and you have an unapproachable spaghetti.

Try to keep methods to 200 lines in high performance code, and see your performance crash and burn like Icarus' flight.

When you read the comments in the code, you can see that they simplified the code to a single module, and embedded enormous amount of know-how to keep the code approachable and more importantly, sustainable.

For someone who doesn't know the language or the logic in a piece of code, the set of comments which outline what the code does is very helpful. In six months, your code will be foreign to you, so it's useful for you, too.

Comments are part of the code and the codebase. If you're not updating them as you update the code around them, you're introducing documentation bugs into your code. Just because the compiler doesn't act on them doesn't mean they are not functional parts of your code. In essence they're your knowledge, and lab notebook embedded in your code, and it's way more valuable in maintaining the code you wrote. They are more valuable than the code which is executed by the computer.

Best practices are guidelines, not laws or strict rules. You apply them as they fit to your codebase. Do not obey them blindly and create problematic codebases.

Sometimes you have to bend the rules and make your own, and it's totally acceptable when you know what you're doing.

Re: Please do not attempt to simplify this code

#32
post #2

// ================================================================== // PLEASE DO NOT ATTEMPT TO SIMPLIFY THIS CODE. // KEEP THE SPACE SHUTTLE FLYING. // ================================================================== // // This controller is intentionally written in a very verbose style. You will // notice: // // 1. Every 'if' statement has a matching 'else' (exception: simple error // checks for a client API ca…

When I looked into Go I found it a bit surprising that someone had created a non-expression-based language as late as ~2009. I have not familiarized myself with the arguments against expression-based design but as a naive individual contributor/end-user-of-languages, expressions seem like one of the few software engineering decisions that doesn't actually "depend," but rather, designing languages around expressions s…

I'm assuming you mean "non-exception". Apologies if I assume incorrectly.

In case I'm correct, this is from Andrew Gerrand, one of the creators of Go:

The reason we didn't include exceptions in Go is not because of expense. It's because exceptions thread an invisible second control flow through your programs making them less readable and harder to reason about.

In Go the code does what it says. The error is handled or it is not. You may find Go's error handling verbose, but a lot of programmers find this a great relief.

In short, we didn't include exceptions because we don't need them. Why add all that complexity for such contentious gains?

https://news.ycombinator.com/item?id=4159672

Re: Please do not attempt to simplify this code

#33
post #27

Earlier quoted context omitted.

hahaha well Kubernetes is the opposite of a special shuttle that keeps on flying. It crashes all the time, version updates etc. If you want stability go to apache or nginx.

I've never seen Kubernetes crash. I don't have that much experience with operating k8s clusters, but on those I've seen it just kept on working.

Same. Pods will crash, run out of memory, fail to get scheduled, etc... but I have never seen kube itself crash.

Re: Please do not attempt to simplify this code

#34
post #22

Earlier quoted context omitted.

Wasn't a poor safety record whut killed the shuttle. It was the cost, and anticipation of degraded safety, in the future. Even though more astronauts died, because of the two shuttle accidents, than any other NASA disaster, the safety record was absolutely amazing, when we consider everything that was going on. The code seems damn good code.

The space shuttle became obsolete technology after all those years. Would've needed a redesign.

> The space shuttle became obsolete technology after all those years. Would've needed a redesign.

Are people aware of how old the technology is that's currently putting objects and people into space? No, the space shuttle was not obsolete. It was expensive... very expensive. To this day, we still don't have a replacement for it's capabilities though.

Re: Please do not attempt to simplify this code

#35

Earlier quoted context omitted.

Well over 100 successful missions carrying a bunch of people and gear up into outer space and then bringing them back home. I hold it in a good light now, and will likely continue to feel that way. As far as human progress and net good, it was a success.

100 is frankly not that impressive for software. A 2-9 system will sometimes work 100x in a row, and a 3-9 system usually will.

As far as we know, software never caused any dangerous incidents for the shuttle. You can't say that about Arianespace (Ariane 4 #1) or SpaceX (a couple of crashes while trying to land - low stakes though) or Airbus ("just" some bad UX in critical situations) or Boeing (software basically killed a few hundred people).

Re: Please do not attempt to simplify this code

#36
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…

There's nothing inherently wrong with a 200-line-long method. If the code inside is linear and keeps the same level of abstraction - it can be the best option.

The alternative (let's say 40 5-line-long methods) can be worse (because you have to jump from place to place to understand everything, and you can mess up the order in which they should be called - there's 40! permutations to choose from).

Re: Please do not attempt to simplify this code

#37

Earlier quoted context omitted.

2/100 catastrophic failures (deaths of entire crew) is not a good record even by the standards of spaceflight.

For what it's worth, were any of those catastrophic failures caused by bad code?

Did the amount of time spent on code formatting incur an opportunity cost for more impactful engineering safety investments?

Re: Please do not attempt to simplify this code

#38

Earlier quoted context omitted.

When I looked into Go I found it a bit surprising that someone had created a non-expression-based language as late as ~2009. I have not familiarized myself with the arguments against expression-based design but as a naive individual contributor/end-user-of-languages, expressions seem like one of the few software engineering decisions that doesn't actually "depend," but rather, designing languages around expressions s…

I'm assuming you mean "non-exception". Apologies if I assume incorrectly. In case I'm correct, this is from Andrew Gerrand, one of the creators of Go: The reason we didn't include exceptions in Go is not because of expense. It's because exceptions thread an invisible second control flow through your programs making them less readable and harder to reason about. In Go the code does what it says. The error is handled o…

You appear to have misread "expression" as "exception"; this is completely unrelated. An expression-based language is one that lets you do `let blah = if foo then bar else baz`, for example.

Re: Please do not attempt to simplify this code

#39

Earlier quoted context omitted.

Wasn't a poor safety record whut killed the shuttle. It was the cost, and anticipation of degraded safety, in the future. Even though more astronauts died, because of the two shuttle accidents, than any other NASA disaster, the safety record was absolutely amazing, when we consider everything that was going on. The code seems damn good code.

2/100 catastrophic failures (deaths of entire crew) is not a good record even by the standards of spaceflight.

But in neither case was it due to a code failure that put the shuttle into an unrecoverable state, but rather one the falls into materials and/or mechanical engineering.

Re: Please do not attempt to simplify this code

#40
post #4

// KEEP THE SPACE SHUTTLE FLYING. I understand the intent, but it is a bit funny that the comment references a system that is no longer operational due to its poor safety record. In ten years or so, will people even remember the Space Shuttle in a good light?

> a system that is no longer operational due to its poor safety record

the safety problems with the shuttle were, broadly speaking, hardware problems and not software problems.

from "Appendix F - Personal Observations on Reliability of Shuttle" [0], which was Richard Feynman's appendix to the report on the 1986 Challenger disaster:

> To summarize then, the computer software checking system and attitude is of the highest quality. There appears to be no process of gradually fooling oneself while degrading standards so characteristic of the Solid Rocket Booster or Space Shuttle Main Engine safety systems.

he specifically highlighted the quality of the avionics software as an example of how engineering on a project like the Shuttle could be done well, and wasn't doomed to be low-quality and unsafe simply by virtue of being a large complicated government project.

0: https://www.nasa.gov/history/rogersrep/v2appf.htm

Post reply on HN