Saturday, February 20, 2010

C++: Forgotten Syntax

Well I do realized this post is later than my usual time (I usually have a post done Thursday or Friday, and schedule to post it at 3:00PM on Saturday.. In case you weren't aware, that's what I do) But I will still post nonetheless. This week I'll be giving a couple tips on C++, although you can't really depend on MY tips unless you yourself are more of a beginner than me. Personally, I've been with C++ for almost a year now, I took a class at a junior college, and I've been going through C++ Primer in my spare time. You can at least trust my opinions because I have more experience than about 50% of the other C++ newbies who learn how to write a hello world program and call it genius.

I want to call attention to a few things in C++ that personally annoy me, the things you and I, and millions of other C++ programmers commonly forget, resulting in a million compile-time errors. First of all, the ever-so-beloved semi-colon. Who would have thought that one small semi-colon has the power to completely change the output of a program? Secondly, brackets. It is common to forget the ending bracket, but how many times have you forgotten both the beginning AND ending brackets? Also, what are the unseen consequences of forgetting a "delete" command?

Well, the most common problem is probably forgetting semi-colons. This is usually quite easy to do, especially after typing out a long statement, but with practice, it'll begin to be similar to a second nature. There's really not much I can say about semi-colons.

In my opinion, the most annoying problem, and second most common (to semi-colons) problem is forgetting brackets. Every once in a while, I think, "You know, I don't need brackets here, it's just one line." But later I go back to that for loop or if statement or whatever, and I add a couple extra lines for some reason, but I forget those damn brackets!


The above picture is a good example of being able to write an if..else statement without the use of brackets. Now notice the difference the number of lines makes:

This code looks right doesn't it? Wrong, it is tricky to tell because of the indention (which I had to add myself, the editor wouldn't for me). A lot of times, if you are sure you are going to be typing in more than one line, and probably most of the time no matter what, you are in a habit of adding brackets, but when you go back to add a line or two, you totally forget about the brackets. Again, with practice, most people get better at remembering these things.

The third, and most important, and least noticeable problem is forgetting to deallocate memory, which is why you really shouldn't allocate pointers and that crap in the first place unless you absolutely have to. Has anyone here every ran a program, and then ran it again later without restarting... and then ran it again later, and again, without restarting? Well after doing so, did you notice your computer was extremely slow? So you open up task manager and kill every last process you can think of, and then you are down to 25 processes yet your memory usage is still at 93%. What's happened is called a memory leak, and in short... using new without using delete causes this. And even larger, using a million news without deletes causes this in a large scale.

Let's suppose you do remember your delete statements, you allocate memory for a bunch of arrays, array1, array2, array3, etc. and then you make absolutely sure you remember to delete them, so you have delete array1; delete array2; delete array3;. Well sorry to break it to you, but that's not gonna cut it. That's going to delete the starting pointer (the pointer pointing to array1[0], and array2[0], and the rest) but it won't delete the entire array. To fix this you must use delete [] array1;

So there you have it, now you will be extra careful to remember those semi-colons and brackets. And hopefully you don't have to think about deallocating too many memory slots.. Besides, allocating them in the first place is already some fairly advanced stuff that you really don't need to be fooling with unless you know what you are doing. Typically I don't even think of allocating memory except for as a last resort... which means I haven't ever actually done it in my own project where I'm not following a guide that tells me to use new and delete!

Have fun!

Saturday, February 13, 2010

Mass Effect review

The latest game I've played has been like a revelation for me! I am a science fiction fan, and also a fan of role-playing games, and guess what game has both of those elements? Mass Effect was created by BioWare, the same guys that made Neverwinter Nights, Star Wars: Knights of the Old Republic, and most recently, Dragon Age: Origins (and Mass Effect 2) After I realized how much I had played Mass Effect (I beat the game THREE TIMES and then this morning I caught myself about a third of the way through the fourth) I knew that it was it. Mass Effect was totally the game I've always been looking for. When I bought it, it sounded vaguely familiar, and for a month after I got it (caught it on sale for $14.99 by-the-way :p I wish I could catch Mass Effect 2 on sale for even $34.99) it was just like every other game I buy, I spend up to $20 and get a game that sits on my virtual shelf until I decide it's taking up too much space and delete it (only to be downloaded again a week later)

Well, anyways, the thing about Mass Effect that I really enjoy is the fact that you play it once, and you are like "heh that was pretty good" then you play it a second time and alter the settings just a tad bit, and then you find yourself thinking, "I don't remember this part!" and then a few familiar things happen, then you get some crazy achievement, and you go like "wow how did I not get that achievement the first time!" This is obviously, though, a feature that most role-playing games have, called re-playability.

Another great thing is the controls. You can assign abilities to certain hot-keys, and it's got a quick-save feature! Plus it has an instant pause you can use during combat to assess the situation a little bit, and you can also switch weapons and use abilities from that screen. One annoying thing is the automatic cover system. You'll want to be careful when walking up close to walls and things or you'll turn around and duck... while your enemy is in a critical position and it'll just take 3 shots to down him, and now you are stuck up against this stupid wall! The cover is sometimes useful when you are facing a ton of enemies, your shields go down or your weapon overheats so you take cover and use some first aid or wait for your weapon/tech/biotic abilities to recharge. It would be a lot better if there was a hotkey to do this though, instead of automatic.



My absolute favorite part of this game was definitely the storyline! Drew Karpyshyn was even good enough to write books that extend the storyline for you and really make you feel like part of the action! I don't want to give you too many details on the storyline, to avoid spoilers and mad people, but I will say that it's an awesome storyline. You can start out as a male or female, you can select your background (but that only changes one sidequest and gives you a couple extra renegade/paragon points) and you can select your class. The class part is the best, I first played as a soldier... that was pretty fun, then I played as an infiltrator, that was ALSO pretty fun, but I couldn't use assault rifle/shotgun :( (you can after unlocking an achievement like making 250 kills with a shotgun or assault rifle, the same with sniper rifle) My favorite, was the sentinel. It combines biotic and tech powers, so no weapons (unless you get that achievement I mentioned above) but biotic/tech is like pwnage!

Mass Effect was a great game, AWESOME voice acting (well female shepherd was awesome, but male shepherd was kind of dull. Everything else was also pretty good but I didn't hear it during EVERY single conversation so I can't put my finger on anything else.) great storyline, great re-playability. The graphics weren't exactly up to par, but the biotic/tech animations were still some pretty great stuff! I give Mass Effect a 9.5!

Saturday, February 6, 2010

Synergy (software) review

Well last weekend I found this cool stuff called Synergy, and so I decided I'd write a review on it. It's really a great piece of software if you have more than one computer; it allows you to control multiple computers with one mouse. If you know me, you might know that I have a laptop with it's screen plus a second monitor, and I also have a desktop with a nice monitor, and I'm a bit of a multi-tasker in the sense that as I write this review, I also have a browser open with about three other reviews on this specific software, I've got Trillian open, I've got MedieMonkey open playing music, I've got Notepad++--which is the best notepad replacement ever (next software review?)--with 6 documents open and I've also got Gmail and Google Calendar open. For some reason I have an English paper and two other OpenOffice documents (including this one) and I've got a virus scan running on my laptop.. You know? When I put it in words, it seems like I've got every program installed on my computer open right now, but anyways, the point is: I'm kind of a multitasker.
Well multitasking, as most people is hard without one of two things: Alt-Tab and multiple monitors. The multiple monitors part is different, but it makes things a whole lot easier, because at one time, I can see this document, my calendar, and in a tab a thing that tells me I have one unread message (wonder who that's from.. oh well I'll check it after this) and I also have a quick play/pause button for my music. When I'm writing research papers, it sucks having to alt-tab between browser, read a little, alt-tab back, type a little, etc.--It's nice when I can just turn my head a little, read a little, turn my head BACK, type a little.
Well now that I have three total monitors, it also means I have two keyboards and two mice (mouses?) and half the time, I'll start typing on one keyboard and then I realize I'm typing on THE WRONG KEYBOARD! Yes, once I even shut down the wrong computer using keyboard shortcuts and ended up losing about half an hour's worth of work opening all the applications I was planning to use! <--That's actually an exaggeration. With Synergy I have solutions to every problem every presented in this universe, in fact I considered nicknaming it 42. You know, the answer to the universe and everything... oh whatever it was a joke, anyways, with Synergy, I can move my mouse from my desktop to my laptop AND BACK!!! That part totally blew my mind away. Then I realized I could copy-and-paste from one computer and back (goodbye netpaste, you are no longer needed) and I could move DOCUMENTS from ONE COMPUTER and back!!! Wait let me test that, just a second.. ok you can't move documents from one computer and back, and that is why you use shared folders. But I thought, this is the sickest thing ever to happen to my desktop and laptop, it's like they've become married, they have joined souls and become one. Well now I have seen a problem: I can't use alt-tab to switch between firefox on my laptop and openoffice on my desktop. Well simple, Synergy has shortcuts which let you switch the keyboard/mouse between computers, and problem solved.
Well Synergy is a really great piece of software, it's been very helpful. I'd give it a 5/5 easily. I think you can connect more than just two machines together too, you could probably have 5 or even 10 computers together :D Oh and the cool thing, do you have two computers because you like Linux and Windows? Well no problem, or maybe you like Mac and Linux (such a Windows-hater!) well no problem! Synergy works across multiple operating systems at the same time :) So in conclusion: do you have two computers? Good, get Synergy. Bye.