Recent comments in /f/explainlikeimfive

Nagisan t1_iybrn9u wrote

Exceptions can open up a whole pandora's box in the flow of a program. I can't speak for every language (because there's lots I don'tknow), but at least with what I'm most familiar with the function does return to the line it was called from depending on how you handle the exception.

In the case of your function catching the exception, you can fail gracefully by logging an error, at which point the program will continue and the function will return to the line that called it then just chug right along (if the result of the function wasn't necessary for the program to continue).

In the case your function doesn't catch the exception, it will bubble up to the place it was called from and repeat this process (if the exception is caught at the higher level, my second paragraph happens, otherwise it bubbles up again, repeat until something catches the exception or the program reaches the main function and crashes).

So yeah, exceptions can be the oddity here, but they also can continue to work the same as no exceptions when it comes to the flow through a program.

1

explainlikeimfive-ModTeam t1_iybrho2 wrote

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

ELI5 is not for straightforward answers or facts - ELI5 is for requesting an explanation of a concept, not a simple straightforward answer.

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

1

NCreature t1_iybrgct wrote

A lot of that money is in shares of his company, stock options, investments, etc. It's not cash. It's not like he has a giant money bin like Scrooge McDuck full of gold and people will be like "what do we do now?"

Also billionaires die all the time. And any number of things can happen with the wealth they leave behind. Often the shares get bought back or divested. Over time the family's personal stake in the company often diminishes sometimes down to basically nothing. The Walt Disney Company is a good example where the Disney family really no longer has any real stake or major influence.

Wealth often just passes down in some form to next of kin but it doesn't always happen that way. Many people have famously not left their fortunes to their children and instead given it to charity or bankrolled other companies (or governments). The US in general doesn't have a ton of multi generational super wealth especially if the younger generations don't really do anything to keep up the wealth or the mechanism that created the wealth. Today's Carnegies, Rockefeller's, Duponts and Vanderbilt's still have some decent money but it's a rounding error compared to their great grandparents. John D Rockefeller's personal wealth in the late 1800s was $900 million or $24 billion in today's dollars. That being said people like Elon have so much personal wealth, literally more than many countries entire GDPs, that we are in somewhat uncharted waters. I'm actually not sure what would happen with Elon's $191 billion.

2

nesquikchocolate t1_iybr9zv wrote

Your body weight is mostly water.

You drink a liter of water, you gain 1 kilogram of weight.

You urinate 1 liter, you lost 1 kilogram.

When you're starving, your body functions slow down significantly, meaning you start to retain the water that you drink, so you don't lose weight like that..

But you still need to drink water and urinate, else your blood becomes toxic!

1

bradles0 t1_iybr5rp wrote

remember what 1+2x3 actually MEANS - multiplication is a shorthand for multiple additions, and further up pemdas exponents are multiple multiplications; so you simplify back down the line.

1+2x3^3=1+2x(3x3x3)=1+((3+3+3)+(3+3+3)+(3+3+3))+((3+3+3)+(3+3+3)+(3+3+3))=55

The other reason is the practical considerations - if you have 5 boxes of a dozen eggs and 2 extra eggs, you have 5x12+2 eggs; the standard case for multiplication will be rows + columns + leftovers, and there are FAR fewer cases where you care adding more rows or columns instead of adding in the leftovers, so it's easier to note the special times when you are adding more columns than the times when you are adding the leftovers.

1

chortling2 t1_iybqywn wrote

Right? Redefining food as necessity rather than an indulgence for future generations has got to happen.

People like going into space but don't want to eat space food? The hypocrisy of humans knows no bounds.

Another example: people like luxury boats and are realistic about not being able to afford big ass yatchs. Yet ask them to live in an urban small space and they balk. No, we need single family homes and will fight tooth and nail to preserve our "right" to disallow multi unit housing of any kind.

2

generous_cat_wyvern t1_iybqmwc wrote

>functions send the program to another line of code but then return back to the line the function is called from once the function is done.

Except for when Exceptions are thrown, but I guess that's why they're called Exceptions :p (I actually don't know if that's the reason, I probably just made that up) But even Exceptions propagate up a call stack in a predictable manner.

As an aside, it blew my mind when I found out that in ASP.NET, redirects happen by internally throwing a ThreadAbortException behind the scenes that can't be handled by normal means. It made sense that code after calling redirect didn't execute, and the only way to have code behave that way is if an Exception is thrown, I just never put two and two together.

0

Sloloem t1_iybovkb wrote

Yikes, I'd actually seen code kindof like that written by outsourced contractors for a financial services firm I used to work for. They created these "god" functions that ran through multi-step processes by wrapping the whole thing in a giant for loop and using If's on the iterator like if (i==1)... (i==2)... (i==3) to block each step. It really hampers extensibility.

> Question for you: if I want to improve my coding skills (because I only took one class in school, and have just picked other stuff up as I go), would it be a good exercise to re-write all their code using the structure you've outlined?

Assuming you're talking about re-writing the IF-GOTO code your robots use in more structured style, yeah absolutely. Changing the underlying implementation of some functionality while maintaining its public contract is actually the definition of "refactoring". Being able to cleanly refactor code and write code that's cleanly refactorable are actually the underlying goals of a lot of current best-practices in Object-Oriented programming so it's definitely an important skill to practice.

> And/or if I'm trying to learn another language like python specifically, see if I can re-write it in that, so I can learn that syntax & commands at the same time?

Porting code directly like that is an interesting activity but maybe something that's more of an intermediate activity once you have the fundamentals down. I thought this phrasing was kind of pompous when I first heard it but most languages have "idiomatic" ways of doing some things that is considered the correct way to write code in that language. Of course the languages are flexible enough that they would allow you port structure and style of another language's idioms to this new language, but those sorts of idiomatic patterns usually come out of some key feature of the language and have fundamental advantages in terms of code expressiveness or performance. So it's best to learn "Pythonic" ways of writing code that might be very different from how someone who'd trained as a Java or C++ developer would usually think of implementing them. Then once you feel like you can write Python, you can try re-implementing functionality that used to be written in some other language and paradigm in Python rather than trying to re-write some Java using Python. It's a slight language shift but I think it's a good way to frame it.

In a professional setting you're also unlikely to see a company trying to do a 1:1 re-write of an existing product. The switch in tech stack is usually driven by a desire to benefit from some killer feature of the new stack like NodeJS's fast async I/O or something else, and to do that you usually need to write idiomatically and respect the eccentricities of the language and the framework.

22

nemplsman t1_iyboolz wrote

I bet there's a more precise explanation than just "we agreed to it." Without looking it up, it seems it's something having to do with this:

Consider this formula:

  • 4 x 8 + 9 - 2 x 7 + 9 ÷ 3

We know that the multiplication sign between 4 and 8 only acts between those two numbers. And the multiplication sign between the 2 and 7 only acts on those two numbers and the division sign only acts on the 9 and 3. BUT, the +4 and -2 and +5 could literally be anywhere else in the formula and nothing would change. Basically, the exact location of the multiplication and division symbols between two numbers matter, whereas the exact location of the numbers added and subtracted doesn't matter.

I don't think this is just because we decided to do it this way as a convention. It's because the multiplication and division signs are unique in that they specifically imply that a calculation should happen between the two numbers on either side of the operation.

Maybe a way to think about it is that multiplication and division essentially transforms the adjacent numbers. Examples:
- 3 x 8 (three, eight times is 24; or eight, three times is 24).
- 45/3 (45 split into 3 is 15).

Numbers that are added or subtracted are more just independent from the rest of the numbers as they can appear anywhere (they don't necessarily need to be added to the adjacent number).

−6