music |
| | OSdata.com |
white space
summary
The educational goal of this subchapter is to learn what the white space characters are in your chosen programming language and to learn how to use whitespace to make your programs easier to read, understand, and maintain.
Whitespace is used for clarity and ease of understanding. The term is borrowed from art and design.
white space
Whitespace is used for clarity and ease of understanding. The term is borrowed from art and design.
While whitespace characters vary by language, they generally include any characters that dont print on the page, such as the space or blank character, tab, new line, carriage return, and form feed.
An important use for whitespace is to visually show the structure of a program. A programmer can use indentation to show logical and lexical blocks of code. Indentation and use of white space is normally optional. See example in preceeding chapter on free form vs columns.
Brian Kernighan and Dennis Ritchie (the original creators of C) recommend in their famous book The C Programming Language that programmers use indentation to emphasize the logical structure of the program. They also recommend writing only one statement per line, and using blanks around operators to clarify grouping. And they point out Although C compilers do not care about how a program looks, proper indentation and spacing are critical in making programs easy for people to read.
Some languages use indentation as a required language feature. Blocks of code are marked by indentation. This approach is called the off side rule (a term borrowed from soccer or international football). Some programming languages using the off side rule include: ISWIM (the first to introduce the idea), ABC, Curry, Haskell, Lispin, Miranda, Nemerle, Occam, Pliant, Python, and YAML.
Whitespace characters may be used almost anywhere in a c program. There are a few locations where whitespace is forbidden (such as between a function name and its argument list). There are a few places where whitespace is required (such as preventing ambiguity).
whitespace characters in c |
name |
ASCII (hex) |
source code representation |
blank or space |
20 |
\040 or typed space |
backspace |
08 |
\b |
horizontal tab |
09 |
\t |
vertical tab |
0B |
\v |
form feed |
0C |
\f |
newline or line feed |
0A |
\n |
carriage return |
0D |
\r |
Comments in c are supposed to be considered whitespace, but some compilers simply remove comments during parsing.
Whitespace characters in PHP include new line (\n), carriage returns (\r), spaces (or blanks), horizontal tabs (\t), vertical tabs (\v), and end of string characters (\0).
Whitespace is ignored in PHP.
The normal practice in Python programming is to use four space characters for each level of indetation.
Geek humor: There is a programming language called Whitespace. Released as an April Fool's joke on April 1, 2003, by Edwin Brady and Chris Morris of the University of Durham, the language uses only the whitespace characters space, tab, and linefeed, and ignores all other characters (treating normal characters as comments). Binary integers are created by using space as a zero (0) bit and tab as a one (1) bit, numbers being terminated by linefeed. Sequences of the three white space characters are commands. Commands primarily act on a data stack (similar to Forth), although there is a heap for storage. It is possible to insert a working Whitespace program into most ordinary programs.
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.