Month: November 2015

C++ Singleton

In my previous post, I talk about one of C++ pitfall in Global Object and how to avoid it. I forgot is to add is Singleton to handle Global Object. This is actually quite simple in C++, but it must use template. I don’t know for sure if you can’t do Singleton in C++ without template, but as far as I know, you can’t.  So if you don’t like using template then maybe you have to do different approach.

Here are the snippet of my Singleton in Object Oriented manner:

Now what you have to do is inherit this Singleton class to your Global Object class.

In your header (.h) files

And in the implementation (.cpp) files

Notice that there is a line to set static variable?

This is to set your default static variable in singleton to NULL. Why? Because we check if this variable is NULL or not in Singleton Class, so we must initialize the default value for the variable. I know for some compiler, it already initialize like int to 0 or bool to false. But this is not best practice and should have been avoided.

What is DLL Hell?

I keep hearing this when I discuss DLL or dynamic linking, but I don’t know what they mean. Some people I know always telling me to be careful about the distribution of my DLL because it can cause DLL Hell, but they don’t explain it to me what it mean or what it do.

So What is it?

I will explain it with an example.

So Application A installs a Shared DLL X version 1.0, but then Application B install same Shared DLL X but with a different version, let say 1.1 version. It should be compatible because they are using the same DLL. But because they are a different version, they may introduce different behavior about how their DLL works. This kind difference can make Application A crash or error because they expect old behavior, but new DLL provides different behavior.

But if you are reinstalling Application A, it will install Shared DLL X version 1.0 and the Application B will crash because same reason as before.

I hope this can answer your question. If you have any further question, you can ask me in the comment bellow.

Static Linking vs Dynamic Linking?

I have some problem when using C++ library, especially if they are using different C Run-Time (CRT) library configuration such as static (/MT) and dynamic (/MD). Usually, the library I’m using is choosing dynamic CRT for their build configuration, but sometimes there will be a one of the libraries is using static CRT.

My Question is, why they are using Static or Dynamic CRT?

I mean, there must be a reason in C/C++ so CRT can be built with multiple options. Someone on Stack Overflow already asked same question as me. Here are some reason why you choose Dynamic linking and Static Linking.

Dynamic Linking:

  • It looks like Dynamic linking can reduce total resource consumption, especially if more than one process shares the same library with the same version.
  • Dynamic linking mean that bug fixes and upgrades to libraries are quite easy and you don’t need to ship all of your application again. Just update the DLL or/and exe on the user application.
  • Or you can use plugin system for this.
  • But it can introduce you to a problem called DLL Hell. This can will happen if your dynamic linker is insufficiently flexible.

And for Static Linking:

  • With static linking mean you can know that your code will run in very limited environments such as boot process, or rescue mode.
  • Distributing your binaries become really easy, at a cost of sending a large and more resource hungry program.
  • Some people around me that more knowledge about this say that it may start faster rather than dynamic linking one. But it depends on the size and complexity of your program and the OS loading strategy.

So what should I use, dynamic or static linking?

It really depends on what you need and what you want with your application. But for me, I think I will always stick to the dynamic linking configuration. Because it provides all of what I need. And what the most important is, most libraries I’m using always build using dynamic CRT. Since you have to use same CRT configuration, I think I will get less problem in linking if I stick with Dynamic Linking.

Of course, this is coming from what my understanding about C/C++ dynamic and static linking. If you know more or what I wrote is wrong, please tell me in the comment bellow.

Some Pitfall Using Global Object in C++

When doing programming project, you may need to have a global object in your application. At least that what happen to me. Maybe because I need it for all my code or required by my sub-system or any other reason you can think of. But whatever the reason is, I frequently need to make a global object.

In C++, this can be done with multiple ways, such as:

Static Class

Or you can use a static class. But since in C++ you can’t really using static class (in C it will be ignored if you are using static keyword in class), you can do static method instead:

Above solution is easy and great to solve global variable for you. But it has some problem. You can’t really use more than one instance of the static method. So if you need more than one instance of a global class, then you can’t really use static approach.

Which will lead you to a second approach,

Global Variable

This is the easiest ways, or mostly programmer that new to C++ will do it like this:

Then you can make infinity instance of “DataFiles” and it is a global object.

But, it has consequence

It will cause you a problem if your global object needs other global objects to be initialized first. For example in the code example above global object “IOAnalyzer” need “DataFiles” to be initialized first, or some other class needs to be initialized first. Why is this problem?

In C++, a global variable is initialized before entry point, in this case, “main(void)”. One problem with this is ordering. You can’t control the order in which global object is instantiated first. Sometimes the object is instantiated in order of the link, but you can’t really count on it because it may different in some compiler. Even if it was predictable (ex: you can always make sure in Visual C++ compiler will be instantiated in order), you shouldn’t count on it. What makes this worse is that since C++ constructor doesn’t really have a return value, you are forced to do something ugly to find out if anything went wrong. But this can be solved by using

Global Object Pointer

By defining Global Object as a pointer, you can allocate and deallocate by your own order or at least by the order of what your system need.

With this global object pointer, you can have a proper global variable for your code without allocate or deallocate problem since you can always re-order them yourself. But always be careful when using the global object. They are pretty evil. Especially when a global object is still required by some class. For example, you have class A that need B class to operate but class B already be deallocate, and, of course, this will lead to an undefined behavior or an error, which is what you don’t want to have. Hope this help.

Bitbucket Graph Statistic

If you often working on Github then want to Bitbucket because some reason, maybe you miss the Github statistic like how many commits, contributor statistic, graph, etc. Well, you are not alone.

Github Graph

 

Many people seem to think the same way that Bitbucket need some statistic so we can manage repository better, like Github. Maybe you just want to see how many commit, or want to see Activity Time, or just want to see a nice graph of your repository. Whatever your reason is, I think Bitbucket can improve it service by adding some statistic to a repository.

There is workaround thought, we can use Bitbucket Add-On to add some nice beautiful graph to a repository. The addon name is Awsome Graphs, and it add some graph and statistic to your repository, just like Github.

Bitbucket Graph

Here is how:

  1. Visit your Account add on or click here.
  2. Find AddOn Awesome Graphs, and click “Add” button.
  3. Refresh your repository if you open it in Browser.

That it, easy right. With this, there will at least some statistic to help you manage your repository.

Want to see it in Action?

 

Account Add-On – [Link]

Bitbucket Blog – [Link]

Remove Fallout 4 Nerf Damage

If you found that Fallout 4 combat is like Borderlands series, you are not alone. I have been playing this game for 20 hours in survival difficulty and I miss the feel of high damage in combat when I play Fallout 3/New Vegas modded.

Difficulty

Either enemy dies really fast, or I die from 1-3 bullet shots. This is what I want for Fallout 4 combat, not like Borderlands combat where you have to shoot 100 times. Fortunately, someone made this happen even before Modding tools is released. I have to accept the damage nerf in the Survival Mode before I know this mod exists. I can lower the difficulty so I don’t have to mod it and my damage isn’t nerfed, but I don’t like Stimpack use in lower difficulty. I feel it was overpowered.

There is similar mod exists in Nexus, but I think this one do the job great and without issue. I will provide the link bellow, so if you are interested please check it out.

Eliminate Survival Damage Nerf – [Nexus Mods]

Fallout 4 Need More Key Bindings

As predicted by some of Fallout enthusiast, Fallout 4, just like any other Bethesda games need more key bindings. And some defined key need to be fixed so it can be changed like ‘E’ button that stand for activation key by default. For some people that rebind the key like WASD to ESDF will be annoyed because the ‘E’ key still bound to some command even if they want to change it differently.

Fallout4 2015-11-13 00-08-10-63

But for some key like ‘Left Alt’ is bounded to 3 actions, melee attack, power attack, and throw a grenade. This can lead to a nightmare. For example when you want to throw the grenade to the enemy that chase you, you press the ‘Left Alt’ button for that (default). But because you are panicking, you don’t press the key long enough and your character will only doing a melee attack which lead to the enemy catches up to you.

Or even worse.

You want to do a melee attack, but then you press the key too long. Rather than doing melee attack you throw the grenade. Since you want to do melee attack that mean the enemy is close. You throw the grenade to the target that close will lead to your instant death especially when you are playing on a higher difficulty. Your enemy kill you is normal, it the enemy, their job is to kill you. But killing yourself by your own weapon, except you are doing suicide, it feels really stupid.

At least, that what happen to me when I play Fallout 4. I really do hope Bethesda fix this issue as they fix the UI color too contrasts for some people.

SourceTree, Best Git Client

Today, I want to do a bit of a review to one of my favorite Git Client, SourceTree, made by Atlassian which is a company that makes an online productivity service such as Bitbucket, Jira and many more if you already know it. There’s a reason why I love SourceTree so much that it become an essential application on my computer, its pity though it doesn’t available on Linux. Here are some of them:

SourceTree

It Provides GUI

What is this? 90′?

Unlike the traditional way of using git, using command line tools, SourceTree provides us with easy to use GUI (Graphical User Interface) so you don’t have to remember the syntax to do something. Don’t worry, there is nothing wrong with using a command line. But for new user, especially if they are new in Version Control world. It may easier for them to using GUI based app.

We can see any essential thing in git repository really fast like commit, unstaged files, branch, tag, and more in a single glance without clicking anything.

Common Git Command is in Front

An essential command such as commit, pull, push, create a branch, and merge is displayed right in the front so if you want to do some git command then you can just click on the icon. And if you want to do advance command or the git command you want to do isn’t available in the GUI, there is terminal you can use easily so you can type your own git command on it.

SourceTree-Command

And if you think moving your hand to keyboard and mouse often is annoying, there’s a shortcut you can use.

Oh, and it adds it own feature (non-git feature) like Git Flow for Workflow. So if you are using Git Workflow on your project, it will help you doing any branching, tagging workflow manually.

Windows, Mac OS X support

It supports Windows and Mac OS X so if you are working on that platform like me, you definitely can use this application. But it doesn’t support Linux. It’s a bit a downfall but not feature breaking and Linux user usually already comfortable using a command line tools anyway.

It Git Client, not Github or Bitbucket client

It’s not specific online Git Service such as Github or Bitbucket client. Rather, it was Git Client so if you are using other online Git Service you can still use SourceTree to manage your repository. But if you are using Github and Bitbucket, it can list all your remote repository on your account.

SourceTree-Repository

As you can see in the example above, it list all of my remote repositories stored on Github and Bitbucket. Don’t worry, there’s no work repository here so my secret/work project isn’t displayed. 🙂

Maybe that all feature I like on SourceTree and why I love using this application for now. It has more great feature but what I describe above is what I like and useful to me on SourceTree. Like mercurial support, SourceTree support Mercurial but since I don’t really use mercurial so it doesn’t really useful to me.

If you are interested, why not check it and give it a try? I will provide the link bellow.

SourceTree – [Official Website]

 

Fallout 4 UI is pretty disturbing

Fallout 4 launched today and I must say I was impressed by this new series of Fallout. In fact, I’m bit surprised because really good, better graphic, less glitch, and so on. I won’t review too much because I haven’t played this game for a long time yet.

Fallout 4 UI

Instead, what I want to talk in this post is Fallout UI (User Interface). Yes, that green looking thing in your screen, maybe you can see in the screenshot above. I don’t know if some people or the developer aware of this but the color choice for UI is pretty bad. It really distracts me and it doesn’t feel fit into the game themes.

I mean, its green color really contrast compared to the background. Look at the image bellow for example if you don’t mind, I hide it in a spoiler for you if it will make you uncomfortable.

Color Contrast

At least for some people, the color contrast is a bit too much. And by what I mean of hurting me isn’t mean that when my eyes looking at them and then got hurt or something. It makes me uncomfortable when I see it.

Maybe some modder will make fix this and I will definitely happy, but for now i guess I should enjoy whatever the game offers.

Update 11/12/2014

It looks like Bethesda fix this by adding color settings. Now you can define your own UI Color.