dsavi Posted January 26, 2010 Share Posted January 26, 2010 This guide explains what programming is, and gives a short overview of different programming languages. If you want to learn a specific programming language, I'm sure there will be other guides. What is programming? Programming is, in short, the process of developing a computer program by giving instructions to your computer. It is much like making a recipe. This is a good metaphor, because most people are familiar with the process of cooking and don't have a problem imagining how you would make a recipe. The general process of making a program, along with a continuation of our cake metaphor, is: 1. Planning. Thinking about what the program should do, what the program shouldn't do, and how it should do it. This is like thinking about what you want a cake to taste like. 2. Coding. This means writing the actual code (Using a programming language) that implements the idea that you have of how your program should work. A simple idea can be surprisingly difficult to express in code! This is like writing the recipe itself, "Mix the dry ingredients with the milk" etc. to create the cake of your dreams. 3. Compiling. This is the process, done automatically by a separate program called a compiler, that translates your code into something a computer can understand called binary. This does not always apply to some languages like Javascript, PHP, and Python: They are compiled when they are run. This is like following the recipe you just wrote, and then putting the cake in the oven. Just like compiling, baking the cake can take some time. 4. Debugging. There will be bugs. The code may make sense to you, but remember, computers do everything you say, no more, no less. You may have forgotten a character here or there, written faulty code, or just generally done something wrong. Whatever it is, it means that your program isn't doing what you want or worse, doing something you don't want. This means you have to go back to step two and look for the problem and if possible, fix it. This is like finding out that you left out the sugar in said cake of your dreams, so you go back and change the recipe. Debugging can take a long time and be very frustrating. 5. Running the program. Well, this isn't really technically part of programming, but it's almost inevitable that you'll want to run your program once you finished it even if you didn't write it for yourself. It's incredibly satisfying, just like eating the finished cake you just made. It's what makes programming worth it. That's a very basic overview of making a program. In the real world if you program professionally, you will very likely have to document your code to tell people how it works so that they can extend it or fix bugs. So what's a programming language, then? A programming language is a language that a compiler can translate into instructions that a computer's processor can execute. Human languages are full of complexities that are often even difficult for other humans to understand, let alone computers. So various programming languages have been invented that have strict rules and simple syntax and grammar. High and low level programming languages One thing that is often said about programming languages is that one or another is a "High level" or "low level" programming language. A low level programming language is quite close in syntax to the instructions given to a processor, and is therefore often incredibly difficult to learn and understand. A high level programming language is closer to human languages, and 99% of the time requires far less code to express an idea and is therefore more often than not very easy to learn and understand. Why use low level programming languages at all, then? Well, since they are so close in syntax to the instructions given to a processor, it requires less instructions to execute which makes it faster and possibly use less RAM. However, since it requires a lot more thought on the part of the programmer, it is often very impractical to write more than 20 lines of it. High level languages are the other way around; Ideas are expressed easily and you can code almost as fast as you can type but the resulting program is almost always slower. An example of a high level programming language is Javascript or PHP (Which are both usually compiled every time they are run), and an example of a low level programming language is assembler, which is possible to even compile by hand. Languages like Java, C, and C++ are somewhere in between, giving a balance between speed and how fast they can be coded. Just to compare, take a look at an example of a very low-level language (ARM assembly language):BUILD MOV R0, R1 ; Move numbers into R0 SUB R2, R2, #1 ; Decrement R4 ADD R1, R1, #1 ; Increment R3 STR R0, [R3] ; Store the value from R0 into memory (only stores a 1) ADD R3, R3, #4 ; Increment the pointer by four bytes (definitely works) CMP R2, #0 ; Is this number in R0 equal to 32 (stopping point)? BNE BUILD ; Start all over again if they're still not equal. MOVEQ R11, R3 ; Hey, we have the end of the array, let's keep that. SUB R11, R11, #4 ; //Offset by 4, ran into this bug earlier. MOVEQ PC, R14 ; Return to main when finished.No, I don't know what it does either. :lol: And now look at a higher level language, any of the examples of programming languages below should show you the difference in readability. Basic programming terminology: VariablesJust like in math class, a variable is a number usually represented by letters because the actual value can change. Variables are the nouns of programming languages. Functions A function is code that has been written so that it can be used over and over again. Functions are the verbs of programming languages.An example of a function, in C: (C++/Java/PHP have similar syntax) #include <stdio.h> int somefunction(void) //Declare a function called "somefunction", see "return variables" and "arguments" to see what the "int" and "void" are there for. { //Any code you want goes in here. I put some in just to make it do something. int i = 0; if (i == 0) { printf("Hello\n"); } return 0; //See "return variables" to see why this is here } This way, you can "call" the function by stating the name of the function in your code:#include <stdio.h> int main(void) { somefunction(); //Does whatever has been written in the above example, in this case prints "Hello" } Arguments A function often accepts arguments, which are values (Often variables) that change the way the function is run.In the function declaration (In the place the function is defined), the arguments are described. The name and data type (See data types below) are always defined, if any argument is defined. The default value can also be defined, but is optional. The default value is the value used if the argument is not defined when a program calls the funciton. #include <stdio.h> int somefunction(int variable1, char variable2[], int variable3 = 3) //function "somefunction" accepts three arguments, the first two are integers and the last is a character string. variable3 is 3 by default. { printf("%i\n", (variable1 + variable2)); //Print the sum of variable1 and variable2 puts(variable3); //Print variable3 return 0; } You can "call" this function like this: somefunction(5, "Hello World", 7); //Prints the sum of 5 and 7 and the text "Hello World" Optionally, however, you can call it without specifying the last variable, because we gave it a default value: somefunction(5, "Hello World"); //Prints the sum of 5 and 3 and the text "Hello World". We specified variable3 to be 3 if it wasn't specified when the function was called, remember? Return variables Return variables are values "returned" by functions. To see what is meant be "returned", consider the following function:#include <stdio.h> int testReturn(void) //Function "testReturn" returns an integer value { return 0; //All this function does is "returns" 0. } Now, look at how this function can be used:int var; //We have a variable "var", which is an integer var = testReturn(); //var becomes whatever testReturn() returns, in this case 0. So how is this useful?Well, imagine you want a function that processes a variable, doing this and that with it without changing any of the variables passed to it as arguments.#include <stdio.h> int processVar(int exampleVar) { int i; int j; for (i = 0; i < exampleVar; i++) { j += (exampleVar + i); //Add (exampleVar + i) to j } return j; } Now, this program does absolutely nothing that is useful, but it illustrates how returns are used. To get the return variable from this function, it's just the same as before:#include <stdio.h> int main(void) { int a = 5; int b; /*Line 1, see below*/ int b = processVar(a); /*Line 2, see below*/ printf("%i\n", <img src='http://forum.tip.it/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' />; } Or, for short you could merge lines 1 and 2, like this:int b = processVar(a); b receives the value returned by processVar. Simple as that. Conditionals Conditionals designate blocks of code to be run under certain conditions. Often the case is that if an expression is evaluated to be true, (Like if a variable is true) then a certain line(s) of code is run. Conditionals can be extended to run different code if one expression evaluates to false but another to true, or if two expressions evaluate to true etc. Two basic examples of the two most important types of conditionals, in C, C++, or Java: (Most languages use this syntax or very similar)bool largerThanFive, lessThanFive, equalToFive, wut; int var = 3; //Our variable has a value of 3. //The most common type of conditional: The If-Then-ElseIf-Else if ( var > 5 ) //If the our variable var is larger than five... (Which it is not) { largerThanFive = 1; //This code would run if var was larger than five. lessThanFive = 0; } elseif ( var < 5 ) //If our variable var is less than five, which it is... { largerThanFive = 0; //Then set largerThanFive to false (Zero is false) lessThanFive = 1; //and lessThanFive to true (Larger than or less than zero is true) } elseif ( var == 5 ) //If our variable actually is five, which it isn't either (Notice the two equals signs) { equalToFive = 1; //Then set equalToFive to true. } else //If *none* of those things are true about our variable... { wut = 1; //Well then it's not a number anyway, or it's eleventeen or something. In anycase, wut. } Loops Loops are a way of repeating code without writing the same code more than once. Not only do they clean up your code, but they allow you to also tell the computer when to stop running code instead of running it a fixed number of times. There are four kinds of loops, the for, while do-while and foreach or enhanced for. 1. for for does four things, in this order:1. Sets up the loop, often by assigning a value to a variable. The loop does this once. (Or, optionally, not at all. The first three steps are actually unnecessary if you want an infinite loop, a loop that does not end)2. Tests an expression for true or false, like the if-then-elsif-else conditional. Also optional.3. Executes code if the expression is true, stops the loop if the expression is false and continues on with the program.4. Executes code, most commonly incrementing (Adding 1 to) a variable. Go back to step two. int i; for (/*Step one*/i = 0; /*Step two*/ i < 2; /*Step four*/ i++) { /*Step three. Notice: three.*/ printf("Davis is awesome."); /*I have bad self esteem, ok? This is my programmer's approach of fixing it. :P */ }What this program does:1. Make i zero.2. If i is less than two, then go to the next step. If not, exit the loop.3. Print "Davis is awesome".4. Add one to i, and go back to step two.So it prints "Davis is awesome" five times. So true, so true. :razz: But why three times, and not two, like it looks at first glance? Because i starts from zero. (0 - 2 = -3, so the code is run and therefore i is incremented three times.) 2. while while is a simplified version of for. It only tests an expression and executes code instead of setting up the loop and executing other code as well. It works like this: 1. Test an expression, if the expression is true continue to step two. If false exit the loop.2. Execute code, go to step 1. int i = 0; while (i < 5) { printf("Davis is awesome."); i++; }As you can see, if you want to set up the loop, you have to do it outside. 3. do-while do-while is a slightly different type of while loop. It has a separate part that is always executed at least once, and before each iteration of the loop.int i = 0; do { i++; } while (i < 5) { printf("Davis is awesome."); } 1. i is incremented.2. If i is less than five, go to next step. Otherwise, end the loop.3. Print "Davis is awesome.". Go to step 1. As you can see, the three basic types of loops do pretty much the same thing. foreach, however, is mostly for iteration through arrays or array-like variables. 4. foreach foreach, or enhanced for, is for looping through arrays. It works like this: 1. Go to the next array member, or if the array has ended, exit the loop.2. Execute code, go to step 1. I will write this in PHP as I am most familiar with foreach in PHP and it is maybe the easiest to understand. $array = array("1" => "tomatoes", "2" => "apples", "3" => "bananas", "4" => "pears"); foreach ($array as $key => $value) { echo $key . " " . $value . "<br>"; } (Set up an array with the values:1 => tomatoes2 => apples3 => bananas4 => pears)1. Get the array that we will work with and the next key/value pair, and define the variable names of the keys (In this case, I have made all the keys numbers) and the values (The values here are fruits. Tomato is first. Controversy! :o )2. Execute code, in which $key is the name of the key and $value is the name of the value. Go to step one, unless we just used up the last array value. This program prints:1 tomatoes2 apples3 bananas4 pears foreach is used in PHP, Python, Java, and bash scripting. Data types Different variables store different kinds of data, some hold more and some less. Here are some of the most common ones, some languages don't have specified data types, but they are essential to other languages. Integer (int): An integer is a basic data type. It holds any integer, positive or negative. Integers do have ranges. RuneScape players among us may be interested to know that the max value an integer can hold in Java is +2,147,483,647, which is the maximum amount of cash you can have in game. Float: This is a bit fancier than an integer. it can hold decimal values as well as whole numbers. Double: The same as a "float", but takes more memory and has "double precision", hence the name. Boolean: This type holds either "true" or "false". String: A string is used to store a "string" of characters, or an array of characters. For example, if I wanted to store the word "hello" I would use a string variable. They can also hold numbers, but cannot be used for calculations unless they are casted(turned into) an int, double, or other numerical data type. Array: Arrays are not strictly data types in themselves, but they are used as extensions of other data types (In C/C++, especially char or int) to create multiple values with an index. This is useful for storing multiple values in a way that can be looped through easily. Arrays can have multiple dimensions, that is, arrays can contain arrays. Struct: In C/C++, a struct is similar to an array in the way that it stores multiple values, but the values can be of different data types. It is more of a way of organizing data. Major programming languagesI plan to put up some examples of each major programming language, more elaborate than just "Hello world", here. Contributions welcome. :) Major programming languages, listed alphabetically: [spoiler=C]Used for: Just about everything. Operating systems and programs alike are written in C. A simple language, but very powerful and flexible.Been around since: Forever. Like 1972.Pros: Very simple syntax, there are all kinds of libraries for it. Probably the fastest higher-level language. A good skill to have.Cons: Parts of the language like pointers can be confusing.Alternatives: C++, Java, C##include <stdio.h> int somefunction(void); int main() { somefunction(); } int somefunction(void) { int i; float j; for (i = 1; i <= 10; j = ++i) { if ( (j/2) == (i/2) ) { printf("i is even\n"); } else { printf("i is odd\n"); } } } [spoiler=C++]Used for: Just about everything. Many programs are written in C++.Been around since: 1983Pros: Like C, but with the additional advantage of object-oriented programming (Like Java). Still makes for fast-running programs.Cons: Parts of the language like pointers and object-oriented design can be confusing.Alternatives: C, Java, C##include <iostream> using namespace std; class cat { private: int size; public: void set_size(int); int get_size(); }; void cat::set_size(int newsize) { size = newsize; } int cat::get_size() { return size; } int main() { cat Garfield; Garfield.set_size(20); cout << "The size of Garfield is: " << Garfield.get_size() << endl; return 0; } [spoiler=Java]Used for: Similar to C, it can be used for just about anything. It's commonly one of the first programming languages taught to programming students. It has a reputation for not being as fast as C but over the years it has been fine tuned to be of comparable speed.Been around since: 1995.Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least). Portable by nature. (You can almost always compile it on any operating system that has a Java compiler without changing any code)Cons: Not quite as fast as C, generally not ported to consoles as well.Alternatives: C++, C, C# public class Example{ public static void main(String[] args){ someFunction(); } public static void someFunction(){ int i; float j; for(i = 0; i < 10; i++){ j = i; if((j/2) == (i/2)){ System.out.println("i is even"); } else { System.out.println("i is odd"); } } } } [spoiler=PHP]Used for: Web programming, especially with databases such as MySQL. Tip.it uses it, this forum is written in it, and several huge sites use it too for example facebook.Been around since: 1995Pros: Very easy syntax, eventually you can write code almost as fast as you can type. At the same time though, it has some incredibly powerful features like object oriented programming. Very wide usage, many job openings for PHP programmers.Cons: A scripted language that is compiled every time you run it, so compared to languages like C, C++ or Java, it is quite slow. (There is a compiler for it, but it's not in widespread use and right now you have to compile the compiler yourself in order to use it)Alternatives: Python, Perl<?php $array = array( "Lorem" => "ipsum", "dolor" => "sit", "amet" => "consectetur" ); foreach ( $array as $key => $value ) { echo $key . " " . $value; } echo "<br>"; for ( $i = 1; $i <= 10; $i++ ) { if ( $odd = $number % 2 ) { echo "\$i is odd<br>"; } else { echo "\$i is even<br>"; } } [spoiler=Python]Used for: General scripting, scripting using APIs of programs such as Blender 3D and the GIMP, web programming.Been around since: 1991Pros: Very easy to learn. An excellent language to learn as a first language. Easy syntax, incredibly powerful. Lots of programs have APIs for python, plenty of extensions and libraries. Can be compiled.Cons: Can't be optimized that much, not as fast as languages like C/C++ and Java.Alternatives: PHP, Perl, C++def somefunction(): for i in range(1, 11): j = i + 1 if j/2 == i/2: print "i is even" else: print "i is odd" def main(): somefunction() if __name__ == '__main__': main() [spoiler=Javascript]Used for: Browser scripting, such as all the fancy animations and features on facebook, some general scripting like pythonBeen around since: 1995Pros: Quite easy to learn, lots of great libraries like jQuery for animation, which makes it a pleasure to work with. Can be compiled, technically.Cons: Not at all useful for making real programs, has a lot of quirks especially between different browsers.Alternatives: No real alternative when it comes to browser scripting, but for more general scripting, Python and maybe PHP. function somefunction() { for (i = 0; i < 10; i++) { if ((%i)/2 == 0) { document.write("i is even<br>"); } else { document.write("i is odd<br>"); } } } [spoiler=C#]Used for: Similar to C, it can be used for just about anything. Microsoft's primary programming language for its flagship development platform, .NET.Been around since: 2001Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least). Portable by nature. (You can almost always compile it on any operating system that has a .NET or Mono compiler without changing any code)Cons: Not quite as fast as C, but probably faster than Java and GUI doesn't look that good on non-Windows OSs, even with GUI toolkits other than Windows Forms.Alternatives: C++, C, Javapublic class example { public static void Main() { SomeFunction(); } public static void SomeFunction() { for (int i = 0; i < 10; i++) { if (i % 2 == 0) { System.Console.WriteLine(i + " is even"); } else { System.Console.WriteLine(i + " is odd"); } } } } Some tips on learning programming languages If you want to get a strong handle on a new language, or even to gauge how well you know your current languages, it is best to tackle problem solving problems, instead of trying to design a program with a purpose. With problem solving you need to understand the syntax and the semantics. Not just copy and paste code and hope it all works out. Figuring out the following problems, or how to write programs that can solve the below programs will definitely increase your understanding of the language or even help you further in becoming a programmer. The following are the basic problem solving tasks I've been told to complete through-out the online tutorials and in-class conditions. This is a list of those problems that I think bring the best outcome in the understanding of the language. Try to mentally figure out how to solve these problems first however: Loops: 1. Write out 1 to 10 using a loop only.2. Retrieve two numbers as input, and loop from the smaller number to the highest number, then stop.3. Using only loops write out a multiplication table for the number entered by the user (If they enter 10, do the multiplication table up to 100 - this is a full 10x10 'grid' of numbers, if the number entered was 10, if it is 8, it would be an 8x8 'grid'). Strings: 1. Enter a string as input to the program, and have the program find any occurrences of any character entered by the user.2. For each letter in a string, increase it so it changes to the next letter ahead of it in the alphabet. Do not increase punctuation symbols or spaces.3. Read from a file, and for each LINE in the text file, write that line backwards (including punctuation symbols). Not the entire document backwards, but line by line backwards.4. In a text file, find any 'scattered occurrences' of the word entered by the user. If the word was 'pie', then your program would go through the text file to find the straight scattered occurrences of the letters 'p', 'i', and 'e'. At the end it would output the number of occurrences found and where the occurrences are by line number. Arrays: 1. Swap every two index values in an array, using a loop.2. Create a multiplication table using an array.3. Create a 4x4 Sudoku puzzle using an array, without any graphical support, all text based. --- Doing these basic problem solving tasks, you should gain a higher understanding of whatever language you're trying to learn, or get a handle on. This is also very basic in terms of where problem solving can get to in computer programming. Most universities are or should be handing out this level of problem solving questions to first years. Credits:y_guy_4_life (Wrote most of the part about data types, Java example)Tiigon (Python and C++ examples)Jard_Y_Dooku (C# description and example)Makoto_the_Phoenix (ARM assembly language example)skatedog111 ("Programming tips" section) Link to comment Share on other sites More sharing options...
obfuscator Posted January 26, 2010 Share Posted January 26, 2010 Great post Davis, hopefully it can be stickied once its done. I'll try to come up with some terms shortly. Introduction to data types This section will contain basic information about data types, which are stored in variables. Integer (int): An integer is a basic data type. It holds any integer, positive or negative. Integers do have ranges. Runescape players among us may be interested to know that the max value an integer can hold in java is +2,147,483,647, which is the maximum amount of cash you can have in game. Double: This is a bit fancier than an integer. it can hold decimal values as well as whole numbers. Boolean: This type holds either "true" or "false". String: A string is used to store a phrase. For example, if I wanted to store the word "hello" I would use a string variable. They can also hold numbers, but cannot be used for calculations unless they are casted(turned into) an int, double, or other numerical data type. "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Liquid_1520 Posted January 26, 2010 Share Posted January 26, 2010 The debugging part by far takes the most amount of time XD 90% of the mistakes I make are forgetting to close the tags lol. so i'll have an <a href="www.teamlnd.com>Team LND</a> and wonder what's going on for about 10 minutes, than realize that i forgot the other " lol It's the stupid errors that are always hardest to spot XD Link to comment Share on other sites More sharing options...
dsavi Posted January 28, 2010 Author Share Posted January 28, 2010 Updated it, will update again this afternoon. Didn't get time in the last few days to do it. Link to comment Share on other sites More sharing options...
obfuscator Posted January 28, 2010 Share Posted January 28, 2010 I did what you did for C with Java. [spoiler=Java]Used for: Similar to C, it can be used for just about anything. It's commonly one of the first programming languages taught to programming students. It has a reputation for not being as fast as C but over the years it has been fine tuned to be of comparable speed.Been around since: 1995.Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least).Cons: Not quite as fast as C, generally not ported to consoles as well. public class example{ public static void main(String[] args){ someFunction(); } public static void someFunction(){ int i; float j; for(i = 0; i < 10; i++){ j = i; if((j/2) == (i/2)){ System.out.println("i is even"); } else { System.out.println("i is odd"); } } } } EDIT: Ok done, I don't know C so I don't know if its the exact java version of what you were trying to do. "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
JoeDaStudd Posted January 28, 2010 Share Posted January 28, 2010 Nice start.I think you should add some information on basic flow control (if's and switches) and something about basic loops (while and for).Anything which pretty much stays the same in most languages. [hide=Drops]Dragon Axe x11Berserker Ring x9Warrior Ring x8SeercullDragon MedDragon Boots x4 - all less then 30 kcGodsword Shard (bandos)Granite Maul x 3Solo only - doesn't include barrows[/hide][hide=Stats][/hide] Link to comment Share on other sites More sharing options...
dsavi Posted January 28, 2010 Author Share Posted January 28, 2010 Yeah, I'll add that to the basic terminology thingy. Link to comment Share on other sites More sharing options...
The Runar Posted January 29, 2010 Share Posted January 29, 2010 Here's a Python version of your C example program: def somefunction(): for i in range(1, 11): j = i + 1 if j/2 == i/2: print "i is even" else: print "i is odd" somefunction() The Runar's (OSRS) DIY blog - most viewed Blogscape blog ever! Contract? /人◕ ‿‿ ◕人\ Link to comment Share on other sites More sharing options...
RSBDavid Posted January 29, 2010 Share Posted January 29, 2010 [spoiler=Visual Basic]Used for: Desktop applications and librariesBeen around since: Late 1980'sPros:Easy to learn for beginnersCan quickly make applicationsCons: Not the best language for cross-platform applicationsNot commonly used anymore like Java or C++Alternatives: If you are a person who wants to program for a living, do yourself a favor and learn something besides visual basic. If you are a hobbyist programmer, then this will be alright for you. SwiftKit is made with visual basic. (all of this is from memory so sorry if I make a mistake) A basic function Function addNumbers(byval num1 as integer, byval num2 as integer) Dim result as integer result = num1+num2 return result End Function [hide=A basic visual basic coding tut]Variables: Variables are usually created in this format: Dim (variable name) as (variable type) Although you can use Private,public, Const, and static in some declarations. For example: Dim strData as string Dim intAppleCount as integer Static count Const PRICE as string = 40 When declaring strings, you must wrap the string in quotations. Instead of declaring three variables such as:Dim intA as integer Dim intB as integer Dim intC as integer You can do Dim intA, intB, intC as integer Loops:There are two types of loops: The first type is Do- While. dim intX as integer = 10 Static count Do While count < intX count += 1 loop The next type of loop is a For-Next loop. For i as integer = 1 to 10 debug.writeline(i) next Strings Lets look at the following sentence: "The cat in the hat has 9 pizzas" lets say we want to replace that 9 with "nine". All we would have to do is: Dim strSaying as string = "The cat in the hat has 9 pizzas" strSaying.replace(9,"nine") That should replace the number 9 with "nine"[/hide]I have to move some stuff in real life so I will finsih this later. 1 [software Engineer] - [Ability Bar Suggestion] - [Gaming Enthusiast] Link to comment Share on other sites More sharing options...
dsavi Posted January 29, 2010 Author Share Posted January 29, 2010 Could you write one example and other details (Since I don't know much about VB) in the same format as the others? [spoiler=Language name]Used for:Been around since:Pros:Cons:Alternatives:code example Link to comment Share on other sites More sharing options...
RSBDavid Posted January 29, 2010 Share Posted January 29, 2010 Will do. [software Engineer] - [Ability Bar Suggestion] - [Gaming Enthusiast] Link to comment Share on other sites More sharing options...
dsavi Posted January 30, 2010 Author Share Posted January 30, 2010 I wish there was some way to paginate this. It's too long to read like it is. Link to comment Share on other sites More sharing options...
RSBDavid Posted January 30, 2010 Share Posted January 30, 2010 I wish there was some way to paginate this. It's too long to read like it is. Hide tags? [software Engineer] - [Ability Bar Suggestion] - [Gaming Enthusiast] Link to comment Share on other sites More sharing options...
InkofDeath Posted January 31, 2010 Share Posted January 31, 2010 If you want to learn why or how programming languages work, as well as the fundamentals of any language (like the data types, syntax...etc) or you don't know where exactly you want to begin with, with what language or whatnot, then this can give you an idea: http://academicearth.org/lectures/intro-to-comp-sci-goals It explains the basic principles of programming. As well, if you follow any of the other lectures, it does expand your ability to think properly. Course, Examples & Lectures are in Python. I think this will be useful to beginners since when I first learned programming I was only told what the syntax was for, not why it was there. Which can make learning everything so much easier. Link to comment Share on other sites More sharing options...
Makoto_the_Phoenix Posted February 3, 2010 Share Posted February 3, 2010 Pretty good start to a guide, but there are some things that I'd have liked to include. 1) There are different types of loops across different types of languages. C/C++/Java/C#(?) make use of the standard three - for, while, and do-while, but other programming languages (including Java), such as Python and Bash have a different variant called the "enhanced for", or foreach. Quick Java example: ArrayList<Integer> myNums = new ArrayList<Integer>(30); int i = 0; while(i < myNums.length()) { myNums.add(i, (Integer)i); i++; } for(Integer num: myNums) { //Structure: For each Integer, internally referred to as num in the collection myNums System.out.println(num); } Python does the same thing with its "for" loop structure by default by use of the range() function: for x in range(0, 10): print x 2) A distinction between what an object and what a function actually are. I've seen CS students struggle with this one at first, and the best way to show them would be to plop down a textbook in front of them, and call that an object. 3) If you'd like I can dig up some examples of my old ARM projects, and show you some examples of low-level language code. 4) Quick correction to the Python code: def somefunction(): for i in range(1, 11): j = i + 1 if j/2 == i/2: print "i is even" else: print "i is odd" def main(): somefunction() if __name__ == '__main__': main() Overall it's pretty good! Keep it up :) Linux User/Enthusiast | Full-Stack Software Engineer | Stack Overflow Member | GIMP User...Alright, the Elf City update lured me back to RS over a year ago. Link to comment Share on other sites More sharing options...
das1330 Posted February 4, 2010 Share Posted February 4, 2010 Great post Davis, hopefully it can be stickied once its done. I'll try to come up with some terms shortly. If this continues to grow, I will sticky it. Link to comment Share on other sites More sharing options...
dsavi Posted February 4, 2010 Author Share Posted February 4, 2010 Yeah, I took a break from writing it for a few days, will probably finish it within the next 2-3 days. Link to comment Share on other sites More sharing options...
Obtaurian Posted February 4, 2010 Share Posted February 4, 2010 I know absolutely nothing about programming, but would like to get into it. A friend of mine recommended Visual Basic, so I may just try tinkering with that soon. Very cool thread. :thumbup: To put it bluntly, [bleep] off. Link to comment Share on other sites More sharing options...
dsavi Posted February 4, 2010 Author Share Posted February 4, 2010 Personally I'd start with Python or PHP. (I started with PHP myself but I think that Python is better to start with) Very simple languages that have aspects that can be applied to more complex languages like Java and C++. @Makoto: 1. I was thinking that foreach was maybe too specific (I thought it was only used in PHP and Bash) to put there. I'll get that up.2. I didn't know that people had that problem. I suppose PHP just does a good job of seperating them.3. That would be incredibly cool :)4. I tested the code myself and it worked fine, but I'll let the people that actually know Python argue about that. :P Edit: Added some ~6,000 characters. Enough for today. Link to comment Share on other sites More sharing options...
Jard_Y_Dooku Posted February 5, 2010 Share Posted February 5, 2010 Used for: Similar to C, it can be used for just about anything. Microsoft's primary programming language for its flagship development platform, .NET.Been around since: 2001Pros: Simple syntax like C, huge support and libraries. Easy to learn (the basics at least). Portable by nature. (You can almost always compile it on any operating system that has a .NET or Mono compiler without changing any code)Cons: Not quite as fast as C, but probably faster than Java and GUI doesn't look that good on non-Windows OSs, even with GUI toolkits other than Windows Forms.Alternatives: C++, C, Javapublic class example { public static void Main() { SomeFunction(); } public static void SomeFunction() { for (int i = 0; i < 10; i++) { if (i % 2 == 0) { Console.WriteLine(i + " is even"); } else { Console.WriteLine(i + " is odd"); } } } } Go ahead and format it yourself... I can't stand this editor, it's total junk. Never trust anyone. You are always alone, and betrayal is inevitable.Nothing is safe from the jaws of the decompiler. Link to comment Share on other sites More sharing options...
dsavi Posted February 5, 2010 Author Share Posted February 5, 2010 I wrote almost all the code for this guide in a separate editor. (gedit) Link to comment Share on other sites More sharing options...
dsavi Posted February 6, 2010 Author Share Posted February 6, 2010 I need an example of C++ and then I think I'm pretty much finished. Anyone got one? Link to comment Share on other sites More sharing options...
The Runar Posted February 6, 2010 Share Posted February 6, 2010 #include <iostream> using namespace std; class cat { private: int size; public: void set_size(int); int get_size(); }; void cat::set_size(int newsize) { size = newsize; } int cat::get_size() { return size; } int main() { cat Garfield; Garfield.set_size(20); cout << "The size of Garfield is: " << Garfield.get_size() << endl; return 0; } The Runar's (OSRS) DIY blog - most viewed Blogscape blog ever! Contract? /人◕ ‿‿ ◕人\ Link to comment Share on other sites More sharing options...
Makoto_the_Phoenix Posted February 6, 2010 Share Posted February 6, 2010 Here's some C++ for you to use. #include <iostream> using namespace std; void first_func(); void second_func(); int main(int argc, char** argv) { first_func(); cout << "\n"; second_func(); cout << "\n"; return 0; } void first_func() { int f=1, i=2; while (++i<5) { cout << " i = " << i << ", f = " << f << "\n"; cout << "product = " << (f*=i) << "\n"; } cout << f; } void second_func() { int f=1, i=2; while (i++<5) { cout << " i = " << i << ", f = " << f << "\n"; cout << "product = " << (f*=i) << "\n"; } cout << f; } Also, here's an example of ARM assembly code. This is from an old project, so it has tons and tons of documentation (and I would assume that the code tag wouldn't know what this is). What the snippet actually does is explained in the snippet itself. BUILD MOV R0, R1 ; Move numbers into R0 SUB R2, R2, #1 ; Decrement R4 ADD R1, R1, #1 ; Increment R3 STR R0, [R3] ; Store the value from R0 into memory (only stores a 1) ADD R3, R3, #4 ; Increment the pointer by four bytes (definitely works) CMP R2, #0 ; Is this number in R0 equal to 32 (stopping point)? BNE BUILD ; Start all over again if they're still not equal. MOVEQ R11, R3 ; Hey, we have the end of the array, let's keep that. SUB R11, R11, #4 ; //Offset by 4, ran into this bug earlier. MOVEQ PC, R14 ; Return to main when finished. [EDIT] Tligon beat me to the punch! :P Linux User/Enthusiast | Full-Stack Software Engineer | Stack Overflow Member | GIMP User...Alright, the Elf City update lured me back to RS over a year ago. Link to comment Share on other sites More sharing options...
dsavi Posted February 8, 2010 Author Share Posted February 8, 2010 Used Tiigon's C++ and Makoto's ARM. :) I think that this is done now, unless someone has some correction to make. If someone would read through this/get someone to read through this it would be great. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now