Thursday, April 15, 2004

Very soon I should have a blogging engine of my own up and working. I got a copy of DasBlog and with a bit of tweaking it seems to suits me rather fine. I would however like to see

·         Hierarchical comments

·         Ability to delete comments without getting into XMLs

·         Enabling description views only on certain aggregate views.

·         Where is the archives feature?

 

The blog should be going up on www.thinkingms.com, a site that is run by Pandu. The only problem is that I don’t seem to be thinking MS all the time :-)

 

Until the blog is formally up I guess you will see me manually predate entries at the end of each entry.

 

(To the tune of Jingle Bells)

blogging site blogging site

blogging all the way,

oh what fun it is to send

an entry on its way ... hey !

Apr 15 2004 Thursday 12-23PM

Thursday, April 15, 2004 1:55:29 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

I finally got copies of my first article published about the DDL. The article was published in the .Net Developer Journal.
http://www.sys-con.com/dotnet/

 

The DDL was a language that my team developed during our final year college project. At that time, we believed that it was a one of a kind language. Of late we have come across similar work done by Professor Godmar Back of Stanford University.

 

The DDL language basically lets one specify binary data formats and the language interpreter provides services to interact with data of that format. Read more about the DDL at the project homepage:

http://ddl.sscli.net/

 

Professor Godmar Back’s DataScript language is described here:

http://datascript.sourceforge.net/

Apr 14 2004 Wednesday 01-24PM

Thursday, April 15, 2004 1:35:38 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

Following Sean Anderson’s approach to bit counting for 64 bit machines on his bit twiddling hacks page here: http://graphics.stanford.edu/~seander/bithacks.html

 

I wrote my own:

A Modulo Based Bit Counting Approach For 64 Bit Systems

http://www.thinkingms.com/pensieve/homepage/articles/tech/bitcounter64/bitcounter_64bit.htm

http://www.thinkingms.com/pensieve/homepage/articles/tech/bitcounter64/bitcounter_64bit_2.htm

 

Sean has graciously linked to me now and that makes this the first time my name exists under the great stanford.edu. Neat uh?

Thanks Sean.

Apr 13 2004 Tuesday 12-06PM

Thursday, April 15, 2004 1:34:35 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

One of the things that’s rather high on my mind’s sort order these days is Ruby programming. I have been thinking about what makes ruby so neat a language to use, simply by virtue of what the language lets me do.

 

One of the early things that got me hooked to Ruby, was its support for iterators. If you have been spoiled by many years of C programming, like me, then its time to wake up and take a look at a few things that C can’t pull off, at least not very easily.

 

What is an iterator?

Let’s take a look at code like this, where there is a piece of code that produces value and a piece of code that consumes values.

 

void produce()
{

for (int i=0;i<100;i++)
            if( i%5 == 0)
                  consumer(i);

}

 

void consumer(int v)
{

printf(“%d”,v);
}

 

All things considered this code is fine, except that the producer invokes the consumer. And simply because of that the consumer cannot maintain state. The only way the consumer can maintain state, ie remember something between two calls is to save variables into either static variables, or globals or into some object.

 

The would be the argument if the consumer function tried invoking the producer, where the producer will have to have a very contrived piece of code to remember variable values between calls.

 

From a perspective, an iterator solves exactly this problem. This is a ruby code:

 

def producer

      for i in 0..99

            if (i%5 == 0)

                  yield i

            end  

      end

end

 

def consumer

      producer() do |v|

            print v

      end

end

 

The ‘def’ keyword starts a function/method declaration. The code above for the producer should be rather easy to understand, except for the yield statement.

 

What does the yield do? The yield causes the function producer() to exit with the return value of the function as the parameter of the yield, in this case ‘i’.

 

The difference between yielding a value and actually doing a return is that the function can continue execution from the point of the yield statement.

 

The consumer function then simply invokes the producer() function and catches each of the yielded values. That is why these is a ‘do’ statement and a corresponding ‘end’ statement in the consumer code. The parameter for the do-end block is the ‘v’ that is enclosed in ||. Every time the producer yields a value, the value is available in ‘v’ and the do-end block is executed. When the block finishes the producer continues after the point of the yield.

 

So if you want to, say calculate the sum of all the values that the producer yields, then you can

 

def consumer

      sum = 0

      producer() do |v|

            sum = sum + v

      end

      print sum

end

 

 

Now that you have been introduced to the idea of iterators, I suggest you do some thinking about, especially if you have done a fair bit of C programming. Imagine how these functions would have to maintain state, what their call stacks will look like and such.

 

Now let me clean up on a few things. In ruby all functions are called methods, formally. So let’s start calling them methods. Secondly a lot of the Ruby libraries are built to support iterators so you will see the idea being used a lot. Thirdly, the do-end block can also be written as { } curly braces.

 

The methods that I have written have been written in a drawn out C-like style, so that the ideas are clear despite the slight difference in syntax. So lets just rewrite the two methods slightly more ruby-ishly and close this blog entry.

 

def producer

      100.times{|i| yield i if i%5 == 0}

end

 

def consumer

      sum = 0

      producer {|v| sum = sum + v}

      print sum

end

 

You can get Ruby from here, for your windows box:

http://rubyinstaller.sourceforge.net

Apr 13 2004 Tuesday 11-05AM

Thursday, April 15, 2004 1:31:50 AM (Eastern Standard Time, UTC-05:00)  #    Comments [3]  | 

I started out by saving my blog files on my hard disk. Here is a little Ruby hack that I have to help manage by blog entries on my local disk. Presently I just write blog entries as small word doc files and save the files with the title of the blog as the filename. Then I figured that it would be more useful if, for sorting purposes I could name the files also by date and time.

 

A naming like this would be convenient:
Apr 13 2004 Tuesday 01-18AM - First Blog Entry.doc

 

Now I would not want to type in a name like this by hand, I’d just like to save the file and then have some little proggie do the rename for me. Here is a ruby script to do just that.

 

dater.rb

$format = '%b %d %Y %A %I-%M%p '

$format_pattern =       /^\w+\s\d+\s200\d\s\w+\s\d\d-\d\d(A|P)M\s.*/

 

def rename file,count=1

      $filename = Time.now.strftime($format) + "- " + file

      $alternate_filename = Time.now.strftime($format) + "[#{count}] - " + file

      if count == 1

            File.rename(file,$filename)

      else

            File.rename(file,$alternate_filename)

      end

end

 

if ARGV.length == 1

      rename ARGV[0]

else

      #~ Lets try anbd find the file to rename

      count = 1

      Dir["*.doc"].each do |file|

            puts file

            #~ See if this file needs renaming

            unless $format_pattern =~ file

                  puts "Renaming : " + file

                  if count == 1

                        rename file

                  elsif count == 2

                        #~ More than one file, so shift to "[count]" syntax

                        File.rename($filename,$alternate_filename)

                        rename file,count

                  else

                        rename file,count

                  end

                  count = count + 1

            end

      end

end

 

This snippet does the following

-          if a filename is given as an argument it simply renames the file.

-          if no file name is given it does search and rename in the current folder.

It basically looks for all doc files and sees which ones seem to be already renamed appropriately and skips those. Then it renames any file that it finds by prefixing the date time.

 

As an addition it also sees if there are multiple files to be renamed, in which case it puts a special count prefix also which is enclosed in []. Now all I need to do is to double click on my ruby script every time I save a blog entry into my entries folder.

 

That’s just what I am going to do with this one. :)

 

There is a Peter and Gordon West singing Hundred Miles in the background. Now the music has changed to Iris – Goo Goo dolls. I am feeling wishful. I also think I need to sleep now.

 

And I don’t want the world to see me

‘cause I don’t think that they’d understand

When everything’s made to be broken

I just want you to know who I am

- Iris, Goo Goo dolls

Apr 13 2004 Tuesday 03-25AM

Thursday, April 15, 2004 1:30:56 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

