Contents in Detail
LEARN TO PROGRAM WITH SMALL BASIC
An Introduction to Programming with Games, Art, Science, and Math
Majed Marji and Ed Price
San Francisco
LEARN TO PROGRAM WITH SMALL BASIC. Copyright 2016 by Majed Marji and Ed Price.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
20 19 18 17 16 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-702-4
ISBN-13: 978-1-59327-702-4
Publisher: William Pollock
Production Editor: Laurel Chun
Cover Illustration: Josh Ellingson
Developmental Editors: Hayley Baker and Tyler Ortman
Technical Reviewer: Vijaye Raji
Copyeditor: Anne Marie Walker
Compositors: Laurel Chun and Kathleen Miller
Proofreader: Lisa Devoto Farrell
Indexer: BIM Indexing & Proofreading Services
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900;
Library of Congress Cataloging-in-Publication Data
Names: Marji, Majed, author. | Price, Ed, 1978- author.
Title: Learn to program with small basic : an introduction to programming
with games, art, science, and math / by Majed Marji and Ed Price.
Description: San Francisco : No Starch Press, [2016] | Includes index.
Identifiers: LCCN 2015039128| ISBN 9781593277024 | ISBN 1593277024
Subjects: LCSH: BASIC (Computer program language)
Classification: LCC QA76.73.B3 M3743 2016 | DDC 005.1/3--dc23
LC record available at http://lccn.loc.gov/2015039128
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the authors nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
COVERS SMALL BASIC VERSION 1.X. WINDOWS 7 OR HIGHER REQUIRED.
ABOUT THE AUTHORS
Majed Marji is a senior development engineer at General Motors and an adjunct faculty member at Wayne State University in Michigan. He is also the author of Learn to Program with Scratch (No Starch Press).
Ed Price is a senior program manager in engineering at Microsoft. He holds an MBA in technology management and has been a professor at Bellevue College. He runs customer feedback programs for Azure Development, Visual Studio, and Small Basic.
CONTENTS IN DETAIL
INTRODUCING SMALL BASIC
GETTING STARTED
DRAWING BASICS
USING VARIABLES
DRAWING SHAPES WITH TURTLE GRAPHICS
GETTING USER INPUT
EMPOWERING PROGRAMS WITH MATH
MAKING DECISIONS WITH IF STATEMENTS
USING DECISIONS TO MAKE GAMES
SOLVING PROBLEMS WITH SUBROUTINES
EVENT-DRIVEN PROGRAMMING
BUILDING GRAPHICAL USER INTERFACES
REPEATING FOR LOOPS
CREATING CONDITIONAL WHILE LOOPS
GROUPING DATA IN ONE-DIMENSIONAL ARRAYS
STORING DATA WITH ASSOCIATIVE ARRAYS
EXPANDING TO HIGHER-DIMENSION ARRAYS
ADVANCED TEXT MAGIC
RECEIVING FILE INPUT AND OUTPUT
FOREWORD
Computer programming is magical. Programmers make computers come to life, and with the right tools, the possibilities are limitless. But even todays skilled programmers started with something very small and simple.
I have often wondered what exactly makes programming exciting. The answer, I think, is how even tiny programs can make things happen instantly. When I was twelve, I was introduced to BASIC for the first time. The sheer simplicity of it struck me. It was inviting, not intimidating. And at the time, BASIC was everywhereit had taken the new world of microcomputers by storm.
My first program worked flawlessly and gave me the instant gratification that kept me wanting to do more. This is what it looked like:
10 PRINT "Hello"
20 GOTO 10
These two lines of code just printed Hello again and again and againbut thats all it took to get me hooked.
Fifteen years later, while working at Microsoft, I signed up to teach programming to a group of fifth graders. It was then I realized that as programming as a discipline had gotten more and more sophisticated, the simplicity of BASIC had been lost. There was no easy way for children to experience the same instant gratification that I experienced using BASIC.
When researching tools that could make learning computer science fun and welcoming, I stumbled across the article Why Johnny Cant Code). The article, published by Salon in 2006, argues that todays children are missing out on computer science because there arent easy-to-use languages like BASIC readily available.
This inspired me to create Small Basic, a simple and easy way for children to learn programming.
But its been far from an individual effort. Since launching Small Basic in 2011, the outpouring of support from the community has been incredible. The programming environment has extended in ways I couldnt have imaginedsensing hands and faces with Kinect, talking to robots, and even integrating with enterprise databases. Small Basic has been translated into more than twenty languages, and at the time of this writing, more than 280,000 programs have been uploaded to http://www.smallbasic.com/ by children around the world.
The original vision of Small Basic is now being carried on by Ed Price and Michael Scherotter, along with the support of active community members like Nonki, LitDev, and many more.
Majed Marji is no stranger to teaching programming. Following his success with Learn to Program with Scratch, I was really excited to hear he was going to author this book along with Ed Price. Im happy to see Learn to Program with Small Basic come alive and be available for everyone who wants to take their first step into programming. The book does a great job of introducing beginners to programming concepts while keeping the content fun and engaging.
Welcome to the magical world of programming. What do you want to create today?
Vijaye Raji
Creator of Small Basic
Director of Engineering, Facebook
Former Principal Software Architect, Microsoft
ACKNOWLEDGMENTS
This book represents the culmination of hard work from many people to whom I owe my thanks. Id like to begin by recognizing the editorial and production departments at No Starch who have done an outstanding job in bringing out this book to life. In particular, it is a pleasure to acknowledge the help of our editor, Hayley Baker, and our production editor, Laurel Chun, who worked hard to ensure that everything came together like it was supposed to.