Programming

Some material on programming. Most of the free stuff I link to here comes from
https://github.com/EbookFoundation/free-programming-books/blob/master/books/free-programming-books.md
 or
http://www.cheat-sheets.org/
 or
http://freecomputerbooks.com/.

This page is a very good introduction to programming with a lot of linked resources.

See also Chua Hock-Chuan’s programming notes:
https://personal.ntu.edu.sg/ehchua/programming/index.html

Learn X in Y minutes:
https://learnxinyminutes.com/

The Hello World Collection:
http://helloworldcollection.de/

#######################################

Python and Java are popular and not so hard to learn. Also it’s good to know how web sites are put together.

Web Programming

HTML, CSS, JavaScript, PHP and MySQL: these are the five main languages used in making web sites. HTML describes the structure of the web page: headings, paragraphs, forms and widgets. HTML without CSS looks ‘raw’. CSS is the special sauce that makes HTML look presentable. JavaScript provides code for menus and special effects to make your web page interactive. PHP is the server side language for making dynamic websites, e.g. if you need to log in to a web site this is handled by PHP. MySQL is an open source database management system. See this question on Quora .

HTML, CSS and JavaScript are what are called ‘client side’ languages: they are interpreted by your web browser. PHP and MySQL are ‘server side’ languages: they ‘live’ on the server. If you want to set up a web server on your computer you will have to install what is called a LAMP stack (Linux, Apache, MySql, PHP) (WAMP/MAMP if you use Windows/macOS). Apache is open source web server software.

HTML Dog tutorials (covers HTML, CSS and JavaScript):
http://www.htmldog.com/

A HTML and CSS tutorial from Chua Hock-Chuan:
https://personal.ntu.edu.sg/ehchua/programming/webprogramming/HTML_CSS_Basics.html

Links to HTML and CSS cheatsheets:
https://cssauthor.com/html-and-css-cheat-sheets/

JavaScript cheat sheets: 1, 2, 3.

JavaScript from wikibooks:
https://en.wikibooks.org/wiki/JavaScript
JavaScript The Right Way:
http://jstherightway.org/

A guide to installing a LAMP stack:
https://personal.ntu.edu.sg/ehchua/programming/webprogramming/AMP_Setup.html

PHP cheat sheets: 1, 2.
PHP Programming from wikibooks:
https://en.wikibooks.org/wiki/PHP_Programming
PHP The Right Way:
https://phptherightway.com/

A MySQL cheat sheet:
MySQL from wikibooks:
https://en.wikibooks.org/wiki/MySQL

Some web programming books:
Julie C. Meloni, Jennifer Kyrnin, HTML, CSS and Javascript All in One, 3e
Marijn Haverbeke, Eloquent Javascript, 3e
https://eloquentjavascript.net/
Robin Nixon, Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5, 5e

Python

python.org

A beginner’s Python tutorial:
https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial

A Python cheatsheet:
https://groklearning-cdn.com/resources/cheatsheet-python-1.pdf
A set of cheatsheets to go with the book Python Crash Course by Eric Matthes:
https://ehmatthes.github.io/pcc/cheatsheets/README.html
 (As a single PDF file: )
Another cheat sheet:
https://perso.limsi.fr/pointal/_media/python:cours:mementopython3-english.pdf

Some Python books:
Al Sweigart, Cracking Codes with Python
 Author website: http://inventwithpython.com/
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
 Author website: https://dbader.org/
Code the Classics – Volume 1. The code is available from the website and also comes with the Raspberry Pi OS.
https://wireframe.raspberrypi.org/books/code-the-classics1
Brett Slatkin, Effective Python, 2e
Luciano Ramalho, Fluent Python

Java

Introduction to Java programming from Chua Hock-Chuan’s programming notes:
https://personal.ntu.edu.sg/ehchua/programming/java/J1a_Introduction.html

A Java programming cheatsheet:
https://introcs.cs.princeton.edu/java/11cheatsheet/
 (As a PDF: )
