Snake case

Updated: 03/10/2024 by Computer Hope
Screaming green snake.

Snake case or snake_case is a naming convention where all letters are converted to lowercase, and spaces are replaced with an underscore (_). It is used in computer programming when a variable or subroutine contains a space, which doesn't work with CamelCase. For example, if you had a subroutine with a date and time function, it could be called "date_and_time."

A variation of snake case is called screaming snake case, where all letters are uppercase, and underscores still replace spaces. If this naming convention were used, our example above would be "DATE_AND_TIME."

How to convert text into snake case

Converting text to snake case can be done with a few lines of code, as shown in the Perl example below.

my $snake_case = "Computer Hope example.";
$snake_case =~ s/ /_/g; #Replace all spaces with underscores
$snake_case = lc($snake_case); #Lowercase all text my $screaming_snake_case = uc($snake_case); #Create uppercase version
print "Snake case = '$snake_case' and Screaming snake case = '$screaming_snake_case'\n";

When running this code, "Snake case = 'computer_hope_example' and Screaming snake case = 'COMPUTER_HOPE_EXAMPLE'" would be printed in the command line.

Use the conversion tool below to convert any text to snake case, screaming snake case, and other forms of converted text.

Conversion tool


CamelCase, Case, Programming language, Typography terms