Almost all programming languages these days are case sensitive. When you're writing source code, whatever that language is, and there's a word like while or true, if your language expects that word to be all lowercase, then it should always be written that way.
That’s because when you're trying to run a program, you must take your source code and expect it to be compiled or interpreted. For example, if you have that word true which, according to the syntax of that programming language should be written in all lowercase, but you write it with an uppercase T (True) either accidentally or intentionally, the compiler won’t say, oh, it's okay, I know what you were going for. It just won't work!
Fig 2.2.1: Compiler/interpreter generates an error because of wrong capitalization
It's not like writing an email where you can make a few mistakes with your capitalization and still expect to be understood. Look, this is programming and these are rules, not guidelines. Okay?
There are a few typically older programming languages like some version of BASIC, Ada PASCAL, Fortran and SQL which don't care if you use any combination of uppercase or lowercase or mixed case letters in your source code. But these days, begin by assuming that every programming language is case sensitive and is very picky about it.
It's common when you first see some source code examples, even before you've started writing any code that you might think, okay, I don't yet know exactly what this source code is doing, but this language here seems to be mostly lowercase.
But then you see a few words with first letters in uppercase or perhaps you find that occasionally some words are written in all caps. It can be confusing when you don't know why. Does this actually mean something or did the programmer just left the camp's lock key on when he was typing this?
Fig 2.2.2: A program with the word NULL in all caps
Well, it's true. There is usually a meaning to those differences. Just as in written English where we will capitalize different words based on the type of word they are.
Take a regular sentence like this:
next wednesday, i will drive you to the airport to fly from phoenix to london.
In correct written English, I'm supposed to capitalize the opening word “Next” of this sentence. I should also capitalize days of the week (“Wednesday”) and proper nouns like “London” and “Phoenix”. Also, in English, we're supposed to capitalize the word “I”, but we don't capitalize the word “you” or “we” or “they”.
But in a different language like written German, that little piece is the other way around. We're supposed to capitalize the word “Sie” for you, but not “ich” for I. I want to point out this out not to get into language semantics, but to show that yes, just as in real world languages, you are going to find differences in what programming languages choose to capitalize.
As one example in Python, T, the first letter in the word true is capitalized whereas in Swift it is all lowercase. Now, this is not random. It's just that different languages choose to emphasize different things just as English and German do.
Fig 2.2.3: Comparing capitalization of the word “True” in Python and Swift
When you're looking at a whole bunch of different languages as we're doing here, these differences can seem daunting, but in practice they're not. That’s because when you start to write source code, you're going to pick a language and then it's easy to deal with this.
Fig 2.2.4: Sample 4 different programming languages: Javascript, Python, ALGOL and Swift
Here's why.
Back to this sentence.
Next Wednesday, I will drive you to the airport to fly from Phoenix to London.
Imagine asking a room full of people why in written English do you capitalize I but we don't capitalize the word you. A lot of people are going to shrug and say, I don't really know. I write it this way because I always read it this way. That is a perfect way to begin writing source code.
If you start writing, for example, Swift and think, I'm going to write the word true with a lowercase t because whenever I see it in Swift, it always seems to have a lowercase t and I'm going to write the word string with an uppercase S because whenever I see it in this language, it seems to have an uppercase S.
That's a great way to begin. Are there some deep syntactical reasons and theoretical explanations we could get into to explain the differences in capitalization between programming languages? Sure.
But those things just aren't that important right now. If you were learning how to write English and you wrote your first sentence like, “hello, i am a programmer”, what you'd want is somebody saying, Hey, you should capitalize this I. What you don't need in that first sentence would be a long lecture on the history and theory of capitalization rules of this singular first-person pronoun in all its contractions.
There will be plenty of time to have those discussions and better times for them. Right now the most important thing is consistency to recognize that whatever language we might be using that the same word with the same meaning is always capitalized the same way.
Here's one thing that makes this even easier. In programming, we don't have rules like in written English where the word “next” is not capitalized but if you put it at the start of a sentence, then it is. No, it is simpler here in a programming language.
It doesn't matter if a word is at the beginning of a sentence, if it's lowercase, it's always lowercase. Actually we don't talk about writing sentences in a programming language.
We deal with the idea of writing statements and it's about time we talked about those statements.