"The dismal science" is a derogatory alternative name for economics coined by the Victorian historian Thomas Carlyle in the 19th century. The term drew a contrast with the then-familiar use of the phrase "gay science" to refer to song and verse writing.
The phrase "the dismal science" first occurs in Thomas Carlyle's 1849 tract called Occasional Discourse on the Negro Question, in which he argued in favor of reintroducing slavery in order to regulate the labor market in the West Indies:
Not a "gay science", I should say, like some we have heard of; no, a dreary, desolate and, indeed, quite abject and distressing one; what we might call, by way of eminence, the dismal science.
It was "dismal" in "find[ing] the secret of this Universe in 'supply and demand', and reducing the duty of human governors to that of letting men alone". Instead, the "idle Black man in the West Indies" should be "compelled to work as he was fit, and to do the Maker's will who had constructed him".
Carlyle's view was attacked by John Stuart Mill as making a virtue of toil itself, stunting the development of the weak, and committing the "vulgar error of imputing every difference which he finds among human beings to an original difference of nature".
Note that Carlyle did not originally coin the phrase "dismal science" as a response to the economically-influential theories of Thomas Malthus, who predicted that starvation would inevitably result as projected population growth exceeded the rate of increase in the food supply. However, Carlyle did earlier use the word "dismal" in relation to Malthus' theory in Chartism (1839):
The controversies on Malthus and the 'Population Principle', 'Preventive Check' and so forth, with which the public ear has been deafened for a long while, are indeed sufficiently mournful. Dreary, stolid, dismal, without hope for this world or the next, is all that of the preventive check and the denial of the preventive check.
Many at the time and afterward have understood the phrase in relation to the grim predictions drawn from the principles of 19th century "political economy". According to Humphry House: