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

Wednesday, March 13, 2013

Book: When Brute Force Fails

"When Brute Force Fails - How to Have Less Crime and Less Punishment", Mark A. R. Kleiman, 2009, 227 pages

Mark discusses how to improve our crime control policies by shifting from raw punishment to more intelligent methods and the obstacles that make it difficult. The basic idea is to concentrate efforts on high risk individuals. The most original ones are investing in parenting education and making post-release well being of prisoners a performance criteria of prison wardens.

Saturday, March 02, 2013

Fun for nerds stuck in boring meetings

Most meetings I attend are %90 boring and only 10% useful. I found that if I have pencil and paper I can prevent boredom by doing some simple derivations. By "simple" I mean that the derivation should take less than 5 minutes so that I can still follow the meeting. Here are some examples that I use to keep myself busy:

Friday, March 01, 2013

Detect Turkish characters with Java

To check if a string contains Turkish characters with Java, i.e. any of "ıİşŞğĞüÜöÖçÇ", you can use the following function (bonus: how to check if a string starts with a number):

Tuesday, February 12, 2013

The main obstacle in writing unit tests

I am an advocate of unit testing and try to implement them as much as possible. In the beginning of a software project, it is relatively easy and most of my tests pass. As my code gets bigger and bigger, tests start to fail. What is interesting is that the pass/fail behavior is not smooth, i.e. the number of passed tests might be lower than a month ago although I have written many new tests:

As my unit test base gets larger, the main reason of failure becomes out-of-date tests that need to be updated to match the design. In the messy middle portion of the project, I realize that I spend more time updating tests than fixing bugs found by my tests. There is so much oscillation that I'm on the verge of loosing hope and think about abandoning unit tests. If I persevere, I eventually reach a point where all my tests pass, but it takes a lot of will power. That is for me the main unit test challenge.

Bonus tips:
  • How do you know if you have good coverage for your new code? Try removing a line or a constraint check. If all tests still pass, you don't have enough code coverage and you probably need to add another unit test.
  • Testing only public members leads to tests that can withstand constant code refactorings and internal implementation changes, while still making sure the overall functionality stays the same.
  • When approached poorly, unit tests can achieve the opposite results, stealing valuable time and complicating the testing process.

Friday, February 01, 2013

Dude, WTF is this shit?!

I am involved in maintaining legacy Java code written by long forgotten souls and came across a mesmerizing function that finds the minimum of an array. It boils down to the following:
static int findMin(int[] orgArray) {
    //A typical "WTF is this shit?!" case...
    int[] sortedArray = Arrays.copyOf(orgArray, orgArray.length);
    int minValue = 0;
    for (int i = 0; i < sortedArray.length; i++) {
        if (orgArray[i] == sortedArray[0]) {
            minValue = orgArray[i];
    return minValue;
    //TODO: This function should be simplified as follows:
    int minValue = orgArray[0];
    for (int i = 0; i < orgArray.length; i++) {
        if (orgArray[i] < minValue) {
            minValue = orgArray[i];
    return minValue;
A classic "WTF is this shit!" case...

If we analyze the first algorithm, we can assume that Arrays.sort() method will run at O(n*log2(n)). The following for loop will run at O(n) time. So in total it runs at O(n*log2(n)) + O(n) which asymptotically converges to O(n*log2(n)).

The second algorithm uses a single for loop and runs at O(n).

Update - November 5th, 2016: There is a somewhat similar looking case (determining if there are repeating elements) where using Arrays.sort improves performance ["Data Structures and Algorithms in Java", 6th Edition, p.174-5]:
/∗∗ Returns true if there are no duplicate elements in the array. ∗/
public static boolean unique1(int[ ] data){
    int n = data.length; 
    for (int j=0; j < n−1; j++)
        for (int k=j+1; k < n; k++)
            if (data[j] == data[k]) 
                return false; // found duplicate pair
    return true; // if we reach this, elements are unique
The above funtion runs in O(n^2). Using Arrays.sort, we can decrease the running time to O(n*log2(n)):
public static boolean unique2(int[] data) {
    int n = data.length;
    int[] temp = Arrays.copyOf(data, n);
    for (int j=0; j < n−1; j++)
        if (temp[j] == temp[j+1])
            return false; // found duplicate pair
    return true; // if we reach this, elements are unique

Thursday, January 10, 2013

Bankaların nefis (!) web sayfaları

Bankaların web sayfaları pek kullanıcı düşünülerek yapılmış gibi görünmüyor, özellikle de büyük bankalarınkiler (para ile empati ters orantılı). Duygu pıtırcığı reklamlar vermeyi bilirler de misal az önce olduğu gibi EFT talimatım ad kısmındaki uyuşmazlık nedeniyle gerçekleşmediğinde uyarı maili atmak onların ufkunu aşar. Bu bloğa karşılaştığım özensiz konuları yazayım da sinirim geçsin biraz:

Ziraat Bankası:
* EFT talimatı verirsiniz, IBAN'ı doğru yazsanız bile ad kısmında en ufak bir fark olursa talimatınız önce gerçekleşti görünür, "işlem tamam" diye düşünürsünüz. Ama kısa bir süre sonra para sessiz sedasız hesabınıza geri yatar, olur olmaz mesaj/mail atmakta beis görmeyen bankanız bu detayı size ne mail ne de mesajla bildirmez. Ancak alıcı size telefon açıp "hacı para nerde?" dediğinde haberiniz olur.

* Havale yaparken hep vadesiz hesabımı kullanmama rağmen default seçenek hep "hazine operasyonları" zımbırtısı olarak gelir.

İş Bankası:
* Havale hesabı eklemek için şimdi adını unuttuğum nalet uygulamayı cep telefonuma kurmam gerekir. Ama benim basit telefona o naneyi kurmak mümkün olmadığından havale hesabını ancak imzalı dilekçe fakslayarak ekletebiliyorum. İş Bankası ile tüm ilişkimi minimize etmeme neden oldu bu nefis kısıtlama, kendilerini tebrik ederim.

* Vadeli hesapla ilgili hesap yapmak deveye hendek atlatmakla yarışır.