music
OSdata.com: programming text book 

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.

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

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 don’t 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.

C

    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.

PHP

    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.

Python

    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).


return to table of contents
free downloadable college text book

view text book
HTML file

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.

previous page next page
previous page next page

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2007, 2010, 2011 Milo

    Created: September 8, 2007

    Last Updated: March 18, 2011


return to table of contents
free downloadable college text book

previous page next page
previous page next page