If you had to find me on the net where would that be – read on. Why would this be interesting for anyone is because if you happen to share the same interests then you might come back to reading my blog, and maybe I could get to know you too.

 

Homepage:
http://www.thinkingms.com/pensieve/homepage

This is like great general mish-mash, hitch-hikers style. If you want to download any of code I have written, then you might want to go here.

 

DDL project homepage:

http://ddl.sscli.net

I am co-author of the DDL language. The DDL or Data Definition Language is a language for defining binary data formats. What the DDL essentially lets you do is that you can define a file format in DDL format (which is rather intuitive, if you understand how to write structures and if conditions in C) and then host the DDL interpreter in a program that you write. The hosted DDL interpreter lets you interact with the file format on the disk, even with individual bits, without you having to develop any of the file handling code yourself.

 

Technical Communities:

http://groups.msn.com./bdotnet

http://groups.msn.com/cochindotnet

These are .Net user groups in India. The first one is the Bangalore user group, the largest in the country with 2300+ members and the second one is the local user group at Cochin, where you have ~200 members. Some of these groups are great places to fish for ideas.

Apr 13 2004 Tuesday 01-56AM

Thursday, April 15, 2004 1:29:10 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Wednesday, April 14, 2004

It's been a long time that this has been getting postponed for, but here it goes - this is my first blog entry. Well, it's not a real blog entry, in the sense that I and not typing this into a blogging software but rather am typing this into a word document. In time I will find a blogging engine or write my own and have this up on the net.

I am a computer science graduate from Model Engineering College, Cochin and am currently working with the great Indian software industry at Bangalore. I work with this technology called .Net - if general computing holds an interest for you, then the term might be familiar.

I have a homepage here:
http://www.thinkingms.com/pensieve/homepage
where I have some work that I have done, handful of articles and other stuff related to my general existence and interest around computers and computing.

I indulge (or at least used to) in a certain manic amount of programming. I am not very old in computing, as old as some people I have had the pleasure of knowing. My first real exposure to programming was in the summer of 96, when I started out with programming on Foxpro (yes, believe it).

Strangely as fate would have it then, a lot of Cochin city was running old boxes and 386 machines were a luxury. So it was like I had the chance to grow up in a time warp. And needless to say, most machines ran (the now mythical) DOS.

DOS programming, especially once you start playing around with TSR's and SVGA and writing GUI routines and simulate your own multitasking environments was a very special kind of education. I don't know if any of the future generation will ever have that pleasure and honestly, since I have never seen it any other way, I wonder if they will ever see these things and feel the joy of writing values onto your VGA card's control registers.

It's been a funny trip since then and I presently spend my time of Windows boxes. I spend my time exploring *nix boxes for a while in between, but try as I might they did not hold my fancy very much. Probably I learned things the wrong way, but I used to compare things to what I could do in DOS and that just killed the joy in everything.

In that sense .Net is probably one of the few real pleasures that I have come across. A very sensible mature platform with very good design choices and excellent implementation. Some of my early attention to .Net seemed have got me some attention too (http://www.microsoft.com/india/mvp/indiamvp.aspx#RoshanJames). I also try and stay true to my C/C++/Asm roots. I also have an indulgence in Ruby (the programming language) - Ruby is an excellent dynamic language with support for neat constructs such like closures, iterators, dynamic interfaces, mixins and more. It also brings continuations and some real beasts of programming as well, in addition to being a fully object oriented general purpose interpreted language with a nice libraries and good integration of regular expressions and flexible collection types in the language. One difference with Ruby and other languages, esp Perl (or what little of it I have tried) is that Ruby actually makes you feel happy while writing a code; unlike the sort of happiness you feel when you are glad you have finished coding.

In addition to the 'way of the code' I like music - Bob Dylan, Simon and Garfunkel, U2, Cat Stevens/Yusuf Islam, John Denver, Don McLean

I think I will stop on my first entry now.

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

Apr 13 2004 Tuesday 01-18AM

Wednesday, April 14, 2004 9:04:25 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |