12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1The way ofthe programThe goal of this book is to teach you to think like a computer scientist. This way of thinking combinessome of the best features of mathematics, engineering, and natural science. Like mathematicians,computer scientists use formal languages to denote ideas (specifically computations). Likeengineers, they design things, assembling components into systems and evaluating tradeoffs amongalternatives. Like scientists, they observe the behavior of complex systems, form hypotheses, andtestpredictions.Thesinglemostimportantskillforacomputerscientistisproblemsolving. Problemsolvingmeanstheabilitytoformulateproblems,thinkcreativelyaboutsolutions,andexpressasolutionclearlyandaccurately. Asitturnsout,theprocessoflearningtoprogramisanexcellentopportunitytopracticeproblem-solving skills. That’s why thischapter iscalled, “The way of theprogram.”Ononelevel,youwillbelearningtoprogram,ausefulskillbyitself. Onanotherlevel,youwilluseprogramming as ameans toan end. As wego along, that end willbecome clearer.1.1 The<strong>Python</strong> programming languageTheprogramminglanguageyouwilllearnis<strong>Python</strong>. <strong>Python</strong>isanexampleofahigh-levellanguage;other high-level languages you might have heard of areC, C++, Perl, and Java.There are also low-level languages, sometimes referred to as “machine languages” or “assemblylanguages.” Looselyspeaking,computerscanonlyexecuteprogramswritteninlow-levellanguages.So programs written in a high-level language have to be processed before they can run. This extraprocessing takes sometime, which isasmall disadvantage of high-level languages.Theadvantagesareenormous. First,itismucheasiertoprograminahigh-levellanguage. Programswritten in a high-level language take less time to write, they are shorter and easier to read, and theyaremorelikelytobecorrect. Second, high-level languages areportable, meaningthattheycanrunon different kinds of computers with few or no modifications. Low-level programs can run on onlyone kind of computer and have toberewritten torun onanother.Due to these advantages, almost all programs are written in high-level languages. Low-level languagesareused only forafew specialized applications.Two kinds of programs process high-level languages into low-level languages: interpreters andcompilers. An interpreter reads a high-level program and executes it, meaning that it does what the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!