Case Sensitive Languages
Every language, system, or program has the capability to differentiate between different case alphabets. If a programming language doesn’t work properly in upper case and lower case letters interchangeably, it is called as a case sensitive language. Other terms for it is case specific or case preserving languages. In case sensitive languages an error may be generated if there is some difference in the case type of any variable, function, or library or other things that may cause errors.
These case sensitive languages do discern between different names and queries, but if the case is not correct or there is some problem in it then it might not be able to provide the correct file or query. For example, if a user wants something like a book from a library then “Library” is entered by the user with a upper case L in ‘library’ the system might not recognize it as a stored file as there is a change in case and may also not give the expected result or even an error.
There is something opposite of case sensitive i.e. case insensitive, just as its name implies in case insensitive languages, there is no ability to differentiate between upper and lower case letters. Examples of case insensitive languages are ABAP, Ada, Fortran, Pascal, etc.
There are many case sensitive languages, some of them are as follows:
- C
- C++
- C#
- Java
- Verilog
- Ruby
- Python
- Swift etc.
Many more other languages are there that are case sensitive. In all these languages, there can be a wrong case if there is a file, library, function, variable, etc. that you have to call or use then it has to be written exactly as the programming language requires it. The compiler reads the code and if there is a problem in the case of anything then it gives syntax, or, runtime, error etc.
Let’s take an example, Java is a case sensitive language therefore the keywords, function names, variables, and other identifiers are to be typed with care and consistent capitalization. Now, for instance, when typing the “for” keyword, you must type "for", not "For" or "FOR". Just like this if there is a variable named study_hub, then it can be written in many ways such as “study_hub” , “Study_hub” or “Study_Hub” or even “STUDY_HUB”.
C language is also considered as a case sensitive language because any term like ‘new’ and ‘New’ are different in it. Just like C language, if a programming language is case sensitive then a program can have a wider range of functions and names, i.e. char can be used as a function and Char can be used for something else. But this increases the difficulty in programming for new developers. Due to there being confusion in the cases of the letters like there might an error due to this as they might not completely understand all the different functions, libraries, and other rules for variable naming, etc.
In order to write a code, the programmer needs deep knowledge to type it in the correct case otherwise, the incorrectly written code might alter the whole meaning of the code.
Program to show Case Sensitivity in C++ and Python:
First let’s check case sensitivity in a C++ program with a basic C++ program to print a sentence:
#include<iostream>
using namespace std;
int main(){
Cout<<"Program to show case sensitivity in C++.";
return 0;
}
Output:
main.cpp: In function ‘intmain()’:
main.cpp:7:5: error: ‘Cout’ was not declared in this scope
7 | Cout<<"Program to show case sensitivity in C++.";
| ^~~~
Here, the cout() function is used with an uppercase ‘C’. Due to this, an error is generated. This can be corrected by writing the cout() function in the correct case, i.e. in lowercase cout(). This shows that C++ is a case sensitive language.
Now, let’s show the case sensitivity in the Python language by another basic output printing program in Python:
print("Program to show case sensitivity in the python language.")
Print("Hello")
Output:
Program to show case sensitivity in the python language.
Traceback (most recent call last):
File "<string>", line 2, in <module>
NameError: name 'Print' is not defined. Did you mean: 'print'?
>
In this code, the first print() function is displayed as it is in the correct case whereas the second print() function displays an error in line 2. This shows that Python is also a case sensitive language.
All the other programming languages also work in similar ways with some variations according to their compilers.