There's one guy who has a PHD in shanties and the Black Flag team hired him as a consultant. Saw him give a speech once, it was so cool. Shanties had a lot of functionality and trace their roots back to - at least - Caribbean and American slaves field songs.
Shanties were used to coordinate work on board the ship and as such there's loads of different types of shanties. Running down to Cuba was probably used when you were lowering rowing boats and the like, if I had to make a guess.
Shanties also allowed the crew to complain to the officers/bring issues to attention outside the formal chain of command.
The shantyman would sing the same shanty until whatever task was at hand was done. This means the shantyman had to be a great improviser.