User:Xerol/Intro to Programming

I might get started on a generic Intro to Programming book for use in "Intro to X" courses for Wikiversity: School of CompSci. Book would cover generic programming concepts (from variable assignments/calculations to control structures to functions) with examples in several languages.

Tentative Outline
 * Variables
 * Concept of a Variable - What one is, why they're important, and data types (integer, float, string, etc.)
 * Initialisation - Discussion of allocation of memory.
 * Assignment - They're called 'variables' for a reason.
 * Operations - Basic math stuff for numerical variables, and string operations.
 * Comparisons/Boolean Operations
 * This would basically be the whole "Less than/greater than/etc." and "OR/AND/NOT/etc." in prepraration for the next section.
 * Basic Control Structures
 * If-Then-Else
 * While/Do-While
 * For-Next
 * Switch
 * Functions - Discussion of inputs/outputs.
 * Standard Functions (Ones included with basic libraries or by default)
 * I/O
 * Mathematical
 * Other things I forgot
 * Arrays
 * Libraries - This is just a basic overview of the expandability of programming languages.
 * Program Structure - Now that we've defined the basic elements of programming languages, we can begin to build a program.
 * "Hello World"-type program
 * Creation of a program to perform a task

Examples may be provided in a large number of languages, either directly in-line or as links to other books. However, considering that this book is intended to be a very introductory look at the basic building blocks of programming languages in general, the examples should either be provided in as many different languages as possible, in pseudo-code, or not at all.

For section 5, Program Structure, this is where pseudo-code starts to be insufficient. As such, the examples here would be very basic in nature. For example, the Hello World program might be as follows:

Include IO Library main: output "Hello, World" quit

A certain style of pseudo-code would be introduced throughout the book, and would inevitably be creating a pseudo-language of sorts. The task program could be, perhaps, to read in 5 numbers from a file and output the numbers, their average, and each number squared to the screen. The squaring would need to be computed via a function. The pseudo-code might look something like this:

Include IO Library Include File Library Declare function square(integer n) returns integer main: declare numbers (array of 5 integers) declare sum (integer) declare average (float) open file for (1 to 5) get number from file and store in numbers array set sum to 0 for (1 to 5) add numbers to sum divide sum by 5 and store in average for (1 to 5) output numbers output average for (1 to 5) output square(numbers) quit function square(integer n) returns integer: return n*n

The format may need to be worked on a bit, I'm not entirely sure how to present functions in pseudocode yet. Generally the point is to show the code in words rather than syntax as much as possible, but once you get into functions you almost have to use some syntax of some sort. However, by this point in the book, all of the individual concepts will have been explained and the general idea from here is to tie the concepts together into an entire program that could be translated into any language (for the most part). For something like FreeBasic, you wouldn't have a Main function and you wouldn't have to include any libraries for screen or file IO, but anything like that would be covered in the very opening areas of any course on the subject. The above program wouldn't be given straight out, but built piece-by-piece throughout the chapter, in the format of solving the "problem" at hand: Getting numbers from a file and outputting the average and squares. This kind of thing is what I originally intended by the purpose of the book but I'm now seeing that for any larger programs it'll be extremely difficult to explain with elegant psuedocode.