A list of Java cheatsheets:
https://www.rankred.com/java-cheat-sheets/

Some Java books:
Java Programming from wikibooks:
https://en.wikibooks.org/wiki/Java_Programming
Rogers Cadenhead, Sams Teach Yourself Java in 24 Hours, 8e
Joshua Bloch, Effective Java, 3e

#######################################

C and UNIX

Introduction to C from Programming Notes:
https://personal.ntu.edu.sg/ehchua/programming/cpp/c0_Introduction.html

An introductory C tutorial fron LinuxConfig:
https://linuxconfig.org/c-development-on-linux-introduction-i

Another from cprogramming.com:
https://www.cprogramming.com/tutorial/c-tutorial.html

Another: https://www.programiz.com/c-programming

C for Python programmers:
http://www.toves.org/books/cpy/

A cheat sheet by J.H. Silverman:
http://www.math.brown.edu/~jhs/ReferenceCards/CRefCard.v2.2.pdf

Some C books:
C Programming from wikibooks:
https://en.wikibooks.org/wiki/C_Programming
Robert C. Seacord, Effective C: An Introduction to Professional C Programming
Brian Kernighan and Dennis Ritchie, The C Programming Language (2e, 1988) (‘K&R C’)
Jens Gustedt, Modern C
https://modernc.gforge.inria.fr/

The ‘right-left rule’: help in deciphering those C declarations:
http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

There is also a program called ‘cdecl’ that can translate C declarations into English:
https://cdecl.org/
I first came across a version of this program in the book Expert C Programming by Peter van der Linden.

More on pointers:
https://boredzo.org/pointers/
includes a demonstration program written as one single file, or as multiple files with a makefile.
A tutorial on pointers and arrays by Ted Jensen
https://pdos.csail.mit.edu/6.828/2012/readings/pointers.pdf

Unlike interpreted languages like Python or Java, C is a compiled language. This means that you have to write a source file then run it through a compiler to create an executable, written in the machine language of whatever architecture you compiled it on. On Linux the C compiler is called gcc. The simplest way of compiling a program is to run gcc hello.c in the shell. This will produce an output file called a.out. You then run it by typing ./a.out in the shell and pressing enter. But if you have several C source files in a directory their output files can’t all be called ‘a.out’. You need to give each output file its own name using the ‘-o’ flag, like this:
gcc -o hello hello.c
gcc has a lot more options than that. See this page from Rapid Tables:
https://www.rapidtables.com/code/linux/gcc.html

More complicated C projects, consisting of multiple source files, use a tool called make to automatically build programs and libraries from source code to derive the target program. Here is an example from github of an implementation of the HOC (‘Higher Order Calculator’) program from The UNIX Programmming Environment by Kernighan and Pike. Download the archive, unzip it into a directory. Open a terminal window in the directory and type make. The make program uses the makefile to compile all the C files and links them to form an executable. Now if you want to use it, in the terminal type
./hoc 〈ENTER〉
2 + 2 〈ENTER〉
 4
2 ^ 4 〈ENTER〉
 16


A gcc and make tutorial:
https://personal.ntu.edu.sg/ehchua/programming/cpp/gcc_make.html

Core Utilities, the GNU implementation of the basic UNIX tool set, contains the C source files for programs such as cat, ls, rm:
https://www.gnu.org/software/coreutils/

Build Your Own Lisp (in C):
http://www.buildyourownlisp.com/



An introduction to Unix from wikibooks:
https://en.wikibooks.org/wiki/Guide_to_Unix
List of Linux cheat sheets:
https://www.nixtutor.com/linux/all-the-best-linux-cheat-sheets/
A Linux command line reference:
http://www.pixelbeat.org/cmdline.html
The Unix Acronym List:
http://www.roesler-ac.de/wolfram/acro/all.htm
A bash cheat sheet:
Bash tutorial from linuxconfig:
https://linuxconfig.org/bash-scripting-tutorial
Bash Scripting from wikibooks:
https://en.wikibooks.org/wiki/Bash_Shell_Scripting
Bash guide from Greg’s Wiki:
http://mywiki.wooledge.org/BashGuide
http://folk.ntnu.no/geirha/bashguide.pdf
See also Bash Pitfalls (a sort of ‘How Not to Write Bash Scripts’):
http://mywiki.wooledge.org/BashPitfalls
Unix Toolbox:
http://cb.vu/unixtoolbox.pdf
The Art of Command Line:
https://github.com/jlevy/the-art-of-command-line

Unix comes with its own documentation in the form of man pages. You access them by typing ‘man’ and the name of a command or topic in a terminal e.g. man ascii, man hier (the file system), man printf, man gcc (that’s a long one), man bash, man grep, man sed, man awk; man man.

There are also info pages, which originated with the GNU project. They are often more detailed than man pages, e.g. info sed is much more detailed than man sed.

Some introductory Unix (Linux) books:
Daniel J. Barrett, Linux Pocket Guide, 3e
Scott Granneman, Linux Phrasebook, 2e
William E. Shotts Jr., The Linux Command Line, 2e
http://linuxcommand.org/
Brian Ward, How Linux Works, 3e

Mark G. Sobell, Matthew Helmke, A Practical Guide to Linux Commands, Editors, and Shell Programming, 4e

What these resources all have in common is that they all refer to the command line. UNIX and Linux systems make use of many GUIs (KDE, GNOME, Xfce, Cinnamon, Mate) but to really harness the power of the operating system you need to become proficient in command line. The program which handles the command line interface is called a command language interpreter or shell. One of the most popular shells for UNIX is bash (‘Bourne-Again SHell’). The shell is not just a command interpreter it is also a programming environment. You can write short programs called shell scripts that act like custom commands.

UNIX has a class of command line programs called filters, which operate on a data stream, producing another stream. Individually they usually do simple things, but they can be chained together in pipes to do clever things. See this example:
https://www.geeksforgeeks.org/piping-in-unix-or-linux/.

Some of the more powerful tools in UNIX’s box are grep, sed and AWK. Before you get into those, you should find out about regular expressions:
http://www.regular-expressions.info/
https://personal.ntu.edu.sg/ehchua/programming/howto/Regexe.html
https://regexr.com/
cheat sheet:
http://www.cheat-sheets.org/saved-copy/regular_expressions_cheat_sheet.pdf

grep searches plain-text data for lines that match a regular expression. sed is the UNIX stream editor. It performs basic text transformations on an input stream. AWK is a special-purpose programming language designed for text processing and typically used as a data extraction and reporting tool.

An article by Matt Might covering regex, grep, sed and AWK:
http://matt.might.net/articles/sculpting-text/

grep tutorials:
https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html
https://shapeshed.com/unix-grep/

Sed cheat sheets: 1, 2.
Eric Pement’s collection of sed one-liners:
http://www.pement.org/sed/sed1line.txt
And with commentary from Peteris Krumins:
https://catonmat.net/sed-one-liners-explained-part-one
Sed tutorials from sourceforge:
http://sed.sourceforge.net/grabbag/tutorials/

AWK cheat sheets: 1, 2.
AWK one-liners:
http://www.pement.org/awk/awk1line.txt
https://catonmat.net/awk-one-liners-explained-part-one
An AWK Primer from wikibooks:
https://en.wikibooks.org/wiki/An_Awk_Primer
AWK manual from GNU:
https://www.gnu.org/software/gawk/manual/

Books:
Dale Dougherty and Arnold Robbins, Sed & Awk, 2e
Jeffrey E.F. Friedl, Mastering Regular Expressions, 3e

Shell-scripting books:
Arnold Robbins, Nelson H.F. Beebe, Classic Shell Scripting
Steve Parker, Shell Scripting: Expert Recipes for Linux, Bash and More
Carl Albing, J.P. Vossen, bash Cookbook, 2e

Perl

