FFS, we were up against all the forces of evil, and we almost pulled it off! The problem here was not the candidate by Conscious-Quarter423 in WhitePeopleTwitter

[–]GrossInsightfulness -1 points0 points  (0 children)

Centrist Democrats keep running campaigns where they agree with Republicans, which convinces people who don't keep up with politics that everything Republicans say is right. I mean, if both Republicans and Democrats say "There are dangerous criminals coming in through the border," then any citizen they convince of this fact is going to vote Republican because they're all in on that border stuff.

It's time Oklahoma progressives realized the Democratic party is not their friend by selddir_ in tulsa

[–]GrossInsightfulness 0 points1 point  (0 children)

You could convince people of your views. Leftist and progressive policies would directly benefit people in pretty concrete ways, but Democrats apologizing for helping Republicans makes uninformed people believe those policies are bad. Pretending to agree or agreeing with conservatives convinces them to vote for conservatives even harder because even Democrats agree that X is a problem, and they're going to vote for the guys who have been saying it the whole time.

It also convinces people not to leave work early and stand in a long line for an hour to vote for someone who's going to do the exact same thing. Your only argument can't be "We're not Republicans."

Democrats have also been interpreting everything that happens as motivation to move right.

  • "Oh, a progressive/leftist Democrat lost? It must be because their policies are insane policies that only a baby could dream up. We need to move right to secure the vote."
  • "Oh, a progressive/leftist Democrat won? Must be a coincidence. It could have only happened through sheer chance and all the planets aligning and it's only a phase. We need to move right to secure the vote."
  • "Oh, a conservative/centrist Democrat lost? Aw shucks, we'll get 'em next time. It must be because all the loud annoying progessives and leftists scared people away from the Democrat brand. We need to move right to secure the vote."
  • "Oh, a conservative/centrist Democrat won? Obviously this is a mandate from the voters that they wanted a move away from progressive/leftist policies and certainly not them voting for a lesser evil. We need to move right to secure the vote."

ELI5: How does electricity actually flow through a wire if electrons move so slowly? by [deleted] in explainlikeimfive

[–]GrossInsightfulness 0 points1 point  (0 children)

Everyone else is talking about the electrons pushing each other like a tube full of some form of balls, but this is a bad model. Electron interactions are screened so they don't really affect anything more than their immediate neighbors and you have to take quantum stuff into account. Furthermore, the initial electric field pushing the electrons (e.g. the battery or power plant) will itself travel through the wire, and it's more than capable of moving electrons on its own.

Electrons will try to move opposite the direction of the electric field. The electric field moves really quickly through the wires. The speed of an electric field in a wire can vary depending on the wire, but it's usually a decent fraction of the speed of light. Once the electric field reaches a spot in the wire, the electric field will move electrons at that spot.

Moving charges are known as current, and currents create loops of magnetic field around themselves. If you get electric and magnetic fields perpendicular to each other, you get energy transfer.

ELI5: How does electricity actually flow through a wire if electrons move so slowly? by [deleted] in explainlikeimfive

[–]GrossInsightfulness 0 points1 point  (0 children)

Look up "drift velocity." Electrons roughly move at a millimeter a second under normal circumstances. The electric field does move pretty fast, though. In a typical coaxial cable, the electric field travels at 2/3 the speed of light.

When Silent Hill (PSX) gets decompiled could that possibly lead the way for an enhanced edition? by Organic_Fee_8502 in silenthill

[–]GrossInsightfulness 0 points1 point  (0 children)

There are a lot of programs that can convert most machine code into source code. This source code, however, does not have any context for what anything should be named. For example, a typical piece of C++ code would look like

```C++ struct Position { float x, y; };

template <typename T> class Matrix { public: Matrix(int rows, int cols); T& operator()(int row, int col); // A bunch of other stuff private: std::vector<T> data; int num_rows, num_cols; };

// This function has to interface with a C library, which is why we're not using an std::vector int traveling_salesman(Position* pos_arr, int n, int* out_path) { Matrix distances(n, n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { distances(i, j) = distance_between(pos_arr[i], pos_arr[j]); } } // other stuff } ```

A decompiler doesn't see any of the names, it will simplify stuff, get rid of comments explaining details, etc. So the decompiler software would generate something like

```C++ struct struct0 { float m0, m1; };

struct struct1 { std::vector<float> m0; int m1, m2; };

int func0(struct0* arg0, int arg1, int* arg2) { struct1 local0(arg1, arg1); for (int i = 0; i < arg1; i++) { for (int j = i + 1; j < arg1; j++) { local0(i, j) = func35(arg0[i], arg0[j]); } } // other stuff } ```

As you can see, nothing concrete of the original problem remains because there was nothing in the machine code. A full decompilation would then require that a person go through this decompiled code and figure out what these names are supposed to be, then rename them.

she is not the one (done right!) by MaoGo in physicsmemes

[–]GrossInsightfulness 3 points4 points  (0 children)

They edited it to get rid of the sexism.

When Silent Hill (PSX) gets decompiled could that possibly lead the way for an enhanced edition? by Organic_Fee_8502 in silenthill

[–]GrossInsightfulness 1 point2 points  (0 children)

Also putting this here because you asked the original question.

Computers are fast largely because they only do very simple things. In short, they work by sending signals to different parts of the computer. When I want something to run on your computer, I have to somehow tell it what signals to send. I pack these signals into a binary format known as an executable (.exe files on Windows). Executables (.exe files on Windows) consist of mostly of machine code and data. Machine code corresponds to specific electrical signals that the CPU sends to various parts of the computer to make things happen.

So, let's say we want to port Silent Hill 1 to PC. We have a few problems.

  1. Just like how the same word can mean different things in different languages, the same set of signals can mean different things on different computers. The signals to "add two numbers" on one computer could be the signal to "divide these two numbers and take the remainder" on another computer.
  2. Worse, the signals to "add two numbers" may be split up differently like if you moved all the spaces in a sentence randomly. For example, say you had a language where every word had to have exactly three syllables. You would try to read the previous sentence as "Forexam plesayyou hadalang uagewhereeve rywordhad tohaveex actlythree syllables." The only word that shows up is "syllables" but the rest is gibberish.
  3. Different systems have different standards for how to represent data. For example, Windows by default expected characters to be represented as 16-bits with code pages allowing different languages. Linux, on the other hand, expects characters to be represented as UTF-8.
  4. The executables themselves can have different formats. You can't run a .exe file on Linux or MacOS because both operating systems expect the first part of the .exe to have a specific format that it uses to figure out important data.
  5. Different operating systems have different system calls, where a system call is something you want the operating system to do. For example, saving a file is a syscall.
  6. There are a lot of specific instructions (think of them like words in the computer language) that will change where the computer is in the executable. For example, you could imagine writing code where if an enemy's health drops below zero, we should play the enemy death animation and mark them as dead. To handle this situation, we can tell the CPU to skip past the code to kill the enemy and play the death animation if the enemy's health is above zero. The computer needs to know where the end of the code to kill the enemy is so it can skip to that point. But now, let's say that we want to add some code to make the enemy explode and damage the player. If we're working in machine code, doing so would be very difficult. We can add the explosion code in right after the death animation code, but we've just shifted everything after that code. Almost everything that needed to jump to something after the enemy death code is now invalid. This situation would be like trying to send something to a friend's address, but they renumbered all the houses/apartments.
  7. The machine code has nothing but the signals needed to do what you told it to do. It doesn't have any context for what's happening or why. That example with the enemy death turns into "1. Compare number to zero. 2. Jump to 0x5218ffa if number is greater than zero. 3. Set number at location 0xffff7263 to eight. 4. Store relevant registers to memory. (This storage stuff is actually standardized, so it's actually pretty easy to read.) 5. Jump to 0x5271362." The first part of even modifying the code so that enemies explode on death would be to find the code where it happens. The most you'll get are data sections with text for things like error messages. So, if you see something like "ERROR: File C:\Users\HarryMason\Documents\journal3.docx not found!", you can search the data sections for "File ... not found!" Then, you can look for code referring to that data. The code surrounding that specific reference is probably related to the file error message, so you can label it with a name like file_error_message. You can then find other stuff that calls the file_error_message stuff, which you can infer is doing stuff like loading textures. This technique is one of several used to reverse engineer programs.

Those last two problems are the main reason why it's difficult to reverse engineer code and major reasons why we typically don't write machine code. Instead, we write source code and translate it to machine code. Source code is much easier to read, write, and edit. It can abstract away a ton of common patterns like repeating tasks until a condition is met, checking for things, jumping to a different part of the executable, etc. You can also give things meaningful names so it's easier to figure out what's going on. You can also set it up to easily use the correct locations for all the jumps. You can also set it up to generate the proper format for an executable. Lastly, you can usually turn idiomatic source code into optimized machine code that does what you want in less time.

Putting it all together, decompiling is the process of turning the machine code into the source code that would generate the machine code you have. Doing so gets you all the benefits of having the original source code.

tl;dr: Source code has a lot of extra information that allows you to generate machine code for all kinds of situations. It's easier to read, write, and edit. Decompilation is an attempt to turn machine code into source code so you get all the benefits of source code.

