• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Intro to Programming (Code-Free Approach)

Level 31
Joined
Jul 10, 2007
Messages
6,306
Ever wonder how to program? Does the text bother you? Have you always given up in the past?

When programming, there are two portions to it. First, there is the actual programming portion. Second, there is the syntax of that programming. The study of syntax is a whole other thing. Many people teach both syntax and programming together, making it very difficult for new people to learn how to actually program.

This attempts to teach programming and then syntax.

To begin, a program is a set of instructions. The operating system sends these instructions to the CPU, which then executes them. The CPU runs these instructions via electric signals.

When you code a script like JASS, the JASS is translated by Warcraft 3 into the operating system instructions, which are then sent to the CPU. CPU instructions can also be directly accessed nowadays.

There are many different types of programming instructions. From here, these are combined into many different useful constructs, in much the same way that you would combine a lot of different materials to build a table, a chair, or whatever else.

When making a program, you have two types of code. You have executable code and non-executable code (data).

Non-executable code is just a block of memory. If you think about a really, really long road, then a portion of that road would be a block of memory. The entire road would be all of memory.

A block of memory is a group of smaller memory blocks. Each smaller memory block is a group of memory. You, as the programmer, work with the big memory blocks and the smaller memory blocks. You leave the operating system to work with the tiny memory blocks. It'll combine them all up for you. The smaller memory blocks are just called values.

attachment.php


So if you were to have a number like 693, then depending on the computer, it would probably be split up into two pieces of memory (like in the above diagram). When you read this value, you will just see 693. This is because the operating system (or warcraft 3 or whatever) will retrieve these pieces of memory for you and combine them into the 693 that you are seeing.

The first piece of memory in a memory block is where that memory block is located. A programmer doesn't care about the rest. All that matters is where the memory block starts and how long it is.

Block 1 would start at 0 and be of length 3 (remember, programmer's only care about the values, not the blocks). For the operating system, it would be of length 6. In a language like c++, the length would also be 6. You would divide the length by the length of each value to get the value length. In the above diagram, the value length is 2 (there are 2 pieces of memory for each value). The block length is 6 (total memory in block). 6/2 = 3 (this is the number of values in the block).

A block that only has 1 value in it is called a scalar. A block with multiple values in it is called an array. Why make a big difference between the two with the names? Because that's how programming languages are designed. A scalar is just a special case of an array. It would be an array of length 1 (a memory block of length 1).

When you program, you only ever work with scalars. The scalar stores the location of the memory block (its starting position). From here, you can add to the scalar to get to any other slot in the block. For example, in order to get to the first slot in an array, you would add 0. To get to the 5th slot, you'd add 4. Why 4? Check out the following diagram of some general block of memory with 31 values. The positions of the values are labeled relative to the block's address (its position in memory). This means that the 0 here is not 0 in memory, it's 0 + block address.

attachment.php


However, even though memory is so simple, data structures are a huge deal. You can use memory in very interesting ways to create very interesting things.

Many structures are founded on making one piece of memory store the position of another piece of memory.

In the following diagram, suppose that you do not know the length of the block. If you do not know this, then you can only assume that it's a length of 1. However, that first slot stores the position of the next slot that should be read in the block.

attachment.php


So, if we look at slot 0, it tells us to go to slot 16. This tells us to go to slot 5, and so on.

attachment.php


This is what is called a linked list. It's linked because each thing in the list tells us where to go to get to the next thing. It's singly linked because there is nothing pointing back. This is actually how linked lists are done in JASS. You use lots of blocks of the same size. One block will give you this road map (the linked list), the next block might give you a value, and so on. A third block might give you the road map in reverse (how to go backwards). If you know how to go forward and backward, that is called a doubly linked list.

So here is the JASS way of doing linked lists

attachment.php


If you have these 3 blocks, then for any given position, you can read the next position from block 1, the first value from block 2, and the second value from block 3.

Languages like c++ let you create blocks of whatever on the fly of whatever size you like. This is mostly how c++ does linked lists. In a c++ linked list, only 1 value is ever stored. The value points to the block being stored in the list. Notice how these linked lists are limited by computer memory. In JASS, they were limited by the size of the parallel arrays. They also only take up as much memory as needed. In JASS, there was a ton of unused memory. You would be storing 0 (the position of the first block in the list). Really, you would actually be storing a block that pointed to the first block in the list.

attachment.php


Lists are very powerful. Many times, a programmer will not know how much storage they will need for their data. In a game, data is continuously added and removed.

Linked lists are just the beginning. There are many, many, many data structures. These data structures can be layered on top of each other and combined to do some really cool things.

Here is a list of most data structures: http://en.wikipedia.org/wiki/List_of_data_structures. You should strive to learn all of the data structures in that list.

Now that you know about memory and the basics of how it can be used (besides just storing values in it), you are ready to learn about code execution and the various ways to control the flow of how the code is executed.

Recall that a program is a collection of code and data (executable and non-executable data). Up to this point this tutorial has covered non-executable data.

Executable data, just like non-executable data, is stored in memory. It is always stored in a single block of memory (not really, it's a bit complicated in the background, but whatever). The CPU stores a counter, which is the current instruction it is on. It just executes the current instruction and increases the counter. It moves forward in this way forever. If you had a block of memory from 0-31, it would execute all instructions in that block and even move past the 31 and start executing random data. Instructions are just numbers (the CPU has a huge table of instructions and you give it a number for what instruction you want it to execute). As a programmer, we don't have to worry about the CPU too much, but it does help to know how it operates so that we know about the basics of code flow.

If we had a set of instructions

Instruction 1
Instruction 2
Instruction 3
Instruction 4

they would be executed as follows

1, 2, 3, 4

After 4, it would stop. This is thanks to the nice operating system and Warcraft 3. They don't let the CPU spin out of control and blow up.

If you were to write a program, that program's instructions would be executed line by line. A compiler reads your file and translates it into a raw set of instructions. Warcraft 3 sorta does this for JASS.

Most of the programming stuff that people use are actually sets of instructions (one instruction for you in a language is translated into many instructions). This is to make our lives easier. You wouldn't want to write 10-20 lines of code to do 1 simple thing, right? Especially when those 10-20 lines are the same every single time and you have to write them over and over and over again. It gets annoying. That's why languages are made. vJASS was made so that we wouldn't have to work with fugly raw parallel arrays, triggers, and so on. You saw those blocks for a list. Imagine if you had 500 of them in a map. Now you have to search through 500 different blocks and try to remember what blocks go with what. Yea, not fun.

One of the most useful instructions that a CPU has is a jump statement. This lets you essentially set the program counter. In effect, you can jump from one line of code to another line of code. Besides this, the CPU also has conditional jumps, meaning that if a condition is true, then you do the jump. These two things put together will define all of our instruction flow.

The first type of flow is what is called a function. If you imagine a block of instructions, a function would be that block. If you were to run a function, the program counter would jump to the start of that function and start executing it. At the end of that function, it would jump back to where it was.

In the following diagram, somethings runs Function A. Function A eventually runs Function B. Return returns to the calling function. When Function B returns, it goes back to Function A and continues execution from where it left off. When Function A returns, it goes back to whatever called it and that thing continues executing from where it left off.

attachment.php


What if you wanted to somehow give a function a set of values to work with?

Suppose you had a function called beat eggs. It should perhaps know how fast you want to beat the eggs and how many eggs you want to beat.

Function: Beat Eggs
Parameter 1: How Fast To Beat The Eggs
Parameter 2: How Many Eggs To Beat

And then maybe, when it returns, it gives the calling function the eggs.

How would this be done? Remember, you have a bunch of memory to work with. Let's say that every function has a block of memory for it called Parameters. You store your values into this block and then call the function. When the function finishes, it has another block called Return. It stores whatever values it wants to return into this block and you, the calling function read it. This would be one way to do it. The cool thing is that programming languages do all of this for you automatically in the background, so you don't have to worry about it. You just have to let everything know what the function takes and what the function returns.

Function: A
Parameters: Value1, Value2, Value3
Return Parameters: Value4

The next flow is the conditional jump. If the condition is false, a jump is performed. Most languages expand on this by adding some more jumps. At the end of the first instruction set (where no jump happened), it will jump to the end of the second instruction set (where the jump happened).

attachment.php


There is a further expansion where you actually have a set of conditional jumps. This is normally implemented by using nested conditional jumps. The result is the following diagram.

attachment.php


The final type of flow that this tutorial will be covering is the loop. It jumps back to a first instruction. Within the loop, you can place what is called a break. A break jumps outside of the current flow. For example, in those if statements, it would jump to the regular instruction. Most languages only allow you to break out of loops and what are called switch statements.

If you want a conditional break, put it inside of a conditional jump.

attachment.php


You should now be capable of studying the syntax of a language of your choice. I recommend JASS followed by c++.



Learn 5 languages + UML (while doing the stuff below): python, c++, java, haskell, scheme

Data structures: http://en.wikipedia.org/wiki/List_of_data_structures

After you get through trees, start learning algorithms (continue and finish data structures)

http://en.wikipedia.org/wiki/List_of_algorithms

After algorithms, start on design patterns

http://en.wikipedia.org/wiki/Software_design_pattern#Classification_and_list
http://en.wikipedia.org/wiki/Architectural_pattern#Examples
http://en.wikipedia.org/wiki/Interaction_design_pattern

After design patterns, work on set theory

http://en.wikipedia.org/wiki/Set_theory

Finish learning the 5 languages and all of the stuff above.

next, study computer architecture (study verilog and c too)

http://en.wikipedia.org/wiki/Computer_architecture

Now study databases with web design (html, javascript, php, web java, SQL, asp.net with c#, perl, XML)

Next, study compilers (Antlr + optimization) (thorough), operating systems (thorough), networking (intro), HCI (intro), computer graphics (intro), and AI (intro), mobile development (intro with objective c).

Finally, learn these languages: Lua (embed it), lisp, prolog, assembly, erlang

Start working with a team on some open source project (check github or some other site). You should know how to use svn and git. Be sure to significantly contribute to at least 4 projects that are not your own. This will get you used to working with others and teach you about the stages of software development.

After you do all of this, you should be a master programmer. You'll then be able to specialize in a specific field and you'll be able to work on research to expand that field.
 

Attachments

  • 1.jpg
    1.jpg
    116.7 KB · Views: 473
  • 2.jpg
    2.jpg
    31 KB · Views: 427
  • 3.jpg
    3.jpg
    32.2 KB · Views: 439
  • 4.jpg
    4.jpg
    21.6 KB · Views: 469
  • 5.jpg
    5.jpg
    94.1 KB · Views: 465
  • 6.jpg
    6.jpg
    44.5 KB · Views: 473
  • 7.jpg
    7.jpg
    44 KB · Views: 482
  • 8.jpg
    8.jpg
    24.6 KB · Views: 415
  • 9.jpg
    9.jpg
    20.3 KB · Views: 437
  • 10.jpg
    10.jpg
    19.2 KB · Views: 443
Last edited by a moderator:
Level 31
Joined
Jul 10, 2007
Messages
6,306
If by the ending you mean

Where to go from here?

Then I just put that up there if people want to continue studying past this point. They'd have to do a lot of their own research or take classes ;).

The end part should take you a few years to complete. Probably 4-5. Whoever completes it will be a super programmer >.<. They should also study physics and math :\. Studying simulation physics alongside physics would be very good.


The intended audience is people that know nothing about programming but would like to learn :). This tutorial takes the approach of syntax being a different issue from programming.

This tutorial does cover a lot very quickly, but by covering it this way, people won't be bothered later by pointers, passing by reference vs by value, and so on. They won't even have to worry about all of these things that universities normally teach because they will understand it intuitively as they have this good foundation to work off of.
 
Top