MAZYOD’S
DEVDIARY

Blabbering on, and on, and on…

Gmail Filters

It seems inevitable that once you start using GitHub seriously, you run into this issue where you just get overwhelmed by the number of emails sent in a single hour. It also gets distracting and annoying when you just don’t have the time to go over them, and need to see everything else.

That’s where Gmail filters come into place.

It is probably an ancient concept that is widely used in the developed countries, but for a developing county, emails where never our thing. “MSN” was. That caused us to be less interested in investing time organizing our inbox, and more interested in changing our profile pictures and status messages on IM clients.

(Note to you youngsters, MSN was what we called all IM services, which was only MSN initially, then GTalk, … etc. “Let’s chat on google’s MSN!” was a common phrase.)

The Filters

Setting them filters is super easy, and convenient. After going to the gmail web app, just search for the pattern of emails you want to filter. It should update the view to show you the result. You can use this to validate your search query. After that, click the small gray arrow next to the search button, and choose “create filter from search”. Le Done.

Conclusion

Stop allowing your valuable time to be slowly consumed by all those emails that you don’t need to see immediately. That especially applies when you are at work, or in the mood to do great things. This will come in handy.


Unity

Shit is getting real (⌐■_■). I started looking into Unity (again), and this time round, there is no backing out.

There were a lot of flaws in my previous approach to learn Unity. I tried desperately to ignore the editor and code everything, as I would normally do in cocos2d. That caused major nightmares and headaches, and me giving up eventually.

Not anymore. The first thing to master is not C#, but the editor instead. Starting with Unity website’s awesome tutorial line up, I think I learned a lot more than I would have if I were to just desperately try to get a game up and running just through code.

With the editor basics out of the way, I think I’ll just go ahead and run through the rest of the tutorial for the time being, and then implement a dead simple game from scratch to test what I learned.

Conclusion

This is a mark in history of when I started taking Unity seriously. I am not sure where it will end, but I sure hope it ends well, since it’s taking lots of time learning, and other projects are being delayed because of this >_<.


Memory Preallocation

No, no, I am not referring to the pooling of high-level objects and caching them, that’s child’s play. I am referring to hard core C level memory preallocation, slicing, and pooling.

What I’ll do is, I’ll run through the thought process I went through, and that should give the best perspective to the reader about how this works.

Wait, Why?

I did mention this in a post from long, long ago. Read it up.

The Problem Statement

Thankfully, we have a lot of constraints that makes this problem a lot easier than it would have been if they weren’t there. I am taking advantage of most of the constraints, but not all, unfortunately.

The problem is:

Preallocate and reuse blocks of memory that would service a single type of object, which is the GameState object.

Sweet! So, the size of the objects are all the same, since they are of the same type! That makes things a lot easier. There is also the fact that they are allocated and freed in a LIFO fashion, but I didn’t rely on that property, which could’ve simplified things even more.

The Block Of Memory

So… What is this block of memory? Should be easy! Just an array of whatever the type of objects we want to create!

1
memBlock = malloc(sizeof(GameState)*preallocate);

Cool. Now, we have our memory block.

The Tracking

We need to track which memory blocks are available and which are not! Again, if I were to use the fact that I am doing DFS in my code, I can easily do the tracking using a single index that tells me how much of the memory block is consumed. Whenever a block is returned to the pool, it has to be the last block, since it’s LIFO…

(OK, I just went to check the code, and found something that bothered me, so I fixed it, then in turns out due to recent changes, the game is crashing, so I fixed that as well…)

I really need to make use of the LIFO property… It makes things a lot simpler, but anyway.

So, we are assuming that the memory is returned to us in random order. For example, we provide blocks 0, 1, 2, 3, and then block 2 is returned to us, while 3 is still being used. Hence, the requirement of a more detailed tracking.

The way I implement this is by creating an array of pointers. Pointers to what? GameState, of course!

