Room 514

Classes, curriculum, education…

The Lightweight Introduction to Programming March 28, 2008

Filed under: ICE3M,ICE4M — mryantho @ 3:39 am
Tags:

Good morning Computer Scientists.  Read the following post and please summarize  for your own notes.

This a ultra-stripped down introduction to concepts in programming.  This is a starting point from no knowledge.  So if you come across this page and you have some background in programming, and you notice some things aren’t technically correct ~ you might care but my grade 11 students do not.  As a side note for my students, programmers tend to have serious idiosyncrasies (peculiar tendencies), a common one is the need to correct people when they feel a slight misinterpretation of their craft has been made.

Let’s start with some simple explanations of concepts in programming.  Many times I will use “real world” examples.  It isn’t that programming isn’t part of our reality, I mean that we have our every day world an the virtual one we are creating through programming.

Variables – A variable is something that represents something else.  It is that simple.  In math class when we say x+2 = 5, we are basically saying that x is representing a 3.  We could also say more generally that x is representing a number, integer, real number whole number, prime number etc.  A variable can also represent a word, a password might actually represent “iluvamericanidol.”  In real life, our name is a variable that represents us.  We’ll say “Jon Smith” rather than describe every characteristic that makes up John.  It is easier to use a variable.  You should name variables something meaningful like “person_height” rather than “z.”  You should know that you cannot name variables certain keywords.  Keywords are special words in the language that have special meaning.

Basic Data Types – Data can be different things.  Most often it is numbers and strings (letters, words, text.)  These are our basic types of data.  Later we’ll talk about advanced data types, but these are data types made of our basic ones.  Most programming languages have the following (or similar) basic data types.

  • Integers (ints) – These are whole numbers positive or negative (1, 34, -987)
  • Decimals (floats) – Decimal numbers (2.34, 4.00, -783.23)
  • Strings – Text and letters (“a”, “hello”, “jkhjhjj”)

Properties (Attributes) – Properties are things that an object has.  They are the things that describe the object and in most cases make it unique.  In real life we have trees.  Some properties of trees are colour, height, weight and type.  There are surely more, we’ll just look at these ones.   Colour is a property, if the colour of the tree is green, then the property colour has a value of “green.”  So properties have three parts, the property name, the value, and the type.  Types of properties are things like numbers, words, etc.  You can think of properties as special variables that belong to an object.

Objects – I should point out that in programming, Objects don’t exist in every programming language.  Languages like Squeak, Java, and C++ are “object oriented.”  That basically means that everything is an object (this is especially true in Java.)   languages like C and PERL are not object oriented, however, a skilled program can use constructs like objects if they wish.  An object is just something we represent in programming that is like its real life counterpart (or would be like if it existed.)  So if we were making the Need For Speed 30 car racing game, we might want to code a car object.  This car object would have properties, like weight, type, colour, etc.

IDE (Integrated Development Environment)– An IDE is where the programmer works.  If Word is for a writer, an IDE is for a programmer.  It allows programmers to write programs and usually provides helpful features.  This means it might have special display windows, or that it colour codes key words.  For most languages you don’t need a nice IDE and you could just use something like Notepad.  But a good IDE can really help you along.

Boolean Algebra– Boolean Algebra are like equations that can only have one of two results, either True or False.  In boolean algebra, something like 8 < 30 would equal True.  An expression like Brittney Spears AND Albert Einstein are both really smart, would be False because they are not BOTH smart (Albert Einstein is dead.)  The AND is called a boolean operator.

You’ll notice above that I used AND.   AND is a boolean operator.  We also have OR and NOT as the basic operators.  An expression like “I know how to drive a car OR I know how to fly a plane” would be True.  That is because I do know how to drive.  As long as one of the statements is True than the whole statement is true.  A NOT operator simply reverses the expression, so a true statement results in false and vice-versa.

Comparison Operators– These are operators that are also used in boolean algebra.  The expressions will still result in true or false.  In the example I used before: 8<30 is True, the “<” is a less-than operator.  These are often used to compare numbers but can also compare strings, or even objects.  We use the operators < (less-than), > (greater than), = (equal-to), and  != (not equal-to).

Functions (or Methods) – Functions are named chunks of code.  Programmers create functions to perform a job that the program will complete often.  That way instead of re-writing the same chunk of code over and over again.  That is the easiest thing to see.  Think about directions to school.  If we had to re-write code for each day of school, it adds up.  It is easier to have a function called “go_to_school,”  you’d never miss class again.

Functions also make our program more easy to understand when we look at it.  That’s because we name our functions things that makes sense.  So if we saw a function called “stringToInteger(x)”, we might guess that it converts the string x to an Integer.  As a side note these chunks of code are called blocks in Ruby.

Syntax– Syntax is the rules of a language.  English is a language and it has rules.  Those rules are called its grammar.  If we don’t use grammar correctly, even though we are using English words, our message will be lost.  The same is true for programming languages.  We need to follow the rules of our language or the computer won’t be able to understand what we want the program to do.  Every language has its own syntax.  Some programmers will have preferences and say one language’s syntax is more difficult than another language’s grammar.  And syntax can be tricky; forgetting a semi-colon may cause a whole program to crash.  And you thought English grammar was difficult.

Semantics – Remember when Homer said “Let’s not get bogged down in semantics.”?  I do…and I laughed.  Well, if there is something that can bog you down, it’s semantics.  Semantics is the meaning of a message.  Basically it’s what the message you are trying to get across.  While syntax is how you say something; semantics is what you are saying.  In programming, when we discuss semantics, we are talking about what you are trying to do with your program.  Are you trying to solve a complex calculation?  Create artificial intelligence for a game? Launch a space shuttle?  Getting your semantics correct, means creating a program that completes the correct steps to solve a task.

Visit this site: http://cisnet.baruch.cuny.edu/holowczak/classes/programming/ for some more information.  Use these explanations to add to your understanding.  Remember, you are expected to make notes…its is your homework.

Also for homework, visit this site: http://tryruby.hobix.com/ .  It will give you a very brief introduction to Ruby.  Don’t worry if a lot of it doesn’t make the most sense yet.  It will get better in time!

 

5 Responses to “The Lightweight Introduction to Programming”

  1. Bharadwaj Says:

    This is te first time I am visiting here through google alerts.
    I am pursuing my 11 class in India. And after coming here I just felt bad for what I have been missing all this time.
    I have been working on Python, PERL and C# but never ever did I analyze them. Absolutely everything is precise. And really admiring stuff. Just written as if you were to written only for me, and this I refer to the entire Blog..really very encouraging work. And thanx for sharing with us.

    -Gladly looking forward for more.
    Bharadwaj
    Ubuntu Developer, https://launchpad.net/~bharadwaj-j

  2. Rikko Says:

    Yeah our teacher is the best!

  3. mryantho Says:

    Yes Rikko, your teacher has skills. Like bow hunting skills.

  4. Rikko Says:

    See the new WoW Class? Bard? Its pwnage, its like guitar hero on World of Warcraft.

    http://www.worldofwarcraft.com/wrath/features/bard/bardclass.xml

    Check how ridiculous this is sir….

  5. mryantho Says:

    The WoW Bard may be an April Fool’s joke. 😉


Leave a comment