Today, the first day of the semester, will be a pretty typical 'first day of class'. We'll cover the course syllabus, then take a brief tour of the course website so you'll know where to find your project, reading, and homework assignment information. If time remains, the rest of the class [or the second class meeting for the two-a-week section] we will begin to look at some of the fundamental concepts of database systems and the associated theory. |
First things first:
First we need to cover the basics, since fundamentals are critical to success in anything!
There are many many many many many books and links that can help you with Python programming. A few of these are listed here. I've tried to get some of the better ones, 'better' meaning 'more complete' in terms of texplanations and examples. As I uncover more good ones, I'll be adding them to the list, so check back several times during the semester to see what new things have been added.
And don't worry, you won't be responsible for knowing anything particular about the sites, only the information about Python Programming.
Integrated Development Environmentsor
IDEs; examples include the venerable Eclipse IDE from this site, and NetBeans, which is direct from Oracle at this location. All of these tools have lovely syntax coloring which you can use
stockor customize to your heart's content. Some allow you to add links to compile and even run your code. The IDEs have the advantage of compiling as you go, which shows you the error of your ways with nearly every keypress. Some people [like me] find that distracting, and I usually advocate for learning how to program WITHOUT using an IDE to start with. There is plenty of time in your career to learn them later, but whatever floats your boat…
And now for the dreaded pariah of all classes, the
tell-the-professor-all-about-me
excercise, which is guaranteed to have you all shifting uneasily
in your seats! So, tell me a little about yourself, including:
All homework assignments will be done individually, unless group work is preferred. We will determine which way on the first day of class. You are free to collaborate in discussing the concepts, but you must submit your own work, either individually or as a group. If submitting as a group, only one copy needs to be submitted. I will be comparing to make sure, and I'm wise to things like simply changing variable names and so on……
Assignments are mixed, with exercises consisting of both programming projects and short answer
questions. As many of you may have heard, I'm a big believer in fostering critical thinking
skills, so there will be questions that are intended to make you think about what you are doing in
various respects like morals, ethics, and decomposition of problem statements as well as just breaking
the problems into smaller parts to solve them.
All homework will be submitted in GitHub. Please get an account if you don't already have one, and make a repository for this class. Please be sure that I am a collaborator on your repository so that I can clone it and can upload evaluations to it. Also, make your repository private so that no one but you and I can see anything of its contents.
Please name your repository CMSI-3630_<your-last-name>
. I have automated scripts set up
for evaluating your work that expect this naming convention. If you change that convention you will
break my scripts. You should also have a directory [folder] hierarchy in your repo that looks like the
following structure:
I will be using this folder structure to perform the evaluations of your work. I use the GitHub desktop on my Windows machine to duplicate your repo locally for doing those evaluations, and I have several scripts that I set up to facilitate compiling and running your programs and projects. Any deviations from the above structure means my scripts will not work with your submissions, so you will NOT get credit. IF YOU NEED HELP GETTING THIS SET UP, PLEASE ASK ME, ONE OF YOUR CLASSMATES, OR ONE OF THE TA'S [teaching assistants] IN THE KECK LAB DOOLAN 112 to assist you.
Additionally, CODE THAT DOES NOT COMPILE WILL NOT BE EVALUATED. PERIOD. The time for submitting code with compile errors is past. In a very few cases, if there is some really small error that I could fix with a single edit, I had a nominal policy of correcting those errors if there were only one or two obvious ones. Any more than that, though, and I will NOT be doing that, so it's best to make sure your code compiles/runs before you turn it in.
REMEMBER: I use the command line for compiling and running. If you are using
an Integrated Development Environment [IDE] like IDLE, be sure your program can be successfully run
from the command line. It's an extra step for some of you, yes, but this reflects the real world of
software development – just because it works for you in IDLE doesn't mean that the USERS who run
your code will be running it from IDLE, if they even HAVE IDLE. Most of your users will think
IDLE
is that thing your car does before you step on the gas.
OK, let's state the obvious up front: JAVA IS NOT JAVASCRIPT. If you had me for
CMSI 185 or CMSI 186 [or anything else] you should realize this already. Professor Forney has a little
saying on his website: Java is to JavaScript as Car is to Carpet.
…or something like that.
The point is, despite the similarity in the names, they are two very different animals. JavaScript
is an interpreted language, which means that the computer [actually the JavaScript interpreter
that is RUNNING on the computer] interprets each line of JavaScript code, one-at-a-time, turning it
into the executable code [bit patterns] that the machine can actually execute. The same thing goes for
Python ~ interprested language, meaning there is an engine
of some sort that actually runs your
code.
On the other hand, Java is a compiled language, which means you have to run a software tool called a compiler on your source code to translate it BEFORE you can run it.
Actually, it's even a bit more complicated than that, because the Java compiler translates the source
code into what is known as byte code
, which is not really runnable on the hardware processor of
your computer either. Instead, there is a program called the Java Virtual Machine, or JVM
,
which is sort of like a layer on top of the operating system of your computer that will run the Java
byte code. It is the JVM that interprets the byte code into what the computer CPU/GPU can actually
execute. Most of the time, you don't care about this, and your USERS certainly won't give a fig.
But it IS an important distinction…
We'll see this again in a week or so.
Apart from being compiled vs. interpreted, Java is a statically-typed language, while
JavaScript and Python are dynamically-typed languages. This means that in JavaScript
or in Python, you can define a variable horse
that has the string
in it, then three lines later you can set the value of Trigger
horse
to be 37
, and
the JavaScript or the Python interpreter will happily handle that for you. However, with Java, you
must define horse
to have a specific data type, like String
, and it will
forever after [in THAT program] be of the String
data type – you can never put a
number in it, because it will be an error.
Something that the languages have in common, although they implement things differently, is the idea
of OBJECTS
. An object is essentially a user-defined, complex data type. We'll
see more of THAT later, too.
# Python code, dynamically typed myString = "This is a string in the Python Language." primeNumber = 23 # this is a 'number' data type in JavaScript myAmount = 234.56 # this is ALSO a 'number' data type myString = 23 # this is NOT an error!! [Dynamic typing]
Start up your Python interpreter and enter the above code to see what happens!
// JavaScript code, dynamically typed var myString = "This is also a string in the JavaScript Language."; var primeNumber = 23; // this is a 'number' data type in JavaScript var myAmount = 234.56; // this is ALSO a 'number' data type myString = 23; // this is NOT an error!! [Dynamic typing]
Enter the above JavaScript code in the Script Runner to see what happens there.
// Java code, statically typed class Tester { String myString = "This is also a string in the Java Language."; int primeNumber = 23; // this is a 'primitive' data type, an 'integer' double myAmount = 234.56; // this is a 'primitive' data type, a double-precision number myString = 23; // this is an ERROR!! [Static typing] }
Try typing the Java code into a file, then compile it [or check your editor marks] to see the error. You
can also try typing it into the Python Tio.run page to see what
happens there. [TIO
stands for Try It Online
~ a pretty cool tool!]
So that all the sections of this class can get the same introduction to the Python Language [as well as
to Data Structures in general], Dr. Toal, our LMU resident programming language 'mystic chef and guru'
has put together several REALLY GOOD web pages to introduce the Java language. I have, with his express
permission, modified those pages for use with Python, and we'll be using those pages for the first few
weeks of this course to augment our learning experience.
Here is the first one, called
Python Workshop
!
So, within that context, a CLASS is a user-defined data type, which can be used as a sort of template to make objects of that class. It is a named collection of things that can hold data, and things that can operate on that data.
There is really a LOT more to it than this, but for brevity's sake I'm reducing it to the bare bones
The fact that classes define data and the behaviors that can operate on that data leads to the idea of encapsulation, also known as data hiding. The basic idea is that the programmer defines the data in the class, and then also defines the operations for that data, which allows her to have complete control over how that data is accessed. If everything is private to the class, only the methods within that class may access the data directly; any other object will have to call some method [a gettor or settor] to access the data.
Here is an example in Java, properly annotated so you can see what it looks like in a statically typed language:
/** * A simple Java Class file example * @author Professor Johnson * @version 1.0.0 */ public class Sample { private String myString = "This is a string in the Java Language."; private int primeNumber = 23; // 'primitive' data type, an 'integer' public double myAmount = 234.56; // 'primitive' data type, a double-precision number /** * Constructor * @param value String to set in the myString field */ public Sample( String value) { myString = new String( value ); } /** * Method to reset the "myAmount" field value * @param newAmount double precision value to set the field to * @return the integer value that is the reset amount */ public double resetAmount( double newAmount ) { myAmount = newAmount; return myAmount; } /** * Method to determine if a number is prime * @param value an integer which is potentially a prime number * @return boolean value, true if the value passed is prime, false if not */ public boolean isPrime( int value ) { boolean result = false; // some code that determines prime-ity return result; } }
And here is the same thing in Python:
class Sample: myString = "This is a string in the Python Language." primenumber = 23 myAmount = 234.56 def __init__( self, value ): # this is the 'constructor self.myString = value def resetAmount( newAmount ): myAmount = newAmount return myAmount def isPrime( value ): result = False # some code to determine prime-ness of 'value' return result # this is how we instantiate the class s1 = Sample( "New string") s2 = Sample( "Another new string") # this is how we can access the values print( s1.myString ) print( s1.primenumber ) print( s2.myAmount )
This assignment is to make sure you have your environment working, so you are ready for the rest of the semester. It is perfectly OK to ask your classmates for assistance if you get stuck and I am busy helping someone else.
You will need to do the following to produce your first program for this session:
quasi-IDEcalled IDLE that you can use easily
sayHello.pyin a the
classwork01
directory on your local
drive.
Hello, World!to the console using the
print()
function.
input()
function
Hello, World!message to say
Hello,followed by the name that the user has input. For example, if the user enters
Dorothy, your program should output
Hello, Dorothy!Don't forget to add the exclamation point at the end!
dog
, $237.19
, and
just pressing Enter
without entering anything. See if you can break your program, and
if you can, figure out why it broke and see if you can fix it. If you CAN'T break it, see if you
can figure out why it's so robust which is the term for a program that
will handle [nearly] everything gracefully.
SayHello.py
file to your repo
piSolver.py
which will approximate the mathematical
value of PI using a Monte Carlo
Simulation approach. The estimation simulation will be described in class. Specifically,
your program should:Throwlots of random darts at a
unit circlewhich is inscribed inside a square. A square that is around the unit circle will thus have an area of
four units
and the inscribed circle will have an area of
PI times r2 which since r = 1
will be just PI.
four
to get an estimate for the value of PI
math.PI
which you will need to research how to use
math
and the random
modules. To do this you need two lines at
the top of the source file:
import math import random
Do a bit of research on the Internet to find out how to generate random numbers!
shell scriptfile to run the program many times with many different inputs, to display the output of each run
piSolver.py
file to your GitHub repo
I know this isn't due for a while, but i wanted to give you a heads-up on the homework assignments that you will be doing this semester. They are all available from the syllabus page, but just to make sure …
That's probably enough for the first week. Be sure to check out the links to the related materials that are listed on the class links page. Also, don't forget the project page!
I hear, and I forget.
I see, and I remember.
I do, and I
understand.
— Ancient Chinese Proverb