Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 35 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 35 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 35 -

Bild der Seite - 35 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 35 -

1.8 ConcludingRemarks 35 messages. This also goes for lower and upper case letters. If you (after importing from math) give the command pi, you get 3.1415 . . .. However, if you write Pi, you get an error message. Pay attention to such details also when they are given in later chapters. 1.8.2 WriteReadableCode When you write a computer program, you have two very different kinds of readers. One is Python, which will interpret and run your program according to the rules. The other is some human, for example, yourself or a peer. It is very important to organize and comment the code so that you can go back to your own code after, e.g., a year and still understand what clever constructions you put in there. This is relevant when you need to change or extend your code (which usually happens often in reality). Organized coding and good commenting is even more critical if other peopleare supposed to understandcode that you have written. It mightbe instructive to see an exampleof code that is not very readable. If we useourveryfirstproblem, i.e. computingtheheighty ofaball thrownupin theair, themathematical formulationreads: y=v0t−0.5gt2. Now,insteadofourpreviousprogramball.py,wecouldwriteaworkingprogram (inbad style!) like: # This is an example of bad style! m=5;u=9.81;y=0.6 t=m*y-u*0.5*y**2;print(t) Running this code, would give the correct answer printed out. However, upon comparison with the mathematical writing, it is not even clear that the two are related,unlessyousit downand lookcarefullyat it! In this code, • variablenamesdonotcorrespondto the mathematicalvariables • thereareno(explaining)comments • noblank lines • nospace toeachsideof=and- • several statementsappearon the same linewith nospace inbetween When comparing this “bad style” code to the original code in ball.py, the point shouldbeclear. 1.8.3 FastCodeorSlowerandReadableCode? Innumericalcomputing, there isa strongtraditionforpayingmuchattention to fast code. Industrialapplicationsofnumericalcomputingoften involvesimulations that
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python