Nature doesn't get to start from scratch when it comes to baking up a new organism. Okay, the whole process started from scratch (billions of years ago), but scratch still meant using what was there. Evolution works on what is available.
This means that a new kind of fin evolves from an older structure that already exists. This is just luck. The older structure may or may not have had a similar function. That doesn't matter. What matters is that existing parts can be used in a new way and this helps the animal adapt.
Evolution does not create perfect structures. The traits that can get the job done best are kept, but "best" is a relative thing. Let's say we were asked to put together the most amazing outfit ever. If we could have anything we wanted, we'd get a very different outfit than if we had to start with only the things in our closet right now.
The scientist and writer Stephen Jay Gould described a perfect example in the "thumb" of the giant panda. Pandas have six digits on their front paws. The sixth digit is used like our opposable thumb, but is actually a modified wrist bone. It turns out that modern bears, the closest relatives of pandas, have a slightly enlarged version of the same bone and tendons that happen to connect at the right point. Panda ancestors had some available parts that, with a bit of change, could become thumb-like.
Want to make a wing? Compare bat and bird wings. Bats and birds have wings put together from the same bones that make up any vertebrate forelimb, but natural selection made wings in different ways. Flight evolved multiple ways using a similar starting point. Natural selection works on what already exists, but it can come up with lots of possibilities.
No one way is better. It is just a matter of survival. If wings become a problem, animals with wings might disappear or wings would evolve into something else.
In building the animal family tree, scientists rely greatly on the fact that nature is always messing about with existing parts. This helps show which things may be related to which others. This gets tricky though. Dolphins and sharks are shaped the same, but turns out they aren't very related. Still, anatomy gives us clues.
Until we recently came up with techniques like genetic testing, comparing parts was much of what we had to go on. Fortunately for people who like to think about these things, nature leaves lots of clues in pandas' thumbs and bats' wings.