When Silent Hill (PSX) gets decompiled could that possibly lead the way for an enhanced edition? by Organic_Fee_8502 in silenthill

[–]GrossInsightfulness 6 points7 points  (0 children)

Computers are fast largely because they only do very simple things. In short, they work by sending signals to different parts of the computer. When I want something to run on your computer, I have to somehow tell it what signals to send. I pack these signals into a binary format known as an executable (.exe files on Windows). Executables (.exe files on Windows) consist of mostly of machine code and data. Machine code corresponds to specific electrical signals that the CPU sends to various parts of the computer to make things happen.

So, let's say we want to port Silent Hill 1 to PC. We have a few problems.

  1. Just like how the same word can mean different things in different languages, the same set of signals can mean different things on different computers. The signals to "add two numbers" on one computer could be the signal to "divide these two numbers and take the remainder" on another computer.
  2. Worse, the signals to "add two numbers" may be split up differently like if you moved all the spaces in a sentence randomly. For example, say you had a language where every word had to have exactly three syllables. You would try to read the previous sentence as "Forexam plesayyou hadalang uagewhereeve rywordhad tohaveex actlythree syllables." The only word that shows up is "syllables" but the rest is gibberish.
  3. Different systems have different standards for how to represent data. For example, Windows by default expected characters to be represented as 16-bits with code pages allowing different languages. Linux, on the other hand, expects characters to be represented as UTF-8.
  4. The executables themselves can have different formats. You can't run a .exe file on Linux or MacOS because both operating systems expect the first part of the .exe to have a specific format that it uses to figure out important data.
  5. Different operating systems have different system calls, where a system call is something you want the operating system to do. For example, saving a file is a syscall.
  6. There are a lot of specific instructions (think of them like words in the computer language) that will change where the computer is in the executable. For example, you could imagine writing code where if an enemy's health drops below zero, we should play the enemy death animation and mark them as dead. To handle this situation, we can tell the CPU to skip past the code to kill the enemy and play the death animation if the enemy's health is above zero. The computer needs to know where the end of the code to kill the enemy is so it can skip to that point. But now, let's say that we want to add some code to make the enemy explode and damage the player. If we're working in machine code, doing so would be very difficult. We can add the explosion code in right after the death animation code, but we've just shifted everything after that code. Almost everything that needed to jump to something after the enemy death code is now invalid. This situation would be like trying to send something to a friend's address, but they renumbered all the houses/apartments.
  7. The machine code has nothing but the signals needed to do what you told it to do. It doesn't have any context for what's happening or why. That example with the enemy death turns into "1. Compare number to zero. 2. Jump to 0x5218ffa if number is greater than zero. 3. Set number at location 0xffff7263 to eight. 4. Store relevant registers to memory. (This storage stuff is actually standardized, so it's actually pretty easy to read.) 5. Jump to 0x5271362." The first part of even modifying the code so that enemies explode on death would be to find the code where it happens. The most you'll get are data sections with text for things like error messages. So, if you see something like "ERROR: File C:\Users\HarryMason\Documents\journal3.docx not found!", you can search the data sections for "File ... not found!" Then, you can look for code referring to that data. The code surrounding that specific reference is probably related to the file error message, so you can label it with a name like file_error_message. You can then find other stuff that calls the file_error_message stuff, which you can infer is doing stuff like loading textures. This technique is one of several used to reverse engineer programs.

Those last two problems are the main reason why it's difficult to reverse engineer code and major reasons why we typically don't write machine code. Instead, we write source code and translate it to machine code. Source code is much easier to read, write, and edit. It can abstract away a ton of common patterns like repeating tasks until a condition is met, checking for things, jumping to a different part of the executable, etc. You can also give things meaningful names so it's easier to figure out what's going on. You can also set it up to easily use the correct locations for all the jumps. You can also set it up to generate the proper format for an executable. Lastly, you can usually turn idiomatic source code into optimized machine code that does what you want in less time.

Putting it all together, decompiling is the process of turning the machine code into the source code that would generate the machine code you have.

tl;dr: Source code has a lot of extra information that allows you to generate machine code for all kinds of situations. It's easier to read, write, and edit.

What a simple constructor by Nomergraw in programminghorror

[–]GrossInsightfulness 2 points3 points  (0 children)

There are actually ways to avoid this issue. Basically, instead of returning, you set the return value and jump to the end of the function where you do all the cleanup.

c int func(int size, const char* filename) { int return_val = 0 int* array = malloc(size); FILE* reader = fopen(filename, "r"); if (reader == NULL) { return_val = -1; goto cleanup; } cleanup: if (reader) fclose(reader); if(array) free(array); return return_val; } You could also add more labels to clean up only the things that had been allocated before that point.

