Entries in Programming (6)

Sunday
Jul242011

Hangman!!

So, the week wasn't very saturated with learning and/or coding, like the previous one.  Instead I've managed to pull the so far biggest code of my whole study, the 'Hangman' game in C++. :)

Two things.  First, I grow suspicious that it was mentally important to get this game done to get me going forward.  I've never ever tried anything like this before, even during my 'Java days'.  Second, this wasn't really hard!!  Yes, it took about three hours to quickly assemble the code, polish it, and fix bugs.  It'll now take a few more re-runs to check for any other problems, but so far the code seems to be working just fine.

Here's how it went.  First, I've created a very simple dictionary, just a simple text file with words for each letter of the alphabet.  So, I've got 26 words this way.  On a side note, one feature of my code is that if I now do any changes of the dictionary (f.ex. add more words), I do not have to re-write anything, it'll take whatever size there is, and will choose a random word out of that size.  What can I say?  I love 'vector.h'  :)

Then, I was pretty much following my own flow and wrote pieces of code as needed.  I didn't make too many functions (which I definitely could do), and I believe I could've managed to do without the multitude of imports, unusually high in this case, but since stability and speed are not affected, it's all right.

One key thing the whole structure of my program is based on is the entities separation.  I have one array of letters of the word for computer to refer to (it's always open, no hidden letters), and another array initially 'starred' (********), this one is for the player, and as the letters are guessed it reveals the corresponding fields.  This made it very clear and easy to keep track of what the computer 'knows' and what the user sees about the same word.

I've also implemented the alphabet array where I mark what letters the user has already checked, and this allows for warnings like 'You have already used this letter', thus a smarter program.

As I said I am yet to play with the newly created game, but even at this point it produces a very solid and fun result!!  It's been a great day today!

Saturday
May142011

Pointers...

Last week activities included coding, reading, and re-reading.  One particular topic I found to be not so clear is pointers.  The idea is quite simple, and it was easy to understand it, but the sytax and implementation is something I still have to wrap my head around.  My strategy is re-reading and watching the lectures over and over again, as well as coding the examples and exercises.

The rest of the topics (including archives, enumeration, data structures) were quite clear to me from the very start, since most of the same ideas were introduced during Java CS106A course.  So, I had no problems understanding and writing code for corresponding exercises.  I hope to be done with the topic of pointers next week, and proceed with the usual study-flow.

One little thing on the side.  I started to read "Zero Day" by Mark Russinovich, a must-read for any security-minded person.  Mark is the person behind SysInternals anti-malware solution, so he knows what he's talking about.  But most of all, Mark appeared to be a pretty good writer -- the novel doesn't let me go! :)

Saturday
May072011

Coding More and More...

It's definitely a quality shift happening during this week regarding my C++ studies.  I was reading and watching lectures for a pretty long while, and did much less coding.  This week it's definitely all about exercises and practice!

I actually prefer it to be this way, coding in XCode is relaxing and pleasant experience, I'd even say I enjoy it a lot!  Also that Textastic app on my iPad for 'on-the-go' programming helps me to stay focused on a problem during my commute or when I have a small window of free time.  I do rough prototyping on iPad as well (I use Notes+ for that purpose, and it works really well;  however there are many great solutions out there!).

There is an important difference in coding in XCode and in Textastic, which I'd like to bring about this time.  In the XCode it's very easy to track a bug or a typo, highlighted variables are easier to identify too, and of course you can just compile and see if the result is the one you want right away.  This makes me less cautious about misspelling and typing in general.  It also tends to soften my logics, or do less thinking about the algorithm.

Textastic does C++ highlighting, but it is limited to standard functions of the language and doesn't include variables.  This makes it quite tricky to write a working program from the scratch.  And you cannot actually debug it, since there is no way to do it on the iPad by any means.  This all makes me to pay more attention to implementation of my logics, to do more preparations (sketching out the algorithm, or as I call it prototyping), be carefull about spelling, etc.  For many people this would mean that it is completely useless waste of time to do this 'on-the-go' programming.  But I also know that it will be very easy for me to debug my program later in XCode, so I tend to use up as much time as possible to code using Textastic, and I am sure it not only saved me time, but also increased my learning speed and quality of the study.

And speaking of Textastic (yes, I do like this app a lot, really great and thoughtout piece of software) it's going to be updated very soon, hopefully in a couple of days with many more useful features (Cyrillic code page support, just to name one which is quite nice for me to have now), and I am very excited to see it!

Sunday
May012011

Getting Used To...

All the time since last post I was practicing my C++ programming skills, watching lectures, reading the textbook.  And while this may seem like not much to have been done, this is a very important part of, what I call, 'getting used to' process.  I am developing my pace, learning my motivation, and building a valuable tool-set for the future.

Speaking of that set, I should mention that some time ago I'd started to collect and organize various bits and pieces of information which I find may be useful in the future coding/design process.  I utilize Instapaper for that purpose (on a side-note it's really a great tool itself for these kind of tasks), and have already assembled around 50 articles on iOS/MacOS coding and developement, as well as on best practicies in design, usability, and visual arts.  I also use Zite, the personalized iPad magazine/reader to get to the new articles, and it did handle the task pretty well so far.

Once again, seemingly not much news, but it all builds up into a solid foundation, at least that's my feeling.

Monday
Apr182011

First C++ Program (already!)

So, I couldn't help but to brag that my C++ coding skills are much more apparent than I anticipated!  It looks like I am 'remembering' the language, it's so familiar to the look and feel!  And I also enjoy Xcode 4 a lot, which shouldn't be much of a surprise.

My productivity got another boost as well, and that's what I've come up with in the morning:

As some may guess this is source code for a simple program which spells out a number in English (the range is from 0 to 999,999).  Yesterday evening it seemed to be a very complicated task, but I did it in hour and a half before breakfast completely on my own (including debugging!).  If such pace continues on, I'll be coding in Objective-C by this summer!