Askville.Amazon.com says the expression means trying to remain cheerful in difficult circumstances. “It is a great temptation to try to cheer oneself up by whistling or singing in a dark and lonely place” One reference can be found in Robert Blair’s “The Grave” from 1742. “The Schoolboy…Whistling aloud to bear his Courage up.” A comment said that villages were a day’s travel apart in the Middle Ages, cemeteries were at the edge of towns, and spirits came out at dusk to frighten travelers. The travelers believed loud noises would keep the spirits away. Some would bang on pots and pans and others would whistle or shout.