- About Future
- Digital Future
- Cookies Policy
- Terms & Conditions
- Investor Relations
- Contact Future
Advanced Course: Object-Oriented Programming
Taking a look at the bigger picture
Using only the tools we’ve discussed so far, you can write functions that manipulate variables in all sorts of ways—the foundation of pretty much any program you want to write. Unfortunately, as the complexity of a program increases, it becomes difficult to maintain code that’s organized and easy to understand using only those concepts. As an example, if you were writing code for a bank to keep track of its customers’ accounts, you would quickly end up with hundreds of functions and thousands of variables. It would become very difficult to understand what was going on in the code at any particular place, and more generally how the whole thing works.
That’s what object-oriented programming (OOP) is for. OOP is a paradigm that allows you to group variables and functions together into classes, which are (usually) meant to model things or particular concepts. For instance, in the bank example, we might start by creating a class called “Account,” which simulates a user account. Classes are made up of variables and functions (called methods when they’re part of a class), so we start by figuring out what data (variables) and capabilities (methods) an account needs to have. For variables, we might use account number, the account holder’s name, and the balance. For methods, we would want the ability to deposit money, which would increase the balance variable, and withdraw money, which would decrease it.
Once you’ve defined a class, you have to instantiate it for every object you’re modeling. So in the bank example, we would create a new instance of the account class for every customer of the bank—that way every person can have his or her own account number and balance.
It all sounds very complicated until you get to play around with it yourself, but the basic idea of OOP is that we set up a system of tens, hundreds, or thousands of objects that can cooperate with each other to produce the effect that we want.
Object-oriented programming is not the only programming paradigm in use, but it is the most common. Understanding the core concepts of classes, objects, and methods is the last hurdle to programming in languages like Java, C#, and Python.
Learn to code at your own pace with these great online resources
We've talked a bit about semantics, syntax, and structure, the three things you need to write code. If you were able to follow along, you already know enough to start writing simple programs, and you can pick up the rest as you go. If it still seems a little murky, don’t worry—programming is the kind of thing that really only clicks when you try it yourself. Here are some tips for getting your feet wet:
CodeAcademy is the best resource there’s ever been for complete beginners to learn coding. It’s a series of interactive tutorials that teach you the fundamentals of programming, one bit at a time. In each lesson, you’ll write actual code that compiles and runs right in your browser, and the lessons build on each other gradually enough that you’ll rarely feel out of your depth.
Once you’ve gotten started with a language, the programmer Q&A site StackOverflow.com is the best repository for answers about more complicated topics. Don’t start asking questions right away (someone has almost certainly asked about anything you’re running up against), just use the search function to find answers related to any problems you have.
It's not the most newbie-friendly site on the web, but Stack Overflow is an unparalleled resource for programmers.
Of course, Google is great for solving almost any sort of problem, but it’s especially good for issues related to programming. Maybe it’s because the people who tweak the Google search engine are programmers themselves, but Google is excellent at picking out relevant pages from various programming languages' documentation.
Ultimately, the key to learning to program is to not let yourself get overwhelmed. Hopefully, the concepts we’ve covered in this article have been enough to pique your interest, but don’t worry if it’s still a little confusing. Take your time, make use of the online resources available to you, and you’ll have conquered the final frontier of PC power-use before you know it.
Two ways you can get started making something cool
If you don’t pay much attention to the game-development scene, you might never have heard of Unity, the game engine that’s quietly revolutionizing indie development. What’s so good about it? Two things: First, Unity is a flexible and powerful engine for making 3D and 2D games. Unity takes care of all the low-end graphics and physics processing, so you can focus your coding energies on the high-end gameplay decisions. You can code in Java-Script or C# in Unity, and it can automatically build your game for you on almost any platform, from the PC to the PlayStation to the iPhone.
Second, and perhaps more amazingly, Unity is available to everyone for free. Where previously a high-quality game engine would have to be licensed for tens of thousands of dollars, Unity lets you code professional-quality games for free. There are a few features that you have to pay for, but the free versions should still have all the tools you need.
To get started with Unity, visit www.unity3d.com and download the free IDE. There are plenty of great resources for learning to use Unity online, and the IDE comes with an extensive sample project and tutorial.
If physical projects are more your thing, you can write programs that control devices in the real world, using a microcontroller like Arduino or Raspberry Pi. These microcontrollers feature small, inexpensive processors and can be programmed from your computer. By wiring the microcontroller to electronics including motors, sensors, and lights, you can build anything, from a robot to a sous vide machine
An Arduino board features a microcontroller chip, along with input and output ports to hook it into any project.
So, what are you waiting for? Get out there and start making something!