1
memPtrStack = malloc(memPtrStack, sizeof(GameState *)*preallocate;

The first thing I do, is initialize this array of pointers to point to the respective index in the memory blocks array:

Then, let’s say three requests came in for memory blocks. We move the index by three, and “give” those pointers to the caller:

Finally, when the pointer is suppose to be freed, who ever called the alloc must give use the pointer back so we add it into the pointer stack, and that block will be available again for the next time alloc is called:

The Expansion

OK, if you think the above was a bit lame, I don’t blame you. That was super basic stuff. The fun kicks when when we want to expand the memory.

A request for a memory block comes in, but we already gave out all the memory blocks! What should we do!! Expand the memory block, obviously. I wish we could use realloc, but we can’t.

The most painless way is to probably do the following:

First, instead of allocating an array of memory blocks that is assigned to the memBlock variable, we change the variable to memBlocks, and make it an array to and array of memory blocks:

1
2
memBlocks = realloc(memBlocks, sizeof(GameState *)*(index+1));
memBlocks[index] = malloc(sizeof(GameState)*preallocate);

So, on every expansion, we bump the number of blocks allocated, and dynamically increase the size of the memBlocks array with realloc, and then assign the newly created space to a memory block.

Of course, with the new block available, we expand the memPtrStack and add pointer of the newly created blocks. (I won’t add the code, since it is ugly. I need to fix it).

Why we can’t use realloc:

It would have been so awesome if the use of realloc was possible, but it isn’t. What realloc does is request more contiguous memory, but the currently memory block allocated might not have any free memory beside it! In those cases, realloc needs to copy the current memory to another location, while allocating the new required space as well.

Since we are sending pointers to the callers, moving the underlying memory will make those pointers point to a memory address no longer managed by us!! Hello EXC_BAD_ACCESS.

The Performance

I haven’t really tested the performance of this versus the non prealloc’s performance, but I really want to do that soon. I already have the benchmarks from the Objective-C bot, and the non prealloced C bot on this page. I need to run the non prealloced tests again, since I moved to static libraries and cocos2d-x, which may or may not affect performance. Then, I can safely do the prealloc tests.

Now, if this prealloc thingie gives me another major boost, I can probably implement an AI that can easily beat top Dama players without breaking a sweat :D

Conclusion

It kills me that this hasn’t made it to my game’s update yet…. IT KILLS ME.


Android Static Libraries

I have had some grief trying to link the AI library of my game with the cocos2d-x game. Most of the grief was due to a silly, silly mistake from my end.

First, I didn’t immediately realize that I need to compile the library for Android, as I tried to link it against the iOS library. I quickly realized how silly this was, so I went on a journey on how to compile static libraries for Android.

It wasn’t bad. All I had to was provide an Android make file with the build steps, and an application make file with the supported architectures. Then, I had to plug these to a dummy project, so the make file gets triggered or something.

That was pretty easy, especially with the samples provided with the NDK. I replaced one of the samples organs with my things, and it compiled the thing! Hurray!

Then begins my nightmare…

As I tried to link it against my game, I used some reference online, which is to simply do the following:

1
2
3
4
5
6
7
8
include $(CLEAR_VARS)

LOCAL_MODULE := my_static_lib
LOCAL_SRC_FILES := ../../lib/MyLib/$(TARGET_ARCH_ABI)/libMyLib.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

This is probably the first thing I tried, and it gave me errors about missing symbols… WHAT?! I freak out and use nm command, and it shows that the library doesn’t have any symbols… “GREAT! THE BUILD SYSTEM IS BROKEN”, I cried in rage. As I hopelessly spend hours trying to figure the source of the problem, I keep telling myself: “It’s working on iOS, why not android? Because the build toolchain is broken”. If something like that was broken, someone ought’ve noticed… /facepalm.

After posting on stackOverflow, a guy told me how the nm command doesn’t work on these libraries, and I should use the binaries provided by the ndk to check, which I did. The symbols were all there…. WHAT?!

I kind of lost hope there… So, I took all the source files and included them into the project directly. No more static library linkage… Oh wait, but there is more.

As I added the source files, the iOS no longer compiled, and complained about missing symbols!! As I looked closely, I laughed hysterically at my silly, silly mistake…

So, in the code, which I only built for iOS up until now, it was using an old version of the library, and when I added the most recent source files, it threw errors, since in the up-to-date source I had done major function name changes…

While biting my lips, I updated the code to the newer APIs, and decided to build the libraries again. Voilla, it worked like a charm.

tl;dr: iOS was linked against an old library, android was linked against a new library, code was referencing older library API, Android failed to build, I laughed hysterically at one point.

Conclusion

Again… Think clearly, identify the root problem properly, don’t making any friggin assumptions.


KPT v5.1.0

KPT v5.1.0

It is official. The new update is released and is in the wild, and I think users should appreciate this update the most. The thing about this update is that it finally has what we call a “full adhan”, which has been requested by users for a while.

Initially, I thought that Apple might remove the stupid 30 second restriction, but it became quite apparent that the restriction isn’t going anywhere. So, we had to improvise instead.

Other improvements include 12/24 time format setting, which I had disabled because Apple recommends we just take the setting of the device. There was a user who was complaining about not knowing how to change it, so I just provided the ability to change it anyway.

To my misfortune (hey, I just realized the play on words Riot did with Ms. Fortune /facepalm), I had not properly configured the crash reporter SDK, so I wasn’t getting any crash reports. The thing is, even if your app is like the simplest app ever, with very little code, it will still crash. For example, in my case, I am getting a crash in a low level C++ implementation of SocketStream thing, which I totally don’t have any control over.

The feature I liked the most was the tweet highlights. Now, new tweets appearing in the app will be highlighted in order to show the users what they missed. I also hook that up with the tab bar, in order to highlight the tab at the bottom.

Conclusion

This is nothing compared to what is yet to come to KPT! IT WILL BE REVOLUSTIONIZED!!!! OK, that is probably too much.


What Happen?!

It seems like the pace of them posts is dropping to an alarming rate. Two posts per week is not how this is suppose to work! There is also too much to say for me not to say anything…

OK, I just spent like 3 hours writing this post, and decided to split it into three other posts just because it was just too damn long xD


Workflow & Pipeline

Seriously, do you want to just get shit done? Do you want to finish all those tasks in your list, but still have time to play League of Legends? Well, keep one thing in mind:

It’s all about the workflow/pipeline.

Don’t work hard! Work smart.

The second statement above seemed cheesy to me when I heard it the first time. I can not stress how accurate it is, though. Let’s go over some practical examples, shall we?

Me Blogging

I am a lazy programmer, and I want to do everything the programming world has to offer. That is definitely impossible, but how can I come as close as possible to that goal?

My previous blogging pipeline was like, go to wordpress.com, open their lousy editor, write lousy messed up HTML, save draft, preview, wait for loading… Oh man, it was horrible. The result? 5 posts per year or something…

Moving to Octopress, and using Sublime Text to write the posts, and terminal to deploy in a single line, everything fell into place. I have literally went into a blogging frenzy recently, and that’s all thanks to the ability to focus on the task, and not how to achieve it!

Application Development

Oh, those horrible, horrible days before git, and before automated tests… And, I will probably look back, and pity the non CI’d environment, as well.

I mean, after using git effectively on my apps, it was easy to tell what changes were made, and what needs to be tested for an upcoming release. Not to mention tracking versions using tags, and running automated tests in a matter of a few clicks.

Now, it is possible to release 2-3 application updates in a month, at least, without breaking a sweat. KPT v5.1.0 has been uploaded with many new features and goodies!

Reusability

After you find yourself suffering because of the “HOW” and not the “WHAT”, know that you are in deep trouble, and you must fix it.

For example, I really suffered from managing audio files, and always forgot where that script was, and what are the settings, and how to move the assets over, … UGH! Just horrible.

Solution? Go back to this post about scripting awesomeness. Let’s see hoe much my script library has grown in a week or so…

Sweeeeeeet.

Conclusion

Of course, all this, and everything on the blog, is a reminder to myself before the reader… FOCUS ON THE WHAT, NOT HOW!! Unless you just wanna do stuff for the sake of it, and just… drift in life.


Textfields in Cocos

I reached that part where I need the user to type stuff into the game… To my surprise, the first implementation that jumped at me was in CCTextFieldTTF, namely, the TextFieldTTF class.

This class didn’t have the create methods conventions, and felt weird. After implementing the thing, it turns out that the freaking thing is so bad, and barely looks anything remotely like a textfield. I was in shock.

I did a quick search about this, and it seems that the implementation of TextFieldTTF is in pure OpenGL, to be multiplatform as other parts of the code are. That’s when the CCEditBox implementation caught my eye.

I launched the cocos2d-x tests, and navigated to Extensions->EditBox, and there it was. A native, responsive, fully functional textfield that your eyes would love to see. Makes me wonder why not just wipe TextFieldTTF off the face of the planet.

Then, I found the sad truth. Since TextFieldTTF was a native implementation, it had to be implemented separately for each platform, and that is not trivial, especially with all the platforms that cocos2d-x supports.

The current implementations are half decent, but there were missing parts in the Mac implementation, that I went ahead and patched. I think I can actually contribute to this part as I develop my game, since I need it, and it’s behind in the cocos2d-x repo.

Conclusion

ALL HAIL OPEN SOURCE!!


Notification Center

After scratching my head for a while looking for a reason why cocos2d-x’s latest version deprecates NotificationCenter (formerly known as CCNotificationCenter), I found this thread in the issues section.

Apparently, the NotificationCenter was deprecated in favor of the new EventDispatcher class, which handles every single event you can think of, from keyboard strokes, touches, actions, … you name it.

So, the new way to do notification thingies is:

1
2
3
Director::getInstance()
  ->getEventDispatcher()
  ->dispatchCustomEvent("This is an event!");

Of course, this is a bit ridiculous to type all over the place, so we #define it:

1
2
3
4
#define gEventDispatcher Director::getInstance()->getEventDispatcher()

// Much better:
gEventDispatcher->dispatchCustomEvent("This is an event!");

Here Goes Nothing

Kuwait Prayer Times app has been approved and is pending developer release… Even after all the rigorous testing, I can’t help but get an uneasy feeling about this…

The thing about this update is, as I said, I moved a lot of assets to resource bundle, and that could cause things to weirdly break somehow…

AAAARGH!! I’ll just release it and hope that if anything bad happens localytics or hockeyapp will alert me and allow me to react ASAP.

Here goes nothing!


Cocos2d-x With a RESTful Backend

For the upcoming game, I want to build a very simple, yet scalable, convenient backend service that can easily be reused across multiple platforms.

After researching and checking, it seemed that all the game server solutions that provide TCP/UDP streaming and whatnot are extremely overrated for simplistic games that one developer like me could ever hope to make. Hence, I shut that door firmly, and moved on. (I am looking at you, SmartFoxServer).

After researching even more, it was as clear as day that RESTful service are dominating the backend development world. Not only are they super popular, and usually supported by any client app development tool, but it is also … awesome.

There are already attempts to make RESTful APIs for streaming, and that’s what twitter recently implemented. This changes everything, and makes a RESTful backend my target for the upcoming, and hopefully all future games.

Doing it in Cocos2d-x

In cocos2d-x, I wrote a very simple wrapper around the HttpClient class that defined my RESTful API:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace KDAPI
{
    /* API callbacks */

    typedef std::function<void(std::string error)> RegisterCallback;

    typedef std::function<void(std::string error)> LoginCallback;
    typedef std::function<void(std::string error)> LogoutCallback;

    ...

    /* API requests */

    void Register(const std::string& username, const std::string& password, RegisterCallback& callback);

    void Login(const std::string& username, const std::string& password, RegisterCallback& callback);
    void Logout(const std::string& username, RegisterCallback& callback);

    ...
}

The callbacks are in the form of C++11 lambda functions, and the API calls are simply C++ functions, not even included in a class or nothin.

So… Now, I need to make this work.

Conclusion

Only fools will tend to conceal knowledge!! I will try my best to write all my silly findings here, just in case someone finds it useful, for some reason.


Mother Flippin C++

I have spent a considerable amount of time due mainly to my lack of C++ knowledge, but I can’t help but blame the mother flippin C++ compiler and rapidjson developers… (P.S link is SFW).

In C++, there is a concept known as sending an object by value, as a whole. We don’t see that in Objective-C nor Java, let alone scripting or higher level languages. That object you pass around by value gets copied implicitly, sometimes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Car
{
    std::string model;
};

void printCar(Car car)
{
    std::cout << car.model << std::endl;
}

int main()
{
    Car car;
    printCar(car);

    return 0;
}

A very basic entry level C++ example (that I hope I didn’t mess up). Sending Car this way will implicitly invoke the copy constructor, since:

  1. We are passing car by value.
  2. We aren’t invoking the copy constructor explicitly, so it is implicit.

This can obviously get very dangerous if you are not careful, since the car object can get pretty damn big. Hence, some developers, especially ones writing reusable code, such as a library, can add restrictions to stop you from making this mistake.

In rapidjson, the developers chose to simply override the freakin copy constructor and make it completely unavailable. To my extreme misfortune, I was doing an implicit copy to a JSON object, and the library didn’t like it.

Fine, just change it? Well, that’s easy to say after I figured out the freaking problem!! The error was so absurdly vague, it made me grow a few white hairs. The error was so bad because, for one, it was a linker error, and second, it was something like:

1
2
Undefined symbols for architecture i386:
rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GenericValue(rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&)

If you haven’t realize it , the second line is a single type… ლ(ಠ益ಠლ). It’s equivalent, in a sense, to int or std::string. Yeah, that is totally ambiguous.

Let’s break it down:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
rapidjson::GenericValue
<
    rapidjson::UTF8<char>,
    rapidjson::MemoryPoolAllocator
    <
        rapidjson::CrtAllocator
    >
>::GenericValue(rapidjson::GenericValue
<
    rapidjson::UTF8<char>,
    rapidjson::MemoryPoolAllocator
    <
        rapidjson::CrtAllocator
    >
> const&)

I REPEAT… THAT IS A SINGLE TYPE!!!!!

“Yo, Joe. Can you implement this simple algorithm for me in C++? Oh look, you probably finished it… Wait, what? That is just you declaring a variable?”

Now, the C++ compiler is blamed for throwing such an undebuggable error, and the rapidjson developers are blamed for not using explicit keyword on the copy constructor.

Explicit copy constructors is a concept one of the developers at Sourcebits taught me, which is quite something. You can mark a copy constructor with an explicit keyword, which will make an object throw a compilation error if it was gonna be copied implicitly. It also gives the developer an option to copy the object explicitly, since he’s doing it, well, explicitly.

Conclusion

I have already downloaded Unity3D, but I can’t make myself abandon what I started, so I’ll see this through, and see if I can retain my sanity before this project ends…


Expeling a Large Number of Words

This post is complete rant about things … So, prepare for I shall expel a large number of words at you! (This phrase is completely stolen from my super awesome boss [in the past], Geoffrey Hunt).

How to Learn Coco2d-X

The best way to learn cocos2d-x is by far to look at the tests. The cocos2d-x team got tired of regression, and need to move faster with their ever growing community, hence they allocated an insane number of man power to write tests for pretty much everything.

In any case, these tests are well written and not only provide a regression test, but also a great source for examples that you can learn from.

As for me, I need to start dispatching HTTP requests, and I discovered an HTTPClient class in cocos, and I have no idea how it should be used. That’s when I read in the comments to look at the tests, and it hit me that I should have done that from the start.

POST vs GET

Unfortunately, today I got stuck on a stupid problem related to HTTP requests, as well! While at work, I was trying to debug NSURLCache, which is this new hotness that should cache NSURLRequests transparently, using Last-Modified, ETag, … etc.

The cache in our app, though, was refusing to store the requests I was trying! I changed the headers, tried to call the cache and store the request manually, just nothing was working… I went on stackoverflow, and searched for like 10 different questions with my problem, and none of them gave a reasonable answer. I was at boiling point.

That’s when I read this answer on stackoverflow that said:

We changed our request from POST to GET, and passed the parameters in the URL instead. That made NSURLCache work.

I laughed so hard at that. I was like, “Dude, I wish life was that easy! GET requests are GET requests, and POST requests are POST requests!”. I meant, we can’t easily switch our API, and wreck havoc so easily…

So, I chat my colleague up about this answer, and he laughed a little, and then went, “Oh, dude. You can’t cache POST requests at all, you know that, right?”. I stood like a complete fool at that point…

Of course I knew!! Our professor at the uni specifically told us that sending POST requests will ignore the cache!! POST requests are suppose to change the state of the backend, so it won’t be cached … Ever. I completely missed that.

Conclusion

I think I should get going now, and finish this HTTP thing I am doing, since it seems exciting, to say the least.


C++ References

This was … The most annoying this about migrating a project from cocos2dx 2.x to 3.0 is by far this problem, especially if you’re an average C++ programmer, like me…

Have a look here:

1
2
3
4
5
6
7
8
9
10
void setThingie(const std::vector<type>& other)
{
    _thingie = other;
}

...

std::vector<type> other;
setThingie(other);
other.push_back(something);

Do you see a problem above?

Here is the question:

We are passing the other vector by reference, that’s as clear as daylight. Then, we mutate it by adding an object. Does that effect the _thingie variable? … The answer is NO-da >.<

The previous containers used in cocos2d-x were all derived from CCObject, which meant you had to handle the memory management, as well as use pointers to pass things around. Switching to these objects made my design break.

In the game, I am creating a tree of possible paths, and each node contains a reference to the parent’s container, so it can see it’s “brothers”.

“Why not just give the child a pointer to the parent, and access the container through the parent?”

Of course, I would have done that… The issue is that the parent has four containers, and the child could be in any one of them. It’s as if the parent has 4 wives, and I am giving the child a pointer to the wife that gave birth to him!

In any case, with the issue above, the wife- I mean, the parent container was being mutated, but the child didn’t know! For example, the wife had a baby, so this child should know he has a brother.

1
2
3
4
5
6
7
8
9
10
11
12
13
// old code:
parent.containers = CCArray::create(4);
child.parentContainer = parent.containers[0];

// new code: BAD - Even by assigning a ref, it gets copied!
parent.containers = std::vector<Vector<Obj *>>(4);
// child.parentContainer is Vector<Obj *>
child.parentContainer = parent.containers[0];

// new code: GOOD - this finally solved it
parent.containers = std::vector<Vector<Obj *>>(4);
// child.parentContainer is const Vector<Obj *>*
child.parentContainer = &parent.containers[0];

This isn’t all diamonds and roses, it’s a very fragile design, unfortunately. By assigning a pointer, we risk having a dangling pointer when the parent goes away before the child, so we must make sure that never happens.


Copy to Clone

One the annoying changes introduced in cocos2d-x 3.0 is changing the copy method to clone. I don’t know why honestly, but it silently changes the return value from a retained object to an autoreleased object >.<

Since copy is based on the Objective-C copy method, developers expected it to return an object with a retain count of one, which it did. So, you would have to manage the memory yourself:

1
2
3
auto object = otherObject->copy()
object->doSomething();
object->release();

Unfortunately, if my use case was the code above, I wouldn’t have spent 10 minutes trying to find the cause of the crash. I did something asynchronous with the copied object, hence it crashed on a different runloop, making it 10x harder to debug >.<

In any case, from now on, use the new clone method, since copy is deprecated, and make sure you keep in mind that it’s autoreleased!!


Cocos2dx 3.0 Callbacks

Another seemingly interesting change is to callbacks. Previously, relied on ugly macros and weird syntax to pass a callback method to an instance:

1
2
3
4
5
6
7
FiniteTimeAction* callback = CCCallFuncO::create(
    this,
    callfuncO_selector(
        KDContentLayer::_switchLayer
    ),
    screenLayer
);

However, they now migrated to one of the new awesome features of C++11, which is std::bind.

1
2
3
FiniteTimeAction* callback = CallFuncN::create(
    std::bind(&KDContentLayer::_switchLayer, this, screenLayer)
);

Cocos2dx 3.0 createWithFormat

Apparently, the cocos2dx guy introduced a new class, Value, which I can see lost of “value” coming from it (I had to get that out of my system).

In any case, CCString is gone… and so is the awesome createWithFormat method, which allowed us to create string on the fly with format, like the really awesome languages.

Fret not! There is actually a replacement for that in the new API:

1
std::string string = StringUtils::format("Yaaay!! %s %s %s", "This", "is", "Aweeeesome!!")

apiary

For this weekend, I have made a switch to backend development. I haven’t touched the project for a while, and it seems I have a severe misunderstanding on how the process should be…

Mistake #1

I had a freaking GUI application written with Kivy in order to test the backend! I mean, I loved kivy, and wanted to test it out anyway, but … Not for this, man!!

Testing systems must be autonomous!! As you add more features to the backend, checking for regression should be done with a simple hit on the “Enter” key. That’s why, the first thing I need to do is migrate the GUI app tests to use pyTest + requests.

Mistake #2

I am using Google App Engine (GAE) for the backend, and I was trying to write unit tests using their recommended testbed/unittest combo. It’s all good until I realized that the test cases I was trying to write were for the webapp2 router, not he GAE goodies (memcache, datastore, … etc).

So, as mentioned, I am migrating to pyTest, and hopefully life will be all rainbows and unicorns.

Mistake #3

The first thing I tried to do when I jumped on the project was to write the pyTest cases, however, there was one slight problem… I don’t freaking remember how I designed the API responses!! I know the request is gonna return a JSON response, but … What exactly??

Of course, I could just jump into the code, and look all over the place for the JSON response builder and stuff, which might change, and I might forget or break, since it looks different in code…

That’s where apiary came in. Design and even test the API before you freaking implement it?! That’s freaking genius. This way, I can hopefully do some rapid development… In their website, it has this pic:

I don’t disagree, but in my case, it will probably be:

1
design <--> write test case

That will be awesome. Then, hooking the test cases with the actual GAE application, I can immediately start working on making all the tests pass!

Conclusion

I thought that the point of working at a company/startup was to learn the industry standards and tools… That is just a secondary goal, actually. The greater learning experience is in how to approach and tackle problems.


Now, It is a Must

I don’t even recall if I… Oh, I did blog a bit about what I have been doing, which is the code sharing thing and stuff related to Kuwait Prayer Times. Well, there we go:

I finally submitted. Even though I wrote that blog post about testing, I did even more testing, and found like a bunch of other bugs, that lead to other bugs in the Mac app, which almost drove me nuts trying to make everything perfect. It just can’t be perfect.

In any case, the most important “feature” I added lately, is to properly support migrating all the user preferences from the old version. I usually don’t care about that, and require the user to delete the app and reinstall it or something, but not this time, and no more of that in the future.

Hmm… Let’s see what else was there… Yeah, if you used the app, and selected an athan sound, the label shows truncated in the settings view. I decided to remedy that, and use the MarqueeLabel library. It has quite a few problems, but it works with a small hacks here and there.

The most apparent issues that I faced was that the label just completely disappears, the animation stops, and the animation speed plays at half speed, initially. I hacked all but the last issue, which I found to be too mundane to work on.

Conclusion

Mac KPT update, iOS KPT update pushed to Apple… You just cannot imagine how it feels to free up that task from my plate.


Open Your Source

YAY! Today is a great day. I have been working on a small, yet deep, iOS component that allows iOS developers to easily add drop-in auto complete features to their apps. Maniac dev awesomely tested it out, and posted it on his blog.

Working on this project gave me a true insight on what it takes to write an open source project. I had to make sure that everything is clearly defined for the developers who’ll use it, and hopefully contribute back.

I tried as much as possible not to write ugly workarounds nor hacky code, that was a challenge as well. I almost had to refactor the whole thing each time I wrote a few lines of code. (Not to mention that every new feature I add must be properly planned to not screw the design).

Conclusion

Yeah! It’s a great experience writing an open source component, but let me let you in a little secret. I didn’t initially write it for fun, nor to use it in my apps. I actually wrote is as a test to get into Telly, which it passed :D