Shades on sunny day. (Taken with instagram)

Shades on sunny day. (Taken with instagram)

Just my wallpaper. (Taken with instagram)

Just my wallpaper. (Taken with instagram)

Just some California sky. (Taken with instagram)

Just some California sky. (Taken with instagram)

Debugging to understand

These days I’m doing lot of debugging in Eclipse in order to find bugs, sometimes to understand my own code which I wrote long time ago.

I found it very helpful to step-through your code and check every assumption you made during the coding are valid. 

Changing the variables on the fly to see how your code react is added benefit. After all it makes you a good programmer if you can debug faster.

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

        — Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.

— Anil

Usage of List vs Map in Java

There are many reason to select one data structure over other. Here is one way to select between List vs Map.

List is perfect choice for iterating over elements. Time complexity of retriving element by index is O(1)

Map is perfect choice to searching an element by it’s key. Time complexity of contians operation is O(n). Where as time complexity of contains on list is O(n2

So if I don’t use contains operation then I prefer List over Map. Otherwise I choose Map data structure.

— Anil Madamala

Testing pinterest

In 2027, in a chaotic world in which humans can no longer procreate, a former activist agrees to help transport a miraculously pregnant woman to a sanctuary at sea, where her child’s birth may help scientists save the future of humankind. Pin It

Using Git as source control

I read this article and thought it’s a neat way to use git for real development projects.

 http://nvie.com/posts/a-successful-git-branching-model/

I use github to have release quality code in a place which in not my laptop or office. Github is owesome with all it’s features.

Here is my wish, 

     I want to use git, even for personal projects from now on. There is nothing wrong with having zip snapshot of code everyday. But it’s only 100 times harder to maintian (merge, branch and diff etc.)

Common errors in setting java heap

English words with letters sum equals 100 

Here is java code to populate the list.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 
import java.util.Map;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class WordTotal100 {
public static void main(String[] args) {
// read big.txt file
try {
String fileStr = readFileAsString(“words.txt”);
String[] words = fileStr.split(“\r?\n”);
int count = 0;
for(String s: words) {
if(stringToInt2(s.trim()) == 100) {
System.out.println(s);
count++;
}
}
System.out.println(“number of words with 100 sum: “ + count);

} catch (IOException e) {
e.printStackTrace();
}
}

// convert file into string
private static String readFileAsString(String filePath)
throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();
return fileData.toString();
}

public static int stringToInt2(String word) {
int sum = 0;
char[] chars = word.toLowerCase().toCharArray();
for(char c: chars)
sum += (int)c;
return sum - (96 * chars.length);
}
}

Here is what I did to get as many distinct words as I can.

<unix/mac>$ cat /usr/share/dict/words > words.txt

I did this program for fun. No other meaning to it.

Readability of code and code conventions

Writing code is not difficult. If you know the logic you can write code.

What’s really difficult is to write readable code. Let’s say you wrote most clever code in the world. If it is not readable, then who is going to fix the bugs in the code. I’m sure that even you can’t understand your code after couple of months.

Following coding coventions is not waste of time or difficult. If you are a Java programmer, just Google for “Java coding conventions”. Select any link and try to follow some rules which make sense to you. 

Naming is everything for readable code. Choosing proper names for variables, classes, functions reduces the need to write documentation. Only write comments where you can’t exress what you are trying with the code. And use whitespaces in a way that makes code more readable. Feel free to break the rules, but not for the sake of breaking conventions. 

Here is a link to the Official Java code conventions, 

http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

I’m not saying I write most readable code. But I always belevie that’s very important for being a good programmer.