music
OSdata.com: programming text book 

OSdata.com

functions

summary

    This subchapter looks at functions.

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

stub section

    This subchapter is a stub section. It will be filled in with instructional material later. For now it serves the purpose of a place holder for the order of instruction.

    Professors are invited to give feedback on both the proposed contents and the propsed order of this text book. Send commentary to Milo, PO Box 1361, Tustin, California, 92781, USA.

functions

    This subchapter looks at functions.

    Functions are named by a valid identifier.

    Quick summary of the rules for building valid function identifiers in several major languages, using regular expressions:

Ada[a-zA-Z](_?[a-zA-Z0-9])*
ALGOL-68[a-z][a-z0-9 ]*
Awk[_a-zA-Z][_a-zA-Z0-9]*
B[_a-zA-Z][_a-zA-Z0-9]*
BourneShell[_a-zA-Z0-9]+
C[_a-zA-Z][_a-zA-Z0-9]*
C#[_a-zA-Z][_a-zA-Z0-9]*
C++[_a-zA-Z][_a-zA-Z0-9]*
COBOL[a-zA-Z][a-zA-Z0-9-]*
30 character maximum
Classic REXX[a-zA-Z!?@#][a-zA-Z0-9!?@#]*
Common Lispanything without a space and is not a number
E[_a-zA-Z][_a-zA-Z0-9]*
Eiffel[a-zA-Z][_a-zA-Z0-9]*
F#[_a-zA-Z][_a-zA-Z0-9']*
FORTRAN[A-Z][A-Z0-9]*
maximum of six characters
Forthanything without a space and is not a number
GNU-bc[a-z][a-z0-9_]*
Haskell[_a-z][_a-zA-Z0-9']*
Java[_a-zA-Z$][_a-zA-Z0-9$]*
JavaScript[_a-zA-Z$][_a-zA-Z0-9$]*
Lispanything without a space and is not a number
Maple[_a-zA-Z][_a-zA-Z0-9]*
Mathematica[a-zA-Z][a-zA-Z0-9]*
Matlab[a-zA-Z][_a-zA-Z0-9]*
Mercury[_a-z][_a-zA-Z0-9]*
merd[_a-z][_a-zA-Z0-9]*[!?']*
Modula-3[a-zA-Z][_a-zA-Z0-9]*
MUMPS[a-zA-Z%][a-zA-Z0-9]*
OCaml[_a-z][_a-zA-Z0-9']*
Pascal[a-zA-Z][a-zA-Z0-9]*
Perl[_a-zA-Z0-9]+
Perl6[_a-zA-Z0-9]+
PHP[_a-zA-Z][_a-zA-Z0-9]*
PL/I[a-zA-Z][a-zA-Z0-9]*
Pliant[_a-zA-Z][_a-zA-Z0-9]* or '[^']*'
Prolog[_a-z][_a-zA-Z0-9]*
Python[_a-zA-Z][_a-zA-Z0-9]*
Rebol[_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*&|=~-]*
or
[^0-9[](){}":;/][^ \n\t[](){}":;/]*
Ruby[_a-zA-Z][_a-zA-Z0-9]*[!?]?
Scheme[_a-zA-Z!0&*/:<=>?^][_a-zA-Z!0&*/:<=>?^0-9.+-]*
SmallTalk[a-zA-Z][a-zA-Z0-9]*
SML[_a-z][_a-zA-Z0-9']*
Tcl[^ \t\n\r\f]+

   “Procedure names should reflect what they do; function names should reflect what they return.ÊFunctions are used in expressions, often in things like ifs, so they need to read appropriately.
        if(checksize(x))
   “is unhelpful because we can’t deduce whether checksize returns true on error or non-error; instead
        if(validsize(x))
   “makes the point clear and makes a future mistake in using the routine less likely.” —Rob Pike, Notes on Programming in C, February 21, 1989

    Suggestion from Bjarne Stroustrup, creator of C++
        [g] Don’t use inline functions; except as a significant optimization.

mismatched types

    According to Brian Kernighan, co-creator of the AWK and AMPL programming languages and co-author of K&R C, one of the three most common errors for new programmers is mismatched types in a fucntion call.

Ada

    “15 A subprogram is the basic unit for expressing an algorithm. There are two kinds of subprograms: procedures and functions. A procedure is the means of invoking a series of actions. For example, it may read data, update variables, or produce some output. It may have parameters, to provide a controlled means of passing information between the procedure and the point of call. A function is the means of invoking the computation of a value. It is similar to a procedure, but in addition will return a result.” —:Ada-Europe’s Ada Reference Manual: Introduction: Language Summary See legal information

other

   “2. Functions delay binding: data structures induce binding. Moral: Structure data late in the programming process.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13

   “9. It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13

   “94. Interfaces keep things tidy, but don’t accelerate growth: Functions do.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13


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 © 2010, 2011 Milo

    Created: November 5, 2010

    Last Updated: September 27, 2011


return to table of contents
free downloadable college text book

previous page next page
previous page next page