.. _cosc1336-lab-orientation: Lab Orientation ############### .. wordcount:: .. vim:ft=rst spell: .. include:: /references.inc Today, we will get set up to write programs using Python_. If you intend to do all of your work in the Computer Studies labs located at most ACC campuses, there is not much work to do. However, I highly recommend that you set up a personal computer so you can work on class assignments at home or wherever you like. I carry a laptop around everywhere I go, and can work anywhere I end up (except in Yellowstone Park - not much Internet access there!) I own several computers (too many according to my wife!) and have set up my systems so I can work on any of them. Installing required tools ************************* To complete this course, you will need the following tools on your system. .. note:: If you need help getting any of this done, see me right away. You cannot afford to get delayed doing course work because of system setup problems. Remember you can use any Computer Studies lab at any campus to do your work. * Python (version 3.7.x) - see :ref:`installing-python` * Programmer's text editor - see :ref:`installing-vim` * Git - to manage your code - see :ref:`installing-git` Our Work Environment ******************** We will not be working in a full Windows development environment for this course. Instead, we will work mainly using a simple environment called the `Command Prompt` window. See :ref:`command-line` for more information. Building "Hello, World" *********************** For reasons long forgotten, it is a tradition for new programmers in any programming language to cause their very first program to display "Hello, World!" on the console. Are you up for this? Open up the Python interpreter ============================== Start off by going to the :term:`command prompt` window and type in this: .. code-block:: text c:\> python With any luck, you should see this: .. code-block:: text c:\> python Python 3.3.0 (default, Apr 11, 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright" or "licenses" for more information. Wonderful! We have a running Python to play with. See that last line with the three angle brackets? That is the Python prompt. Python is waiting for you to type in some Python code. We do not know how to do that yet, I hear you cry out! Well, let's get out first "program" out of the way. Type this: .. code-block:: text >>> print("Hello, World!") Hello, World! >>> When you pressed the "Enter" (or "Return") key at the end of the first line, what you typed was processed by Python, and whatever happened was displayed on the screen. Well, actually, something displayed only if that line made something get displayed, and the ``print`` thing made whatever was found inside the parentheses print. In this example, what was inside those parentheses was a ``string``, just a sequence of characters surrounded by double quotes. You see the result on the next line followed by another prompt. Let's try something a bit different: .. code-block:: text >>> message = "Hello, World!" >>> print(message) Hello, World! >>> Hmmm, what have we here? Well, actually, we told Python to save a copy of the string with the text we want to display somewhere where it can find it later. We also told Python to tag that place with the name "message". Later we will call this name a "variable" since we can save another string later and use the same name. Don't get frazzled, this will get clearer as we go. ***************************** Saving your program in a file ***************************** We seldom write real programs using something like the Python interpreter. Instead, we use a simple text editor to place the code in a file and ask the Python interpreter to run the file for us. That save us typing in the program over and over. Picking a text editor ===================== .. warning:: Religious discussion follows! Programmers use special editing tools that are smart enough to help them write their programs. Good editors know all about most of the languages in popular use. These editors are not the kind you may have used up to now. Instead, they simple record the keys you type in and do not embellish the file with stuff designed to make it look fancy when printed on a piece of paper. So, never, NEVER, open up anything like Microsoft Word thinking you will write a computer program with it. .. warning:: The other Microsoft tools found on all systems are equally poor for programmers. Never use ``NotePad``, or ``WordPad`` for writing programs, either! Picking an editor is a very personal thing. You will probably explore several before you land on one you keep using. All :term:`Integrated Development Environment` tools you might use have some form of editor, but I still like to know a good editor I can use for any task a computer geek is likely to need an editor for. I use an editor I first learned over 40 years ago, and I like it because it is available on every machine I use. That editor is called ``vim`` and there is a nice Windows version of it called ``gVim``, and one for the Mac called ``MacVim``. I like it because it is a solid programmer's editor, and it is "scriptable", meaning I can teach it new tricks by writing a bit of code in Python (or in its own scripting language). I have this editor installed on all the lab machines for those of you taking a programming class in the classroom, and recommend that you install it on your system of choice for programming at home (or work - no, forget I said that!) .. note:: If you already use an editor you like, by all means use it. But remember that you may find yourself working on many systems during your professional career, so pick your editor carefully! Creating our program ==================== Assuming you have the editor installed, open it up using an scheme you like. I usually pin an icon on the `TaskBar` at the bottom of the page when the editor is open to make getting it open easy. (Just right click on the ``gVim`` icon at the bottom of the screen when the program is running and select `Pin to TaskBar`). Remember that ``vim`` is a modal editor, so to enter your code you press lower case "i" (look for the **INSERT** at the bottom of the window). Then enter your code: .. code-block:: python print("Hello, World!") Hit the escape key to return to command mode. Save your program using the :menuselection:`file --> Save As`` selection, then navigate to the place you want to store your code. .. note:: We will go over storing lab projects for this course and the use of Git_ in a later lecture. Save your program in a file named ``hello.py``. Running the program =================== Once you have your program file saved, open up a :term:`command prompt` window and do this: .. code-block:: text python hello.py You should see your message. ********** That's it! ********** If you get to this point, you have the most important tools installed. In the next lecture, we will add one more tool that we will use to "submit" your work to me for grading. Actually, the tool, called Subversion, is a very important tool in the programming world. It is a :term:`Source Code Control System` that teams of programmers use to track the code in a project and changes to that code as the project is developed. This is a good tool to see in action while you are in school, since you will be using such a beast in any real job you get where software is developed! .. vim:filetype=rst spell: