Learn to Code in 30 Days
with MiniScript and Mini Micro
Joe Strout
MiniScript Press
Copyright 2020 by Joseph Strout
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law.
For permission to use material from this text or product, submit all requests via email to books@miniscript.org
Project consultation, production and manufacturing under the direction of Dane Cornel Petersen at Petersen Books. For details, send e-mail to Dane@PetersenBooks.com
Printed in the United States of America
First Edition
10 9 8 7 6 5 4 3 2 1
Dedicated to Michelle, for her steadfast support and encouragement in all my endeavors
Acknowledgments
Writing a book is a big task. I couldnt have done it without the patience and support of my wife, Michelle Strout, who also served as a very capable copy editor. The book is much better than it would have been without her help.
Im also grateful for the support of Dane Petersen at Petersen Books, whose assistance was invaluable in turning a raw manuscript into the beautiful book before you.
About the Cover
The word CODE on the front cover is a magnified view of the large font in Mini Micro, with pixels separated for visibility. The large swaths of color represent the red, green, and blue components of any color in computer graphics. That adorable animal gracing the cover is a chinchilla, the official MiniScript mascot. Like MiniScript, the chinchilla is not yet widely known, but is universally loved by all who have had the pleasure of discovering its existence.
Introduction
Congratulations! By selecting this book, you have chosen an unusually good way to learn computer programming. Whether this is the start of a professional career, or just a new and rewarding hobby, you will look back on this day as a pivotal moment.
Computers today are everywhere not only on our desks and in our pockets, but in our televisions, cars, kitchen appliances, game consoles, VR headsets, and on and on. Every one of those computers does the amazing things it can do because programmers wrote some code. Its no exaggeration to say that our entire civilization runs on computers, and the computers do the bidding of their programmers.
For all their amazing, almost magical power, what a computer does is fundamentally simple: it follows instructions, step by step. Programming is the process of writing out these instructions in a way a computer can understand.
Computers cant (yet) really understand human languages, such as English. Human languages have all sorts of ambiguities and things that are left unsaid. Attempts to make them more precise end up with the sort of complex, long-winded text you find in end-user license agreements and other legal documents. So engineers have developed various computer languages that are designed to be brief but precise, and those are the languages we use to write computer programs. Heres an example:
| c = input("Enter temperature in Celsius: ").val |
| f = c * 5/9 + 32 |
| print "That's " + round(f) + " F." |
| if c < 2 then print "BRR!" |
A small program in MiniScript.
If youve never done any programming before, this may not make much sense to you yet. Dont worry it will, by the end of the book! For now, just notice that a computer language looks a little bit like English, with recognizable words like input , print , if , and then . And it also looks a bit like grade-school math, with symbols like + and = . You already know English and you already know grade-school math, so once a few basic rules are explained to you (covered in the first few chapters of this book), youll have no trouble reading and writing this sort of computer code.
The code shown above is in a computer language called MiniScript , which you will learn over the next few weeks. MiniScript is just one of many computer languages. There are literally hundreds of languages in common use; some of the most famous ones are JavaScript, Python, C# (pronounced C sharp), and C++ (pronounced C plus plus). However, MiniScript is a particularly good choice for a beginning programmer. It was very carefully designed to be as simple as possible, while still being powerful enough to use in real, nontrivial programs. It is inspired by the best features of other languages, but lacks the baggage they all bring along. MiniScript is free, and can be used in a variety of ways, including to create your own games, simulations, and data analysis software.
Other languages can do similar things, but they are generally not quite as simple or easy to learn as MiniScript. New programmers often struggle learning the syntax of a language, that is, the rules about exactly how to write what youre trying to say. MiniScript is syntax-light it uses only the bare minimum of extra punctuation and odd symbols. Other languages tend to have more. For example, heres the same program in C++:
| #include |
| #include |
| #include |
|
| int main() |
| { |
| int c; |
| std::cout << "Enter temperature in Celsius: "; |
| std::cin >> c; |
| float f = (float)c * 5/9 + 32; |
| std::cout << "That's " << round(f) << " F.\n"; |
| if (c < 2) std::cout << "BRR!"; |
| } |
The same program, but written in C++.
This does the same thing as the MiniScript code above, but as you can see, there are a lot more extras required: semicolons at the end of most lines, curly braces, several #include lines at the top, and odd symbols like << and >> . All that extra stuff gets in the way of learning the real core of programming, which is figuring out what you want to happen, step by step.
How to use this book
The book is divided into 30 chapters, designed to be done at about one chapter per day. Each chapter is about 10 pages long, and shouldnt take too long to do. However, in every chapter, you will find code examples. The best way to learn is to try these examples on your own machine!
To do that, you will need a desktop computer. Almost any kind of desktop computer will do: it can run Windows, Mac, or Linux, and it doesnt have to be particularly new or powerful. But you do need something, or youll be missing out on most of the fun of the book, which is the joy of typing in some code and making things happen.
To give you an example of the sort of thing youll be learning to do, and also make sure your computer is right for this, here is your first task! Open a web browser, and go to this address:
https://miniscript.org/MiniMicro |
You should see, right in your web browser, something that looks like one of those computers you might see in movies from the 80s.
Welcome to Mini Micro.
Dont let the old-fashioned appearance fool you! This is a virtual but modern computer, capable of creating sophisticated games and simulations. Want to try some? Type in the following commands, precisely as shown be careful to match the punctuation and capitalization exactly.