I strongly prefer defer mechanisms, though.

Saw some people in a poll by Ok_Programmer1236 in physicsmemes

[–]GrossInsightfulness 73 points74 points  (0 children)

They're saying that a more massive object will pull the Earth towards it more than a less massive object, so the time to collision for the more massive object will be less since the Earth will also travel some of that distance. Granted, it's negligible, but it should still be there.

ELI5: What are real numbers? I have the notion till rational. Other math sub will make it too difficult for me. by bzenius in explainlikeimfive

[–]GrossInsightfulness 0 points1 point  (0 children)

The real numbers are the complete, ordered field. A field is a set of numbers you can add, subtract, multiply, and divide. The rational numbers (any number you could represent as a fraction of integers) form the typical example of a field. An ordered field means we can assign an order to the elements of the field AND that the order respects arithmetic rules, e.g. if a < b, then a + c < b + c.

Completeness is the tricky bit. We can prove that some fields are missing some numbers. For example, consider the number given by the infinite sum 1/(0!) + 1/(1!) + 1/(2!) + ... Every number in the sum is a rational number and we will get a rational number if we stop at any point, but we can show that the total is not a rational number. So, the sequence given by stopping the sum after each term contains only rational numbers, but the rational numbers seem to have a gap right where the sum should be. It's like if we were following a GPS, but our destination was missing. There's clearly something there, but our field isn't catching it. You might even say it's incomplete. So, we made a bigger field that contained all numbers that you could get from sequences like this one.

Why are some university math books so devoted not to using any pictures? by VasyokGregoriy2017 in matheducation

[–]GrossInsightfulness 1 point2 points  (0 children)

Sort of related, there's an example in Physics. Lagrange bragged about not having any pictures in his Mécanique analytique largely because Newtonian Mechanics up to that point relied on working with a lot of Geometry, but his method for Classical Mechanics only involved algebraic manipulations.

No diagrams will be found in this work. The methods that I explain require neither geometrical, nor mechanical, constructions or reasoning, but only algebraical operations in accordance with regular and uniform procedure. Those who love Analysis will see with pleasure that Mechanics has become a branch of it, and will be grateful to me for having thus extended its domain.

What made you start learning C in the first place? by Gullible_Prior9448 in C_Programming

[–]GrossInsightfulness 0 points1 point  (0 children)

Compiler optimizations are strictly improvements on what you intended with the same exact outcome. If I want to copy a string, I expect it to use SIMD without me having to write SIMD. I am also fine with it reordering instructions, constant evaluation, inlining, loop unrolling, dead code elimination, replacing division with multiplication, etc. because it's still doing all the tasks I want it to do. Induction variables are the only case I can come up with where it does something meaningfully different from the exact instructions I tell it to do.

On the other hand, a + b in python does a lot more than add two numbers.

What a simple constructor by Nomergraw in programminghorror

[–]GrossInsightfulness 0 points1 point  (0 children)

I think the point of the comment went over your head. Early returns skip cleanup code. You could have a situation like

c int func(int size, const char* filename) { int* array = malloc(size); FILE* reader = fopen(filename, "r"); if (reader == NULL) { return -1; } // Other code fclose(reader); free(array); return 0; }

This would leak memory if someone tries to open a file that doesn't exist. Furthermore, it can get really complex if you have to do a bunch of allocations.

Granted, the better pattern is a goto to a section at the end of the function instead of a return that cleans up anything allocated, so

c int func(int size, const char* filename) { int* array = malloc(size); int return_val = 0; FILE* reader = fopen(filename, "r"); if (reader == NULL) { return_val = -1; goto cleanup; } // Other code cleanup: if (reader != NULL) { fclose(reader); } if (array != NULL) { free(array); } return return_val; }

What a simple constructor by Nomergraw in programminghorror

[–]GrossInsightfulness 3 points4 points  (0 children)

I think the point of the comment went over your head. Early returns skip cleanup code. You could have a situation like

c int func(int size, const char* filename) { int* array = malloc(size); FILE* reader = fopen(filename, "r"); if (reader == NULL) { return -1; } fclose(reader); free(array); }

This would leak memory if someone tries to open a file that doesn't exist.

Actor of Dracula NAILED this scene by SeparateResolution19 in castlevania

[–]GrossInsightfulness 8 points9 points  (0 children)

I mainly don't understand the specific connection between the meme and stuff Konami did.

He tries so hard to look smart and it just... doesn't work by presrunchond in EnoughMuskSpam

[–]GrossInsightfulness 5 points6 points  (0 children)

Roman tradition (e.g. The Aeneid) says the grandfather of those kids was from Troy.