Let's put it in git terms. Humans and chimps are derived from a common ancestor, so you can imagine them as two diverging forks of the same codebase, with their common ancestor being the last commit that they both share. Since then, either or both could have performed any sequence of additions, deletions, edits, duplications, etc., including cutting large sections out of one file and pasting them into another. However, for chimps and humans, the fork was recent enough that the vast majority of lines of code have been untouched since the fork, so for the vast majority of lines of human code, you can identify the corresponding line of chimp code, and vice versa. So when we talk about "Gene A" in humans and "Gene A" in chimps, this is presuming that the region of the genome containing Gene A is relatively unchanged between the two species. However, as you and others have pointed out, just because the gene's sequence is identical or nearly identical in the two species doesn't guarantee that it performs the same function in the two species. You could make an analogy to modifying a global variable in a completely different file that drastically changes the behavior of a function, even though that function's source code is unchanged.
So roughly speaking, a gene is a region of DNA that operates as a functional unit. The most well well-understood function is encoding a protein product and regulating its production. And when we talk about the "same" gene in different species, we're using "same" informally to refer to the genes in the two species that are derived from the same gene in their common ancestor. Usually, but not always, these genes perform the same or similar functions in the two species. Unlike a function in computer code, however, the bounds of a gene are not well-defined, and can overlap other genes or be non-contiguous.
So roughly speaking, a gene is a region of DNA that operates as a functional unit. The most well well-understood function is encoding a protein product and regulating its production. And when we talk about the "same" gene in different species, we're using "same" informally to refer to the genes in the two species that are derived from the same gene in their common ancestor. Usually, but not always, these genes perform the same or similar functions in the two species. Unlike a function in computer code, however, the bounds of a gene are not well-defined, and can overlap other genes or be non-contiguous.
For more: https://en.wikipedia.org/wiki/Homology_%28biology%29#Sequenc...