Respectfully, this is not telling the whole story.
Regardless of whether you use TCP or UDP, wifi is still susceptible to interference from other radio sources in the area, strong magnetic fields, and even solar radiation. On top of that, wifi itself is designed to bend before breaking, metaphorically, so it has poor timing characteristics.
Ethernet does not have these problems, or not to nearly the same degree.
Do you have a source on the 20 meter limit? I’ve connected Macs together with 100 meters of ethernet and never had a problem.
To the original question, though, connecting one Mac to another directly with ethernet is completely fine and as long as you don’t need a third device to be part of the network, I recommend it.
As to the advice about TCP vs. UDP, on a two-computer network you are not going to encounter the kinds of problems that UDP is known for. I wouldn’t worry.
Best
Sam
—
Sam Kusnetz (he/him) | Figure 53