Type perldoc perlintro in a terminal for an introduction. perldoc is Perl’s built-in documentation. It might not be installed by default on your Linux distro. Also available online: https://perldoc.perl.org/. man perl or perldoc perl gives an overview of perldoc.

Cheat sheets: perldoc cheat, 2, 3, 4

Perl one-liners:
https://github.com/pkrumins/perl1line.txt/blob/master/perl1line.txt
http://www.catonmat.net/blog/perl-one-liners-explained-part-one/

Perl books:
Perl programming from wikibooks:
https://en.wikibooks.org/wiki/Perl_Programming
Schwartz, foy, Phoenix, Learning Perl, 7e (‘The Llama Book’)
https://archive.org/details/LearningPerl7thEdition/
And the sequels, Intermediate Perl (‘The Alpaca’) and Mastering Perl (‘The Vicuña’).
Mark Jason Dominus, Higher Order Perl
https://hop.perl.plover.com/book/

The Editors: Vim, Emacs

Vim is a clone of the original UNIX vi editor. If you have Vim installed type vimtutor in a terminal for a tutorial introduction.

Cheat sheets: 1, 2, 3

Vim user manual: https://www.vi-improved.org/vimusermanual.pdf
(Also available from within vim if you type :help user-manual.)

Vim adventures: https://vim-adventures.com/

vimtips: http://zzapper.co.uk/vimtips.html

Websites: www.vim.org, vimawesome.com

Book:
Drew Neill, Practical Vim, 2e

Emacs ‘the extensible, customizable, self-documenting, real-time display editor’.
Emacs home page:
https://www.gnu.org/software/emacs/emacs.html
Manual:
https://www.gnu.org/software/emacs/manual/emacs.html
Cheat Sheet:
http://www.cheat-sheets.org/saved-copy/emacs-refcard-a4.pdf

Which is better?
https://slate.com/technology/2014/05/oldest-software-rivalry-emacs-and-vi-two-text-editors-used-by-programmers.html
https://en.wikipedia.org/wiki/Editor_war


Some oldie but goodie UNIX books:
Kernighan/Pike, The UNIX Programming Environment
Maurice J. Bach, The Design of the UNIX Operating System

More advanced UNIX books:
Nemeth, Snyder, Hein, Whaley, Mackin, UNIX and Linux System Administration Handbook, 5e
W. Richard Stevens and Stephen A. Rago, Advanced Programming in the UNIX Environment (‘APUE’), 3e
Michael Kerrisk, The Linux Programming Interface

#######################################

Algorithms

A website with analysis of algorithms, with implementations in the popular programming languages:
https://www.geeksforgeeks.org/fundamentals-of-algorithms/

See also:
https://www.tutorialspoint.com/data_structures_algorithms/
https://www.programiz.com/dsa

The Dictionary of Algorithms and Data Structures:
https://xlinux.nist.gov/dads/

Some algorithm books:
Aditya Bhargava, Grokking Algorithms
George T. Heineman and Gary Pollice, Algorithms in a Nutshell
Robert Sedgewick, Algorithms in C
I got the 1990 edition of this book for cheap from Abebooks; The Definitive C Book Guide recommends the 1997 edition.

Matters Computational by Jörg Arndt:
https://www.jjj.de/fxt/fxtbook.pdf

More advanced algorithm books:
Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms (‘CLRS’).
Donald E. Knuth, The Art of Computer Programming (4 vols) (‘TAOCP’)


The mathematical backround – some discrete mathematics books:
Oscar Levin, Discrete Mathematics: An Open Introduction
http://discrete.openmathbooks.org/dmoi3.html
Seymour Lipschutz, Marc Lipson, Schaum’s Outline of Discrete Mathematics
Norman L. Biggs, Discrete Mathematics
Kenneth H. Rosen, Discrete Mathematics and Its Applications
Graham, Knuth, Patashnik, Concrete Mathematics
Lehman, Leighton, Meyer, Mathematics for Computer Science
https://courses.csail.mit.edu/6.042/spring17/mcs.pdf

A cheat sheet from the TeX Showcase:
http://www.tug.org/texshowcase/cheat.pdf

Think Stats: Probability and Statistics for Programmers
http://www.greenteapress.com/thinkstats/

#######################################

Close to the Machine* – Assembly Language and Computer Architecture

* title of a book by Ellen Ullman

Intel Assembly

Cheat sheets: 1, 2, 3

x86 Assembly Guide (32-bit):
https://www.cs.virginia.edu/~evans/cs216/guides/x86.html

Another version of the same, but re-written to use the AT&T syntax, which is more traditional on UNIX systems. However NASM on Linux uses the Intel syntax. https://www.cs.yale.edu/flint/cs421/papers/x86-asm/asm.html

This page explains the main differences between AT&T and Intel syntax.

X86 Assembly from wikibooks:
https://en.wikibooks.org/wiki/X86_Assembly

Sample x86-64 Assembly programs using the Netwide Assembler (NASM):
https://www.csee.umbc.edu/portal/help/nasm/sample_64.shtml

When I tried these programs on my Linux system, I kept getting a segmentation fault whenever I tried to run them. This question on stackoverflow explains how to get round this. You have to add ‘-no-pie’ to the gcc line of the makefile:
gcc -no-pie -m64 -o hello_64 hello_64.o

Paul Carter’s book on PC Assembly Language. It uses 32-bit mode, but will still work on a 64-bit OS:
http://pacman128.github.io/pcasm/

A free book by Ed Jorgensen on x86-64 Assembly programming with Ubuntu:
http://www.egr.unlv.edu/~ed/x86.html

Ray Seyfarth, Introduction to 64 Bit Assembly Programming for Linux and OS X, 3e

ARM Assembly

Cheat sheets: 1, 2, 3, 4

ARM Assembly using Raspberry Pi:
http://www.microdigitaled.com/ARM/ASM_ARM/Software/ARM_Assembly_Programming_Using_Raspberry_Pi_GUI.pdf

A free book on ARM Assembly on the Raspbery Pi:
https://personal.utdallas.edu/~pervin/RPiA/RPiA.pdf

A book on Assembly Language programming with the Raspberry Pi:
Bruce Smith, Raspberry Pi Assembly Language RASPBIAN Beginners: Hands On Guide


Some low level books:
Henry S. Warren, Hacker's Delight, 2e
Igor Zhirkov, Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture

Compilers

A compiler translates code written in a high-level language into the machine code of whatever architecture it runs on. CPUs only understand machine code, so somewhere along the line whatever you want to run on the computer has to be translated into the machine language of that CPU.

Compiler Books:
Torben Mogensen, Basics of Compiler Design
http://hjemmesider.diku.dk/~torbenm/Basics/
Keith Cooper, Linda Torczon, Engineering a Compiler
Aho, Lams, Sethi, Ullman, Compilers: Principles, Techniques, and Tools (‘The Dragon Book’)

Architecture

A primer of computer arithmetic and character encodings:
https://personal.ntu.edu.sg/ehchua/programming/java/DataRepresentation.html

Logic circuits, adders, memory circuits:
http://www.toves.org/books/logic/
http://www.toves.org/books/comps/
(From http://www.toves.org/cso/)

Some introductory books:
Eben Upton, Jeffrey Duntemann et al., Learning Computer Architecture with Raspberry Pi
Jon Steinhart, The Secret Life of Programs

Computer Architecture books by David A. Patterson and John L. Hennessy:
Introductory:
Computer Organization and Design: The Hardware/Software Interface (‘Patterson and Hennessy’)
More advanced:
Computer Architecture: A Quantitative Approach (‘Hennessy and Patterson’)

The Hennessy/Patterson books are written for people who design computer systems. For a treatment written more from the point of view of a programmer see:
Computer Systems: A Programmer’s Perspective by Randal E. Bryant, David R. O’Hallaron