PDA

View Full Version : Learning Basic Programming in the Playground



MethosH
2009-10-27, 10:33 PM
Welcome to "Learning Basic Programming in the Playground"!

We have seen many threads about "hey, I want to learn how to program" or "I have a question about C" and even "How the heck to I program games? o.O".

And those threads will just keep coming, so why not make something of it?

The idea of this thread is for us, Programmers in the Playgrounds, to write/share some tutorials and basics for the starters, suggest compilers and reply to questions.

Every F.A.Q. and tutorial that end here I'll put on the main post.

I don't have time to write anything specific right now (since it is 1:37 am and I need to be up in 4 hours), but tomorrow I shall start my first tutorial for those that want to learn the basics of programming.

This thread is just starting up, so it will be prettier with time! Trust me :smallbiggrin:

The first step:

First steps: 1 - What is programming and algorithms? (baby steps and the "if then else" statement.

First ask yourself this... Do you know what it means “programming”? Do you know what an algorithm is? What a compiler is? What a programming language is? Before you even start rushing on Java or anything you think grownups use to make those nice games you play you need to understand those things.

If you feel you want to jump right into the action of basic logic you may as well skip this next step. (That is why I’m putting it under spoilers)


The act of programming is using logic and applied math in algorithms to solve problems.
Some may say that you need the knowledge of the technology, but the technology itself is just a tool for the programmer craft, it isn’t the soul of programming.

As Wikipedia would say, algorithms are effective methods for solving problems using a finite sequence of instructions.

Your work as a programmer is to figure out how to solve those problems. Think of algorithms or even use some that are around and are clever solutions. Now let’s talk about the logic behind them.


On every code from now on I’ll use a didactic tool called “pseudo-code”. A pseudo-code is a form of algorithm that does not correspond to any programming language, but is a set of instructions that humans can easily understand.

Now that you understand that an algorithm is a set of instructions you need to know what those instructions are.

Since we are working in a pseudo-code they can be anything you like. Let’s work a sample up so you understand it better.

Say we want the computer to make us a sandwich, first we will tell him what we are trying to do and then tell him what to do. Something like this:

Make me a sandwich:
Get bread.
Get meat.
Get tomato.
Get mustard.
Cut bread.
Get 2 pieces of bread.
Put meat on first piece.
Put tomato above the meat.
Put mustard above the tomato.
Put second piece of bread above mustard.

There you go, we have a very logical sandwich, this is pretty straight forward, but it isn’t very fun. It actually sounds kind of dumb. So let’s make things interesting.

Say we want to do something that forces the computer to make a decision, how will we do that? For example we want the computer to let us know if a given bread is rotten. We know that a bad bread has those nasty green spots. So we let the computer know that.

Is the bread rotten?
Get bread.
Does bread have green nasty spots?
If yes then
Show us it’s not good and throw it away.
Else
Make me a sandwich.

Pretty simple isn’t it? This is the basic “If then else” statement and you will find it in most of computer languages.

Well, that is all for know. I’ll be back later with another topic. Next part: Variables and Loops.



Tutorials:

Python

Python 2.x tutorial (http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python/Intro) (Thanks Fostire)
Python 3.0 tutorial (http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3) (Thanks Fostire)


HTML

Basic HTML by Jokasti


I know TI-Basic, HTML/CSS, and Java, so here's some HTML Basics:
(follow along in Notepad for best results)
HTML is used to make text look better. That is it's fundamental objective.
In HTML, text is in tags. Tags are the < and > signs, and look like this:
<html>
The <html> tag is used to start an HTML document, and </html> closed the document. In most cases, if you open a tag ( <blah> ) then you must close the tag ( </blah> ).
Essentials in a HTML Document: <html> tag, <head> tag, and <body> tag.
Each of these tags needs to be closed. So a basic document is:
<html>
<head>
My Webpage
</head>
<body>
This is my text.
</body>
</html>

That is the format for most HTML documents, but when you get into more serious stuff that changes.
The <title> tag is used to put a title on a page. See up there on the tab where it says "Giant in the Playground..."? That's the title. The <title> tag goes in the <head> and must be closed. So:
<html>
<head>
<title>
My Webpage's Title
</title>
My Webpage's Head
</head>
<body>
This is my text.
</body>
</html>

If you save these with a name, and then add .html to the end, you can open them in your browser.
That's the basics, and I'll add more later.



TI-Basic:

TI-Basic by Jokasti


TI-Basic
--------
For use on a TI-83 calculator and up.
~
To begin, hit that Program Key. Usually it is "PRGM" and near the middle.
You should see three options, "EXEC, EDIT, and NEW".
You can Execute code in EXEC, edit it in EDIT, or create a new program in NEW.
For now, hit NEW, and type in the name of the program.
The first thing you need to learn is the DISP function. It displays text and variables on the screen. To get to it, go to I/O (for Input/Output), and it should be the third option. Hit ENTER, and DISP is now in your program.
It should look like: PRGM:NAME
:DISP
Then hit ALPHA, " " (for a space), and open quote ".
Type any text you want, and end it with another quote ".
Will continue later.



C#:

A small guide for new C# users (http://msdn.microsoft.com/en-us/beginner/bb308756.aspx) (Thanks Rowsen)




Exercises:


General:

A quick exercise by pendell:


Okay guys, Here's a quick exercise:

Reverse a singly-linked list.


That's an elementary question that gets asked a lot during job interviews to separate real programmers from people without IT background who read up on the buzzwords and are faking it on their resume. It's a question any second year CS student should be able to answer. Bonus points if you can do so without allocating new memory.

Respectfully,

Brian P.





Others:

Why not use GOTO?

http://imgs.xkcd.com/comics/goto.png

DoomITP
2009-10-28, 08:36 PM
This looks like it'll be useful once people find some tutorials for it.

Fostire
2009-10-28, 09:07 PM
Python 2.x tutorial (http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python/Intro)
Python 3.0 tutorial (http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3)
They're both the same tutorial except that one was updated to Python 3.

They're both very simple and great for beginners.

someonenonotyou
2009-10-28, 09:08 PM
Cool i always wanted to try Programming but im a GIANT procrastinator

Jokasti
2009-10-28, 09:33 PM
I know TI-Basic, HTML/CSS, and Java, so here's some HTML Basics:
(follow along in Notepad for best results)
HTML is used to make text look better. That is it's fundamental objective.
In HTML, text is in tags. Tags are the < and > signs, and look like this:
<html>
The <html> tag is used to start an HTML document, and </html> closed the document. In most cases, if you open a tag ( <blah> ) then you must close the tag ( </blah> ).
Essentials in a HTML Document: <html> tag, <head> tag, and <body> tag.
Each of these tags needs to be closed. So a basic document is:
<html>
<head>
My Webpage
</head>
<body>
This is my text.
</body>
</html>

That is the format for most HTML documents, but when you get into more serious stuff that changes.
The <title> tag is used to put a title on a page. See up there on the tab where it says "Giant in the Playground..."? That's the title. The <title> tag goes in the <head> and must be closed. So:
<html>
<head>
<title>
My Webpage's Title
</title>
My Webpage's Head
</head>
<body>
This is my text.
</body>
</html>

If you save these with a name, and then add .html to the end, you can open them in your browser.
That's the basics, and I'll add more later.

~~~
Personally, I learned the basics of HTML from Neopets (www.neopets.com), and then when I was curious, went to w3schools (www.w3schools.com). If you think you understand it, give them a shot.

MethosH
2009-10-28, 09:46 PM
Thank you guys for your contribution :D
I'll write something more basic for those that really know NOTHING about it (Like basic logic and basic compilers and stuff) as soon as I get back home (day 3).

I've updated the thread.

Jokasti
2009-10-28, 10:11 PM
TI-Basic
--------
For use on a TI-83 calculator and up.
~
To begin, hit that Program Key. Usually it is "PRGM" and near the middle.
You should see three options, "EXEC, EDIT, and NEW".
You can Execute code in EXEC, edit it in EDIT, or create a new program in NEW.
For now, hit NEW, and type in the name of the program.
The first thing you need to learn is the DISP function. It displays text and variables on the screen. To get to it, go to I/O (for Input/Output), and it should be the third option. Hit ENTER, and DISP is now in your program.
It should look like: PRGM:NAME
:DISP
Then hit ALPHA, " " (for a space), and open quote ".
Type any text you want, and end it with another quote ".
Will continue later.

Dr Bwaa
2009-10-28, 10:35 PM
I'll write a Scheme intro because Scheme is way fun :smallbiggrin: Give me a few hours; I should be able to put it up tonight and you can just link to the post =)

Decoy Lockbox
2009-10-28, 10:54 PM
TI-Basic
--------
For use on a TI-83 calculator and up.
~
To begin, hit that Program Key. Usually it is "PRGM" and near the middle.
You should see three options, "EXEC, EDIT, and NEW".
You can Execute code in EXEC, edit it in EDIT, or create a new program in NEW.
For now, hit NEW, and type in the name of the program.
The first thing you need to learn is the DISP function. It displays text and variables on the screen. To get to it, go to I/O (for Input/Output), and it should be the third option. Hit ENTER, and DISP is now in your program.
It should look like: PRGM:NAME
:DISP
Then hit ALPHA, " " (for a space), and open quote ".
Type any text you want, and end it with another quote ".
Will continue later.

I love programming on the TI-83. I mean, the language sucks and the text-entering is awful, but its so handy sometimes. Back in 8th grade I wrote a program that found the roots for a quadratic equation, then sold copies of it for 25 cents a pop. Oh, those were the days....:smallbiggrin:

Plus, you can write equations and formulae as text in a "program" and use it to gain an almost certainly illegitimate leg-up on tests. I don't recommend doin' this, but, you know, just sayin'

One nifty resource for learning programming languages or practicing are college compsci class web pages. They have programming projects that can be completed or attempted to practice various aspects of the language. For example, if you wanted to learn about hash tables via writing a rudimentary tic-tac-toe AI in java, you could go here (http://www.csee.umbc.edu/courses/undergraduate/341/fall08/projects/proj4/341-fall08-p4.shtml)and check that out. Its almost like taking a college class, minus the lecture, for free. Actually, given that many college students don't go to class at all, its more or less just like taking a college class for free.

pendell
2009-10-28, 11:21 PM
I strongly encourage everyone learning programming to study patterns (http://en.wikipedia.org/wiki/Design_pattern_(computer_science)) and anti - patterns (http://en.wikipedia.org/wiki/Anti-patterns).

These are general concepts that show up in all languages. Patterns (used appropriately) work in every language well. Anti-patterns are foobars that can be done in any language.

I would also strongly recommend that everyone study programming languages from multiple families, if they want to understand programming. Families include:

-- object-oriented (C++, Java, Smalltalk)
-- structured (c, pascal, FORTRAN)
-- functional (LISP here (http://savannah.gnu.org/projects/gcl/)).

The more ways you understand programming, the better handle you have on the concepts.

I will try to contribute to this when I can.

Respectfully,

Brian Pendell

Jokasti
2009-10-28, 11:49 PM
I love programming on the TI-83. I mean, the language sucks and the text-entering is awful, but its so handy sometimes. Back in 8th grade I wrote a program that found the roots for a quadratic equation, then sold copies of it for 25 cents a pop. Oh, those were the days....:smallbiggrin:

Plus, you can write equations and formulae as text in a "program" and use it to gain an almost certainly illegitimate leg-up on tests. I don't recommend doin' this, but, you know, just sayin'

One nifty resource for learning programming languages or practicing are college compsci class web pages. They have programming projects that can be completed or attempted to practice various aspects of the language. For example, if you wanted to learn about hash tables via writing a rudimentary tic-tac-toe AI in java, you could go here (http://www.csee.umbc.edu/courses/undergraduate/341/fall08/projects/proj4/341-fall08-p4.shtml)and check that out. Its almost like taking a college class, minus the lecture, for free. Actually, given that many college students don't go to class at all, its more or less just like taking a college class for free.
That's how I learned, Trial and Error.
I sold soooooooooooooo many programs.
I remember PSAT's were the best times to sell memory programs with lists of math functions/equations and how they should be used.
I also had a teacher that periodically looked at the memory of every calculator, but I made an Output() program that looked exactly like the memory screen.
Good times.

Dr Bwaa
2009-10-29, 02:45 AM
I'm going to point you guys at the Scheme guide I promised, which, naturally, has gotten wildly out-of-hand as soon as it started. It's not done yet; it'll take me a couple days, but I put it in its own thread (http://www.giantitp.com/forums/forumdisplay.php?f=29) so as not to clutter up this one with comments/suggestions. If any of you guys feel like heading over there and giving me your thoughts, it would be sweet! I'll post in here again when I get it finished so you can link it :smalltongue:

MethosH
2009-10-29, 07:46 AM
Nice to see that this thread is actually on the move :)
I'll be away for a few days (5 days) but keep posting your contributions, I'll update the thread as soon as I get back

Archonic Energy
2009-10-29, 09:50 AM
10 print "hello world"
20 goto 10

Run

oh you meant basic not BASIC :smallwink:

Rowsen
2009-10-29, 10:43 PM
A small guide for new C# users:
http://msdn.microsoft.com/en-us/beginner/bb308756.aspx

Yes, it's written for kids but it's quite a decent guide. My programming teacher refers us to it all the time :smallbiggrin:

pendell
2009-10-31, 08:39 AM
Okay guys, Here's a quick exercise:

Reverse a singly-linked list.


That's an elementary question that gets asked a lot during job interviews to separate real programmers from people without IT background who read up on the buzzwords and are faking it on their resume. It's a question any second year CS student should be able to answer. Bonus points if you can do so without allocating new memory.

Respectfully,

Brian P.

Evilfeeds
2009-10-31, 10:44 AM
Few small points.

I think that if you're attempting to create a programming thread, you really want to focus on a single language, rather than having a dozens of tutorials for a variety of things. Imo, the best languages to teach people are Java, Python, C# and ActionScript.

Writing HTML isn't programming. [1]

Tutorials on how to program a calculator doesnt seem particulary useful. Its cool to show off to your friends if you happen to have that calculator, but its a very limited programming environment, and you really can't do huge amounts with it.

The XKCD comic doesnt really belong here. Yes, I know xkcd is teh lolz, but putting it there wont actually help anyone understand why you shouldnt use goto. (Aside from that, goto is a perfectly acceptable command when you know what your doing).

I'd suggest that, if your serious about trying to teach programming, pick a structered, free language (java, for example) and write a bunch of tutorials for that, starting with the basics (how to install eclipse) running up to bouncing a ball around on screen.


[1] I suppose HTML 5.0 could be, but I dont think thats what was meant.

pendell
2009-10-31, 09:36 PM
Few small points.

I think that if you're attempting to create a programming thread, you really want to focus on a single language, rather than having a dozens of tutorials for a variety of things. Imo, the best languages to teach people are Java, Python, C# and ActionScript.



I disagree.

I have written professionally in JAVA, C++, Smalltalk, Fortran, PERL, and a host of other languages. The principles of good programming are the same in any language. Once you understand the *concept* of programming,
learning the syntax and unique features of a specific language is fairly trivial.

This is the whole point behind software patterns, which I linked to upthread.
There are certain problems which crop up over and over again throughout
programming, and the standard solutions can be implied in any language.
These are called patterns.

There are also mistakes people make over and over again which show it's possible to truly f*** up in any language. Spaghetti code, poor comments, the project Death March, the undocumented mass of features known as the ball of mud -- these world-class goofups occur in all languages, whether you're writing in COBOL or Python.

These are called "anti-patterns", also linked upthread.

Thus: If you want to be a good programmer, understand the basic concepts which underly all programs. At their most basic, all programming languages implement the same basic artifact: The Turing machine (http://en.wikipedia.org/wiki/Turing_machine).

As such, there are some very basic commonalities that exist in all programming languages. Understand those commonalities, and you're well on your way to being a superb developer regardless of the language you choose.

Fail to understand these basic concepts, you're going to have trouble being good regardless of what language you choose.

Respectfully,

Brian P.

Evilfeeds
2009-10-31, 11:03 PM
Stuff

You're seriously trying to argue thats theres no difference between learning fortran and learning java?

Hell, even the difference between C++ and Java is massive.

Its not enough to learn "the principles of good programming" - you need to actually learn how to code. Also, people dont want to read 4000 books on avoiding gotos and spaghetti code and code maintainance - they want to learn how to move a shape about on screen, and be able to say "i did that". Preferably in less than an hour. Once they have the basics, THEN you can start worrying about programming principles.

bluewind95
2009-10-31, 11:07 PM
For the very, very basics of programming (For those who have never plunged into the murky depths of it before), I think the logic comes first.

I think a good tool would be this program called Raptor, in which you do flow charts and you can run them to test your logic.

pendell
2009-11-01, 01:36 AM
You're seriously trying to argue thats theres no difference between learning fortran and learning java?


You are exaggerating my statement.

Yes, there are differences between the languages; but my experience is that language is a tool, not the thing itself. Once you've reached a certain point in your career -- mine was third-year computer science -- when the tools become more or less interchangeable.

I have successfully run a 15 year career (so far) on this principle, as have the other two highly skilled developers in my office.

Of course there's a big difference between learning fortran and Java, they are from different families altogether. Java is object-oriented, FORTRAN is structured.

So perhaps I was a bit imprecise: There are overall principles of programming that apply to all languages.

There are additional principles that apply within different language families.



Hell, even the difference between C++ and Java is massive.


You think so? I think Java's an excellent trainer for C++, because it teaches solid object-oriented practices without any of the horrible gibberish we find
in C++ (multiple inheritance? Passing pointers by pointers to change the value of a parameter? "Friend" protection level? Malloc? BLAH).

In any case, but the difference between Java and Python and Smalltalk are much less. Similarly, the differences in programming FORTRAN and programming BASIC and Pascal.



Its not enough to learn "the principles of good programming" - you need to actually learn how to code. Also, people dont want to read 4000 books on avoiding gotos and spaghetti code and code maintainance - they want to learn how to move a shape about on screen, and be able to say "i did that". Preferably in less than an hour. Once they have the basics, THEN you can start worrying about programming principles.

Who said learning the principles was enough? Of course you need hands-on practice, and a lot of it -- but if all you have is practice in one language, in one way of doing things, you're going to be fairly limited both in technical skill and what you can do.

Certainly that's the case if someone is in junior high or high school and is just barely starting out. But if you want to program professionally, it is important to be able to program *well*. Code samples developed independently are standard in interviews for technical positions, even at the entry level.

In my line of work, it isn't uncommon to get an assignment in a language we've never seen before, using libraries never seen before. In five days. Again, this is basic entry-level job interview screening.

When I was in college, we were taught exactly one language -- Pascal. In our second year courses, all the courses were taught in C. We didn't get the benefit of a multi-week course in programming in C. Instead, on the first day of class the instructor effectively said this: "How many of you know C? Good. The rest of you? Learn it. Here's your first assignment."

You can do this sort of thing if you understand good programming in general as well as a specific language.

So I stand by what I said, but I will amend it slightly:

Yes, it is important to get a language and get hands-on experience with it.
But your professional ability will be greatly enhanced if you not only play with the language, but read up on the general principles, which will stand you well across all languages you encounter. If you have such a grasp, it will be far easier.



I think a good tool would be this program called Raptor, in which you do flow charts and you can run them to test your logic.


For object-oriented programming, I strongly recommend UML (http://en.wikipedia.org/wiki/Unified_Modeling_Language). Very few shops use flow charts any more.

Respectfully,

Brian P.

MethosH
2009-11-06, 06:13 PM
Few small points.

I think that if you're attempting to create a programming thread, you really want to focus on a single language, rather than having a dozens of tutorials for a variety of things. Imo, the best languages to teach people are Java, Python, C# and ActionScript.

Well... If we focus on a single language it wouldn't be a programming thread. It would be a programming language thread.



Writing HTML isn't programming. [1]


Not arguing. Get over it.



Tutorials on how to program a calculator doesnt seem particulary useful. Its cool to show off to your friends if you happen to have that calculator, but its a very limited programming environment, and you really can't do huge amounts with it.


It turns out to be very useful if you happens to have a caculator :smalltongue:



The XKCD comic doesnt really belong here. Yes, I know xkcd is teh lolz, but putting it there wont actually help anyone understand why you shouldnt use goto. (Aside from that, goto is a perfectly acceptable command when you know what your doing).


If you can't lol at XKCD you shouldn't be programming! lol :smallbiggrin:
Now seriously... If people think it is a bad thing to have a XKCD comic on "others" I'll take it off. For now I think it is funny :smalltongue:



I'd suggest that, if your serious about trying to teach programming, pick a structered, free language (java, for example) and write a bunch of tutorials for that, starting with the basics (how to install eclipse) running up to bouncing a ball around on screen.


Not trying to "teach"... I'm more trying to help and support. And point ways... And give programmers a place to help each other on the playground... I'm thinking now that I need to change the thread name.

----

On another note:
I've uptade the thread and I'll start a tutorial on basic logic.

MethosH
2009-11-06, 08:04 PM
Done, I've added the "First Step" section. This is were all people that don't know ANYTHING at all should go first : )