Recent comments in /f/explainlikeimfive

lynxerious t1_iyaywme wrote

The flow of the program is determined by your imperative or declarative programming. You do things once by once or declare what would happen if an event occurs.

Goto messes up this flow and makes the code way harder to track. It gives programmers too much freedom, they need to be constrainted by shackles or eveything gonna be catastrophic once day.

1

MagicSquare8-9 t1_iyays63 wrote

It's "just a convention", but it's something so ubiquitous that pretty much many mathematician independently came to the same thing.

Historically, it used to be context-dependent, sometimes you add first. For example, look at this picture: https://en.wikipedia.org/wiki/File:JakobBernoulliSummaePotestatum.png . Can you guess which line you add first and which line you multiply first? If you understand the math, you can figure it out, but if not, this can be confusing.

Eventually, various mathematicians made up various different conventions on how to write and interpret formulas. Even though they produce different convention, one thing are shared among them all: multiplication takes priority over addition (unless superseded by other stuff like brackets and lines). And there is a good reason for that. Multiplication distributes over addition, so it's a lot easier to write an expression as a sum of product than a product of sum. In other word, a lot more formulas would end up requiring you to do all the multiplications first to get a bunch of products, and then doing addition to add up those products. So it is a lot simpler to make that the default: by requiring that multiplication takes priority over addition, you don't have to put brackets everywhere.

So even though it's "just a convention", there is a mathematical reason behind the convention.

30

Belbarid t1_iyaxn9k wrote

The last two times I bought a house, I started with a soft limit and a hard limit on my mortgage payment. The soft limit is how much I intend to pay, the hard limit is the amount I will not go over, no matter what. Both amounts will be less than the max I can absolutely afford.

From there, my approach is to look at the numbers for a 30-year and a 15-year mortgage. Once I get those, I use an amortization calculator to see what happens when I overpay. If the payment amount is lower than the soft limit, I use that as the actual amount I pay. If the payment is between the two limits, I assume I pay the hard limit. Then I choose the mortgage that has me paying the least amount of interest over the lifetime of the loan. The mortgage on our last house was a 15 year and we had it paid off in 9 without stressing our budget.

2

DragonFireCK t1_iyaxbmc wrote

The order of operations is merely a common standard agreed upon by mathematicians. There is nothing innate with mathematics that requires that standard, though having a standard of some form is a requirement for the common infix notation.

There are other options, such as pre-fix and post-fix notation, also known as Polish and reverse-Polish notation. With pre-fix notation, you'd write `1+2*3` as `+ 1 * 2 3` or `+ * 2 3 1` and `(1+2)*3` as `* 3 + 1 2` or `* + 1 2 3`. With these, you don't even need to define left-to-right or right-to-left as its implied by the definition - though you have to agree whether its pre-fix or post-fix.

13

d4m1ty t1_iyax8le wrote

Because a bunch of mathematicians got together and came up with a order of operations so that there would be no confusion when looking at a math equation.

It is this way is because all those math nerds said it should be that way. That's it. Left side of the number line is negative because the math nerds got together and said that is how it should be. Much of math and science has shit like this where 'by convention' i.e. nerds got together and made a decision, something is done a certain way.

12

BurnOutBrighter6 t1_iyax6la wrote

It's something we agreed on. Like you pointed out,

1+2x3

would have more than one possible answer unless there was a convention. It would be ambiguous what you actually meant. So people created "order of operations" rules to make it possible to write math without the ambiguous confusion that would happen if there was no agreed convention.

146

explainlikeimfive-ModTeam t1_iyax4y8 wrote

Please read this entire message


Your comment has been removed for the following reason(s):

ELI5 focuses on objective explanations. Soapboxing isn't appropriate in this venue.


If you would like this removal reviewed, please read the detailed rules first. **If you believe it was removed erroneously, explain why using this form and we will review your submission.

1

Skellephant t1_iyax080 wrote

I have sleep anxiety. As in, I literally get panic attacks from realizing that I almost fell asleep. Its pretty annoying to try to go to bed and be totally exhausted, and then suddenly get an adrenaline burst and full panic mode because sleep is spooky. A weighted blanket helps me stay calm as I fall asleep. I love it. I get so much better rest with the weighted blanket, it really changed everything.

20

newytag t1_iyawa1c wrote

Minecraft specifically is procedurally generated. The game world basically consists of a bunch of mathematical algorithms for how to generate the world based on a random input, these are part of the game code and relatively small. That random input is distilled down to a single number called the seed, and using that seed you or any one else can recreate the environment assuming they have the same algorithms (ie. a compatible version of Minecraft). Individual changes the player makes to the world are then stored in the player's save file. But beyond that, the game world can extend almost an infinite amount using the same world generation algorithms (though you might get some oddities once you reach certain practical limits, hence Minecraft enforces an artificial boundary).

Most games do not use procedural generation, their worlds are hand-crafted or at least pre-determined. Even in this case it's not necessarily a problem to store a large world. The game's data might say, this map is 100x100 "virtual metres" and brown, and at coordinate 0,0 is a 2x2x2 metre red cube. It's just a few numbers, it doesn't take much space. Similar to procedural generation, all you're really storing is instructions for how to render the world (you're storing more numbers, but the algorithms for turning the numbers into 3D objects are far less complicated).

Now change the map to be 1000x1000 "metres", and the cube to be 4x4x4 metres. The map is an order of magnitude larger, but all you've really done is change some numbers; you're still using the same amount of data to describe a much bigger world. So the size of the virtual world doesn't really correlated with the amount of data needed to describe it.

What does increase the size of the game data though is complexity. Instead of a single cube, maybe it's thousands of triangles in the shape of a house. It's no longer a solid red colour, but it has detailed wood and brick textures. And the map isn't a 1000m^(2) flat plane any more, it's a realistic terrain with hills and valleys defined by a height map, littered with trees of varying heights at different x,y coordinates. Now your game world needs far more numbers, and other data like texture images, to be stored.

Portable devices today can easily store gigabytes of data and have relatively powerful processing capability; but even so, game developers need to ensure they balance graphical detail with the hardware resources they have available.

1

Any-Growth8158 t1_iyavvpk wrote

Because that is what the mathematics world agreed upon. It doesn't really matter as everyone is consistent and uses the same order of priority. The examples are really just poorly formatted. As a general rule it is good practice to use parentheses since it makes things clearer--especially when using the x for multiply...

Leaving out the parentheses in such a case is just asking for trouble since many people are not aware that operators have an order of precedence.

8

homeboi808 t1_iyavsys wrote

Multiplication is just shorthand for repeat addition, as such the 2 values are linked together, you can imagine an invisible parenthesis.

1 + 2 x 3
= 1 + (3 + 3) , or 1 + (2 + 2 + 2)
= 7


1 + 5 x 10

The above is similar to saying you are adding $1 to a 5-pack of $10s (or a 10-pack of $5s), which equals $51 and not $60.


If you instead meant to have a 10 packs each containing both a $5 & $1, so $60 total, your expression should be:

(1 + 5) x 10

11

DavidRFZ t1_iyavrqc wrote

There is no rule of nature.

There is a rule with how you write math. The rules of order of operations can make some equations look simpler. But you have to make sure that you read the equations the same way that they were written.

76

Dunbaratu t1_iyavlr7 wrote

It has to do with this difference in history:

US states: They were someone else's colonies right up until the point they were collected together into a group called the United States and only then did they stop being colonies and start self-governing.

UK internal pieces: Had a history of having been independent countries already, prior to being collected together into a group called the United Kingdom. That historical difference - that they were once self-contained countries while the US states never had such a period of history - causes the difference.

The formation of the UK was "Here's some independent countries that border each other and compete for space on this island so they have wars against each other. Instead of warring all the time maybe they can just agree to share this island by joining into one nation." (Yes, I know Northern Ireland is on a different island, but that got added to the UK later.)

2

Dunbaratu t1_iyatoyo wrote

First you have to understand how it was originally used, then understand what replaced it, then you can understand why it's not used anymore.

The ability to skip ahead or skip back to a different line of code lets you do a great many things. It's generic and open-ended what it can do. When you create a way to do it conditionally where it won't always execute the goto then it allows for all the standard flows we use today.

An If-block is really just "If this condition isn't true then GOTO the spot just past this block so you skip over it."

An unconditional loop is really just "GOTO a previous line up above so you start executing all this stuff again. When you get back down to this line, GOTO the top again. Repeat."

A conditional loop is really just "IF the thing we're checking for to end the loop isn't true, then GOTO a previous line and run that stuff again."

It's versatile. It can form just about any pattern.

So what's the problem? Well that versatility IS the problem. To understand why a programmer put a GOTO there, to understand what they were trying to do, you have to analyze a lot more lines of code to see what the pattern was. Because a GOTO could really be for a wide variety of purposes. It might be part of an IF. It might be part of a WHILE (thing is true) loop. It might be part of an UNTIL (thing is false) loop. It might be part of a counting loop (FOR loop). It might be to just jump over to a subroutine and return from it.

It's not visually obvious from just looking at it what it's for. You have to trace the code line by line before you can see the big zoomed-out picture of the layout.

It also allowed unique flow patterns that don't fit into one of the commonly known patterns. A clever programmer could have been using it to do something unique that only makes sense in their own mind and doesn't make sense to anyone else.

So, essentially, it can make the program hard to understand, which then means programmers make mistakes when editing it.

The fix was to find all the common things people were using GOTO to do, and create special keywords for those patterns and replace the use of GOTO with those new terms. So you can still do all the same stuff, but in a more descriptive way that actually says what you're doing. You don't have to guess "Which of the 8 or 9 different reasons for using a GOTO might this one be?" when it uses a word like WHILE or FOR or IF that actually tells you which one it is.

But the interesting thing is... under the hood, it's still really all GOTO. At the lower machine language level, you have the various JUMP instructions, which are exactly what a "GOTO" would have compiled into, and as it turns out, is also what the newer words like WHILE and FOR and IF also still compile into.

Under the hood, it's still all GOTO. But now it has more descriptive ways to summarize those GOTOs into human-readable structures.

16