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

Using Git as source control

I read this article and thought it's a neat way to use git for real 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.)

 

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.

 

 

 

You can increase your intelligence: 5 ways to maximize your cognitive potential

While browsing Hacker News I stumbled with the following article. It is well written and easy to understand. I wrote notes while reading the article. By all means go and read the original article. Here is the link to original article. http://www.scientificamerican.com/blog/post.cfm?id=you-can-increase-your-intelligence-2011-03-07

Five primary principles

  1. Seek Novelty
  2. Challenge Yourself
  3. Think Creatively
  4. Do Things The Hard Way
  5. Network

1. Seek Novelty

It is no coincidence that geniuses like Einstein were skilled in multiple areas, or polymaths, as we like to refer to them. Geniuses are constantly seeking out novel activities, learning a new domain. It’s their personality.

People who rate high on Openness are constantly seeking new information, new activities to engage in, new things to learn—new experiences in general.

Excellent learning condition = Novel Activity—>triggers dopamine—>creates a higher motivational state—>which fuels engagement and primes neurons—>neurogenesis can take place + increase in synaptic plasticity (increase in new neural connections, or learning).

Take home point: Be an “Einstein”. Always look to new activities to engage your mind—expand your cognitive horizons. Learn an instrument. Take an art class. Go to a museum. Read about a new area of science. Be a knowledge junkie.

2. Challenge Yourself

Individual brain training games don’t make you smarter.
You need to move on to the next challenge activity. You mastered Sudoku go and play another touch game. It makes your brain smarter.

3. Think Creatively

Contrary to popular belief, creative thinking does not equal “thinking with the right side of your brain”. It involves recruitment from both halves of your brain, not just the right. Creative cognition involves divergent thinking (a wide range of topics/subjects), making remote associations between ideas, switching back and forth between conventional and unconventional thinking (cognitive flexibility), and generating original, novel ideas that are also appropriate to the activity you are doing. In order to do this well, you need both right and left hemispheres working in conjunction with each other.

4. Do Things the Hard Way

Your brain needs exercise as well. If you stop using your problem-solving skills, your spatial skills, your logical skills, your cognitive skills—how do you expect your brain to stay in top shape—never mind improve? Think about modern conveniences that are helpful, but when relied on too much, can hurt your skill in that domain.

There are times when using technology is warranted and necessary. But there are times when it’s better to say no to shortcuts and use your brain, as long as you can afford the luxury of time and energy. Walking to work every so often or taking the stairs instead of the elevator a few times a week is recommended to stay in good physical shape. Don’t you want your brain to be fit as well? Lay off the GPS once in a while, and do your spatial and problem-solving skills a favor. Keep it handy, but try navigating naked first. Your brain will thank you.

5. Network

By networking with other people—either through social media such as Facebook or Twitter, or in face-to-face interactions—you are exposing yourself to the kinds of situations that are going to make objectives 1-4 much easier to achieve. By exposing yourself to new people, ideas, and environments, you are opening yourself up to new opportunities for cognitive growth.

Learning is all about exposing yourself to new things and taking in that information in ways that are meaningful and unique—networking with other people is a great way to make that happen.

Steven Johnson, author who wrote the book “Where Good Ideas Come From”, discusses the importance of groups and networks for the advancement of ideas.

Greatest thing about networking: Everyone involved benefits. Collective intelligence for the win!

Intelligence isn’t just about how many levels of math courses you’ve taken, how fast you can solve an algorithm, or how many vocabulary words you know that are over 6 characters. It’s about being able to approach a new problem, recognize its important components, and solve it—then take that knowledge gained and put it towards solving the next, more complex problem. It’s about innovation and imagination, and about being able to put that to use to make the world a better place. This is the kind of intelligence that is valuable, and this is the type of intelligence we should be striving for and encouraging.

Collatz conjecture

The Collatz conjecture is an unsolved conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937. Check the wikipedia for Collatz sequences. Its wonderfully fun sequence.

Take any natural number n. If n is even, divide it by 2 to get n / 2, if n is odd multiply it by 3 and add 1 to >obtain 3n + 1. Repeat the process (which has been called “Half Or Triple Plus One”, or HOTPO[4]) indefinitely. The conjecture is that no matter what >number you start with, you >will always eventually reach 1. The property has also been called oneness.

Here is the python code to generate the Collatz sequence.