The BIG ACM post

This was a long time due. While I blabber about a lot of things on this blog, I have rarely written anything about ACM or Association for Computing Machinery. During my undergrad at NIT-Surat, it was by far the most important thing in my life, more important than academics or attending classes.

I was inducted into ACM by Sunayana on the very first Linux workshop in my first year. I was sitting behind her, on the second bench, and was making comments about the lack of knowledge of the presenter (yes, I was always into Linux), and I even answered one of the question that was posed to him and he was unable to answer. She was impressed (I am awesome, what up?) and asked me to join and I join I did. Well, Anusha Jayanti(her batch mate, my senior and ACM Vice Chair 2007-08) was with her and I thought she was kinda pretty and you don’t argue or think twice when asked by a pretty girl to join some club she is in. Actually, I had read about ACM on the institute website and was a little curious, and since this was all about computers, joining it was the most obvious thing to do. Oh did I mention, I had internals on the very next day of this workshop and I still decided to attend it. Yes, my apathy towards exams had begun.

One of the first things I was asked to do was to get people to join the ACM Chapter as student members. I, Punit and Sanchit (my classmates) took up this job very enthusiastically; we visited room to room and got people to join (and mind you joining wasn’t free) and at the end of the week we had 130+ members from first year itself, without any poster being put up or any seniors coming to give a brief talk on ACM. The three of us managed it entirely by word to mouth and door to door publicity. That year, and that was the first year of the chapter, we became the largest ACM chapter in the world and were given the Outstanding Chapter Recruitment Award by ACM.

It was in my second year I got some more responsibilities. Sunayana had become the Chair and we worked well together; and along with Punit, as well as Sanchit and Harit, we did some really good events. My first event was a Linux workshop. We had prepared well, made a decent presentation but I was not at all comfortable with public speaking and seeing a crowd of more than 100 that had miraculously arrived for the talk, I was unnerved and literally trembling. But when it began, I cooled down and everything turned out well. I used to have this tactic of just concentrating on one or two member of the audience who seemed interested in my talk and that’s what I did. Almost the entire time, I looked at just one member of the audience who appeared to be deeply interested in the presentation and I was able to deliver a decent talk; all thanks to that member in the audience, you saved the day. Of course such a tactic results in lack of eye contact with the rest of the audience but at least the audience does not see you shivering or stuttering. I have improved a lot since then, and don’t need any such tactic anymore.

It’s the people who make an organization and ACM always got the best in the institute as far as computer science was concerned. Ankur Nandwani (guy with hair like Jonny Bravo, a flirt (a legacy I inherited from him), talks in a strange accent swaying his head from side to side) was the founding Chairperson, he was way too studious and was in the good books of all the faculty. He always liked playing by the rules and his most common statement used to be “I have to talk to Jinwala Sir about this”; only later did I realize that this statement had to be the daily chant of any ACM Chairperson. Ankur’s style of leading the organization was a little laid back and he was good at delegating responsibilities (usually to Rajdeep,Sunayana, Anusha, Punit and me). He was instrumental in doing all the ground work in starting the chapter and get it up and running. Sunayana was the opposite of Ankur. Like me, she didn’t give a damn about exams and hated the system much more than I did. She has great ideas and had a finger on various things happening in the world of computer science. It was her idea to start a Linux Users Group and a Web Design Club; which we implemented and I headed. She always motivated everyone to go for research and enjoyed discussing about various happenings in the field. However, as with most research oriented people (and nerds), she was bad(sorry Sunayana) at execution. Her tolerance for tantrums thrown by the faculty and bureaucratic red tape was nearly zero and her most common statements began with “I just hate…..”. We spent long hours discussing computing, our vision for the chapter and stuff that she hated (usually some faculty or the other). While she came up with ideas, it was mostly Punit and me who implemented them. And that was a good thing, because we learnt to manage before getting to lead. When our time came to lead, we too came up with some good ideas and quite a few not so good ideas; but as far as ideas and vision are concerned Sunayana was probably the best.

Leading a voluntary organization has its own challenges. No one is legally or contractually bound to work for you, you have motivate them, threaten and beg if needed, to make them work. Most importantly, you have to yourself set very high standards of work ethics so that when you ask others to perform, fingers shouldn’t be raised at your own performance. Also ego management is a very tricky affair, you are managing a team of equals and that must always be at the back of your mind; you never know when something just manages to hurt someone’s ego.

No discussion about my time at ACM can be complete without Quest. We decided to do something big and like every other club in the institute, we too wanted our very own fest. So in came Quest, a two day computing event. There were a lot of things going against us; this was the first time a computing event of this scale was happening in this part of the country and there were very few students interested or even good at programming; and even among those few, most were ACM members and helping organize the event. Plus, we got delayed in starting off because of some administrative red tape which was beyond our control. There were two other fests (Autofest and Entrumeet) by two different clubs in the institute about to happen around that time in the college; so there was huge struggle for sponsorships as well as good people to work in the team. We had openly told people that they should expect to get any sort of monetary incentive to work for us and that kept away a lot of people from working for us, some of whom were really good at organizing. We wanted to be a taint free event. The fight for sponsorships and participants from other colleges ensured that that the people in the other two events undercut us and even spread false information about Quest in other colleges. On the days of the event, regional politics by these two clubs caused many students to abstain from our event. The ACM chapter was always against any form of regionalism and we did not employ a tit for tat strategy.

However, the biggest problem with Quest was probably my lack of trust in the commitment of my team, which proved to be a very misplaced notion. I was bad at delegating and impatient for results, as a result of which I ended up doing almost everything and micro managing even the smallest of tasks. When I trusted a person, I gave them complete freedom but if I didn’t I had the habit of interfering in their work. Most of the time the person in question was trustworthy and it was only my fears that prevented me from trusting. And I paid for this heavily during Quest. Of course I ended up trusting and delegating more and more towards the end of the preparations but it was too late then. Nevertheless, my team member surprised me with their ideas and commitment for the event. Akshay and Bimal did an admirable job with managing the events, something I had planned to micro-manage. Biswaranjan did a great job on the Infra end and got his hands dirty with the arrangements. Harit organized the best ever press line up and the smooth press conference impressed the administration. Punit was much much more than just the Sponsorship head. In retrospect, having two conveners, the other being Punit, would have been a better idea. May be I should have been the events head instead of being the Convener. The juniors too did a great job and worked hard in every way to make the event a success. Kudos to them.

I thought Quest would slowly die out as we won’t be able to find interested people. I have been proved wrong this year with more than 400 participants and a very very successful run of Quest. Undoubtedly, the current team has pulled off the impossible.
I think my contribution to ACM was in giving it a proper shape and structure. Ankur was the initiator and Sunayana was a dreamer who had great ideas. I was more into managing and getting things done, building a proper structure, laying down rules, guidelines, dos and don’t and giving the chapter an overall character. We presented the image of a free and fair club, where people are chosen entirely based on merit and not based on regional dynamics. By taking a stand on not fudging our financial statements for personal financial motives, even when that meant that we did not always get the best people to work for us in Quest, we set a precedent for all other events; some followed it and some didn’t. At ACM people did not command respect they earned it; and that was true even if you are a senior. We empowered juniors and they could do their own events or freely argue with us. We made ACM the place to be if you are interested in computing.

 

Besides Quest being a success, 6 teams from the chapter will be participating in the onsite round of ICPC which is a great achievement for us. Kevin Patel needs to be thanked here as he is the one who guided these teams. The current chairperson Deepak (who like me wants to do an MBA) and the vice chair Shrey deserve a round of applause. They have taken the chapter to greater heights and I hope we will continue doing well. We succeed because we choose the best people and give them complete freedom to do their thing. Last year’s interviews were one of toughest and we asked people to write algorithms and solve conceptual questions on the spot when they were probably expecting some globe HR questions like “Why do you want to join ACM?” Some of those questions were taken from Microsoft, Google and Directi interviews. We also set the benchmark high for every generation of members and the final outcome of such a system is that we get better people every year.

Whoaa. That was long. But have I covered everything? Well no, not at all. There is just so much to write and I will keep that for some other time. A lot of what I am, professionally and personally, is because of my long association with ACM. I got to do cool stuff, met and worked with some really cool people and made some great friends.

Advertisements

The first N primes

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//a prime number is one which is divisible by 1 and itself only

//this program prints the first N primes

int main(int argc,char* argv[]){
	char *nums;
	int n=atoi(argv[1]);
	
	int limit=n*log(n)+n*log(log(n));
	
	int count=0;
	/*
	* According to Rosser's Theorem the nth prime lies between
	* nln(n) and nln(n)+nln(ln(n))
	* http://en.wikipedia.org/wiki/Prime_number_theorem#Approximations_for_the_nth_prime_number
	*/
	
	
	int l=(int)sqrt(limit);
	
	nums=calloc(limit,sizeof(char));
	int i;
	
        nums[0]=nums[1]=1;
	//nums[i]=0 its prime
	//else its not prime

        //the Algo used is Seive of Eratosthenes http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
        //Algorithmic complexity O(nloglogn)
        
	for(i=2;i<l && count<n;i++)
	{
		if(nums[i]==0)
		{       
		        count++;
			int j;
			for(j=i+i;j<limit;j=j+i)
			{
				if(nums[j]==0)
					nums[j]=1;//basically if nums[i] is prime then all multiples of nums[i] are non prime
						  //this procedure need to be repeated for only the first sqrt(n) numbers
			}
		}
	}
	count =0;
	
	for(i=0;i<limit && count<n;i++)
	{
		if(nums[i]==0)
		{
			printf("\n%d",i);
			count++;
	        }
	}
	
	return 0;
}		

Primes less than and up to N

This is a simple implementation of the Sieve of Eratosthenes algo

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//a prime number is one which is divisible by 1 and itself only

//this program prints prime less than or upto N

int main(int argc,char* argv[]){
	char *nums;
	int limit=atoi(argv[1]);
	
	int l=(int)sqrt(limit);
	
	nums=calloc(limit,sizeof(char));
	int i;
	
        nums[0]=nums[1]=1;
	//nums[i]=0 its prime
	//else its not prime

        //the Algo used is Seive of Eratosthenes http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
        //Algorithmic complexity O(nloglogn)
        
	for(i=2;i<l;i++)
	{
		if(nums[i]==0)
		{
			int j;
			for(j=i+i;j<limit;j=j+i)
			{
				if(nums[j]==0)
					nums[j]=1;//basically if nums[i] is prime then all multiples of nums[i] are non prime
						  //this procedure need to be repeated for only the first sqrt(n) numbers
			}
		}
	}
	
	for(i=0;i<limit;i++)
	{
		if(nums[i]==0)
			printf("\n%d",i);
	}
	
	return 0;
}		

Finally its done, Cube3_Div Released

Here it is finally, Cube3_div 1.0. This adds Division algebra feature to CUBE 3.2 . Finally, its over. Now can completely devote myself to other projects. Thanks to Verdi March of Sun APSTC Singapore and Markus Geimer and Brian Wylie of Julich Supercomputing Centre for all their help and support.

Download and check (only if you are interested in MPI/Open MPI development). Click here to download.

Python script for Twitter

Woke up at 11 in the morning, brushed my teeth and all…Sat down at my desk to study for the end semester exams tomorrow but did not feel like it…So decided to do something fun..

Twitter is quite popular and people are just dying to join up and tell everyone what they are doing, what they had for breakfast, when they are going shopping and other such ‘important’ details about their daily life, whether people care to listen or not. Nevertheless its a good service.

So yeah, coming back to the point. Long ago I had seen this shell script to tweet from the command line. And I have been into Python over the last few days, so decided to cook up one of my own in Python. Given below is the result of my last 20 minutes of work.

Caution: Won’t work in windows because it does not have curl. Coming up with a Windows version soon.

Save the code in a file say ‘tweet.py’.To run this do a chmod +x tweet.py and then just type ./tweet.py “Your message” and it will be posted. But before that, you will need to open up the tweet.py file and put in your Twitter username and password in it. Check out the third and second lines from the bottom. That is where your username and password goes, inside the quotes. And you are all set.

#!/usr/bin/python
import sys 
from os import popen

def tweet(user,password,message):
    print 'Hold on there %s....Your message %s is getting posted....' % (message, user)

    url = 'http://twitter.com/statuses/update.xml' 
    curl = 'curl -s -u %s:%s -d status="%s" %s' % (user,password,message,url)

    pipe = popen(curl, 'r')
    print 'Done...awesome'

if __name__ == '__main__':

    if len(sys.argv) != 2:
    print "Usage: tweet.py <message>"
    sys.exit()

    message = sys.argv[1]
    if len(message) > 140:
    print "Message too long"
    sys.exit()


    user = "barneystinson" #put your username inside these quotes

    password = "awesomeness" #put your password inside these quotes
    tweet(user,password,message) 

BarCamp Mumbai 6

I am attending BarCamp Mumbai 6 at SP Jain Institute of Management on the 11th of October. For the uninitated a BarCamp is a developer unconference. A BarCamp is an ad-hoc unconference born from the desire for people to share and learn in an open environment. It is an intense event with discussions, demos and interaction from attendees.

Starts at 9 AM and ends at 6 PM. I have registered for a session on SCALASCA and the Division algebra that I am working on for SCALASCA.

So be there. 🙂

How to be a good programmer? My tips

Update: A way better and more comprehensive article on similar lines can be found here http://matt.might.net/articles/what-cs-majors-should-know/ I strongly recommend that anyone serious about programming should read it

At the very onset, let me make it clear that I DO NOT consider myself a good programmer. I rate my coding skills as average and I am still learning and have a long way to go before I am even slightly pleased with my programming skills. Yes I am better than quite a few people when it comes to programming, but thats merely because they are lazy and like to sit on their asses whole day and never bother about programming. Their horrible skills make my less horrible skills look marvellous. I have performed abysmally in ICPC and have never done well in any coding contest worth mentioning (I DO NOT consider college level contests worth mentioning). I havent succeeded yet in Google Summer of Code and my Imagine Cup moderate success (and glorious failure) isn’t much to write home about.

So most of the tips I will mention below are lessons learnt from failed endeavours, they are what I have wanted to be and I am not. So lets dive in.

1.Decide why you want to become a good programmer: Is it because you want a job, preferably in Google, Microsoft, Sun or IBM? Great. Then you will reach nowhere. All good programmers I know are good because they loved what they did. Develop interest in programming. See, programming is the only branch in engineering where you can straightway apply what you learn. Your dad may have a car but he certainly wont allow you to tweak the V2 or swap it for a v6 just to see what happens. But with computers you can do whatever you want. You want to simulate a virus? Cool. Install a virtual OS and run it. Then, when you are done, remove the virtual hard disk. If you are good at what you do, you will get paid and surely get that dream job. Yes, even I want to work in any of the above mentioned companies. But thats not because of the fat paycheck. Its because of the work they do. Because of the exposure I will have. Have you ever bothered to find out what all these companies do and the enabling technologies behind their products or the kind of R&D they do? Jobs will come. Dont make yourself a sucker for one. Sachin is not a great cricketer today because he decided to play cricket to earn money and get dozens of endoresements.

2. Programming languages: Very often people equate good coding skills with number of programming langauges known. Thats just damn untrue. While knowing a lot of programming language is good and sometimes, even, essential; it is more important that you know one or two lanugages very well. I ‘know’ and have used more than a dozen programming languages and yet C and Java are the ones I am truly comfortable at. Thats sad of course. I really wanted to be good at Assembly and Lisp as well. Never got the time or chance to develop those skills. To be good at a language takes years (at least 2 years). Being good at a language means, you understand where it is best used and where using that language makes no damn sense. On the other hand, knowing a language takes anywhere from 3 days to a week. If you are a beginner, learn C first. Don’t buy Yashawant Kanetkar. Buy the book “The C Programming Language” by Brian W Kernighan and Dennis M Ritchie (If you don’t know who they are, do this 1. Slap yourself 2. Google their names). This book is not the easiest but is the best. Its a small book but it is the most powerful. Generations of programmers have been brought up on it. And if you think this book is tough for you, please do not harbour any misplaced desires of being a good programmer and do not waste your time by reading this post further. Programming is an art (not a science. Yes you read it correctly), and like any art it requires painstaking effort.

Some people suggest Python as the first language to be learnt. Python is certainly a good language and is easy too. But you will have to rely mostly on the internet for help as not many around you would know Python. Also C has the broadest usage among all programming languages. Also please DO NOT use Turbo C. Its so fucking outdated. Use GCC. If you are in Windows download Dev C++. It has GCC

Read this (small) essay by Peter Norvig Teach yourself programming in 10 years . Again, do a Google [ 😉 ]search and find out who Peter Norvig is.

3. Algorithms: Any good programmer has a good understanding of algorithms. Its not necessary that you know each algo by heart (in fact good programmers never learn things by rote) but you must understand when to use what. Algos will broaden your understanding and give you new ways to tackle problems. Another important thing is Data Structures. Its more important than algo. Once you have chosen (or developed) the correct data structure, the algorithm becomes self evident. For algo, read the book “Introduction to Algorithm” by Thomas H Cormen et al. You may also refer Andy Tanenbaum’s “Data Structures in C and C++”. Also if you have desires to participate in coding contests (the respectable ones), “The Art of Programming Vol I to V” by Donald E Knuth are mandatory. Also may be “Concrete Mathematics” by Donald Knuth. Again reading does not mean remembering everything. Just try and understand whats written.

4. Coding contests: Coding contests are good for developing your algorithmic skills and they make you think fast. Its a good idea to participate in ACM ICPC or Topcoder.com. Then there are coding contests (like Sun’s Code for Freedom, Google’s Summer of Code, Microsoft’s Imagine Cup) where you develop a complete software. Such contests are spread over many months. Both require different sort of skills. You may be good in one and bad in another and yet you could be a good programmer. Contests like ICPC require lot of practice, fast thinking and you are expected to keep algos at the back of your mind. CFF, GSoC, on the other hand, requires creativity and focus spread over a long period of time. You dont have to come up with solutions too fast and you dont have to mug up algos. ICPC is like T10 while CFF,GSoc and Imagine Cup are like Test Matches. I would suggest you to participate in both types and then decide if you want to focus on either or both.

5. Participating in FOSS projects: You MUST participate in some free software projects. There are just too many. I am working on SCALASCA right now and then I will move on to Sun Grid Engine and Sun xVM Hypervisor and contribute code there. You learn a lot from these. You get to see a lot of code and learn the best practices. And did I mention, it looks good on your CV too. Most people catch cold feet when they go through some of the prerequities of such projects. Take Thunderbird for example. You would need to know a lot of C/C++ and Javascript (for developing modules). Now don’t wait till the day you are an expert in these languages before contributing. Programming is an art, don’t waste time sharpening your pencil when you should be drawing. You can ask me for directions.

6. Design Patterns: Any art is learnt by emulating. And therefore, you must emulate the best. Design Patterns are tried and tested architectural (of the software kind) solutions to some commonly encountered software design issues. And therefore, a basic knowledge of some common design patters in needed if you are planning to develop something that is even moderately complex. I suggest “Head First Design Patterns” from Oreilly as the first step.

7. Learning by emulation: Emulate the best. And this is possible by reading books written by the best and/or going through code from some of the best free software projects. I would urge anyone serious about programming to read the book “The Art of Unix Programming” by Eric S Raymond (dont forget to first slap yourself for not knowing who Eric Raymond is and then googling his name). You are not a programmer if you have not read that book. Period.

Now let me address a few common grouses

a. I dont find any interest in computers and want to do an MBA:Mainly a statement often repeated by Second Year(sophomore) students. Thats really your problem. I did not ask you to take Computers or even to join Engineering. You did not know, or bothered to find out, what you were getting into when you took up this branch of engineering and I am pretty sure you have NOT bothered to find out what awaits you in a MBA course either. I am also quite sure that 2 years after an MBA (if not earlier) you will also say pretty much the same thing about your job. Well what can I say. All the best 🙂

b. I dont like reading the books (or any books for that matter) that you mentioned above: Well this is not yet the world of Matrix where I can just feed in programming skills to your brain. Dont force yourself to read them. You can’t . Do it only if you want to. And if you don’t, please forget about being a good programmer. May be its time for you to use the excuse mentioned above (point a).

c. Give me one programming language that does all: There is none. Each has a different purpose. And thats how things are gonna remain buddy.

d. I want to a ‘real’ project: Thats great. You can do two things:1. Start one of your own 2. Join a FOSS project. But most people are not happy with this. They expect me to ‘give’ them a project, one thats easy (read, should not involve anything other than C and the only files you need to include should be stdio.h, conio.h (yes people here still use Turbo C) and may be string.h and math.h) and I should tell them what to learn. When people say this,they expect to go on a Autopilot ride.

e. I will learn X programming language by this sem/year/decade :There is no way you can sit with a book and learn a language. You need to do some real work with it, develop some real software and not just do those exercises in the book (that is necessary of course but not sufficient). Most of the languages I have learnt are because I was forced to do so as part of some project. Just pick up the basics in a day or two and then apply it to a real life project. Need ideas? Come to me.

Finally as Larry Wall says in Programming Perl : “We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris.

Laziness:So that you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don’t have to answer so many questions about it. Hence, the first great virtue of a programmer

Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer

Hubris: Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won’t want to say bad things about. Hence, the third great virtue of a programmer.

So get set on your way to become a great programmer, the likes of Richard Stallman, Rithcie, Brian, Raymond, Torvalds. All the best.