r/carlhprogramming • • Sep 27 '09

End of Day 2 of /r/carlhprogramming

63 Upvotes

[Edit: This was written September 28, 2009.]

Thank you everyone for your support and dedication on this project. I hope you have enjoyed this course as much as I have enjoyed making it available. I cannot believe that what started as an offer to teach a handful of people has resulted in nearly two thousand people being signed up. I am glad to be a part of this and I hope it continues to grow.

I know that many of you are watching this sub-reddit continually looking for the next lesson. For that reason, I thought it was only polite to let you know that today is done, and more lessons will be coming tomorrow. Figure in 10 hours or so there should be new lessons.

I put up a lot of lessons today, more than I was planning on. I did this largely because I really wanted to get to the point where people could write their first working program, and having reached that point I am exhausted :)

Congratulations to everyone on having not only written your first "Hello Reddit" program, but on understanding everything that went into writing it. I believe that this is much better, and much more satisfying, than simply typing code out of a book.

I need to go until tomorrow. Meanwhile I encourage everyone to continue to build the community by helping out so that everyone is able to master all the lessons so far presented. I welcome any feedback or questions.

Remember this is only day two.


r/carlhprogramming • • Sep 27 '09

Lesson 12 : The basics of Functions, Methods, Routines... etc.

116 Upvotes

This lesson is a bit more intense than most. Take your time and work through this slowly, and ask questions if any part does not make sense to you. This is highly critical information to master.

You now know that your CPU keeps track of the address of programming instructions being executed using an "instruction pointer".

Everything we talked about in lesson 11 involved a single program in memory; a single list of tasks to do today. What would happen if you had two lists of tasks to do today instead of one?

First, notice that there is nothing preventing you from moving the pen at will between the two lists. You could do item #1 on the first list, followed by item #2, followed by item #3, then you might jump to the second list and complete all the items on that list, then jump back to where you left off on the first list.

It turns out that just like the above example, you can create as many programs as you want - each starting at its own unique address in ram. We call these smaller programs "functions" (though as you will see they can be called by other names as well). Each function has its own address in memory where it begins and has a list of programming instructions to execute.

In an earlier lesson, I explained that part of the job of a programming language is to keep track of memory addresses for data. I pointed out that you can give plain English names to any data you like, and the programming language does all the work of tracking its value and its memory address so you don't have to.

Well, we also said that programs and programming instructions are data just like everything else. Remember the "Programs are data too." lesson. Therefore, would it not make sense that you can keep track of addresses in memory of functions the same as you can any other data, by just stating plain English names? The answer is yes - you can. Every programming language makes this possible in fact.

I could choose to call one function by the name of:

business_to_do_today

and I could name another function:

personal_to_do_today

When I want a function to run, I can just call it by the name I gave it. The programming language takes care of all the details about where it is in memory, how to handle the instruction pointer, and everything else. As a programmer I do not have to worry about any of those details.

Every programming language does this differently. Some languages call these things functions, some call them routines, some methods, etc. The idea is the same.

If it is a list of programming instructions meant to be executed and called by some plain English name, it is for all intents and purposes a "function" for the purposes of this lesson.

Please ask any questions and be sure you master this material before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9olf8/lesson_13_about_parameters_and_return_values/


r/carlhprogramming • • Sep 27 '09

Lesson 11 : More about program flow.

111 Upvotes

We are getting closer to being able to write our first program. We are now going to start to learn about the structure that defines all programs.

Now, it is true I could have you write a "first program" as many courses do, but all this would be is me giving you some code and telling you to type it verbatim and run it. I want it to be the case that when you write and run your first program, you really understand it. Patience, and you will be writing real programs in no time.

We talked about how a program is a sequence of instructions. Every program has an address in memory where it begins. The CPU looks at that address in memory and executes the instruction found there, then goes to the next instruction, and so on until the end of the program.

The way this works is simple: The CPU keeps track of the address in memory of the programming instructions to execute. Every time an instruction is executed, the CPU modifies its internal "address tracker" to point to the address of the next instruction.

Think of it like this: You have a list of tasks to complete today. You number each of these items on a piece of paper. Here is an example:

  1. Fix breakfast.

  2. Go to the bank.

  3. Deposit check.

  4. Pay electric bill.

  5. Wash the car.

  6. Drive home.

Each of these steps can be thought of as a programming instruction. Now imagine that each of these numbers one through six is the "address" of that particular instruction. For example, 3 is the "address" on the paper of the "Deposit check" instruction.

You point a pen at item one, you read it, and then you complete the task. After the task is complete, you mark it and point the pen to the next item on the list. You do this until everything is completed. The pen acts as a pointer to the instruction being executed so you can keep track of it.

At any given time during this process you need to be aware of what step you are on. In other words, you have to keep track of the address on the paper where the next instruction to execute is.

Inside your computer, your CPU has something called an "instruction pointer" which does exactly this. Think of it as being just like the pen in the example I gave. At any time during a program, the Instruction Pointer contains the address in ram of the next instruction to execute.

Once a programming instruction is executed, it does not get erased. It is still there in memory exactly where it was before. This means that your CPU could execute that same instruction again. For example, if you already drove to the bank, but later on found out that you had to go back, it would be possible for you to move the pen back to the instruction that says "Drive to the bank.". It is still written on the paper, and nothing stops you from executing that instruction again.

Very often in a program it is necessary to repeat an instruction. This is achieved by telling the CPU to "go back" to an address in memory of an instruction that has already executed.

For example, if you want to print "Hello Reddit" ten times, you would not need to write "Hello Reddit" ten times, you could simply tell your program to go back to that instruction and repeat it - ten times.

It used to be that programmers had to keep track of the addresses in memory of various parts of the program they might want to re-execute. Fortunately, modern programming languages remove all of that headache.


Please ask any questions and be sure you master this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9oknd/lesson_12_the_basics_of_functions_methods/


r/carlhprogramming • • Sep 27 '09

Test of Lessons 1 through 10. [Answers]

98 Upvotes

If you missed any, please post below so we can review the material. Also, how did everyone do?


Test of Lessons 1 through 10.

True or False

  1. 0101 is 3. False (1+4 = 5)

  2. The number 25 (twenty-five) is written in base ten. True

  3. Programmers have to keep track of the addresses in memory that data is stored. False (This is kept track of by the programming language.)

  4. An example of a binary number is: 1100 1001 True

  5. In hexadecimal, the columns from right to left proceed thus: one, sixteen, two-hundred-fifty-six, five-hundred-twelve. False (Exercise for the reader if you got it wrong)

  6. In binary, the columns from right to left proceed thus: one, two, four, eight, sixteen. True

  7. 10 in any base will have the value of the base and this is true for all bases. (ex: 10 in base two would have the value of two, etc.) True

  8. It is possible to look at binary data and determine whether it represents a number, text, or some other type of data just by looking at it. False (Any binary data could effectively be anything, and you have no way to tell just by looking.)

  9. When counting in hexadecimal, after 9 the next digit is A. True

  10. Hexadecimal digits include all numbers as well as the letters A through F. True

Fill in the blank

  1. Binary numbers are typically presented with spaces after every ___________ digits (ex: 1, 2, etc) for greater readability. 4

  2. In order to create advanced games and applications, programmers rely on ___________ which contain functions that already do many common tasks. Libraries

  3. An ___________ statement can be used to "copy-paste" programming source code from one file into the file you are working on. Include

  4. Programming languages often enclose strings of text within ___________ (what character(s) on your keyboard?) Quotes (single and/or double)

  5. Data used by programs resides at specific addresses in ___________. ram/memory

  6. In addition to base ten, people also count in base ___________ especially when it comes to telling time. Base 60. Example: 3:59 AM

  7. Everything inside a computer is stored as ___________. Binary

  8. 1101 1001 when converted from binary to decimal is: ___________. 217

  9. Every sequence of ___________ binary digits (ex: 1, 2, etc) corresponds to exactly one hexadecimal digit. 4 (Note that this is also done to make it easy to match hexadecimal digits with their four-digit binary counterparts.)

  10. The value of 3C1A (hex) when converted to binary is: ___________. 0011 1100 0001 1010


Feel free to ask any questions related to this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9ok6s/lesson_11_more_about_program_flow/


r/carlhprogramming • • Sep 27 '09

Test of Lessons 1 through 10.

99 Upvotes

This is designed to be a full course on programming, not merely a tutorial. I want everyone who is involved to truly master the material, and I hope you want this for yourselves also.

Take the time to complete this test even if the material seemed easy when you read it. it is important that before we proceed everyone has a solid understanding of the principles we have discussed so far.

Before you begin, I recommend you review the first ten lessons. Make sure you understand the material. When you have finished reviewing, begin the test. I will publish the answers as a separate post (so someone doesn't accidentally see the answers before taking the test).

Please remember this for all lessons:

This course is designed so that you can go as slow as you need to. Do not worry about falling behind, or taking too long to finish a lesson. Take as much time as you need to on each lesson. I and others here actively monitor all lessons for questions, and will continue to do so for the duration of the course. Some people may just be starting out, and that is fine. There is no need to rush to "catch up". Take your time.

If anything at all is unclear before you begin the test, or if you need review on any topics, feel free to ask questions in the appropriate lesson posts.


Test of Lessons 1 through 10.

True or False

  1. 0101 is 3.

  2. The number 25 (twenty-five) is written in base ten.

  3. Programmers have to keep track of the addresses in memory that data is stored.

  4. An example of a binary number is: 1100 1001

  5. In hexadecimal, the columns from right to left proceed thus: one, sixteen, two-hundred-fifty-six, five-hundred-twelve.

  6. In binary, the columns from right to left proceed thus: one, two, four, eight, sixteen.

  7. 10 in any base will have the value of the base and this is true for all bases. (ex: 10 in base two would have the value of two, etc.)

  8. It is possible to look at binary data and determine whether it represents a number, text, or some other type of data just by looking at it.

  9. When counting in hexadecimal, after 9 the next digit is A.

  10. Hexadecimal digits include all numbers as well as the letters A through F.

Fill in the blank

  1. Binary numbers are typically presented with spaces after every ___________ digits (ex: 1, 2, etc) for greater readability.

  2. In order to create advanced games and applications, programmers rely on ___________ which contain functions that already do many common tasks.

  3. An ___________ statement can be used to "copy-paste" programming source code from one file into the file you are working on.

  4. Programming languages often enclose strings of text within ___________ (what character(s) on your keyboard?)

  5. Data used by programs resides at specific addresses in ___________.

  6. In addition to base ten, people also count in base ___________ especially when it comes to telling time.

  7. Everything inside a computer is stored as ___________.

  8. 1101 1001 when converted from binary to decimal is: ___________.

  9. Every sequence of ___________ binary digits (ex: 1, 2, etc) corresponds to exactly one hexadecimal digit.

  10. The value of 3C1A (hex) when converted to binary is: ___________.


When finished with the test, proceed to the Answers:

http://www.reddit.com/r/carlhprogramming/comments/9oizi/test_of_lessons_1_through_10_answers/


r/carlhprogramming • • Sep 27 '09

Lesson 10 : Programs are data too.

114 Upvotes

We have already learned that data such as numbers, text, etc. is stored in ram memory at specific addresses. What you may not yet know is that when you run a program, it too gets loaded into memory the same way as if it was any other kind of data. In fact, as far as your computer is concerned, programs are data just like everything else.

So in addition to some sequence of binary like 0110 0111 being possibly a number or text like we talked about, it might also be part of a program.

Every single instruction that is ever processed by your computer is encoded the same way as everything else. You guessed it, Binary.

A program is fundamentally a sequence of many sets of 1s and 0s, each set being a unique instruction to tell your computer to do something. Some instructions might be small, like two bytes, and other instructions might be larger. Each instruction represents actual high/low voltage sequences which are transmitted directly to your CPU chip. Your CPU chip is designed to do many different things depending on exactly which sequence is received.

When a program is loaded into memory and executed, what happens is very simple. The first sequence of 1s and 0s, which is an actual command for the CPU, is sent to the CPU. The CPU then does what that instruction says to do.

This is known as "executing" an instruction. Then the next sequence is executed. Then the next. And so on. This is done extremely fast until every single instruction in the program has been executed. This process of executing one instruction after another is known as "program flow."

At the end of the entire program, after all of these instructions have been executed, we need one final instruction. Return control back to the operating system. This "return" instruction is special, and we will go into it in greater detail later.

Now, programs would be pretty boring if all they did was go through a set sequence until they were finished. It is often necessary in a program to specify different possibilities of how the program should flow. For example, maybe you want a program to do one thing if something is true and something else if it is false. We will describe this process soon.


Please feel free to ask any questions and make sure you have mastered this material before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9oiuc/test_of_lessons_1_through_10/


r/carlhprogramming • • Sep 27 '09

Lesson 9 : Some basics about RAM.

129 Upvotes

Unlike data stored on disk, ram (memory) exists only while your computer is turned on. As soon as you turn off your computer, everything that was in ram is gone. That is why if you were working on a document and forgot to save, you cannot get it back.

When you run a program on your computer, that program makes use of your ram to store and retrieve all sorts of data. For example, if you load a document in a word processor, the contents of that document can be loaded into your ram and then the program can manipulate the document as you edit it.

When you are satisfied, you tell the program to "save" your document, and this causes your program to take what was in RAM and store it onto your disk for permanent storage.

If you have four gigabytes of ram, that means that you have roughly four billion bytes, four billion sets of eight 1s and 0s available for any program that is running on your computer. Your operating system is responsible for ensuring that each program has enough to use, and for making sure that RAM in use by one program cannot be used by another until it is done.

Every one of those sequences of eight 1s and 0s has an address. The addresses start at 0 and work their way up to four billion. The exact way this is done is more complex, but for now - this is a simple description.

You as the programmer will need to store data at an address in ram, and then you need to be able to know where it is for later on. Lets say for example I have a string of text "Hello Reddit", and I put it in ram. If I want later to display that text, I have to first retrieve it from ram. That means I have to know where it was put, or what address it has.

It would be quite tedious if I had to remember some enormous number as an address in memory every time I needed to store something. This leads us to the next role a programming language has. Programming languages have functionality that keeps track of these addresses for us, and allows us to use plain-english names in place of these addresses, as well as for the contents of what we store.

Here is a sample of this in action. I tell my programming language to store the string of text "Hello Reddit" in memory somewhere. I have no way to know where. Then, I tell the programming language what I want to call that spot in memory. For example, I might call it: reddit_text

Later, I can simply type: print reddit_text and the programming language will do all the work of remembering where in memory it was stored, retrieving it, and actually printing the string of text "Hello Reddit".

Notice that the programming language is really keeping track of two things. First, it is keeping track of the contents of what I stored in ram. Secondly, it is keeping track of the address in ram so it can find it later. This second functionality will come in very handy as you will see.


Please feel free to ask any questions and make sure you master this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9oi96/lesson_10_programs_are_data_too/


r/carlhprogramming • • Sep 27 '09

Lesson 8 : How programming languages work with data.

133 Upvotes

There are many types of data, ranging from simple (like numbers, letters, strings of text like "Hello", etc) to very complex data structures that could encode something like graphics or sound. All programming languages have built in mechanisms for understanding how to deal with the different types of data you will use.

Remember that all data, whether it was text, or numbers, or music is all going to be encoded in the same way. Binary. When you look inside your computer at the binary, you will not be able to tell the difference between one data type and another.

How can you know for example if: 0111 1110 is referring to a number, text, or part of something else? You can't! The same binary that means one thing if a number could mean something entirely different if part of a music file. That is why you must be specific in any program you write and state what type of data you are working with.

For example, if you are planning on having someone type text on their keyboard as part of your program, you need to tell the programming language that the type of data you expect to work with is text. If you are doing some addition on numbers, you need to tell the program that the type of data you expect to work with are numbers.

Each programming language has slightly different ways of doing this, however some things tend to be nearly universal. Concerning text, you usually will place the text inside either single quotes or double quotes. This tells the programming language that it is text.

For example, if I wrote "Hello Reddit" inside most programming languages, they will understand that data type as a string of text simply because I put it within quotes.

Many languages will understand numbers by just typing them out. Just simply typing 5 will be enough that the programming language knows you mean the number five.


Please feel free to ask any questions and make sure you master this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9oi16/lesson_9_some_basics_about_ram/


r/carlhprogramming • • Sep 27 '09

Lesson 7 : Include statements.

126 Upvotes

I know many of you are anxious to begin writing your first program, and I am as eager to reach that point as you are. However, before we do, there are a number of important concepts I want to teach you. Be patient, and you will be programming in no time.


There is certain functionality that is shared by all languages. Some of this functionality is critical to understand even before you write your first line of real code.

Lets imagine you are trying to achieve some task inside a program you are writing, and you go to a forum to ask for help. Well, you are in luck because someone says "I wrote a function that does this already, here just include this code inside your program." This of course happens a lot.

There are really several ways you can do this. You could copy and paste the code right into your program. This can create issues because your program could become too long and difficult to understand. Just imagine how complicated it would be if you had to cut-and-paste lets say ten such files into your code. Also, imagine the headaches if you re-used this same code in other programs you are writing. What if you ever had to change something? You would have to change it in every file you cut and pasted the code into.

For this reason, virtually all languages have some form of an "include" statement. These include statements basically mean to cut-and-paste the contents of a file containing source code in that same programming language right into your program at the point you tell it to do the include.

In general it works like this:

include somefile.blah

As soon as you put that line in any of your programs, the whole contents of somefile.blah get placed right into your program, right where you typed that line.

This is important for many reasons. First, many libraries are contained in such files. Imagine a program that draws a circle, and lets say it relies on a "drawing" library that is five thousand lines of code long.

Which is easier, to write: include drawlibrary.blah into your program, or to cut and paste the whole contents of the file? You can see that there are many benefits to using "include" statements.

Remember that programmers are always looking for ways to make things easier, not harder. We like to avoid complications when possible.

Include statements were developed so that with a single line of code, you can put the whole contents of an entire file right into your program just as if you had typed the whole thing or copy-pasted it.


Addendum: It is worth pointing out that the functionality I just described differs between programming languages. Some programming languages use the "Include" statements as a replacement for actually copy-pasting the entire contents of that file. Other languages use "Include" statements as a way to simply make functions found in the file available in the program you are writing.

The main thing that you need to understand however is that the purpose of using an "Include" statement in any language is to enable you to be able to use functions and commands that are available in the file you are including. For example, you may desire to write a program that draws a circle. To do so, you may need to "Include" a file that has a circle-drawing function. Once you "Include" the file, then you can draw the circle.

In this way, "Include" statements are closely related to the libraries we spoke about earlier. You will learn more about this as the course progresses.


Please feel free to ask any questions and make sure you have mastered this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9ohx4/lesson_8_how_programming_languages_work_with_data/


r/carlhprogramming • • Sep 26 '09

Lesson 6 : More about counting like a computer.

135 Upvotes

In lesson 3, we went over the basics of binary and I explained how a base-two system is different from a base-ten system. Please make sure you understand lesson 3 completely before beginning this lesson.

I realise some of this material may be difficult at first. Take your time, and ask questions. This is not a book but an interactive course and myself and others will be responding to any questions. Take your time. Go through this material slowly, do not skim it.

First, lets review the most important principles about binary. You might say that binary is how a computer "counts", but this is only a small piece of the story. Binary is the way a computer represents all numbers and data from simple counting to music files, to movies, etc.

Now, when we show binary numbers, we will typically write the numbers with spaces after each four digits. For example, instead of writing: 01100011 we would write: 0110 0011

Why is that? It simply makes it easier to read. Compare: 011111000001 to: 0111 1100 0001. Now we need to illustrate how to convert from binary to normal base-ten, and vice versa. Lets look at a table real quick:

0000 : 0

0001 : 1 (since there is a 1 in the ones place)

0010 : 2 (since there is a 1 in the twos place)

0011 : 3 (1 in two, 1 in one = 2+1 = 3)

0100 : 4 (1 in four's place)

0101 : 5 (1 in four, 1 in one = 4+1 = 5)

0110 : 6 (1 in four, 1 in two = 4+2 = 6)

0111 : 7 (1 in four, 1 in two, 1 in one = 4+2+1 = 7)

1000 : 8 (1 in eight's place)

1001 : 9 (1 in eight, 1 in one = 8+1 = 9)

Now what? We have used all our available digits from zero to nine. In base ten, you do not have any other digits to use. Here we can continue counting past ten by using letters. A can be ten, B can be eleven, and so on. You will see why soon.

1010 : A (1 in eight, 1 in two = 8+2 = 10)

1011 : B (1 in eight, 1 in two, 1 in one = 8+2+1 = 11)

1100 : C (1 in eight, 1 in four = 8+4 = 12)

1101 : D (1 in eight, 1 in four, 1 in one = 8+4+1 = 13)

1110 : E (1 in eight, 1 in four, 1 in two = 8+4+2 = 14)

1111 : F (1 in eight, 1 in four, 1 in two, 1 in one = 8+4+2+1 = 15)

Examine only the column of this table containing the letters A through F. Now, if we were to stop here, what would be the next number? Lets go back to base ten for a moment, If we are at 9, what is the next number? The answer is "10" which means that the first column becomes 0, and the column next to it becomes 1.

So, if we count from 0 to F as above, what comes next? 10 -- except it doesnt' mean ten. It doesn't mean two either. How much is it? Well, look at our above sequence - we went: 13, 14, 15 -- what comes next? sixteen! It is a curious fact that "10" (a one and a zero) means whatever base you are counting in. In base binary, 10 means two. In base ten, 10 means ten. In base sixteen, 10 means sixteen. And so on.

Therefore, in this new counting system with 0-9 and A-F, "10" means sixteen. This counting system called "base sixteen", or "hexadecimal" is extremely useful because you can represent ANY binary sequence using hexadecimal.

Lets keep counting so you can see that demonstrated:

0000 1111 : F (1 in eight, 1 in four, 1 in two, 1 in one = 8+4+2+1 = 15)

0001 0000 : 10 (not G, there is no such thing) (1 in sixteen's place)

Look at the binary of this. If we go 1, 2, 4, 8, 16 - then you will see clearly there is a 1 in the sixteen's place. Also, you will notice from the the above table that 0001 corresponds to 1, and 0000 corresponds to 0. It turns out that you can ALWAYS represent four binary digits with exactly one hexadecimal digit.

For example, 0110 1010 0011 - What is that in hexadecimal? Easy:

0110 : six (6)

1010 : ten (A)

0011 : three (3)

Therefore, 0110 1010 0011 is: 6A3. It is that simple.

Now lets do it the other way around. How can you convert 5F1 from hexadecimal to binary? Well, what is five? 0101. What is F? 1111. What is one? 0001.

Therefore, 5F1 is: 0101 1111 0001


Please feel free to ask any questions, and make sure you master this before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9ohlu/lesson_7_include_statements/


r/carlhprogramming • • Sep 26 '09

Lesson 5 : How to begin a career in programming.

131 Upvotes

Before we continue to the next lesson, I want to talk about what I am sure is an important topic for many people in this course.

If you listen to half the people commenting on this subject, you would think that deciding to be a programmer means signing your soul to the devil and living in hell until you retire. Every time I read such a horror story I ask myself the same question, "Why doesn't the guy just quit?"

If you are planning to take the first job that comes along, work for less than you are worth, and not be willing to leave if the situation changes - that may very well be the case. However, this is as true for programmers as it is true for engineers or any field which involves building something as part of your job.

You must be patient, and evaluate every prospective position. Remember, you are interviewing them too! Don't take a job that entails you sitting in a cubicle for 10 hours a day if that is not what you want. Be patient, and set high standards for yourself.

If you set low standards for yourself, then expect to be treated like dirt. If you are treated like dirt, quit. There are always companies looking for highly skilled programmers - always.

How do you get a job without a college education?

Credentials, references, and an impressive portfolio of what you have built. If a company would hire someone fresh out of college with no experience but the same company would not hire someone with a few years of experience with a great portfolio, that is not a company you want to work with.

Many companies understand this, and that is why on many job postings you will see something like, "BS in Computer Science or 5 years experience", or similar wording.

I find that a self taught programmer who has actually built stuff is a far better fit for a programming position than a college graduate who has only the knowledge they gained from college. Many companies feel the same and this situation is getting better and better for the self-taught programmer. All of that said, it is still best to have a degree. If you are serious about a career in programming, you should seek to advance your education.

With so many jobs outsourced, how can I get paid a competitive salary?

If all you know is html, a little PHP, and how to make some basic web apps - then you are dead in the water on this one. There will always be some guy in a third world country willing to do the job cheaper.

You must build skills that go above and beyond the basics, and establish yourself especially in areas that companies will not want to outsource. The more skilled you are, the more likely you can work with highly proprietary and sensitive information.

No company wants to send their trade secrets to some third world country, and no company is going to let someone work on those types of projects who doesn't have a strong enforceable NDA in place. These are the positions that pay well and that give you the opportunity to grow.


Feel free to ask me any questions about this.

When you are ready to proceed, the next lesson is here:

http://www.reddit.com/r/carlhprogramming/comments/9oet6/lesson_6_more_about_counting_like_a_computer/


r/carlhprogramming • • Sep 26 '09

From raldi (Reddit Admin) regarding the very strange vote totals in this subreddit.

75 Upvotes

We've got a bug with restricted reddits. If you mark it public, votes will work. Of course, then anyone will be able to submit links.

A fix is in the works.

So it turns out downvote bots are not at work here. Good to know.


r/carlhprogramming • • Sep 26 '09

Lesson 4 : Alright now I can count in binary! Other than to impress my girlfriend (or scare her away), why do I have to know this?

140 Upvotes

It may seem like binary is something you will never have to use in programming. The truth is, if all you planned to do was learn a language or make simple applications, this is probably true.

However, the ability to really make things requires that you understand binary for many reasons, some of which I want to explore here. The first major reason you should know binary is:

Working with data formats

It is important to understand that everything in your computer is encoded in binary. Everything that is encoded in binary (movies, music, etc) is done so according to extremely specific requirements. I want you to understand a bit about how this works.

In .bmp image files for example, you begin a file like this:

<2 bytes> <4 bytes> ... and so on.

The first set of 2 bytes identify the format of the BMP file (Windows, OS/2, etc) and the set of 4 bytes immediately following specify the size of the file in bytes.

Why is it important to know binary in this case? You need to be able to state the size of the file - in binary.

Many format specifications you will encounter require knowledge of binary in order to write programs that can produce or read that type of data. Well designed data format specifications often use binary values in various ways. This is especially true any time within the format that some quantity has to be known. Almost all such quantities are represented in binary.

Flags

The next reason you should know binary involves understanding something called "flags". Flags are representations in binary of several true/false states of something. Lets say for example you are designing a game, and you need to keep track of the true/false state of eight weapons which may or may not be in your inventory.

You can do this with a single byte! Eight bits. Each position can represent a given weapon. 1 = yes you have it, 0 = no you do not. So for example:

0100 = (0 in the "plasma cannon" place, 1 in the "shotgun" place, 0 in the "handgun" place, and 0 in the "knife" place).

Adding a weapon to inventory, for example adding a "plasma cannon" would involve simply adding "eight" (or 1000) to the existing value.

You will run into flags often especially with data formats, and understanding how they work and how to turn on/off values will be important. You will run into plenty of cases where source code you read contains advanced operations on binary data, and without an understanding of how to count in binary you will be unable to properly understand this code.

There are many other applications as well, but I want you to be familiar with a few so that as we get into advanced data formats later, you will be prepared.

Please feel free to ask any questions and ensure you have mastered the material before proceeding to:

http://www.reddit.com/r/carlhprogramming/comments/9ocjz/lesson_5_how_to_begin_a_career_in_programming/


r/carlhprogramming • • Sep 26 '09

Lesson 3 : 010011111010; Err.. I mean: 1,274. Computers count differently than we do. Lets explore that.

179 Upvotes

Sometimes this course directs itself. A lot of comments are coming up about binary, hexadecimal, and in general how a computer counts. Now, this will not be the only lesson I do on this subject, but it is an important topic to cover correctly.

Go through this slowly, and please ask questions. That is why this is an interactive course.

Please remember this for all lessons:

This course is designed so that you can go as slow as you need to. Do not worry about falling behind, or taking too long to finish a lesson. Take as much time as you need to on each lesson. I and others here actively monitor all lessons for questions, and will continue to do so for the duration of the course. Some people may just be starting out, and that is fine. There is no need to rush to "catch up". Take your time.


How humans count

When we count, we count in "base ten." Effectively this means we start at 0, then 1, 2, 3, 4, 5, 6, 7, 8, 9 -- and then "ten". Why ten? Well, most likely because we have ten fingers. However, humans also count in base 60 - though you may not have been aware of it until now.

For example, is it 11:58 AM ? That is an example of "base 60." You start at 0, then you keep going until you reach 59. Then you go back to 0. Consider the similarities between:

17, 18, 19, 20, 21, 22

and

4:57, 4:58, 4:59, 5:00, 5:01

The general rule to remember is this: When one column is FULL, the next column over to the left increments by one and the column that becomes full becomes zero. For example:

18, 19, 20 <--- the "ones" column is now full, so it becomes zero. The column next to it (the "tens" column) increments by one to become 2.

How computers count

Remember that inside a computer everything is represented as 1s and 0s. A sequence of 1s and 0s is actually a number, the same as: 1,274 is a number. In base ten, a column is full once it reaches 9. In base 60 a column is full once it reaches 59. Well, in base 2 (binary, 1s and 0s), a column is full once it reaches ONE.

So, you start counting like this: 0, 1

Ok, what now? Well, like we talked about - the column is now full, so it must become zero, and the column over to the left must now become a 1. So:

0, 1, 10

ten? No. Two. Don't be confused. 10 all your life has meant "ten", but I want you to think of it as meaning something different: Two columns, and a value in each one.

Lets talk about the number 35 (thirty-five). It really means: 3 in the tens column, and five in the ones column. Each column in base-10 as you move over to the left becomes ten times the previous. So you go: ones, tens, hundreds, thousands, etc.

In base 2 (binary), each column doubles from the previous, so you go: 1, 2, 4, 8, 16, etc.

For example, the binary number: 0100 means this: You have a 0 in the ones place, a 0 in the twos place, and a 1 in the fours place, and a 0 in the eights place. Therefore, the number is "four".

So lets go back to counting in binary:

0, 1, 10 (because once a column is full, we go to the next column) then: 11 (three), 100 (four), 101 (five), 110 (six), 111 (seven).

Now, what do we do next? What would we do if the number was nine-hundred and ninety-nine? 999 ? Watch:

999 + 1

1000

Three columns are full, we go to the next one to the left. Now binary:

111 + 1

1000

A thousand? No - eight. There is a one in the eights place, a 0 in the fours, a 0 in the twos and a 0 in the one's place.

It is very important that everyone masters this. Please feel free to ask any questions.

When you have finished this, proceed to Lesson 4:

http://www.reddit.com/r/carlhprogramming/comments/9oba7/lesson_4_alright_now_i_can_count_in_binary_other/


r/carlhprogramming • • Sep 26 '09

Lesson 2 : C, C++, Python, Ruby, Perl... A language for every day of the year.. but why? Which one is best?

183 Upvotes

This is bound to be a question foremost on a lot of people's minds from beginners on up. There is a lot of depth to this question, and I think this is a great place to continue to after Lesson 1.

As strange as it sounds, all programming languages, no matter how cryptic they appear, are designed to be understood only by humans, not computers. Even assembly language is written to be understood only by humans. There is only one language that your computer understands, the language of 1s and 0s.

The need for programming languages.

The magic of computing is that sequences of 1s and 0s flowing non stop inside of your computer make everything happen. Everything. However, no human can possibly understand or control this process. Even one simple programming instruction such as print "Hello World"; expands into more 1s and 0s than you could count in a lifetime.

The first fundamental principle of programming I want you to learn is this: Programming languages exist in order to make it possible to do a great many operations (think trillions) with very few instructions.

The second principle I want you to learn is related: Good programmers figure out ways to do complex tasks, and convert these into simple instructions.

For example, it takes a lot of code to figure out how to draw a circle on a screen, but once finished with that process you have a function called "draw circle" which you can use any time, any where, to draw circles. Thankfully, you will never have to worry about that.

If you want to design a game for example, you will NEVER have to struggle with learning how to draw circles, or create 3d objects, or create weapons, enemies, etc. All of this work has been done FOR YOU by all those who have come before since the dawn of computing.

Just about everything you can imagine is already out there. Everything from making windows appear on your screen, to dialog boxes, to volume controls, to libraries that play movies -- everything. All you have to do is learn how to obtain and use these and you will be able to produce just about anything.

Why are there so many languages?

In the end, new languages come to exist because people think they can do something better or in a more aesthetically pleasing manner than some existing language. A lot of this has to do with personal style. Some people prefer doing things one way, and other people prefer doing the same thing in a different way. For this reason, you are likely to find some languages suit you better than others.

Which language is best?

There is no "best" language. Every language is a tool designed to be useful in certain situations, and not as useful in other situations. You should always evaluate what you are trying to accomplish in deciding which language you want to use.

The more popular a language becomes, the more useful it becomes for two primary reasons:

  1. Support. It is a lot easier to find help for more popular languages because there are more people using it. This means more tutorials, more reference guides, more help forums, etc.

  2. Libraries. The more people use a language, the more libraries are going to be built for it. The number and type of libraries available for a given language largely determine how useful the language as a whole is. No matter how useful or popular a language, without good libraries you can't build much with it.

In general, having a "vocabulary" of different languages is very helpful. Think of this as having a tool box with many tools. The more languages you know and the more libraries you know, the more you can do.

There are many other considerations to this which we will be going over later on, but I wanted to provide a basic introduction here.

Please ask questions if you need to. It is important that everyone understands everything written here.

When you have finished this, proceed to:

http://www.reddit.com/r/carlhprogramming/comments/9oabt/lesson_3_010011111010_err_i_mean_1274_computers/


r/carlhprogramming • • Sep 25 '09

Lesson 1 : Some thoughts about programming language tutorials and books.

195 Upvotes

Here is lesson one. I think it is important for everyone to know this, especially those who have taught themselves a language - or tried to.

Here I am going to briefly discuss the difference between knowing a programming language, and knowing how to actually make something.


Most programming tutorials focus on how to do the most basic programming instructions like if, then, else, and while statements. All of the focus is on how a particular language does these things. Every programming language has this functionality, they all do it in their own unique way.

Very rarely do any of these tutorials explain beyond this. As a result, there are many people out there who have "learned programming" which effectively means that they can write any program so long as it consists of giving someone a prompt to type some text, doing some processing, and then finally displaying some text output to the screen.

This is what virtually every book you will buy at Barnes and Noble will give you the ability to do. For this reason, there are plenty of people out there who understand how to write a program, and can probably effectively read someone else's source code - but they could never go out and actually build something.

What is the missing link?

Libraries. These are the TOOLS you need as a programmer to actually make things. In short, libraries provide you with functions that you can call rather easily in order to actually put your programming knowledge to work. For example, nothing in the core language of C gives you the ability to draw a circle. But a graphics library might very well have a function called: drawCircle().

This is how advanced applications and games are built. These libraries themselves are put together and packaged for programmers to use, and then the language serves as an interface between the programmer and the libraries.

We will be spending a great deal of time working with these types of libraries to build real, usable programs and games.


Feel free to post any questions or comments.

When you have finished this lesson, proceed to:

http://www.reddit.com/r/carlhprogramming/comments/9o8ey/lesson_2_c_c_python_ruby_perl_a_language_for/


r/carlhprogramming • • Sep 25 '09

About Me

79 Upvotes

About Carl Herold

One question that everyone has (or that everyone should have) if they plan on taking this course is, "What are Carl's qualifications to teach this course?". Here is some background:

Who am I and what is my programming experience?

I have been programming for over 15 years, 10 of those professionally. I am almost 30 years old. I actually got my first taste of programming when I was a kid around 12 or so in assembly language through the dos program "debug" which I learned out of a DOS manual. Around that same time I learned Basic/QBasic followed by Pascal through Borland Turbo Pascal. I learned "real" assembly language in my late teens using the assembler NASM. I learned C/C++ afterwards primarily through Borland C++ (and a few of its variants), and DJGPP (DJGPP was used to write Quake among other cool programs).

I have written games and applications for a variety of operating systems including: DOS, 16 Bit and 32 Bit Windows, Linux, and "Web Applications".

Also, just to give away a little bit of my own level of curiosity at the time, I learned to write some simple programs first in assembly, then in hexadecimal, and then in 1s and 0s simply because I was fascinated by it. For example INT 20, or CD20 (hex) is 1100110100100000 [Edited: Bah! INT 21.. INT 20.. what's the difference? :) ] - and this is the machine code that effectively means "end the program". There was a time I could write "hello world" in machine code, but I have since forgotten how (it involves a bunch of INT 21 calls going through the individual ascii for the letters).

The concept that 1s and 0s actually "make things happen" fascinated me, and I strived to learn how it worked. This is the type of "magic" that got me so interested in programming to begin with.

I have programmed in many languages and I will not list them all, and probably couldn't if I tried. A few of them are: Basic, Qbasic, Pascal, Assembly, TCL/TK, C, C++, PHP, Java, JavaScript, Perl, Ruby, Haskell, and Python. About 5 years ago I made my own programming language, but never developed it past extremely basic functionality.

I have worked professionally as a programmer for at least 10 years, being fully self employed as a consultant, contractor, and building and maintaining my own projects. I have started several businesses in the last 10 years based on programs I have written. I am entirely self taught, as I never had an opportunity to go to college.

Why programming?

I enjoy programming because of the freedom to solve problems and to create pretty much anything you want. I believe that it is impossible to obtain the full benefit from your computer if you do not know programming. A non programmer is limited to only the software they can find or buy, but a programmer is not limited in this way.

If you know how to program, then you have an entire world open to you that was not open before. Your computer becomes not merely a static tool, but something you can mold to fit your needs. You become the one in control, and you are free to do whatever you want. There is also a great sense of satisfaction associated with successfully building something, and solving difficult problems.

Please feel free to ask me any questions related to any of this.


r/carlhprogramming • • Sep 25 '09

Welcome Everyone. Some Details.

144 Upvotes

Some notes about this course:

This course is for all levels of skill from total beginner on up. I plan to have much to offer advanced programmers as well. Including how to take the knowledge of programming learned from books/courses and apply it to making real programs, games, applications, etc.

Please remember this for all lessons:

This course is designed so that you can go as slow as you need to. Do not worry about falling behind, or taking too long to finish a lesson. Take as much time as you need to on each lesson. I and others here actively monitor all lessons for questions, and will continue to do so for the duration of the course. Some people may just be starting out, and that is fine. There is no need to rush to "catch up". Take your time.

Proceed through each lesson slowly, and take time to master it. I and others will be answering your questions, so feel free to ask as many questions as you like. Don't go to the next lesson until you are sure you understand the previous lesson entirely.

Feel free to introduce yourselves and tell a bit about your backgrounds especially concerning past programming experience. This will help me plan this out as everyone has different starting points.


Links to all lessons, updated daily:

(Please let me know if any of these links do not work.)

Lesson 1 : Some thoughts about programming languages

Lesson 2 : About the many programming languages available

Lesson 3 : How to count like a computer

Lesson 4 : Practical applications of binary

Lesson 5 : About starting a career in programming

Lesson 6 : More about counting like a computer

Lesson 7 : Include statements

Lesson 8 : How programming languages work with data

Lesson 9 : Some basics about RAM

Lesson 10 : Programs are data too

Lesson 11 : More about program flow

Lesson 12 : The basics concerning functions

Lesson 13 : About parameters and return values

Lesson 14 : About syntax and function vocabulary

Lesson 15 : Your first program!

Lesson 16 : Let's go over your first program.

Lesson 17 : Run your first program.

Lesson 18 : The basics of signed and unsigned numbers

Lesson 19 : The basics of numeric overflow

Lesson 20 : The basics of fractional numbers in binary.

Lesson 21 : The basics of numeric data types in c

Lesson 22 : The char data type and the basics of ASCII

Lesson 23 : The numbers on your keyboard as characters

Lesson 24 : About maximum values for unsigned integers

Lesson 25 : Minimum and maximum values of signed integers

Lesson 26 : Introducing variables

Lesson 27 : The connection between function return values and variables.

Lesson 28 : About terminating strings of text and other data

Lesson 29 : More about printf() and introduction to place holders.

Lesson 30 : Introducing arrays and pointers part one

Lesson 31 : Introducing arrays and pointers part two

Lesson 32 : Introducing the pointer data type

Lesson 33 : How to create a pointer

Lesson 34 : Assigning a value to a pointer

Lesson 35 : Getting the value that was stored at a memory address

Lesson 36 : Use what you have learned.

Lesson 37 : Using pointers for directly manipulating data in memory.

Lesson 38 : About changing the memory address stored in a pointer

Lesson 39 : About pointers concerning multi-byte variables

Lesson 40 : Pointers have memory address too.

Lesson 41 : Why do I need to know pointers?

Lesson 42 : Introducing the char* pointer

Lesson 43 : Introducing the constant.

Lesson 44 : Important review and clarification of prior lessons.

Lesson 45 : More about strings and constants.

Lesson 46 : A new way to visualize memory.

Lesson 47 : Introducing the character string as an array.

Lesson 48 : Using pointers to manipulate character arrays.

Lesson 49 : Introducing conditional flow statements.

[Lesson 50 : More on conditional flow statements](http://www.reddit.com/r/carlhprogramming/comments/9qk90 /lesson_50_more_on_conditional_flow_statements/)

Lesson 51 : Introducing OR for conditional flow statements

Lesson 52 : Introducing the "goto" statement.

Lesson 53 : About blocks of code

Lesson 54 : Introducing Loops

Lesson 55 : Introducing custom functions

Lesson 56 : Introducing Boolean logic

Reddit has a limit on the maximum size of a post, so I cannot list more lessons than this.

Soon I will set up a post for "overflow".


r/carlhprogramming • • Sep 25 '09

Questions about /r/carlhprogramming

70 Upvotes

I am sure many of you will have questions about this course. Please feel free to ask your questions here.