One of my major annoyances in knitting is loose, wavy ribbed stitches. Especially along a cuff or hem, where it's intended to be nice and tight and give some elasticity to the garment. But instead, I often see on hand knit garments a very loose ribbed edge that flows away larger than the rest of the garment. It doesn't look tidy, and it's definitely not functional.
There are two main techniques I implement to fix this problem.
The first issue: The longer floats between stitches.
Let me explain. When you're knitting just knit, or just purl, the strand between each stitch is just long enough to reach the next stitch (obviously). But when you are switching back and forth between knit and purl stitches, now the strand between each stitch has to travel from the back of the work to the front AND between to the next stitch (this is a longer distance).
So the fix: Every time you switch from knit to purl or vice versa, pull the yarn tight before you knit the new stitch. This closes the gap by pulling the yarn to the new edge it's going to start on, instead of letting it just loosely travel that distance.
For example: If I'm knitting, my yarn begins and ends each loop in the back. If I switch to a purl stitch, my yarn will begin and end that loop in the front. If I don't pull the stitches, the distance the yarn travels from back to front adds enough length that the stitches will have a much looser gauge than if you are knitting in plain stockinette stitch.
Partial Fix: Many people suggest just going down a needle size for ribbing to keep gauge even. Although this does make the stitches smaller and therefore can decrease the gauge to match the rest of the garment, it does not solve the issue and the ribbing can still look very untidy. You could pair this strategy with the above strategy for a nice even ribbing though.
The second issue: CO/BO edge is too big or loose.
Proper ribbing has a very nice elastic property to it. I have found that if I cast on my stitches with the same tension that I cast on a stockinette piece, the ribbing is very loose at the cast on edge (as you can see in the above picture).
The solution: Cast on slightly tighter. I cast on quite tight when I knit rib stitches, and that tighter edge helps keep the stitches more structured and holds everything nice and uniform for a quality, beautiful, ribbed edge.
Final thoughts: Try out all of the methods I listed above and let me know what works for you! Let me know if you have a different method that you use as well :) I find that a combination of a snug cast on while also eliminating the extra length between stitches gives me a very nice ribbed edge.