This week’s talk!

Posted: November 17th, 2009 | Author: | Filed under: Programming, This week's talk! | Tags: , , , | No Comments »

This week’s talk is from Joshua Bloch
Efficetive API Design


Google Code Jam – Episode #1 – Alien Language – with Python

Posted: October 15th, 2009 | Author: | Filed under: Programming | Tags: , , , , | 3 Comments »

Here is my solution to Alien Language;
maybe the most readable solution to this question in python, plus using recursion ;)
in some lines code might seem that it is not handling some boundary cases but it is because problem statement promising such cases won’t occur
http://code.google.com/codejam/contest/dashboard?c=32003#

enjoy it, comment it…

import math

def convert(alien_number, source_language, target_language):
    source_base = len(source_language.strip())
    target_base = len(target_language.strip())
    source_number_decimal = getNumberInDecimal(source_base, alien_number.strip(), source_language, target_language)
    target_number_as_list = getNumberInGivenBase(source_number_decimal, target_base)

    target_number = ''
    for d in target_number_as_list:
        target_number += target_language[int(d)]

    return target_number

def getNumberInDecimal(base, alien_number, source_language, target_language):
    i = 0
    source_number_decimal = 0
    reversed_alien_number = alien_number[::-1]
    for d in reversed_alien_number:
        source_number_decimal += weightOfDigit(d, source_language, base, i)
        i = i + 1

    return source_number_decimal

def getNumberInGivenBase(number, base):
    s = list()

    def numInGivenBase(number, base):
        if number < base:
            s.append(number)
            return
        remainder = number % base
        s.append(remainder)
        division = (number - remainder) / base
        numInGivenBase(division, base)

    numInGivenBase(number, base)

    s.reverse()
    return s

def weightOfDigit(digit, source_language, base, digitIndexInNumber):
    return orderOfDigit(digit, source_language) * math.pow(base, digitIndexInNumber)

def orderOfDigit(digit, source_language):
    return source_language.find(digit)

def main():
    f = open('A-large-practice.in', 'r')
    r = open('A-large-practice.in-result', 'w')

    while True:
        line = f.readline()
        if not line:
            break
        caseNum = int(line)
        for i in range(caseNum):
            line = f.readline()
            alien_number = line.split(' ')[0]
            source_language = line.split(' ')[1]
            target_language = line.split(' ')[2]
            result_line = 'Case #' + str(i + 1) + ': ' + str(convert(alien_number, source_language, target_language))
            r.write(result_line + '\n')
            print result_line 

    f.close()
    r.close()

if __name__ == '__main__':
    main()

Code Review tool Rietveld

Posted: March 19th, 2009 | Author: | Filed under: Interesting, Programming | Tags: , , , | No Comments »

According to Wikipedia explanation of code review is; Code review is systematic examination (often as peer review) of computer source code intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers’ skills.”

It is absolutely great to have colleagues to have your code reviewed. There are lots of benefits of code reviewing but most famous ones are as Wikipedia says;

“Code reviews can often find and remove common vulnerabilities such as format string exploits, race conditions, memory leaks and buffer overflows, thereby improving software security.”

And Gil Fink mentions following benefits;

  • Enforcing coding standards
  • Mentoring tool
  • Better quality code 
  • Wider project view
  • Better structured code
  • Nowadays I am a big fan of Python and trying to develop some sort of simple web apps on top of Google App Engine. And recently I watched some talks of Guido van Russom about Python. He  now works at Google and developing with python. No need to mention how Google is caring python. Google App Engine currently supports only python which is a proof. Also it is interesting they picked python before Java. Maybe we can interpret this as power of dynamic programming languages. But I bet next language that will supported by Google App Engine will be Java.

    So Guido has developed a code review tool in Google as his personal project which is called Mondrian. Since Mondrian depends on Perforce and Google Big Table they have released an open source version of it which is more flexible and called Rietveld. And good way of it is that is open source.

    The great thing about Rietveld is that (since it is now in production) it is creating a global code review process. Any one can add their repository link to Rietveld and open their commits to review of world!

    Here is Guido’s talk on Mondrian;