Section 3.1. Programming is About Naming

[Page 38 (continued)]

3.1. Programming is About Naming

Computer Science Idea: Much of Programming is About Naming

A computer can associate names, or symbols, with just about anything: With a particular byte; with a collection of bytes making up a numeric variable or a string of letters; with a media element like a file, sound, or picture; or even with more abstract concepts, like a named recipe (a program or method) or a named encoding (a type or class). A computer scientist sees a choice of names as high quality in the same way that a philosopher or mathematician might: If the names are elegant, parsimonious, and usable.

[Page 39]

Obviously, the computer itself doesn't care about names. Names are for the humans. If the computer were just a calculator, then remembering names and the names' association with values would be just a waste of the computer's memory. But for humans, it's very powerful. It allows us to work with the computer in a natural way.

A programming language is really a set of names that a computer has encodings for, such that those names make the computer do expected actions and interpret our data in expected ways. Some of the programming language's names allow us to define new nameswhich allows us to create our own layers of encoding. We can associate a name with a location in memory, this is called declaring a variable. We can associate a name with a group of Java statements, we call this defining a method (function). In Java you can also assign a name to a group of related variables and methods (functions) when you define a class (type).

Computer Science Idea: Programs are for People, not Computers.

Remember that names are only meaningful for people, not computers. Computers just use the names to find the values associated with them. A good program is meaningful (understandable and useful) for humans.

A program is a set of names and their values, where some of these names have values of instructions to the computer ("code"). Our instructions will be in the Java programming language. Combining these two definitions means that the Java programming language gives us a set of useful names that have a meaning to the computer, and our programs are then made up of Java's useful names as a way of specifying what we want the computer to do.

There are good names and bad names. Bad names aren't curse words, or TLA's (Three-Letter Acronyms), but names that aren't understandable or easy to use. A good set of encodings and names allow one to describe methods in a way that's natural, without having to say too much. The variety of different programming languages can be thought of as a collection of sets of namings-and-encodings. Some are better for some tasks than others. Some languages require you to write more to describe the same program (function) than othersbut sometimes that "more" leads to a much more (human) readable program that helps others to understand what you're saying.

Philosophers and mathematicians look for very similar senses of quality. They try to describe the world in few words, using an elegant selection of words that cover many situations, while remaining understandable to their fellow philosophers and mathematicians. That's exactly what computer scientists do.

How the units and values (data) of a program can be interpreted is often also named. Remember how we said in Section 1.2 (page 7) that everything is stored in groups of eight bits called bytes, and we can interpret those bytes as numbers? In some programming languages, you can say explicitly that some value is a byte, and later tell the language to treat it as a number, an integer (or sometimes int). Similarly, you can tell the computer that these series of bytes is a collection of numbers (an array of integers), or a collection of characters (a String), or even as a more complex encoding of a single floating point number (any number with a decimal point in it).

[Page 40]

In Java, we will explicitly tell the computer how to interpret our values. Languages such as Java, C++, and C# are strongly typed. Names are strongly associated with certain types or encodings. They require you to say that this name will only be associated with integers, and that one with floating point numbers. In Java, C++, and C# you can also create your own types which is part of what makes object-oriented languages so powerful. We do this in Java by defining classes such as Picture which represents a simple digital picture. An object of the Picture class has a width and height and you can get and set the pixels of the Picture object. This isn't a class that is part of the Java language, but a class that we have defined using Java to make it easier for students to work with digital pictures.

Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Year: 2007
Pages: 191 © 2008-2017.
If you may any questions please contact us: