Blog: Keogh Code - Hello World!
Staff writer Siobhan Keogh is a complete noob when it comes to programming. Despite a lack of coding knowledge - does ten-year-old HTML count? - she's decided to teach herself one of the more difficult languages, C++. In Keogh Code, you can follow her progress as she attempts to navigate a whole new world.
Siobhan Keogh | Wednesday, April 18 2012 | 8 CommentsI'm not a programmer. In fact, I'm about as far away from being a programmer as one can get. And yet I find myself attempting to learn how to create apps using C++.
Why on Earth are you doing this to yourself?!
People keep asking me why I've decided to learn to code all of a sudden. There are a bunch of answers to that question, but the simplest one is "for self-improvement". Having more skills is always a good thing. But I'm also just doing this for fun, because I like to accomplish things and I get an immense satisfaction out of seeing them work as they should. I also get extremely frustrated when things don't work as they should, so you should expect me to vent my nerdrage relatively often.
I'm also pretty lucky, because I have an Assistant at home learning to code C++ with me, who has some programming experience (although his experience is in Java). So while I'm new to this, I have a helper.
Why C++?
Others have asked why a complete beginner like myself would choose a difficult-to-learn language like C++. Well, it's partly for your entertainment, dear reader. How are code-junkies supposed to revel in my failures if I'm not, you know, failing? What if other newbies want to follow along and learn from my mistakes?
And besides a general thirst for knowledge, I also have a manic, probably unhealthy passion for video games and the game industry. Since most games are coded in C++, it helps to have a basic understanding of the way games are made when reviewing or talking to developers. And who knows? Maybe I'll eventually get to the point where I can make my own little games that other people will enjoy.
Lesson One - Hello World!
On Sunday, I decided to get started. I bought a book from the Kindle store, Sams Teach Yourself C++ in One Hour a Day (6th Edition). If you want to follow along, I've so far found it extremely helpful - not only does it tell me what to do, but it explicitly tells me what not to do, which is important. In C++, there are always a bunch of different ways you can write code to accomplish the same goal. Some of that code, however, is either regarded as a "bad habit" or "not legal C++" (which seems to be just a fancier way of saying "bad habit").
Over the next couple of days, I endeavoured to create the first program that almost every programmer ever creates - an app called 'Hello World', that simply prints the words 'Hello World' to the screen. It would get embarrassing if I counted how many times I attempted to create this and failed, so I won't tell you. Oh, what the hell. It was six. Six times I tried to create the simplest C++ program possible, and six times I failed.
At first I thought the problem was in the code itself, and spent hours in Visual C++ 2010 (protip: you can get the Express version for free for non-commercial use) diligently copying the code from my textbook, reading it carefully for mistakes, and deleting all the text and starting again. Every time I tried to build the project - a process called 'compiling', for those who are complete n00bs like me - it failed, and I couldn't figure out why. Then I saw a tutorial for compiling on Microsoft's website, and suddenly I realised - my C++ file, which has a .cpp extension and is one part of the overall project file, had to be named 'main.cpp' because of a strange quirk of Visual C++. My textbook told me I could name it anything I wanted, but apparently that wasn't true, because as soon as I changed the filename, everything magically fell together and started compiling.
I launched the application and crossed my fingers. The Command Prompt program flashed on-screen, and then disappeared. Because of yet another Visual Studio quirk, I had to use Ctrl + F5 to run the program or it wouldn't remain open. However, I figured out I could also code the program to pause no matter which way I ran it.
In the end, the code for my working program looked like this:
1. #include <iostream>
2.
3. int main ()
4. {
5. std::cout << "Hello World!\n";
6. char response;
7. std::cin >> response;
8. return 0;
9. }
Line 5 of the code tells the computer to print the words "Hello World!" to the screen. Line 6 and 7 tell the computer to close the application only when the user enters a character on the keyboard.
Seeing my first program come to life after so many failures was deeply satisfying, and kind of addictive. Once, after realising I'd made an error in my code while working on another task, all I wanted to do was run home and fix my mistake.
Next week I'll be blogging again, and this time I'll be coding something just a wee bit more complex - how to set integers and use them to get your computer to calculate for you.
Windows vs. iOS vs. Android:How to choose the best tablet for you
101 great websites:
You haven't heard of yet
DIY desktops:
We ask the pros for building tips
Hot Products || PC World editors iPhone 4S launch pics and unboxing
The iPhone 4S launched at midnight through both Vodafone and Telecom. ... READ MORE
Tux Love || Geoff Palmer Google : Starting to be evil?
Google recently deleted AdBlock Plus from its Android Play Store. This is ... READ MORE
Tech Guy || Juha Saarinen Small balls of solder
The idea that desktops might change forever is enough to send geeks into a ... READ MORE
In a Nutshell || Zara Baxter Logging, not login
At an event in Singapore yesterday, Seamus Byrne, the editor of CNet ... READ MORE
Harley O'Gyver || Harley Ogier Pay for internet by-device? Not on my watch.
So as those of you who follow my twitterstream will know, I'm currently in ... READ MORE
The Arcade || PC World editors New Year, new games
You'er going to laugh. Or at the very least, you're going to scoff and ... READ MORE
Dumb Terminal Live! || PC World editors New Zealand memes: We think we're real funny
We New Zealanders love the internet, and we have a pretty good sense of ... READ MORE





I have had a similar quirky experience with Visual Studio compiling in Windows before. Because of this, I am going to be trying my C++ programs in Linux using the open source gcc/g++ compiler instead. It will be interesting to see how your experience differs.
Posted by scottd at 10:41:55 on April 20, 2012
Flag abuse
int
_,l;\
char*I,
*O[]={"",
"gjstu","t"
"fdpoe","uij"
"se","gpvsui",\
"gjgui","t"
"jyui","tfwf"
"oui","fjhiui",
"ojoui","ufoui",\
"fmfwfoui","uxfmgu"
"i","b!qbsusjehf!jo!"
"b!qfbs!usff/\xb\xb",""
"uxp!uvsumf!epwf"
"t-\xb","uisff!gsf"
"odi!ifot-!","gpvs!d"
"bmmjoh!cjset-!","gjwf"
"!hpme!sjoht<\xb","tjy!h"
"fftf!b.mbzjoh-!","tfwfo!t"
"xbot!b.txjnnjoh-\xb","fjhiu"
"!nbjet!b.njmljoh-!","ojof!mbe"
"jft!ebodjoh-!","ufo!m"
"pset!b.mfbqjoh-\xb","fm"
"fwfo!qjqfst!qjqjoh-!","ux"
"fmwf!esvnnfst!esvnnjoh-!",""
"Po!uif!","!ebz!pg!Disjtunbt!n"
"z!usvf!mpwf!hbwf!up!nf\xb","boe"
"!"};int putchar(int);int main(void
){while(l<(sizeof O/sizeof*O-2)/2-1){
I=O[_=!_?sizeof O/sizeof*O-
3:_<(sizeof(O)/sizeof*O-2)/2?
sizeof O/sizeof*O-2:_==(sizeof(
O)/sizeof*O-2)/2?++l,0:_<(sizeof(
O)/sizeof(*O))-3?(_-1)==(sizeof(O)/
sizeof*O-2)/2?sizeof O/sizeof*O-1:_-1
:_
sizeof(O)/sizeof*O-2)/2];while(*I){putchar(
*I++-1);}}
return 0;}
Posted by Juha at 11:47:01 on April 19, 2012
Flag abuse
Posted by Siobhan Keogh, PCW at 13:30:03 on April 19, 2012
Flag abuse
if in the future you need some help please feel free to check us out at http://www.zeta.co.nz
Posted by Thi at 22:40:03 on April 18, 2012
Flag abuse
One of the tricks with C++ (and many other languages) is to learn to do things right first time - its often hard to change habits once they set in.
If later in your journey you want to learn how to write your c++ (or other language) in a secure way - look us up. (No tricks, no catches, no cost - we are a volunteer community that help people just like you find there feet in secure software development and IT security)
in2securITy New Zealand <- shameless plug
Posted by Laura at 21:13:19 on April 18, 2012
Flag abuse
Posted by Arnie at 18:10:26 on April 18, 2012
Flag abuse
Posted by Matthew at 14:18:47 on April 18, 2012
Flag abuse
Posted by Siobhan Keogh, PCW at 14:45:27 on April 18, 2012
Flag abuse