You want to learn a manageable andminimal subset of foundational programming techniques, without distractingdetails and definitions
You want to learn how to design correctprocedural algorithms, rather than learn any particular programming language
You want to be challenged withdesign-focused problems, rather than weak exercises that only test if youmemorized programming syntax
You have the time at the moment tolearn to program, rather than quickly write code for an upcoming deadline
Table of Contents
INTRODUCTION: What is a programming language?
Exercises.
Solutions to Introduction Exercises:
Chapter 1: Testing
1.1 Introduction
1.2 Input Domain Characterization
1.3 Reverse-Engineering Inputs From Outputs
1.4 Ordering of Inputs
1.5 Boundary Testing
1.6 Testing Inputs of Varying Number
Exercises.
Solutions to Chapter 1 Exercises:
Chapter 2: Decision Making
2.1 Introduction
2.2 Nested Decision Statements
2.3 Boolean Types and Operations
Exercises.
Solutions to Chapter 2 Exercises:
Chapter 3: Debugging, Printingand Functions
3.1 Introduction
3.2 Functions
3.3 Tracing through code
3.4 Debugging and Printing
Exercises.
Solutions to Chapter 3 Exercises:
Chapter 4: Looping
4.1 Introduction
4.2 Loops and Debugging
Exercises.
Solutions to Chapter 4 Exercises:
Chapter 5: Lists and Strings
5.1 Introduction
5.2 Memory Representation of Lists Versus Non-Lists
5.2 Printing Lists
5.3 Strings as Lists
Exercises.
Solutions to Chapter 5 Exercises:
Chapter 6: Functions andControl Flow
6.1 Introduction
6.2 Functions and Memory
6.3 Functions and Control Flow
6.4 Functions and Libraries
Exercises.
Solutions.
Chapter 7: Maps and OtherComplex Types
7.1 Introduction
7.2 Maps
7.3 Complex Types and Memory
7.4 Defining Our Own Complex Types
7.5 Complex Types and Methods
Exercises.
Solutions.
Chapter 8: Exceptions
8.1 Introduction
8.2 Exceptions as Control Flow Modifiers
8.3 Exceptions as Complex Types
8.4 Nesting try-catch blocks
Exercises.
Solutions.
About the Author
INTRODUCTION: What is a programming language?
The question often arises, which programming language should I learn? What is the best programming language? (Wait aminute. What is a programming language?Whatis a program?! Well come back to that in a minute, because first Iwant to talk about ice cream, which is tasty and definitions are potentiallylike cardboard: necessary to hold together various structures, but not veryappetizing.)
What ice cream flavor should I buy? Which one is mostdelicious? That depends if Im looking for a creamy vanilla to go with an applepie, or a tangy sorbet to balance out a desiccated, experimental layer cakerecipe I found in the back section of a magazine in a waiting room. Believe itor not there was once a bubblegum flavored ice cream that was not immediatelydiscontinued as a flavor.
The best flavor of ice cream depends on the situation.Similarly, a certain programming language works best with your run-of-the-mill mobileapplication, while a different one might be appropriate for walking over somethingas esoteric as an abstract syntax tree (and other things mostly programminglanguage researchers might care about). Some languages are easier to learn,some are quicker to use, while others outperform their neighbors, although oftenpopularity determines whatprogramming language is used or taught, as software engineering is a socialactivity that depends on other developers knowing a particular language, aswell as pre-existing software that is available for reuse.
Although there are hundreds of programming languages tochoose from, with new ones constantly being invented, the good news for someonewho is just starting to learn how to program is that all modern programminglanguages share core similarities. This book will teach you these coreprogramming concepts, without relying on any language in particular. Itspossible to learn to program without a programming language, because at theirfoundation, modern programming languages are different ways of trying to tell acomputer to do a small set of basic things.
A programming language is a tool for writing a program, which is a method of communicationbetween a user and a physical computer . The user is a source of data, and maybe a human being, a web application, or a sensor, and there may be more thanone kind of user simultaneously. Regardless of the users manifestation, theirrole is to provide the programming with inputvalues. Some of these values will be data that are meant to be used in acalculation, while other inputs might specify the type of calculation toperform. The program tells the computer how to use the inputs to perform thespecified calculation, and to then returnthe results as output. These resultsmay be displayed to a human user, written to a file, or used in latercomputations.
The computer itself is a physical piece of hardware that isable to store data, retrieve stored data, and perform calculations on the storeddata within one of its components. It also usually has an ability to interactwith its environment in some meaningful way, such as through a keyboard and ascreen. The keyboard is used to collect data that is then stored, while thescreen is used to display data that has been stored previously. There are manydifferent flavors of computers, from the small processor inside yourrefrigerator, to the heavy-duty servers of Google or Amazon. All computers areable to perform the basic duties of data storage, retrieval, and calculationson data, and because we dont live in the 1950s anymore, modern computers arealso able to do many more interesting things like connect to the Internet andorder you pizza.
For our purposes, were going to only focus on the mostbasic functionality of a computer, as even the more complex components (likethe operating system, wireless connection, printers, touch screens, and Instagramfilters for the sixteen photos of the salad someone had for lunch) are simplyamalgamations of these basic concepts. Recall that a program is used tocommunicate between a user and a computer. For example, a user may want acomputer to add the numbers 2 and 3 together. The computer knows how to add twonumbers, but it alone does not know where to get these numbers, or what to dowith their sum. The program is responsible for asking the user to provide thetwo numbers (2 and 3), passing these inputs along to the computer to performthe addition, and then returning the result (5) back to the user (perhaps bydisplaying it on a screen or printing it on a piece of paper). For example, the program, which is run through the computer, may interactwith the user as follows:
What is the firstnumber?
Theuser supplies here. The program asksthe computer to store this first value.
What is the secondnumber?
Theuser supplies here. The program asksthe computer to store this second value.
At this point the program tells the computer to add the twostored values together. Then, it returns the result the computer calculated tothe user:
Their sum is 5.