Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, April 4, 2011

Learning While Coding

The last week or so at work has had me learning how to do some things for when I program which I never expected. They are all things that are important things to be able to do, and a few aren't as difficult as one would expect, though the major one (which I will get to) has been giving me utter headaches, because it leads to a rather large change in programming style and way of thinking.

Warning, heavy geekery ahead. Though really, on this blog, would you expect anything else?

To begin with, Localisation of applications. This is quite a big thing on, well, any piece of software. How do you write a program to work in any language? To make it display properly in Japanese, Chinese, Russian? Apart from the obvious issue of needing someone to translate for you (if you do not know the language), you also need a way to make it easy to inject these language options into your software. For example, if you hardcode all of your strings, then for every language version you need to find where all of these are coded, then change them for each language, then recompile many different language versions. This is completely unmanageable!

Luckily, for me at least as an iPhone programmer, Apple have made it easy. It seems so alien to me, having something from Apple which simply works for a change (my work laptop is living proof to me that the Mac elitist pricks who tell me that Macs are superior to PCs simply are spending too much time staring lovingly at the form of the computer, rather than the fact that the screen is showing that all your apps have frozen)!
To localise an iPhone app, all you need to do is create a strings file (called Localizable.strings - remembering that its z is important because they're American and can't spell. Also, a lost of configuration stuff is skipped by using this particular filename, since its the default), and define a bunch of variables in there. Once you have done that, wherever you code a string in the app itself, replace with the following piece of code:

NSLocalizedString(@"TITLE", nil)

where "TITLE" is the name of the variable, and the second parameter is simply space for a comment to assist a translator with (context matters a LOT in language).
Of course, there is a little bit more to it - you still need to actually localise your strings file. In xCode 4, all you do is go to the localise panel on the right, and add a localisation to your strings file. It asks you what language it is for (since the iPhone will use default language settings based on what the user picks). Then, simply change the variables you set in the above one to the language specific strings. Sorted!

It gets slightly more complex when you are localising images and interface layouts (due to button sizes and things), but this is the general workflow of it. Not bad at all!
(Also, Ray Wenderlich's site is where I found the tutorial that taught me this. Awesome site full of tutorials. Don't freak out when you see the "I'm quitting iOS" post - its an April Fool's troll)

 
Unrelated: Rocks fall, everyone dies

Another important thing I've been learning as part of work the last few days has been how to use a Unit Testing framework for the iPhone. Unit testing is an important part of programming. At least, that's what I've heard - I've yet to see results from it, because all I've been doing is learning how to do it, how to combine it with Mock Objects, and trying to get my head around this enough to write some useful tests.

The theory behind it is that if I write a test that ensures I get correct output from a function I write, then later on if I change the function (refactoring, optimisation, etc), then I can rerun the tests. If the tests fail, then obviously I've changed something to the point where it breaks - aka failed refactoring, where the actual processing has changed. Sounds useful huh?

Well, even more than that, once I've caught up on the tests I should have been writing, I can use this for TDD - Test Driven Development. This is where we write the tests BEFORE the code is actually written. The purpose of this is to force me to think about what is actually needed (in terms of variables and functions), and then ensure that each function works before I move onto something else (since its always nice to see green lights as irrevocable proof that your code works).

As you can probably tell, this is a far cry from my usual method of "think about the system, design some objects, start writing, run the app to see if it works". Hopefully, this'll work much better.

Its just doing my head in at the moment.

I won't go into details on how to get it working on the iPhone, since there are many ways to do it (and this post will go insanely long, and overly technical for those not so code minded), though I will mention that I'm using GHUnit-iPhone for a test suite, and OCMock for the Mock Objects, if you are interested in taking a look.

I will probably integrate some of this onto my home machine so I can work from home if required - and possibly more importantly, for my own work (which has yet to begin / be designed).

Monday, March 14, 2011

Country Coding - A Workday Bookended With Love - Tiger

Kalgar was, as you (his most loyal readers would know) having some problems coming up with topics for blogs, and so I (his trusted companion from a totally different town) took it upon myself to provide him with some...shall we say...inspiration. Okay, so I just suggested that we do a "blog swap", where we write a guest post for each other - the topic of which we decided should be our work days (I was just trying to be dramatic, jeeze...) What follows is that blog post - Tiger.

~~~~~~~~~~~~~~~~~~~~~~~~~

I work as a programmer at Charles Sturt University in Bathurst, a small city surrounded by the country. I used to work at a kind of boutique software house called 'The Project Factory', where I wrote iPhone applications. That was until I was swiftly replaced by Kalgar (of course, I had expressed my intent to leave Sydney, and I thought it would be incredibly rude to dash off before I was replaced, so you know - huzzah for him, and all that.) At the university I pretty much make the applications that allow the admin staff to carry out their student crushing duties, as well as making sure that people have access to our online services and things like that. Interesting stuff!

I wake up in the morning sometime between 7am and 7:30am, depending on what time I got to bed the night before, and I usually start the day by cursing the fact that I stayed up so late playing D&D with my friends again. I then consider what I just thought, and berate myself for decrying the wonders that are out gaming nights. After this I shower, have breakfast, and generally get ready (a process which takes about half an hour) and by 8:00AM I am heading out the door to catch my public transport.

Public transportation in Bathurst is pretty sparse. If you wanted to get up to the university in time for work without enduring the 40 minute uphill walk then you are either limited to a taxi or a bus. The bus up to the uni costs $3.10 for a 10 journey that lasts roughly ten minutes - the prices are not proportional to the service offered, and the bus driver is often late leaving the stop. I would normally not complain about such a trivial matter, only the bus comes once per hour, at 25 minutes past 8. Catching a taxi is significantly more convenient, however a taxi up there would, in Bathurst, cost you $11 on average. I know this, because I have missed my bus on more than one occasion.

Pictured: unrelated, but much more awesome method of transport - Kalgar

Upon arriving at my destination (a full 25 minutes early for work...) I rock up to my cubicle and log into my machine. This is then followed by me banging my hands on they keyboard for three to four hours, in the hopes that the file I'm working on will magically become fixed if, mayhaps, I could just type the correct combination of characters. If I manage to get an easier job during this time, such as restoring someone's access to their uni homepage, or granting a manger request to a forum, then I am incredibly thankful - I am not a morning person. Cannot brain. Have the dumb.

At some time between midday and one in the afternoon, I start my hours lunch. This is, for me, the most glorious hour in the history of hours. Each day is a new culinary adventure based upon what I've prepared the night before. Today, for instance, I'm having leftover sushi that I prepared on the weekend. Sushi, miso soup, tuna, and some tea. That, my temporary readers, is the lunch of kings! Kings of bento!! I usually take my lunch downstairs to hang out in the gaming laboratory with the nerdlings, and watch them play something like HoN or TF2 or something. It's an awesome hour, and it really brings me to life as far as 'starting the day' goes.

After my affable hour of amazing awesomeness and alacrity, I return to work for the remainder of my day. This time, however, I spend until either 4:30 (if I only want to do 8 hours) or 5:00 (if I want to build up some flex time) churning out the most awesome SQR scripts that your being hath ever lain eyes upon. It is during this period that I have done things like stopped half the Distance Ed students from missing their exams because they couldn't change their exam centre - also I'm pretty sure I stopped all war and solved world hunger once.

When the work day is done I pack up my Bag of Holding (or backpack, depending on my mood when I got ready in the morning) and start the 30 minute, downhill walk home. Usually I will stop off at the shops on the way, in order to pick up some stuff that I'll need for my coming evening (including what I'll be using to prepare lunch for the following day) and then head off home to unwind by either watching copious amounts of television, or by playing some kind of tabletop RPG, before going to bed way too late for my own good.

Lather. Rinse. Repeat.

The moral of this story is that work should really consider letting me set my own hours. I mean, I'd still work 8 hours, but if I could maybe work some of them from home I might get a bit more done during the day. Alternatively, if I could work for a bit in the morning, and then return home for siesta or something, before coming back, that would also be quite cool of them. Actually, come to think of it, the uni should totally have rooms for staff members who need a bit of a nap during the day - it would let me try out polyphasic sleep, and finally perform that experiment on myself...

~~~~~~~~~~~~~~~~~~~~~~~
The above post was written by my special guest, Tiger. Who is Tiger? The answer to that, and more of his words of wisdom are available on his blog. Read it, you know you want to.
~~~~~~~~~~~~~~~~~~~~~~~

Wednesday, January 19, 2011

Rambling

I can't really put together a coherent post today. Something about there not being much happening at the moment, and such, so today's post will be a bunch of random thoughts I've had lately so that I stay in the habit of writing things.

The other day, someone mistook me for Jack Black when I walked into their convenience store and bought a drink. This is not the first time, though it typically happens when I don't shave for a few days (though to be fair, that happens most weeks because I shave Mondays, then get too lazy to do it again until either Friday, or the following Monday). It's tempting to run a social experiment to just stop shaving for a while, and see how many people approach me. Perhaps see how long I can keep the illusion up (probably just long enough for them to realise that the man doesn't wear glasses. Well, not ones to allow him to continue to see anyway...)

I recently started playing around with HGE (Haag's Game Engine) in C++ in preparation for an event I've applied for entering called GameJam. GameJam is an event for insane people where you spend an entire weekend making a game from scratch. Little to no sleep. To enforce this, they give you a topic and a set of keywords, which aren't revealed until the event begins. You are allowed to use whatever libraries you like, however, and so I started getting back into C++, since iPhone programming isn't very conducive to presenting the game on stage at the end of the event.
Anyway, I noticed that the HGE tutorials have only some of the WORST CODE I HAVE EVER SEEN. Its rife with magic numbers, global variables, and cryptic math that makes me want to find whoever wrote that tutorial, and shove a programming practices book down their throat, which will likely have the same effect as sunlight has on vampires (not the Twilight vampires, they're not vampires, they're sparkle fairies).
The engine itself isn't that bad, and it's possible to salvage it, but those tutorials... it physically hurt me to code like that. Once I get a bit more of a handle on the thing I'm totally gonna write a basic framework for myself. Well, less of a framework more of an organisational thing.

Today, I had breakfast for the first time in ages. I used to never be able to eat solid food before 10.30 or 11am, because if I did I would be sick all day. It seems this was a side effect of my undiscovered Coeliac, since typically breakfast foods (cereals, toast, etc) are filled to the brim with gluten. This morning I woke up early (accidentally), and decided to give that gluten free cereal Mum found a go. I didn't feel particularly well as I headed into work today, but by the time I got there the feeling passed. Though having brekky didn't have the utterly electric effect on my energy levels that I've been told it would. Science lied to me?

I have been sleeping utterly horribly lately. No idea why. This might be contributing to my acting quite crabby when I get home from work. I'd apologise, but right now I probably wouldn't mean it :P
So damn tired...

Wednesday, December 1, 2010

First Post

Greetings and salutations, poor fool who dared to venture to my blog.

I don't know why you're here. In fact, I don't even know why I'm doing this, apart from having had multiple people tell me I should write a blog. I'm looking at you Amir and Dwaine.

Well, not really, because if I was looking at you that would be creepy.

So, my name is Andrew, and I'm a geek. I'm into programming, video games, Japanese anime, and Pathfinder.
Pathfinder would be an offshoot of Dungeons and Dragons 3.5, since I found DnD 4.0 was too simplistic.

Speaking of DnD, I really want one of those cool D20 that glows when you roll a critical hit... would be perfect for when I finally wipe out my pesky player party... muahahahaha!

I spend a lot of time nowadays programming for the iPhone. Possibly because I enjoy it, but more likely because its my job.
I do enjoy it though. Enough to have recently purchased a cheap mac (well, cheap for a mac anyway) against my regular human instincts, and have begun development on my own app. More on that another time methinks.

So in this corner of the intertubes, I will occasionally be posting things. A lot of the time, it'd just be opinions on games, anime, etc. Whatever catches my mind at the time. It'll also probably be very rambling. Like this post.

Sometimes though, it may get serious. Even technical at times.
But usually geeky :)

I also *may* forget about this thing altogether. We shall see.

Ciao for now!
~ Kalgar