Tuesday, November 24, 2015

The dangerous pointer to vector

This is actually a really obvious "issue" but I found that some developers (usually the inexperienced ones) simply don't think about this horrible source of bugs:). Now let's see the problem: If you run the code snipped above you will see an output similar to:

The value of our int is: 1
The value of our int is: -572662307
The explanation for this is simple. If you think that is a great idea to hold pointers to vector elements, you are wrong. The vector is basically a resizable array and the actual resize operation is:
  • Create a new and bigger array.
  • Copy all content from the current array to the newly allocated array.
  • Delete the current array and replace it with the newly created array.
See the problem? When the resize occurs, the underlying array is deleted and your pointer is invalidated. So be careful and don't use pointer to vectors.

Sunday, November 15, 2015

Programming Tips: Don't be clever

Everybody knows that debugging is a lot harder than writing code and every code needs to be debugged sooner or later. If not debugged you will certainly need to read it, maintain it, update it or optimize it. Let me ask you a question: If you are as clever as you can when you write the code, how you'll be able to debug it? Debugging is a lot harder than writing code! You will need to be a lot smarter than you were when you wrote the code. My advice is: don't be clever! Write code in such way that anybody can read it, write the most simple code you can and even so, the debugging will give you some headaches. Don't try to be a smartass. Write your algorithm as clear and simple as possible. Coding is not a contest, nobody will think you are limited because you don't write some obfuscated condition. Be clear and concise, your code should be readable by your grandmother, don't make simple things complicated, don't be clever!

Sunday, November 8, 2015

Install Brackets on Kubuntu/Ubuntu

I tried to install Adobe Brackets on Kubuntu 15 but sadly I couldn't do it directly. The problem was an old and obsolete dependency called libgcrypt11. The "solution" for this is for Adobe to update the .deb package but obviously this is not an acceptable solution, for us users. What you can do is install the obsolete libgcrypt11. For this you should:
  • Download the libcrypt11 library from here.
  • Install the package using QApt Package Installer (right click on the downloaded file and Open With QApt Packakge Installer) or from command line using: sudo dpkg -i libgcrypt11_1.5.3-2ubuntu4.2_amd64.deb
  • Install Brackets .deb the same way as above.

Friday, October 16, 2015

C++ IDE vs Text Editors ?

As a VIM enthusiast I think that you can do a great job using a plain text editor + a terminal. Both Emacs and VIM are great tools with IDE like features, great shortcuts, nice plugins...

Sunday, May 3, 2015

Does AdMob work on Windows Phone 8.1 ?

Short answer yes. If you are a developer outside the US and you want to write software for Windows Phone 8.1 you'll probably be interested in adding some ads to your application. One of the best mobile ad provider is AdMob from Google. Good news is that AdMob is available on both Windows Phone 8 and 8.1 Silverlight but NOT in the universal applications. Also note that in Windows Phone 8.1 Silverlight the ads will work if you run your application in the emulator but will not work on your own development phone. This is normal, no need to panic, just test it on another phone and you will see it works.

Tuesday, September 30, 2014

Windows Phone 8.1 roaming issues

This year I bought a Nokia Lumia 620 in spite of the fact that everybody told me that is not the best idea. The thing is that they are wrong, the phone actually works perfectly for the price and Windows Phone 8.1 is not a bad OS. In fact I still think is better than Android but beware dear users because it is not stable yet. I had some minor problems with it but until now I was always saying is OK, at least my phone does not have lags and does not restart during a conversation.