General Gaming Article |
- The Beginner's Crash Course on Computer Programming
- Valve Gives Publishers Tools to Self-Discount Games
- Barnes and Noble to Release Another Nook Color Tablet
- Twitter Returns Hijacked @N Handle Worth $50,000 Back to Owner
- Qualcomm Gives Birth to 64-bit Snapdragons with Eight Cores, Integrated LTE
- Windows 8 Designer Offers Candid Explanation of Metro and Why Power Users Hate It
- Newegg Daily Deals: Nvidia Shield, Adata Premier Pro SP9 256GB SSD, and More!
The Beginner's Crash Course on Computer Programming Posted: 26 Feb 2014 04:19 PM PST Computer Programming: Every PC user should know how to program, and there's never been a better time to learnWith the huge variety of computing devices all around us, it's important to remember what it is that's special about a full-fledged personal computer. We think the main difference can be summed up in one word: mastery. No matter how much time you spend with an iPad or an Android phone or in a web browser, you can never truly master it. There's just not enough there to learn. But the PC? That's different. The PC goes deep. As you develop your mastery over the PC, you move past all sorts of boundaries. First, you learn to replace the software that came on the computer. You discover the command prompt and how to tweak the OS. You learn to build your own PC, and to benchmark it. And then, at the very bottom of it all, there's one last boundary standing between you and true PC mastery. You have to learn computer programming. Why is coding the ultimate test of PC mastery? Because learning how to program is the thing that breaks down the wall between you and your computer—it makes it possible for you to truly understand what's going on underneath your desktop. And, all philosophical ramblings aside, it's a pretty great skill to have. Whether you need to automate a process on your computer or whip up a quick web app for a family member's website, knowing how to code is a big boon. Who knows, you might even be able to earn some money. Learning to program isn't something you can do in an hour, or even in an afternoon. You have to learn to think in a whole new way, which takes dedication and patience. Fortunately, it can also be a lot of fun. In this article, we're going to take a whirlwind tour through some of the most important concepts in computer programming, and we'll direct you to resources that'll help you start your adventures in coding. Basic InformationA Q&A on the ABCs of programming Before we can do anything, we've got to cover the basics. Here's what you have to know before you can get started. When we say computer "programming," what does that really mean?For this article, we're going to use a fairly narrow definition of programming, and say that what we're talking about is the process of creating software on a computer. That process involves writing out a series of commands for the computer to execute, which will create our desired behavior. We write those commands using a programming language. What's a programming language?A programming language is the set of rules that define how we express what the computer should do when it executes the program. There's an incredible variety of programming languages available for use, but the vast majority of commercial and personal software is written in one of a core group of languages including C/C++, Java, C#, Python, and a few others. Modern programming languages share a lot of the same basic concepts and some syntax, so learning your second, third, or fourth programming language is much easier than learning your first. What makes one programming language different from another?Each programming language has its own strengths and weaknesses. C and C++ are low-level languages, meaning that code written in C is closer to the machine code that your CPU understands (see below). Low-level languages can produce faster, more efficient software, so they're used where performance is at a premium—for programming an operating system or a 3D gaming engine, for instance. High-level languages, like Java and Python, have the advantage of being much easier to program in, and the same program can generally be written with fewer lines of code in a high-level language. But which one's the best?There's no one best language—it really depends on what kind of programming you want to do. If you want to program native Windows applications, you'll use C#; if you want to program sophisticated web applications, Ruby would be a good choice; if you want to be the next John Carmack, you should probably start with C. No, for real, which language should I start with?The secret is to not stress too much about whichever particular language you start with. The important things you will be learning are all basic concepts that work pretty much the same in every programming language. You'll learn how to use data structures and conditionals and loops to manage how your code flows. You'll learn to structure your program in a way that's readable and organized. Once you've done all that, learning a bit of syntax to pick up a new language won't seem like much work at all. But, if you really want a suggestion, start with JavaScript. It's an easy language to learn, it's got some practical applications, and its syntax is similar enough to some more-powerful languages like C# and Java that making the transition later on won't be too hard. Is HTML a programming language?Not quite! HTML is a markup language, used to define the contents of a webpage. Although HTML has a specific syntax (a set of rules defining how you have to write things), it doesn't have semantics, or meaning. An HTML document is rendered, rather than executed. That said, if you have written an HTML document, you at least have experience writing a formalized computer language, which may make the jump to programming easier. What's an IDE?An IDE (short for integrated development environment) is the software suite programmers use to actually write programs. They generally include a specialized text editor for writing the source code, as well as the ability to test and debug your program. Two of the most popular IDEs are Eclipse (open source, free, and available at www.eclipse.org) and Microsoft Visual Studio (proprietary and expensive, but with a free "Express" version that's limited to and excels at programming in C, C#, and BASIC). Visual Studio is one of the most advanced IDEs around, and is used by nearly all Windows programmers. How can I start writing a program, Like, right now?Unfortunately, it can be a bit of a hassle to get started coding in most programming languages. You generally have to install and configure an SDK (software developer kit), and sometimes an IDE as well, in order to be able to write and compile code in a new language. It's rarely super hard, but be prepared to spend 15–30 minutes Googling, reading a guide for your chosen language, and setting things up. Fortunately, JavaScript is much easier to get started with. In fact, you can start writing code right this second, using an in-browser coding environment like JSFiddle.net. An in-browser IDE isn't a good solution for serious programming projects, but it's a great way to get started as a beginner. To start writing JavaScript in an interactive environment with structured lessons, you can visit www.codeacademy.com (but more on that later). Click the next page to learn about how it all works.
How Does It Actually Work?When you write a program in a high-level language like Java-Script, the document you create isn't something that your computer's low-level hardware can understand. The CPU has only a limited number of instructions it can perform, such as addition, subtraction, and moving numbers into and out of memory. These instructions are actually physically implemented in the CPU using transistors organized into logic gates. Though modern instruction sets, such as the X86-64 set implemented in any consumer 64-bit CPU, are actually very large and sophisticated, programming for the CPU directly (using a super-low-level language called assembly language) is an arduous, slow process. High-level languages allow you forgo a lot of the technical grunt work. For instance, in a high-level language, you can simply declare and use variables as you please, without ever worrying about what exactly is going on in your system's memory. In assembly language, you have to manually assign data to locations in memory as you use it, and clear up the memory when you're done. In order to get your high-level program to run on the CPU, you need a compiler—a piece of software that optimizes your code and converts it into a machine-readable executable file. Some languages, such as Java, are not compiled, but rather interpreted, which means that the source code itself is distributed, and then compiled on the end user's machine. The upside of an interpreted language is that you can distribute a single file that can be run on Windows, OSX, or Linux. The downside is that whoever runs the file has to have a copy of the interpreter on their machine—an annoyance that anyone who's tried to run a Java-Script applet on a new computer will be familiar with. Core ConceptsUnderstand these, and you've got everything you need to start writing programs in any language VariablesVariables in programming are a little different from the "X"s you remember from high school algebra. In programming, a variable is like an empty container—it can hold a number, a word, or any other data or data structure you want to use in your program. The program can read and change the variable's value as it runs, letting you keep track of and manipulate data. Variables are the basic building block of a program, and most lines of code in any program will include a variable in some form. In some languages, such as Python, a single variable can contain one type of data (say, a number), then can be assigned to hold a different type of data (like a word). In other languages, such as C and C#, a variable is declared, with a particular type, and then can only hold that type of data for the rest of the program. This is the distinction between dynamically typed and statically typed programming languages. ConditionalsMost programs do not run in a vacuum—they accept some form of user input. To deal with the uncertainty that this brings, we need to be able to write code that is flexible, and to do that, we need conditionals. Conditionals are places where the code branches. In most modern languages, they take the form of an if statement, which joins an expression that is either true or false (called a Boolean expression) and a block of code. The if statement says, in a nutshell, "If this Boolean expression is true, execute the following code. Otherwise, skip it." In most languages, if statements can also include an else clause, which allows you to specify a second block of code that will only be executed when the Boolean expression is false. For example, under the "Sample Code" section below, the 99BottlesOfBeer function includes an if statement that checks to see if the "age" variable is greater than or equal to 21, and sets a different variable called "drink" to an age-appropriate libation. LoopsAnother way you can control the order in which code is executed is with a loop. Where an if statement allows you to execute or not execute a certain block of code, a loop allows you to keep executing the same block of code multiple times. There are several different types of loops, but the two that you'll find in almost any programming language are the while loop and the for loop. A while loop works a lot like an if statement. You attach a Boolean (true or false) statement to the while loop, and as long as that statement is true, the loop keeps repeating. Basically it says "as long as this statement is true, keep going." As a consequence, something inside the looping code has to make a change that could cause the Boolean statement to become false, or else the loop will never end. For example, the following code will print out the word "hello" 10 times, then stop: Notice that we used the variable x as a loop counter, to control the number of times the loop runs. The other most common type of loop, the for loop, is basically just a while loop with a built-in loop counter. You tell the loop right away how many times you want it to run, like this: The part after "for" just defines a counter. It says "start with a number (integer) we'll call x, and keep looping as long as x is less than 10. At the end of every loop, increment x by one." FunctionsThe most powerful way to control the flow of a program is with functions, which allow you to reuse code. Also called a subroutine, a function is a block of code that you've given a name to, so you can reuse it any time you want. For example, you could define a function called PrintHelloThenGoodbye by doing the following: Then, if you called that function three times in your code, as follows: Your program would output "hello goodbye hello goodbye hello goodbye." A function can also take variables as inputs, and } Notice the "return" keyword. That passes the following value back to whatever part of the code called the function. So, if somewhere else in the code we called the function like this: The program would print out the number 25. SyntaxMaybe the most intimidating thing about programming is the syntax—the strange punctuation marks and cryptic words that make a page of code look like a foreign language. Fortunately, in most programming languages, syntax is really only a couple of rules that you have to remember, and a lot of syntax is shared between languages. It's all dependent on what language you're programming in, but here are a couple of syntactical elements that are common across many popular languages: Semicolon The semicolon is like the coding equivalent of a period—each line of code ends with one. It's important, because in many languages, line breaks are just for readability, and don't have any effect on the execution of the code. Parentheses Parentheses are used after functions (see above) to contain that function's parameters (or inputs). You might remember this usage from your high school math classes, when f(x) was a function that operated on the variable x. Curly braces In a number of languages (particularly those derived from C), curly braces "{}" are used to enclose and group blocks of code. They're used, for instance, after the control structures described here (if statements, loops, and functions), to designate the block of code that the statement refers to. Indentation Because all of the control structures can be nested inside each other, code tends to take on a sort of hierarchy. A particular line of code might be inside an if statement, which is inside another if statement, which is inside a loop that's inside a function. All that can get hard to keep track of! To make it easier, code is written with variable levels of indentation. The more indented a line of code is, the more deeply nested it is. In most languages, indentation is purely for readability, but in a few (like Python), it actually controls the grouping of code, and is used instead of curly braces. Sample CodeThis oh-so-practical program prints out an age-appropriate version of the song "99 Bottles of Beer." function 99BottlesOfBeer(int age) { var bottlesLeft = 99; if (age >= 21) { while (bottlesLeft > 0) Click the next page to learn how you can take action with computer programming! |
Valve Gives Publishers Tools to Self-Discount Games Posted: 26 Feb 2014 12:12 PM PST |
Barnes and Noble to Release Another Nook Color Tablet Posted: 26 Feb 2014 11:50 AM PST |
Twitter Returns Hijacked @N Handle Worth $50,000 Back to Owner Posted: 26 Feb 2014 09:33 AM PST |
Qualcomm Gives Birth to 64-bit Snapdragons with Eight Cores, Integrated LTE Posted: 26 Feb 2014 08:24 AM PST |
Windows 8 Designer Offers Candid Explanation of Metro and Why Power Users Hate It Posted: 26 Feb 2014 07:12 AM PST |
Newegg Daily Deals: Nvidia Shield, Adata Premier Pro SP9 256GB SSD, and More! Posted: 26 Feb 2014 06:06 AM PST Top Deal: Nvidia's Shield handheld is unique in that it's a rather powerful Android device at its core (Tegra 4 SoC clocked at 1.9GHz) but is also capable of streaming PC games from your desktop over Wi-Fi. We spent some hands-on time with the Shield, and while it's not perfect, it's a decent overall portable. Plus, it's less expensive now than when we reviewed it. The value proposition is even higher as today's top deal, which features the Nvidia Shield for $250 with free shipping and free Newegg $25 Gift Card with purchase. To recap, the Shield sports a 5-inch 720p Retinal display, 802.11n 2x2 MIMO Wi-Fi connectivity, mini-HDMI output, and a few other tidbits. Other Deals: Corsair HX1050 1050W ATX12V / EPS12V 80 Plus Gold Certified Modular Power Supply for $180 with free shipping (normally $210 - use coupon code: [EMCPHHE25]; additional $20 Mail-in rebate) CM Storm Trooper - Gaming Full Tower Computer Case for $120 with free shipping (normally $150 - use coupon code: [EMCPHHE55]; additional $20 Mail-in rebate) Adata Premier Pro SP9 2.5" 256GB SATA III Internal Solid State Drive for $125 (normally $130 - use coupon code: [EMCPHHE54]) Asus Black 23-inch 1ms (GTG) HDMI Widescreen LED Backlight LCD Monitor for $130 with free shipping (normally $170 - use coupon code: [EMCPHHE49]; additional $20 Mail-in rebate) |
You are subscribed to email updates from Maximum PC - All Articles To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |