Friday, April 04, 2014

Returning objects in C++

I recently discovered that returning an object in C++ might not be what you expect. I was surprised because in Java things would be different. Consider the following code:

getClassB() returns the mClassB attribute. Class B is as follows:

I wrote the following main function to test results:

I thought that a.getClassB().setVal(1) would set mClassB.mVal to 1. But when I read it using a.getClassB().mVal I got a meaningless number hinting that mVal was not set.

When I set the result of a.getClassB() to ClassB b and then set b.setVal(2) and read b.mVal I get 2 as expected.

Finally, when I use a.getClassBReference()->setVal(4) and then read it using a.getClassBReference()->mVal, I get 4.

I think that a.getClassB() returns a copy of mClassB which means that a setVal() operation on that copy does not modify a.mClassB.mVal. If you want to modify an field of an object attribute, the getter of that attribute has to return a reference, not a copy.

Thursday, March 06, 2014

Book: Waltzing with Bears

"Waltzing with Bears - Managing Risk on Software Projects", DeMarco, T., Lister, T., 2009, 196 pages

The book tells how things really are: People like tales more than reality, nobody likes bad news. People are 10 times more prone to believe things they like. The odds are against risk management. It is surprising if anybody can do it properly:
"We are like a primitive tribe that tries to hold the devil at bay by refusing to say his name." [p.113]
"The Ethics of Belief" by William Kingdon Clifford, which is mentioned in the book is well worth reading on its own.

Sunday, October 13, 2013


Facebook sayfaları yalan haberin çarpıcı örnekleriyle dolu. Geçenlerde aşağıdaki fotoya denk geldim. Fotonun altına "Arakan yanıyor, müslümanları diri diri yakıyorlar" diye yazmışlar, millet de galeyana gelmiş, verip veriştiriyor, paylaşıyor.

Fotoda insanların düzgünce sıralanmış olması içime bir şüphe düşürdü ve bu resmi google image search'te arattım, işin aslını anlatan 2011'e ait şu sayfaya rast geldim. Kongo'da Petrol tankeri kazası sonucu ölen insanlarmış bunlar (ayrıca Arakan Kongo'da değil, Burma'da). İşin ilginç yanı, ilk başta bu resmi "Müslümanlar Nijerya'da hristiyanları yakıyorlar" diye kullanmışlar!

Ne tarih, ne olay, ne yer, hiçbir şey tutmuyor ama müslümanı da, hristiyanı da "aceba doğru mu" demeden atlıyor! Neyse ki artık internet var da bu hikayelerin aslını anlamak mümkün. Ticari medyaya çuvaldızı batırmadan önce iğneyi kendimize batıralım, gaza gelip bir haberi paylaşmadan önce beş dakikacık araştıralım, komik duruma düşmeyelim.

Bu taktiklere başka örnekler:

Thursday, August 01, 2013

Math tests

Java's java.lang.Math library provides methods for performing numeric operations. It's a good idea to have a basic test list to test the math functions of whichever programming language you are using at the moment. You should know about the behavior of math functions (in cases like overflow) so that you won't waste a lot of time looking for bugs in the wrong places.

Thursday, July 25, 2013

Use exceptions, not error codes

Benefits of handling errors with exceptions instead of error codes [Advantages of Exceptions] :

Normal program flow and error handling can be visually separated which makes code reading easier. Easier to read means less bugs and peace of mind.

Saturday, July 06, 2013

Why most presentations suck

I rarely see a presentation that makes me feel that I didn't waste time. There are many ways to screw up a presentation, and it is not because there isn't information available about how to do it right. The main reason is that people consider it as a chore and don't spend enough time.

When preparing a presentation, my main motivation - independent of the topic - is public relations, i.e. presenting provides me with a chance to give people reason to like me. Once people have a positive opinion of me, it will be easier in the future when I need their help or need to convince them about something they don't agree with.

That's why I usually spend a lot of time for preparations. My method is similar to writing a technical report. I start early (a few days to a few months) and iterate on the way, sometimes changing the topic completely if it doesn't come out as interesting as it sounded in the beginning.

So, seek out opportunities to present and spend time on your presentations, it is an investment into your future.

Monday, April 15, 2013

Installing Junit Offline on Netbeans 7.3

To install JUnit with Netbeans 7.3, you normally need an internet connection during the installation of Netbeans. If that is not the case for you, here is how you do it offline:
  1. Install the JDK and Netbeans 7.3.
  2. Download the files in and put them under <local user>\.m2\repository\junit\junit\3.8.2.
  3. Download the files in and put them under <local user>\.m2\repository\junit\junit\4.10.
  4. Download org-netbeans-libs-junit4.nbm from
  5. Download org-netbeans-modules-junitlib.nbm from
  6. Start Netbeans, go to Tools/Plugins/Downloaded/Add Plugins, select org-netbeans-libs-junit4.nbm and org-netbeans-modules-junitlib.nbm, press install. After about 30 seconds you should see the success message.
Update, April 8th, 2014: To install JUnit with Netbeans 8.0, steps are the same as above. You only have to change the path in steps in 4 and 5 from /updates/7.3 to /updates/8.0