Thursday, February 09, 2006

Re: One Thread to rule them all

I've used threads in C and Java. In C, I used the pthreads (POSIX threads) library. Of course, it's not as peaceful as threads in Java.

Synchronization is done using mutexes and condition variables. Mutexes allow you to avoid race conditions. Condition variables allow you to wait until any specified condition is satisfied. There's a bunch of functions that are used to do this - pthread_mutex_init/lock/unlock/trylock etc. and pthread_cond_init/wait/broadcast etc.

Of course, thread operations are completely procedural in nature - pthread library functions that take as arguments function pointers/thread variables (pthread_t) and such other stuff.

򪪪򪪪򪪪򪪪򪪪Here's a decent tutorial for pthreads.

Sometimes, it's better to just fork() processes and have them communicate using pipes, semaphores in shared memory etc.

Just a personal opinion - while a lot of things are much easier to do in Java, I would still recommend trying them out in C (or C++) atleast once. You just get a slightly 'inside' view of things... not just threads, even stuff like socket programming. However, for day to day use, Java's a better bet.

Have never used threads in Lisp but I do know that there's a package for threads. While Lisp is projected as an AI language, it has support for a whole lot of things from threads, sockets, interfacing with the OS etc. (OT - While the 'biggest deal' about lisp is its natural use to do functional programming, it also supports procedural and object oriented programming)

Monday, February 06, 2006

Re: One Thread to rule them all

The generic question now. Have you guys come across any similar stuff in other languages? Java has had good support for threading since the early days and now in Java 5 this has been greatly enhanced. What about other languages? C++, C#. And anyone have info about dynamic languages like Lisp, Python etc?

I haven't seen the pattern (WorkerThread) that you wrote about... having one worker thread manage multiple tasks. I don't think this pattern is there in .NET. From what I understand, .NET has a different framework. There is probably a one to one similarity with the Threading package (atleast pre Java 5.0). However, .NET has an asynchronous framework built into all delegates. You can invoke delegates with myDelegate.BeginInvoke() and it will run asynchronously. That is, control will be immediately returned. I believe it picks a thread from a ThreadPool and executes it on that in the background. It's pretty nice in that all your own custom delegates get this feature for free.

When talking about UIs and threads there's another important aspect. Any updates to UI controls should only be made by the thread that created it. So if you have a background thread doing some work and you want to display a message in the UI when it's done, you can't simply access the control and update it directly. You need to marshal any updates through the 'owner' thread. Here's an example in C#...

// UI
public class ClientUI : System.Windows.Forms.Form
{
  private System.Windows.Forms.Label lblStatus;

...

  private void UpdateStatus()
  {
    if ( this.lblStatus.InvokeRequired )
    {
      this.lblStatus.Invoke( new MethodInvoker( this.UpdateStatus ) );
    }
    else
    {
      this.lblStatus.Text = "Done!";
    }
  }
}


All UpdateStatus() is doing is setting a property on a Label. UpdateStatus() would likely be registered as a callback. So when the background thread is done with its processing, it would raise an event and UpdateStatus() would get called. When it does, it can't just update the control since it is not the 'owner' thread. So it needs to marshal the call. This is done with this.lblStatus.Invoke(). MethodInvoker() is just a delegate which takes methods that don't have any arguments and returns nothing. Invoke() takes care of the marshalling.

What's the if/then statement for? InvokeRequired is a property on every UI control. It will tell you if the call was made from the thread that owns the control or not. If it does own it, it's just a direct update, if not, it needs to be marshalled.

All UI elements inherit from the Control class and all of them in turn have the InvokeRequired property and Invoke() method.

One Thread to rule them all

In UI Applications it is a requirement to run some tasks in different threads so that the user will not notice a lag while performing some operations. Also often these threads are either of not very long duration or need to be run one after the other. So how do we solve this?


A small diversion to Threads in Java

Now in Java the Runnable interface is used to create threads. Runnable contains a single method run() which needs to be implemented.

<code>
public class MyThread implements Runnable {
public void run() {
//do some task
}
}
</code>

To execute the above as a separate thread you need to call the start method of the Thread class. The Thread class can accept a Runnable instance

<code>
new Thread(new MyThread()).start()
</code>

start() internally performs some housekeeping to actually create the new thread. After performing the necessary operations, Runnable.run() is called.


Back to our UI Application.

What is done is a simple event queue is built for handling all non-ui tasks. Which internally contains a Queue and a single thread.

<code>
public class Worker implements Runnable {

private Queue queue;
private boolean running;

private Worker INSTANCE = new Worker();

private Worker() {
new Thread(this).start();
}

public static Worker getInstance() {
return INSTANCE;
}

public void run() {
if(!running) {
running = true;
while(true) {
if( queue.peek() ) {
Runnable runnable = queue.pop();
runnable.run();
}
}
}

public void addRunnable(Runnable runnable) {
queue.push(runnable);
}

}
</code>

I have just given a basic skeleton here and left out the most important part of synchronizing the class. The running boolean was added to prevent new Thread(Worker.getInstance()).start(). You guys see any more errors? Threads are one of my primary weaknesses which I hope to rectify by learning about the new Java 5 Concurrency features.


For small tasks it is more efficient to use a Worker like this which internally doesn't create a new Thread for each task and re-uses a Thread or even a thread pool. This is because the start() method does quite a bit internally.

In Swing it's suggested to use a SwingWorker class which does something similar. Also Java 5 (Tiger) has added a new SwingWorker class which is additionally Generic.

The generic question now. Have you guys come across any similar stuff in other languages? Java has had good support for threading since the early days and now in Java 5 this has been greatly enhanced. What about other languages? C++, C#. And anyone have info about dynamic languages like Lisp, Python etc?

Saturday, February 04, 2006

Refactoring enhanced

Probably the single most common refactoring one does when writing code is renaming variables. Saw this cool feature in Visual Studio 2005...

Monday, January 30, 2006

Re: Google China

I think Diana Hsieh puts it very eloquently here.

I wish Google had taken a stand and said no to the Chinese Government, but ultimately its their company and they have a right to do what they wish with their search results.

Dinesh.

Friday, January 27, 2006

Google China

Found this article (on yahoo ;-) - Google's Action Makes A Mockery Of Its Values.

You must have heard about Google sensoring their search results to meet China's demands. What dyou think? Once a company goes public, it takes on many more responsibilities. Although an admirable motto - Do No Evil - it was always going to be hard to stick to that when you have to satisfy shareholders. Growth in revenues and profits becomes your number one goal. That is automatically seen as 'evil'. Which is another interesting point... you think a super successful company can ever be seen in a favorable light?

Thursday, January 26, 2006

Re: Another greasemonkey script....

A few minor changes... Instead of an alert, a message is displayed at the top left of the screen for 5 seconds. In the code, the literal "constants" are moved outside of the for loop. The check for presence of both reference and code is moved inside the loop.


// ==UserScript==
// @name Google Analytics Detector
// @namespace http://codeword.blogspot.com
// @description Detects if a page uses Google Analytics
// @include *
// ==/UserScript==

var URL = "http://www.google-analytics.com/urchin.js";
var TRACKER = "urchinTracker()";

var scripts = document.getElementsByTagName( "script" );

var refPresent = false, codePresent = false, log = false;

for ( var i = 0; i < scripts.length; ++i ) {
var script = scripts[ i ];

// Check reference if not already found
if ( !refPresent ) {
var ref = script.src;

if ( ref != null ) {
refPresent = ( ref.search( URL ) != -1 );

if( log )
GM_log( "Tested ref: " + ref + " Result: " + refPresent );
}
}

// Check code if not already found
if ( !codePresent ) {
var code = script.innerHTML;

if ( code != null ) {
codePresent = ( code.search( TRACKER ) != -1 );

if( log )
GM_log( "Tested code: " + code + " Result: " + codePresent );
}
}

if ( refPresent && codePresent ) {
var logo = document.createElement("div");
logo.id = "logo";
logo.innerHTML = '<div style="position: absolute; left: 0px; top: 0px;' +
'border-bottom: 1px solid #000000; margin-bottom: 5px; ' +
'font-size: small; background-color: #000000; z-index: 100;' +
'color: #ffffff; width:200px; opacity: .75;"><p style="margin: 2px 0 1px 0;"> ' +
'<b>Google Analytics enabled</b>' +
'</p></div>';

document.body.insertBefore( logo, document.body.firstChild );

window.setTimeout(
function() {
var logo = document.getElementById( "logo" );
if ( logo ) {
logo.parentNode.removeChild( logo );
}
}
, 5000 );
return;
}
}

Re: Another greasemonkey script....

Here's the first attempt...

// ==UserScript==
// @name Google Analytics Detector
// @namespace http://codeword.blogspot.com
// @description Detects if a page uses Google Analytics
// @include *
// ==/UserScript==

var scripts = document.getElementsByTagName( "script" );

var refPresent = false, codePresent = false;

for ( var i = 0; i < scripts.length; ++i ) {
var script = scripts[ i ];

// Check reference if not already found
if ( !refPresent ) {
var ref = script.src;

if ( ref != null ) {
var URL = "http://www.google-analytics.com/urchin.js";

refPresent = ( ref.search( URL ) != -1 );

GM_log( "Tested ref: " + ref + " Result: " + refPresent );
}
}

// Check code if not already found
if ( !codePresent ) {
var code = script.innerHTML;

if ( code != null ) {
var ACCT = "_uacct";
var TRACKER = "urchinTracker()";

codePresent = ( ( code.search( ACCT ) != -1 ) && ( code.search( TRACKER ) != -1 ) );

GM_log( "Tested code: " + code + " Result: " + codePresent );
}
}
}

if ( refPresent && codePresent ) {
alert( "This smart bastard is using Google Analytics" );
}


Save as analyticsDetector.user.js, open in Firefox and then "Install This User Script..."

Couple things... Besides the code snippet Rahul posted, there is also an external js file that is referenced (http://www.google-analytics.com/urchin.js). I check that both code as well as reference are present. Also in the code, I think "_udn" is optional. It's there on slashdot, but not on codeword, so I don't check for that. Didn't test this very much. Just on codeword, slashdot (detected) and yahoo, microsoft (undetected).

Any improvements?

Wednesday, January 25, 2006

Introduction to Great Design

Joel Spolsky is at it again. He's started a series of articles on design. This one was a bit of deja vu for me. On the flight from Bangalore to Bombay, they made the announcement to switch off all electronic devices. So off goes my cell phone. After landing, I starred at the phone for a minute before giving up and asking Rahul how to turn it on. After reading Joel's article I don't feel like as big a dumbass. How long before we see an Apple cell phone?

Also check This is Broken - "A project to make businesses more aware of their customer experience, and how to fix it". It's a nice site with daily postings on design mistakes seen everywhere.

Tuesday, January 24, 2006

Another greasemonkey script....

I submitted the following as a greasemonkey script (http://userscripts.org) idea proposal

<idea>

Quite a few sites use the Google Analytics service. Sites insert javascript code like -

<script type="text/javascript">
_uacct = "UA-32013-5";
_udn = "slashdot.org";
urchinTracker();
</script>

(The above code is from slashdot ).

A script could be written which shows a simple notification whenever a site visited ; contains Google Analytics javascript.

</idea>

Any takers??

Monday, January 23, 2006

Some free books....

I'm trying to read a bit on Lisp. This interest was spurred by an essay and a podcast by Paul Graham. Dunno how far i'll go... but trying to get a feel of other languages as well.... Also try reading some of his essays.

Basically I got a few books at http://www.freetechbooks.com. You guys could also get something on your topic.

Wednesday, January 18, 2006

Book Reviews

Trying to gauge how good a book before you buy it can be a pretty hard task! Money doesn't exactly grow on trees ;o) One site I have found useful and insanely accurate in terms of their book reviews is www.accu.org. This is primarily a C++ site but they also give reviews for C# and Java.

Before buying any book, I usually run a search through there to see how its rated.

Dinesh.

Modern C++ Design

I would really recommend you to try out "Modern C++ Design by Andrei
Alexandrescu". It is a fantastic book delving deep into C++ Template
Techniques. Its not something a novice can read, but yet if you are
comfortable with C++ templates, then you should definitely give it a
shot!

He opens your eyes to a lot of interesting techniques and in the process
also unravels "Loki", the library (written by him) which implements all
of the techniques!

Policy class, local classes, typelists - the list just goes on, its all
there!! He shows what you can do with even the most simple template
classes viz :-


template<bool>
struct CompileTimeChecker
{
CompileTimeChecker(...) {}
};

template<> struct CompileTimeChecker<false> {};

This relatively simple struct can achieve compile time assertions for
you!

Read it! Its worth it!

Dinesh.

Monday, January 09, 2006

Use that extra bit of vegetable oil at home

This is really one of the most hilarious things I've ever seen -
http://www.tomshardware.com/2006/01/09/strip_out_the_fans/

Keep it cool ;o)

Dinesh.

Friday, December 16, 2005

Re; Free UML Tool?

There is an experimental one being developed at MIT:

http://relo.csail.mit.edu/

Singleton design pattern

Mohnish & I had a small discussion recently about Singleton vs static method only class.

A few advantages of Singleton we came up with were..

Singletons can be subclassed. And preferably used with Factories or Registries.

Another subtle difference was usage. When you have a singleton, you get back a class instance on which you then perform operations. Like..

Singleton singleton = Singleton.getInstance();
singleton.doSomething();
singleton.doSomethingMore();

Compare this to ..

Math.cos(..);
Math.round(..);

The Singleton is just more correct because it allows to think in terms of a type and its behaviour and limits the instances. The static method form does not exhibit the same level of coherent behaviour. It's not the most cleanest distinction but I guess you know what I mean.

I was in the mood to read more on this and stumbled on an article on Javaworld - Simply Singleton. Definitely worth a read.


...which reminded me of a basic feature of Singletons we missed - controlled instance creation

Thursday, December 15, 2005

RE: Free UML Tool?

Revo, Most of the reverse engineering software's that can be found for
UML are not freely available. There's EclipseUML @
http://www.omondo.com/ that you can try. The free version does not have
reverse engineering capabilities and the Enterprise Edition has a 30-day
evaluation limit.

There are others too, but more or less the story stays the same, go to -
http://eclipse-plugins.2y.net/eclipse/plugins.jsp?category=UML

If you do decide to evaluate EclipseUML (which is a plug-in for Eclipse)
make sure you have the dependencies of the EMF, UML and GEF packages
right.

Dinesh.

Sunday, December 11, 2005

Free UML Tool?

Do any of you use any UML tools? I was looking for a tool which would convert existing code (again Java) to a UML Diagram - Class and sequence diagrams.

Preferably the tool should be light on resources.

Monday, November 21, 2005

Ajax & PHP without using the XmlHttpRequest Object

Much cleaner....

http://www.phpit.net/article/ajax-php-without-xmlhttprequest/

Sunday, November 20, 2005

Re: Generics in Java

The other thing is that unlike C++, in Java all the checks (as you said) are done at runtime. Add to this the fact that it has a unified type system where all types (except primitives) inherit from Object makes it even more complicated. Both these are the reason for things like "? extends X" and "? super Y". You don't find these in C++ templates. Everything is checked at compile time so the compiler will warn you if the parameter types don't have expected methods. There's no need to specify that you want parameter types to extend or be the super type of some class.

This generics thread is just going to get more and more complicated. In Java, the compiler checks all* generic code at compilation time.

So if I say,
List<Integer> ints = new ArrayList<Integer>();
ints.add("a String"); //Oops... compilation error

But the bytecode generated will be similar to that generated pre Java 5 with casts inserted by the compiler.

Now there are some cases where you have no option but to make an unchecked cast to make code work. In such cases the compiler is not sure that the code/cast is wrong. So compilation is allowed with an unchecked cast warning.

class UncheckedCast<E> {
 private E[] arr;
 public void meth() {
  arr = (E[])new Object[5]; // unchecked cast
 }
}

Also....
<excerpt>
Generics for Java are accompanied by a cast-iron guarantee: no cast inserted by erasure will fail, so long as there are no unchecked warnings. The above illustrates the converse: if there are unchecked warnings, then casts inserted by erasure may fail.
</excerpt>


"? extends X" and "? super Y" are Wildcards. They are used to increase the range of Types that can be put in or removed from Generic methods/classes. This is a hack to reduce the effects of Erasure. I do not think this will be there in C++ or C#.


A slight diversion..
Does C# too have primitives? I have come across a few instances where having primitives in Java has hurt. Primitives requires having to make all special conversions and stuff. I suppose SmallTalk, Ruby are pure-OOPs wrt this.


I haven't delved too deep into how C# (.NET) has handled these situations. But I think there will be differences since the two implementations are different... no erasure, so type info is preserved. There is something called a constraint which basically allows you to declare an interface you want the parameter type to implement or inherit from some base class or specify that it has a default constructor...

Java too supports Constraints and its called Bounds. So the example Mohnish mentioned for max can be written in Java as...

public static <T extends Comparable<T>> T max (T a, T b) {
 if( a.compareTo(b) < 0 )
  return b;
 return a;
}

Btw Comparable is an interface which takes a generic type T.

I don't remember reading about Bounds/Constraints in C++... How is a similar thing done?

About the C# Constraints...


where T : new() T must have a no-parameter constructor


Java doesn't have anything similar. It seems to be an interesting constraint which should be useful in creating types of T even though the Type T is only known at runtime.


where T : class T must be reference type (a class)
where T : class_name T may be either class_name or one of its sub-classes (or is below class_name in the inheritance hierarchy)


Could you give an example of the usage of the above Constraints. To clarify; the first constraint only takes T, and the second takes T or its sub-class.

Saturday, November 19, 2005

Re: Generics in Java

This blog post made me realize how little I really know about Generics in Java. Conceptually, I feel generics are easy to understand but when looking at these details, it becomes interesting i.e. confusing.

But having said this, I think it's important to take some perspective. Most Java programmers are 'consumers' of APIs. Using these generic classes isn't very difficult. It actually makes better type guarantees and is more natural to use (no messing with casts). The complications of generics only occur when you write generic APIs - this burden is borne by the 'producers'. This is in a way good since there are generally more consumers than producers, so fewer people have to understand the complexities of covariants, contravariants and invariants etc... When was the last time you wrote a generic class?

The other thing is that unlike C++, in Java all the checks (as you said) are done at runtime. Add to this the fact that it has a unified type system where all types (except primitives) inherit from Object makes it even more complicated. Both these are the reason for things like "? extends X" and "? super Y". You don't find these in C++ templates (Atleast I haven't seen them - can someone confirm?). Everything is checked at compile time so the compiler will warn you if the parameter types don't have expected methods. There's no need to specify that you want parameter types to extend or be the super type of some class.

I haven't delved too deep into how C# (.NET) has handled these situations. But I think there will be differences since the two implementations are different... no erasure, so type info is preserved. There is something called a constraint which basically allows you to declare an interface you want the parameter type to implement or inherit from some base class or specify that it has a default construtor...

public T genericMethod<T>() where T : constraint

where constraints can be...

where T : struct T must be a value type (a struct)
where T : class T must be reference type (a class)
where T : new() T must have a no-parameter constructor
where T : class_name T may be either class_name or one of its
sub-classes (or is below class_name
in the inheritance hierarchy)
where T : interface_name T must implement the specified interface


Why the need for constraints? Consider this simple ex.

public static T Max<T>( T a, T b )
{
    if ( a.CompareTo( b ) < 0 )
        return a;

    return b;
}


This will fail at compile time. The compiler doesn't know whether a and b support the CompareTo method. There needs to be a way to limit what the parameter types can be... some constraint.

public static T Max<T>( T a, T b ) where T : IComparable
{
    if ( a.CompareTo( b ) < 0 )
        return a;

    return b;
}


This satiates the compiler since it will make sure that when you call this method, the types of objects used as parameters implement Icomparable.

This seems like a bit of a sidetrack. I'll try and read up some more on C# generics and post any differences/similarities to covariants, contravariants and invariants.

Friday, November 18, 2005

Re: codeWord changes??

Also I was thinking of opening codeWord more. First we can allow Anyone to post comments.

We could also publish codeWord in a few blog directories.


Both are fine by me. Anybody have objections?

Thursday, November 17, 2005

codeWord changes??

I added Google Analytics to codeWord. See Google Analytics. If any of you want the info let me know.

Also I was thinking of opening codeWord more. First we can allow Anyone to post comments.

We could also publish codeWord in a few blog directories.

Suggestions?

Re: Happy Birthday CodeWord

Its been 2 yrs since CodeWord was started..

Happy (Belated) Birthday indeed!

..lets try and write blogs more often.

I'm happy we've kept it up this long, but the posts have been lean and infrequent of late. I've been a big culprit myself. We should all try to get back to the ol days of having long discussions on topics of interest. There's certainly no shortage on things to talk about.

So this is my great rallying call for the troops ala Bill Gates who does it every five years.

Monday, November 14, 2005

Happy Birthday CodeWord

Its been 2 yrs since CodeWord was started..

..lets try and write blogs more often.

Btw. I posted the Generics blog so that I could say the above line!!

Also I suppose I made the Generics blog a bit cryptic. Ask questions incase.

Saturday, November 12, 2005

Generics in Java

I've finally started trying to learn about the new Java 5 features...

Generics is one of the most important. There is a draft book by Oreilly at java.net - Generics and Collections in Java 5. And there are quite a few do's and dont's with Java generics. Definitely makes the language more complicated but it is needed too. Thought of sharing a few interesting excerpts here...

<excerpt>

Array subtyping is covariant, meaning that type S[] is considered to be a subtype of T[] whenever S is a subtype of T. Consider the following code fragment, which allocates an array of integers, assigns it to an array of numbers, and then attempts to assign a float into the array.

Integer[] ints = new Integer[] {1,2,3};
Number[] nums = ints;
nums[2] = 3.14; // array store exception
assert Arrays.toString(ints).equals("[1, 2, 3.14]"); // uh oh!

The subtyping relation for generics is invariant, meaning that type List<S> is not considered to be a subtype of List<T> except in the trivial case where S and T are identical. Here is a code fragment analogous to the one above, with lists replacing arrays.

List<Integer> ints = Arrays.asList(1,2,3);
List<Number> nums = ints; // compile-time error
nums.put(2, 3.14);
assert ints.toString().equals("[1, 2, 3.14]"); // uh oh!

</excerpt>

It is obvious that invariant behavior in generic limits is usefulness. So wildcards can be used to introduce covariant behavior.

<excerpt>

Wildcards reintroduce covariant subtyping for generics, in that type List<S> is considered to be a subtype of List<? extends T>, when S is a subtype of T. Here is a third variant of the fragment.

List<Integer> ints = Arrays.asList(1,2,3);
List<? extends Number> nums = ints;
nums.put(2, 3.14); // compile-time error
assert ints.toString().equals("[1, 2, 3.14]"); // uh oh!

</excerpt>

And it gets even more interesting when...

<excerpt>

Wildcards also introduce contravariant subtyping for generics, in that type List<S> is considered to be a subtype of List<? super T>, when S is a supertype of T (as opposed to a subtype). Arrays do not support contravariant subtyping.

</excerpt>

So there are quite a few differences between Arrays and Generic Collections in Java and the author suggests using only Collections. The covariant and contravariant behavior is used to increase the range of Types that can be used by a Collection of type <T>.

The covariant behavior (<? extends T>) is used to get types from a colletion.

<excerpt>

Here is a method that takes a collection of numbers, converts each to a double, and sums them up.

public static double sum(Collection<? extends Number> nums) {
double s = 0.0;
for (Number num : nums) s += num.doubleValue();
return s;
}

Since this uses extends, all of the following calls are legal.
List<Integer> ints = Arrays.asList(1,2,3);
assert sum(ints) == 6.0;

List<Number> nums = Arrays.<Number>asList(1,2,2.78,3.14);
assert sum(nums) == 8.92;

</excerpt>

So if I have a Collection of a type which extends Number, I know I can atleast safely remove type Number. This is what the author calls the Get principle.


The contravariant behavior (<? super T>) is used to put types into a colletion; which is analogous to the above behavior.


<excerpt>

Here is a method that takes a collection of numbers and an integer n, and puts the first n integers, starting from zero, into the collection.

public static void count(Collection<? super Integer> ints, int n) {
for (int i = 0; i < n; i++) ints.add(i);
}

Since this uses super, all of the following calls are legal.

List<Integer> ints = new ArrayList<Integer>();
count(ints, 5);
assert ints.toString().equals("[0, 1, 2, 3, 4]");

List<Object> objs = new ArrayList<Object>();
count(objs, 5); objs.add("five");
assert objs.toString().equals("[0, 1, 2, 3, 4, five]");

</excerpt>

So if I have a Collection of a type which super Integer, I know I can safely add type Integer. This is what the author calls the Put principle.

Incase a method has to both Get and Put into a same Collection, then wildcards cannot be used. Btw in this blog wherever I have used interesting you can substitute confusing. Yet with a little time and practice generic in Java should not be that tough.

A lot of this is caused because generic in Java is implemented using Erasure in which the type (<T>) is basically removed and casts are added by the compiler. So at runtime there is no info of the type. There are many more quirks caused due to Erasure... but this much is scary enough for one blog.

Could you guys compare generic in C# and C++. Also Mohn what are the new features in C#??

Thursday, October 27, 2005

Re: War on Terror - bash style

When I first read the title "War on Terror - bash style".. i thought it was a typo instead of "War on Terror - bush style"

Good read... I meant the bash one

War on Terror - bash style

Seriously (geeky) hilarious - http://blogs.sun.com/roller/page/ThinGuy?entry=the_war_on_terror_as

Charles Petzold on Visual Studio

 
Avalon's dynamic layout sounds interesting. I actually may be doing a POC on Avalon sooner or later for one the projects here! Hoping the work comes through soon!!
 
Dinesh.
 

Thursday, October 20, 2005

AJAX Apps

Word Processor:
http://www.writely.com/

Calendar:
http://www.kiko.com/

Todo List:
http://www.rememberthemilk.com

Monday, October 17, 2005

Re: Project Anyone??


I generated the pdf of the deverloperworks site and it looks just fine.

It all just depends if you want to play with js or read the article.


Like u said the PDF thing worked fine. What I was a bit confused was how the page style changed. I thought it was doing something funny with javascript. But later it was nothing to do with js; but CSS. With CSS you can specify the media type as well as explained here. So the print css was a no frills style which was auto used when printing.

Actually wanted to play with Greasemonkey.. but will try it later.

Sunday, October 09, 2005

Re: Project Anyone??

Revo,
 
I generated the pdf of the deverloperworks site and it looks just fine. If your purpose is just to read the articles then I don't see why you would want anything else. If you want the frills and colors, then do what mohnish suggested.. Say "File -> Save As" and select the type as *.mht, thats a web archive. I tried that too, its even better than the pdf!
 
It all just depends if you want to play with js or read the article.
 
Dinesh.

Friday, October 07, 2005

Re: Project Anyone??

Also related to this, you guys aware of any JavaScript(js) tools. One thing I use a bit is the Javascript console in firefox. But only get errors for lousy methods I have writen. Is there any way I can get all the js loaded by a site. Or the dynamic tracing/state of all the js variables/methods etc that are currently loaded/working in a page.

Download this extension for Firefox. Here is his site. Probably the greatest invention for Javascript ever. Not exaggeratating!

As for your problem... why don't you just use the 'email this page' link to email the page to your 2 1/2 gig gmail account? Or even easier why not just "File -> Save Page As..."?

Re: Project Anyone??

Just install pdf995 - http://www.pdf995.com..

Thanks,,, I was aware of that tool. First the pages are not very printer-friendly. Too many extra elements. Also the idea was to first get the underlying format. And then try to make some Greasemonkey script to modify the developerworks pages and add another; say PDF link.

Also related to this, you guys aware of any JavaScript(js) tools. One thing I use a bit is the Javascript console in firefox. But only get errors for lousy methods I have writen. Is there any way I can get all the js loaded by a site. Or the dynamic tracing/state of all the js variables/methods etc that are currently loaded/working in a page.

Thursday, October 06, 2005

Re: Project Anyone??

Revo,
 
Just install pdf995 - http://www.pdf995.com.. It installs as a printer and when your page asks you to choose the printer, choose the software one and it will print it to a pdf.
 
Dinesh.

Re: What is Web 2.0?

I had read the article recently. That term seems to have got a lot of buzz of late. I guess one of the things that really got it moving was AJAX interfaces.

What I'm starting to notice is that a lot of 'concept' apps or whatever you want to call it are just trying to ape what regular desktop apps do. Now that there is the new idea of making http requests asynchronously which don't require page refreshes, people are going crazy using it as a hammer and seeing everything as a nail. From the few I've seen - they suck. Sure they are all jazzy making full use of dhtml, now with xmlhttprequests behind the scene. But they are a usability nightmare. They are slow as hell. AJAX is a new concept and with people trying to take it to the limits they are abusing the browser. When you want to use a web app you expect it to work in some 'preconcieved' way - through so many years of surfing the web we've become comfortable with certain conventions. AJAX apps go against it. Plus who the hell wants to use a windows type app through a browser? Adam Bosworth - a big shot at Google - the 'father' of AJAX apps - even posted problems he see a while back.

I'm not saying AJAX sucks. I think it's superb. Really. I feel it should be used to enhance the web experience and accepted paradigms. Not just try to rehash Windows type apps.

Wednesday, October 05, 2005

What Is Web 2.0?

A really good writeup on - What Is Web 2.0? at Oreilly.

The conclusions included the following points....

* Services, not packaged software, with cost-effective scalability
* Control over unique, hard-to-recreate data sources that get richer as more people use them
* Trusting users as co-developers
* Harnessing collective intelligence
* Leveraging the long tail through customer self-service
* Software above the level of a single device
* Lightweight user interfaces, development models, AND business models

What I felt is the most important is Control over "unique, hard-to-recreate data sources". If you can generate/own such data; you can expose an API and thus take care of the other points mentioned.

Another point mentioned is rich UI using AJAX.

Monday, September 26, 2005

Project anyone??

I usually get quite a lot of good articles at IBM developerworks. They would initially offer articles in different formats like PDF; which I would save locally. Recently the site was changed and the PDF format support was removed. Instead a "Print this page" link which calls a JavaScript method is present.

As I do not have a printer on clicking the link, it gives me a "No printer found error". So could any of you guys tell me what method is being called on that link. I do not really know JavaScript and was unable to figure out what gets called.

I suppose the method will return a format which is printer friendly and then I could move ahead from there...

Any takers??

Thursday, September 22, 2005

The Jackpot project

Some pretty interesting stuff in this project. See this link http://www.artima.com/weblogs/viewpost.jsp?thread=116895 at artima.

Jackpot provides a few compiler specific views which can then be used for code-optimization etc. Read the article..

Wednesday, August 24, 2005

Comparing Java and .NET security

I'm back. Hopefully there'll be more traffic from my side.

Here's an interesting paper published by couple of students - Comparing Java and .NET security - Lessons learned and missed. Haven't read it, but scanned some parts and it seemed pretty good.

Saturday, August 06, 2005

Hacking the Linux 2.6 kernel

There is a good tutorial at developerworks on Hacking the Linux kernel..

I havent tried the stuff yet.. but seems like a good starting point to go that one level deeper into the Linux OS. Read Part 1 and Part 2.

Friday, July 29, 2005

Hardware: Super Fast Storage

See this article on anandtech.com which is a good site for hardware reviews. The article is about the review of a new product - Solid State Storage (i-RAM). Simply put, i-RAM has a 4 RAM slots. Put in upto 4*1GB RAM cards and what you get is a super fast and silent Storage device. i-RAM plugs into the PCI slot for power and has a battery backup for maintaining data in the RAM cards after power shut down. More on the power to the card.. "As long as your power supply is still plugged in and turned on, regardless of whether or not your system is running, shut down or in standby mode, the i-RAM will still be powered by the 3.3V line feeding it from the PCI slot."

Costly but cool.

Sunday, July 17, 2005

Re: Java Generics Considered Harmful

He's right to say that Generics adds a certain level of complexity to the language. But it's designed to simplify programming. If you don't abuse it, it is a benefit rather than a hindrance.

Consider C++... Why do people think it's so difficult? It's because there are so many different ways to do things and a lot of the features are abused. But if you only use a controlled subset of the features in a consistent way, that complexity goes down and it becomes manageable.

It's the same with Generics. He's given some examples of some real weird stuff that could be done with it. But why would you want to do it? If the whole point of this is to simplify things, why do things like that? I've used Generics and I feel it has made things better. When you're looking over code and you see them declarations which specify what type of object the data structure contains, it makes things so much more clear.

I can't say people in the .NET community have voiced similar concerns, but that may be partly cause .NET 2.0 hasn't come out yet. Maybe once it's out there for a while and people start seeing problems like this there'll be some complaints. I haven't seen a total/complete comparison between the Java/.NET implementations and what can be done with them so I dunno if what he's talking about can be done in .NET also (I would assume so). So lets see.

As I said, my personal feeling is that Generics is definitely an improvement and is something that is needed.

As an aside - Just noticing these two trends... Java and .NET are moving to things like Generics which require you to specify MORE detailed type information, whereas there's also a huge move towards dynamic languages like Python, Ruby and Javascript which are the opposite and infer all type info.

Thursday, July 07, 2005

Re: Why Indians Aren’t Software Innovators?


In the current software industry, there is little ongoing innovation.

The Indian education system fails to teach underlying concepts and understanding.


What you said about education in India is mostly correct. The majority of the students perform really well by rote learning. Although the Indian educational system has flaws, I suppose the courses in schools are much more rigorous compared to stuff taught in Western countries.


If the Indian education system does not actively foster innovative thinking, one may ask why there are so many successful Indian entrepreneurs in the software industry in the United States.

One reason may be that many of these successful ventures were started by graduates of the Indian Institutes of Technology (IIT).
One many then ask about the success of non-IIT Indian software entrepreneurs in the United States. Most of the remaining Indian entrepreneurs are likely completed graduate studies in the United States have developed innovative thinking through these institutions.


I somehow believe that innovation cannot be taught. Pawan mentioned fostering innovation which is more correct. Without a doubt there are many intelligent guys in India. I believe that there are also many innovators. Why? Simply because of the environment. There is a lot of chaos and huge ammounts of competition. This harsh environment makes the best innovators. Those Indians who move abroad find an environment where it is easier to explore new ideas. They can survive anywhere. Remove red-tape and Indians really thrive.

Also IITians are a bunch of really intelligent guys. But not necessarily good at software and definitely not necessarily good innovators. Innovation like Leadership is self-taught. For a similar reason I find it absurd that people are taught managerial skills in MBA schools.

As Pawan mentioned, there is a less demand for products in India. And so most guys move to services.


Therefore, the Indian software industry will inevitably either perish or will have to become innovative as the payoffs for outsourcing decrease.


The Indian software industry has a very long life ahead. They are already moving to higher end services. From testing jobs, companies are now doing some design stuff too. Even in hardware and other domains, more jobs where high skills are needed are being shifted. The quality of the "outsourced jobs" is improving.

Java Generics Considered Harmful

Ken Arnold is one of the authors of The Java Programming Language along with James Gosling.

In this post on Java.Net blogs; he says..

"I don't know how to ease into this gently. So I'll just spit it out.
Generics are a mistake. "

That is a pretty big statement to make.

His reasoning is that for the benefit Generics offer, they are too complex to learn and hence a mistake.

As lazy as I am I have still not played with Generics; so I cannot say much.

Any such feeling in the .NET world??

Thursday, June 23, 2005

Re: Intel at Apple's Core

I don't think this will be the case at all. Apple isn't going to let you run their OS on PCs. A huge part of their revenue is from hardware

Yur right... Apple will try to control their platform/OS and work on specific hardware too.


Sure, people will manage to get it on PCs and there will be hacks etc... but I doubt it will be anything big. Plus OS X isn't Open Source so there's less incentive for the OS community to bother with it.

Actually MacOSX is open source. See darwinsource/. I knew that they are based on BSD Unix, but just realised they are open source too!!.

IMHO the OSX hacks will get quite popular if it happens..

Admin pics

Admins Ashtray
Admins Ashtray

Admins Archive of Babelfish
Admins Archive of Babelfish

Homeless Admin
Homeless Admin

Wednesday, June 22, 2005

Re: The Future of Microsoft

I did read that article. Linus makes sense. But I don't see his statements supporting what you wrote.

Anyway, since we're on the topic, came across this post from an MS dev... The Innovation Tax

Re: The Future of Microsoft

Relating to my essay, here's a recent interview with Linus about the future of Microsoft that I found on slashdot.

http://blogs.siliconvalley.com/gmsv/2005/06/an_interview_wi.html

Monday, June 20, 2005

Why Indians Aren’t Software Innovators?

In the current software industry, there is little ongoing innovation. The core of the industry relies on the outsourcing of projects from international (mainly American) firms. Based on the experiences of many of my relatives who work for such companies as Infosys, Wipro, Tata Consultancy Services (TCS) and Motorola India Electronics Limited (MIEL), I have observed they are usually given well-defined projects that have little room for creativity. But I believe that this is not an issue for most developers in India since most have been trained to engineer based on solid and well-defined specifications. This mindset is may be due in large part to the style of education in Indian schools and colleges.

Most Indians have been trained to be good engineers but not good innovators. For example, a few years ago, my cousin in India and I were both studying electricity and magnetism as a part of our high school physics curriculums. I was shocked to see how she would solve a problem regarding electric fields and flux using Gaussian surfaces. Her professor had taught the class the standard Gaussian surfaces: sphere, pillbox, etc. The class would then memorize the necessary integrations and formulas to answer any questions on the standard state government exam. However, in my high school we had approached these problems by evaluating them from scratch instead of plugging in numbers into memorized formula. When I asked my cousin a question regarding some of the more general concepts of electricity and magnetism, she could not answer them. Though this is a small example, the Indian education system fails to teach underlying concepts and understanding. Therefore I believe that the Indian software industry is missing “out of the box” thinking which is necessary for software innovation.

If the Indian education system does not actively foster innovative thinking, one may ask why there are so many successful Indian entrepreneurs in the software industry in the United States. In fact, EconomicTimes.com states:

“.3,000 of the technology firms created in the Silicon Valley since 1980 are run by Indian and Chinese entrepreneurs. Accounting for over thirty per cent of the total number of technological start-ups, reaching $19 billion in sales, and creating 70,000 new jobs, these businesses have made significant contributions to the local economy. …Today, there are more than 20,000 Indian millionaires in the Silicon Valley.[1]

One reason may be that many of these successful ventures were started by graduates of the Indian Institutes of Technology (IIT). In order to be one of the 2% of applicants admitted into IIT, students must be able to pass a notoriously difficult entrance exam.[2] Therefore unlike government issued entrance tests for all other Indian universities, where memorizing will work, the IIT entrance test requires students to master the underlying concepts rather than just memorize and drill problem solving techniques.

One many then ask about the success of non-IIT Indian software entrepreneurs in the United States. Most of the remaining Indian entrepreneurs are likely completed graduate studies in the United States have developed innovative thinking through these institutions. Many of my friends who completed an undergraduate engineering degree in India and are now graduate students in the United States, have expressed much appreciation for the American style of higher-level education. For example, when they took a course on operating systems in India, they simply had to memorize the architecture of several major operating systems from a book. However, when they retook the course after immigrating to the US, they actually had to build an operating system which brought a whole new level of understanding.

Secondly, there are no successful software entrepreneurs in India outside the outsourcing arena because there is no direct interaction with potential software consumers. Domestically, there is no significant demand for software because home ownership of a personal computer is limited to a few individuals in the upper-middle class. It is also difficult for an Indian software product company to develop products for international clients because it is hard to determine the customer’s needs from the other side of the world. Therefore the only model for an Indian products company is to establish sales and marketing offices in foreign countries and conduct development efforts at home. However in such a company, market assessment and innovation would essentially be occurring abroad and coding would be done in India – basically what is already occurring in India already.

The third reason we have not seen any product companies from India is because there currently is no need for them. Given the current boom times in India, an entrepreneur is likely to follow a proven formula by founding a small outsourcing company rather than take undue risks to start a products company. Over time, the profitability and attractiveness of outsourcing firms in India will decrease and only then will Indian entrepreneurs be forced to look at other business models.

Therefore, the Indian software industry will inevitably either perish or will have to become innovative as the payoffs for outsourcing decrease. Furthermore, as the domestic demand for software grows, Indian companies will not only have an upper hand in a larger market, but they will also have direct exposure to customer needs. However, in order to expedite this industry transformation, the Indian government should look toward reforming engineering curriculums to cultivate a generation who not just backend engineers but true innovators.


[1] http://www.nasscom.org/artdisplay.asp?Art_id=2692

[2] http://www.indianembassy.org/US_Media/2003/mar/cbs_iit.shtml

Sunday, June 19, 2005

Re: The Future of Microsoft

Microsoft has over 80 products stretched over many markets from mobile device software, to RFID, to MSN services, to desktop applications to video games.

As companies get bigger they need to start looking at expanding their product base. Sure a lot of them won't click (with Microsoft it's a lot), but that's how they can get to the "next big thing". I don't see they having 80+ products stretched over many markets to be a problem at all. They are investing in many areas and they will hope that some of those will click for them. The reliance they have on Windows and Office is unbelieveable. It is an eventuality that these will subside. They NEED to look at other products.

But you can start to see signs from the Microsoft culture that the company is beginning to no longer be as cohesive as it once was. As Microsoft becomes a larger and more mature company, they will always continue to struggle to find the balance of performing with the strength of a large company while maintaining the efficiency of a small one.

I don't think this is anything unavoidable. It's sort of like a country. You have many subgroups and subcultures within. You relate yourself with both. Once a company gets to a certain size, you can't do things the same way as a startup. So rules change and so does the culture. We spoke a little about Google and how it operates. They are small right now, but aggressively hiring left and right. Eventually, the entire company will find itself in a situation similar to how many others before them have. They will need to change. How and what they do will have to be seen. But the certainty is that they won't be the same as they are right now and maintaining the "efficiency" they have right now won't be possible.

This can be seen from the recent resurgence of Netscape’s Firefox browser in the software market. In the Business of Software, it is mentioned that the Netscape Navigator code base grew from “100,000 lines in 1994 to 3 millions lines in 1994”. Netscape’s inability to add new features while maintaining stability in the product was one of the major reasons for their loss in the browser wars.

Yes, ONE of the reasons for Netscape's downfall was because version 4 was a real sucky application. It didn't even compare with IE 4, which was years ahead of it in every way. The most important being its implementation of the DOM. But I won't say that the size of the code was the reason for Netscape releasing such a bad app. I'm sure IE was also had similar number of lines of code. It's how the app is architected that matters. Look at Win 9x vs Win NT. Windows 2k/XP are much larger than Windows 9x, yet they are better OSs. So just trimming down the LOC (lines of code) isn't the answer.

Prahalad’s theory basically claim’s that 90% of the world technology and commercial products are targeting the richest 2 billion people in the world. This in turn has left the 4 billion people who earn less than $4 per day out of the world’s markets. But he thinks that is can all change, because now the “bottom of the pyramid” has reached such a critical mass that companies can still large profits despite smaller profit margins per sale.

I agree. The Asian market is HUGE. And these companies, Microsoft included, will need to do more to make their presence felt there. And not only target the upper/middle classes, but even the lower classes.

A few weeks ago, Microsoft announced they would be releasing stripped down Hindi version of Windows XP to the India market for $70 as a pilot program.

You're talking about Windows Starter Edition right? I actually think this was really stupid. From what I remember, this version only allows you to open up three applications or windows or something. You can't take a product that's sold for X in the US and sell it for around the same price in another country like India or China. Even $70 (Rs. 3000+) is too much. The only way they will come down to a reasonable price is when they start feeling the heat from Linux. China already has Red Flag Linux which is a home baked version. It looks like the Chinese govt. is heavily promoting it since they don't want to rely on a foreign American company. If India, with its IT superpower, status does the same, Microsoft will be forced to bring down the cost.

And regarding language, I think Linux comes in more languages than any other OS. There was a story long back where a small town in some scandinvian country threatened to move to Linux unless MS released a version of Office or Windows in their language.

In conclusion, I feel that in order for Microsoft to maintain their market dominance, they need to focus as a company. They not only need to question whether their new product lines are actually viable and worth pursuing but they also need to streamline their existing flagship products. And finally as software commoditizes, they need to find new ways for the entire software market to grow.

Yeah focus is needed, but at the same time I feel Microsoft needs to try out different markets. They need to see what works and diversify away from their reliance on Windows and Office. It might sound strange but the spread of broadband is a direct threat to Microsoft. As more people have access to high speed internet, they are more likely to store their data in a remote place and work with think clients. Essentially what runs on the client won't matter much anymore - which is exactly what MS is trying to prevent. They are in a catch 22. Classic example is IE. During it's hayday - v. 4, 5, 5.5 - it was absolutely brilliant. Blew everything else out of the picture. But they saw what they were doing... encouraging people to build web apps and not Windows apps. This was fine in a way, since IE only ran on Windows and no other browser supported the cool stuff in IE. But as Mozilla, Opera and other guys started having similar features which could support complicated Web apps, the OS didn't seem to matter much anymore. So they let IE rot. And this is it's present state. Let's see what new developer features IE 7 will have. I'm sure it will have all the general user friendly features like tabs and RSS support etc...

Boy that was a big tangent. Anyway, my point is that yes they need to put out better software with more innovative features, but they need to also expand into other markets or even create new categories of products.

Re: Intel at Apple's Core

I think this is going to be really huge. I've always wanted to try Mac. But the main barrier has been very very expensive non-x86 hardware. I guess this is an issue for lots of other guys. On the home pc front, Apple may gain a larger market share. Not that Apple is going to overthrow MS, but will definitely make inroads into the market share.

I don't think this will be the case at all. Apple isn't going to let you run their OS on PCs. A huge part of their revenue is from hardware and they aren't going to let Dell, HP and all the other PC dudes take that away. Not to mention the fact that Mac OS won't have support for all PC hardware. Did you see the keynote where they made this announcement? I didn't see the whole thing, but I did see the part where he actually made the announcement and gave the reason for shifting - x86 architecture is more efficient at power consumption and will scale better than PPC. I didn't see making the OS available to the larger PC market as the reason. Sure, people will manage to get it on PCs and there will be hacks etc... but I doubt it will be anything big. Plus OS X isn't Open Source so there's less incentive for the OS community to bother with it. They got plenty to play with with Linux etc...

My 2 cents.

Friday, June 17, 2005

greasemonkey

greasemonkey is one really cool firefox extension i came across. From the homepage....

"Greasemonkey is a Firefox extension which lets you to add bits of DHTML ("user scripts") to any web page to change its behavior. In much the same way that user CSS lets you take control of a web page's style, user scripts let you easily control any aspect of a web page's design or interaction."

There are a whole bunch of user scripts for general and specific sites as well. An example of a generic script is Linkify. This script turn all URLs on a page into hyperlinks. Suppose a page contains text like http://java.sun.com, the Linkify script would automatically convert it to a hyperlink ( http://java.sun.com ). Google Butler is an example of a site specific user script. From their web-site

"WHAT DOES IT DO?

1* removes ads on most Google pages

2* fixes fonts on most Google pages

3* Google web search:
3.1o adds links to other search sites ("Try your search on...")
3.2o in news results, adds links to other news sites
3.3o in movie results, adds links to other movie sites
3.4o in weather results, adds links to other weather sites
3.5o in product results, adds links to other product sites

blah blah.. go see the site"

Try it out.. May improve usability of your favourite site!!

greasemonkey works by changing the DOM structure of the webpage. Dunno more details..

Does Opera have a good extension mechanism?

IE7 will be released soon I suppose, but firefox really has some really neat features.. and extensions. You think IE7 will stop firefox from taking the market??

Wednesday, June 15, 2005

The Future of Microsoft

After my experience at Microsoft, though I was quite impressed by what they had achieved up to date, however, the future seemed less promising. Microsoft seems to be stretched too thin. Microsoft has over 80 products stretched over many markets from mobile device software, to RFID, to MSN services, to desktop applications to video games. But you can start to see signs from the Microsoft culture that the company is beginning to no longer be as cohesive as it once was. For example, when other employees working on XXXXXX would use the pronoun “we”, it would refer to the XXXXXX group or occasionally the entire YYYYYYY. The pronoun “they” would be used when referring to other product groups. Though this may seem insignificant, it shows that employees at Microsoft feel a sense of belonging and loyalty towards their own product rather than the company as a whole. As Microsoft becomes a larger and more mature company, they will always continue to struggle to find the balance of performing with the strength of a large company while maintaining the efficiency of a small one.

Instead of diversifying software products, Microsoft can instead simplify their existing products to provide a more secure and stable user experience. This can be seen from the recent resurgence of Netscape’s Firefox browser in the software market. In the Business of Software, it is mentioned that the Netscape Navigator code base grew from “100,000 lines in 1994 to 3 millions lines in 1994”. Netscape’s inability to add new features while maintaining stability in the product was one of the major reasons for their loss in the browser wars. From personal experience, I can see a similar trend emerging from the Microsoft Office code base and would not be surprised to see similar trends. For example, it would sometimes take one week just to check-in code and resolve dependencies – often more time than it would take to write the new code itself. On the other hand, Netscape is beginning to turn around with the release of their latest open-source browser Firefox which has accumulated over 3 million downloads. What makes Firefox so attractive is its lightweight design, fast load times and stability – all traits which Internet Explorer once beat Navigator with but now lacks. As Microsoft product cycles approach 4-5 years, for Microsoft to retain their dominance over other applications and operating systems, they should instead follow the Firefox model and build lightweight, secure and stable software rather than continuing to bloat their existing code base.

As software begins to commoditize in the existing markets, as the industry leader, Microsoft needs to find news ways for the software industry to grow as a whole. This summer I attended a guest talk by Dr. C.K. Prahalad, a world-renowned Professor of Business Administration, Corporate Strategy and International Business at the University of Michigan, who spoke about his “bottom of the pyramid” theory, which may allow Microsoft to do just that. Prahalad’s theory basically claim’s that 90% of the world technology and commercial products are targeting the richest 2 billion people in the world. This in turn has left the 4 billion people who earn less than $4 per day out of the world’s markets. But he thinks that is can all change, because now the “bottom of the pyramid” has reached such a critical mass that companies can still large profits despite smaller profit margins per sale. One example that Prahalad gave of was how Hindustan-Lever, the Indian division of Unilever, now makes 90% of their profits by selling shampoo in small single use sachets, which are more to the poor than large bottles. At the end of the talk, Prahalad asked Microsoft to consider developing products geared to impoverished populations of the world. Not only would this allow Microsoft to enter previously untapped markets but it would also allow the poor to reap the benefits of software technology as well. Prahalad speculated that Microsoft might be able to even double their profits if they were able to successfully target these markets.

It seems that Microsoft may have bought Dr. Prahalad’s theory. A few weeks ago, Microsoft announced they would be releasing stripped down Hindi version of Windows XP to the India market for $70 as a pilot program. In addition, they plan to introduce the same product in local languages to Russia, Indonesia, Malaysia, Thailand and other parts of India. Though Microsoft has claimed they are introducing this product as a response to rampant piracy, it is important to notice that the Indian version is in Hindi and not English. This may also be an attempt to reach out to the general public sector of India rather than the corporate and upper-class sectors where English is generally accepted as a standard.

During a talk, that Microsoft CEO Steve Ballmer gave to employees and new hires this summer, he said that if Microsoft were to reduce China’s piracy level to those of Italy, which are still quite high, then Microsoft would instantly add an additional $2 billion dollars of revenue annually. He added that China will only crackdown on piracy when they have a local software industry of their own. The low cost software initiative may be an attempt to do exactly this: provide an opportunity for developers, particularly in India and Russia, to purchase Microsoft products so that they can begin develop on it on their own. Furthermore, this is also allows Microsoft to “evangelize” these developing countries that do not have preferences yet for Linux or Windows.

In conclusion, I feel that in order for Microsoft to maintain their market dominance, they need to focus as a company. They not only need to question whether their new product lines are actually viable and worth pursuing but they also need to streamline their existing flagship products. And finally as software commoditizes, they need to find new ways for the entire software market to grow.

Re: Intel at Apple's core


Any thoughts about the announcement? Personally I really don't think it's a big deal at all. It's gonna be the exact same setup expect Intel will be richer.


I think this is going to be really huge. I've always wanted to try Mac. But the main barrier has been very very expensive non-x86 hardware. I guess this is an issue for lots of other guys. On the home pc front, Apple may gain a larger market share. Not that Apple is going to overthrow MS, but will definitely make inroads into the market share.

Re: Gentoo's founder is off (to MS)

Yup.. heard about it.

I guess this means very little. Gentoo's founder Daniel Robbins created a great distro and also created a non-profit org which owns the entire distro and related stuff. So his leaving will not affect the distro much. There were a few really absurd(fun to read) forum posts at Gentoo!!

Tuesday, June 14, 2005

Intel at Apple's core

Check out this op about last week's "big" announcement.

Any thoughts about the announcement? Personally I really don't think it's a big deal at all. It's gonna be the exact same setup expect Intel will be richer. IBM will lose one of their most high profile clients (but I think Xbox 360 is gonna use a PowerPC, so don't cry too much for them).

It will be interesting to see how they will port all the apps over. This is actually the main point of the opinion article. All the Open Source apps I've downloaded have versions for all major OS's. This is just amazing. How are they able to develop platform independent code so efficiently? Even Linux itself is available on so many architectures. Gotta take your hat off to them.

Gentoo's founder is off

You heard about this?

Saturday, June 11, 2005

Re: New Member

Btw all of your posts need to bash Microsoft at some level. And you'll have to have a very high level of tolerance against really bad jokes by the other guys..

I failed to mention he interned at Microsoft last summer.

And good idea - the disclaimer about the bad jokes. At least he can't say we didn't warn him.

Friday, June 10, 2005

Re: Are Design Patterns How Languages Evolve?


Another good example in the is the Observer pattern. This is where you want to "observe" another object and be notified when an event occurs. In .NET the concept of an Event is built into the system.


What you mentioned about the Observer pattern is right. An observer(mostly UI) registers with an observable(data) to be notified about changes so that it can update/refresh itself.

I think the Event class you mention actually corresponds to the Command Design Pattern. I do not have a very good idea about this pattern so may be incorrect. Many times patterns are clubbed together to provide a solution.



I find that Design Patterns are discussed more on the Java side. I haven't found much material with regards to .NET. Dunno why.


There are a lot of patterns on the J2EE side. To build a good app.. with good perf, a lot of stuff needs to be done. Java stuff does not shield you that much. It is very easy to build an app that totally sucks in perf. A lot of experience and knowledge is required. .NET i guess protects the dev more. I guess we should try discussing more topics like say persistence as well which is one of the major areas in Enterprise apps.



I've added a new member - Pawan - to codeWord.


Welcome to the group!! Look forward to some good discussions.. on any topic whatsoever.

Btw all of your posts need to bash Microsoft at some level. And you'll have to have a very high level of tolerance against really bad jokes by the other guys..

Tuesday, June 07, 2005

New member

I've added a new member - Pawan - to codeWord. He's a fellow Google intern (You can see some pics on my personal blog). He's a senior from MIT. He's into lots of different stuff... Perl/PHP/MySQL/C#/Java/C++/VB/.NET/Graphic Design. And he's really into religion as well - specifically Hinduism. Not that it's important, but just felt like mentioning it.

So looks like Open Source web tech is going to get some coverage too. Another perspective is always good.

Re: Are Design Patterns How Languages Evolve?

So is this the author is talking about?? But again what I am talking about are not language extensions .. rather just API additions. Mohn mentioned language extensions but somehow I could not relate those to Design Patterns... Any ideas??

What I wrote in my previous post doesn't technically count as design patterns in the way it's used today. You're right. I suppose I was lumping the "hacks" or workarounds together with design patterns. Basically, something that isn't enforced by the compiler or the language but is agreed upon by the community.

As far as design patterns go, they are becoming language features. The Singleton pattern which you mentioned is one example. In the next version of C# (and VB.NET too I think), you can declare a "static" class. This makes it so that you can't create an instance of it. The constructor is automatically private. Another good example in the is the Observer pattern. This is where you want to "observe" another object and be notified when an event occurs (correct me if I'm wrong, or confused it with another pattern). In .NET the concept of an Event is built into the system. So you can actually create events, have other objects delegate their own methods to those events so that they are invoked when that event occurs.

So this is different to what you said about design patterns being built into the API's instead of the language itself.

I find that Design Patterns are discussed more on the Java side. I haven't found much material with regards to .NET. Dunno why.

Re: Are Design Patterns How Languages Evolve?


Are Design Patterns How Languages Evolve? Any thoughts?

.NET introduced the concept of "Attributes". Java 1.5 came out with a similar concept called "Annotations".

It's interesting to see the evolution of languages and how newer features are just formalized notions of what you could do before that feature came to be. More often than not, it was just "hacking" a feature for something it was'nt really meant for.


The links provided by Mohn did confuse me in a way. We could probably have a bit to discuss on this topic.

Design patterns and what Mohn mentioned are different concepts IMHO.

Mohn made a very interesting point about how newer features are added to langs, which were not initially thought of. And sometimes the 'hack' is not so clean as in Generics in Java. I think this is just happening to make the langs more developer-friendly, which is good in a way.

Design patterns are generic solutions to a particular set of problems. Take for example the Singleton pattern. This pattern helps in creating a class of which only a single instance will exist to the most throughout the lifetime of the application. Design Patterns are solutions built over OOP's concepts.

Design Patterns are now being built into languages. Iterators we use within Java Collections can be mapped to the Iterator Design Pattern. Similarly the Java Swing API heavily uses the Observer pattern and others too. The Observer pattern can be used easily in Java by using java.util.Observer and java.util.Observable. The Proxy pattern is also implemented in a way in Java. Mohn had an example ages back(.. which I still haven't read completely!!). The MVC pattern was initially thought of in SmallTalk. But nowadays many languages(or should i say libraries) provide MVC out-of-the-box. Like Mohn mentioned about ASP.NET v2. We now use many Design Patterns without even realising they exist. Many patterns are adapted to better fit the framework so look totally different.

So is this the author is talking about?? But again what I am talking about are not language extensions .. rather just API additions. Mohn mentioned language extensions but somehow I could not relate those to Design Patterns... Any ideas??

Sunday, June 05, 2005

Are Design Patterns How Languages Evolve?

Here's an interesting post. I had sort of mentioned a little about this in a previous post long back. Any thoughts?

Saturday, May 21, 2005

Re: Integrating OpenEJB with Tomcat 5.0


I know what you guys are thinking - "Dinesh talking about EJB


Welcome to the Dark Side!! Btw how many of you all like Star Wars??



I guess you all know that Tomcat is not an EJB Container and as such requires external support for it to work with EJB's, well I at work have been reading on EJB's for the past few days and as usual being my impatient self, just couldn't contend myself with reading the book, I had to see and run some code. Well, I already had Tomcat installed so I was wondering if there's anything I can do to get it working with EJB's and that's when I fell upon OpenEJB. (I think there's also Jboss)


I'll just give a brief intro. Tomcat is a J2EE Web Container which can be used to deploy Java Server Pages(JSP) and Servlets both of which are used to create dynamic web pages. Open EJB is (i suppose) just an EJB Container which allows you to deploy EJB's. OpenEJB and JBoss are open source implementations.



Revo, you'll really love this, that's if you already haven't done it. Just try it out, it's really simple and yet so powerful.


You mean calling EJB's from JSP's or Integrating OpenEJB and Tomcat?

I have used Sun's Reference Implementation(RI) J2EE App Server for deploying my EJB's. The RI includes Tomcat as a Web Container so you do not have to manually integrate. Also the RI has a good admin console. The RI is free for use. I am not sure about the source. I haven't used OpenEJB. I guess the RI will be more user friendly.



It was a great moment to see my SessionBean being called from my jsp. A good experience, but yet I'd rather be writing cryptic C++ code ;)


I am sure you have read about the functionality provided by J2EE App Servers.. all the distibuted stuff.. implicit middleware etc. Writing an app to achieve functionality like this will really take a huge team and loads of cryptic code. Btw are there any C++ App Servers which provide such services??


Also I spoke of the Dark side. EJB's are difficult to use. Don't Make me Eat the Elephant Again is an article that talks a bit on what the situation is today. There are alternatives to EJB like Spring + Hibernate which I have been hearing a lot of but have never had time to read about. Also the EJB 3 release will be coming soon which is based on J2SE 5.0 and heavily uses annotations which should really simplify coding.

Mohn.. could you mention a little about how the .NET framework handles persistence for the Enterprise?? I have heard that it is simple compared to the Java model.

Re: Adventures with Linux


Looking around I came across ndiswrapper on sourceforge. This is a really neat project which uses windows drivers to get linux to recognize the card. I had some trouble with the newest vesion (1.1), so tried different versions (.10, .09), compiled and can it. It worked! So configured "wlan0" and now writing this post in Opera 8.0 on Mandrake 10.0! Just had a feeling of euphoria!


Woohooo... Congrats man on finally getting your wlan working. Mohn had asked me to help with ndiswrapper ages back.. and as lazy as I am, he had to do it himself!!



You would think that having struggled with it for so long, I would be quite sick of it. In some ways I am, but I've also learnt a lot in the process. And this is the essence of Linux.


Exactly. There are so many things we just take for granted when we use Windows. But only for customization etc when you go deep into Linux do you understand a lot more about the OS and other stuff.

Thursday, May 19, 2005

SciTE Text & Code Editor

I have to admit that I'm a Editor freak!! I keep scourging the net for free, fast and good text editors namely for the Windows Platform. On Linux, Vim just kicks everyone else's butt!!

Recently I came across SciTE which in my opinion is one of the best I have ever used. It's simple and extremely fast. It's also extremely customizable and supports an array of programming languages!!

I think I'm going to stick with this editor for quite some time, hope you guys check it out!

Dinesh.

Wednesday, May 18, 2005

Integrating OpenEJB with Tomcat 5.0

I know what you guys are thinking - "Dinesh talking about EJB, GIVE ME A
BREAK!!" ;) But as the Walrus said "The time has come to talk of many
things" :)

I guess you all know that Tomcat is not an EJB Container and as such
requires external support for it to work with EJB's, well I at work have
been reading on EJB's for the past few days and as usual being my
impatient self, just couldn't contend myself with reading the book, I
had to see and run some code. Well, I already had Tomcat installed so I
was wondering if there's anything I can do to get it working with EJB's
and that's when I fell upon OpenEJB. (I think there's also Jboss)

I will not go into what you should do inorder to integrate the two cause
there's already an excellent article available on the subject at OnJava.com.

Revo, you'll really love this, that's if you already haven't done it.
Just try it out, it's really simple and yet so powerful.

It was a great moment to see my SessionBean being called from my jsp. A
good experience, but yet I'd rather be writing cryptic C++ code ;)
(Sorry, I'll be me, always!)

Dinesh.

Tuesday, May 17, 2005

Adventures with Linux

Ok, I admit it. I've been a blind bastard. Blind to Linux and open source. I've read about it and been keeping up with what's been going on in the "community" but never really "got" it. Well, I think something finally hit me - that light bulb turned on. Anyway, I've decided to write some stuff about my Linux experience.

Here's a brief history of my dealings with Linux as a total newbie (warning: boring stuff ahead). What got me interested in Linux, was my India trip in summer 03 when Rahul and Hrishi were using it. Before that, I never really thought about trying it out and didn't have much interest in it. But the way they spoke about it, I couldn't resist having a go at it. So after coming back, I installed Red Hat 9 on a couple of machines. At the time, I had a network setup over the phoneline and wasn't able to get Red Hat to recognize the NIC. Basically I gave up after several futile posts to message boards and many email exchanges with Rahul. Last May, I installed Mandrake 10 in the hopes that it would work. No luck there either. I realize it was my network setup - which was quite rare. So I gave up on that too. Last summer, I changed over to a wireless network. This time, I was a little more hopeful because this was a more common network setup. Anyhow, long story short, I had a usb wireless adaptor and Mandrake didn't recognize it. I remember spending an interesting afternoon with Rahul on messenger giving me step by step instrutions to recompile the kernel with added support for wireless drivers. Unfortunately, didn't work. Also tried Knoppix without luck. Finally, I installed Mandrake on a laptop which had a wirless card built in. This was pcmcia so I was hoping for better. Again, no luck.

Looking around I came across ndiswrapper on sourceforge. This is a really neat project which uses windows drivers to get linux to recognize the card. I had some trouble with the newest vesion (1.1), so tried different versions (.10, .09), compiled and can it. It worked! So configured "wlan0" and now writing this post in Opera 8.0 on Mandrake 10.0! Just had a feeling of euphoria!

You would think that having struggled with it for so long, I would be quite sick of it. In some ways I am, but I've also learnt a lot in the process. And this is the essence of Linux.

I'll post some stuff about some stuff I've liked about Linux next time.

Monday, May 09, 2005

RE: Stroustrup's Interview Leaked...

The "matter" is obviously a bunch of ******* bullshit but I would have liked to believe that it was Bjarne's idea of a joke! :-p

Friday, May 06, 2005

RE: Stroustrup's Interview Leaked...

I second Dinesh's "you got to be kidding right?" comment. Obviously the work of a C programmer.

RE: Stroustrup's Interview Leaked...

You actually thought that it was Bjarne Stroustrup?? You got to be kidding, right??

Dinesh.

Stroustrup's Interview Leaked...

I don't know how far this is true but entertaining to read nevertheless... :-)

Here's the link.

Thursday, May 05, 2005

Implementing "finally"

Java has this great facility when dealing with exceptions called "finally". When you have a finally block, any code within it will execute regardless of whether an exception has been thrown or not. It's a good place to put code that must absolutely positively be run like closing files, database connections and any other similar resources. C# also has it and I believe it's also been standardized in C++, but not sure. Anyway, ever wonder how it is actually implemented?

I wrote a really simple method that just has a try, catch, finally block and examined the bytecode generated using this really cool Eclipse plug-in.

Here's the java code...

public void testFinally()
{
    try
    {
        System.out.println( "try" );
    }
    catch ( Exception ex )
    {
        System.out.println( "catch" );
    }
    finally
    {
        System.out.println( "finally" );
    }
}


and here's the bytecode...

// testFinally()V
L0 (7)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "try"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
GOTO L1
L2 (9)
ASTORE 1
L3 (11)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "catch"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L4
GOTO L1
L5 (14)
ASTORE 3
JSR L6
ALOAD 3
ATHROW
L6
ASTORE 2
L7 (15)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "finally"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L8 (16)
RET 2
L1 (14)
JSR L6
L9 (17)
RETURN
L10
LOCALVARIABLE this Ltest; L0 L10 0
LOCALVARIABLE ex Ljava/lang/Exception; L3 L4 1
MAXSTACK = 2
MAXLOCALS = 4


I don't understand bytecode. I would be interested in knowing more about it. But anyway, you don't need to be a bytecode specialist to understand how "finally" is always executed regardless of exception or not...

This is the "try" part

L0 (7)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "try"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
GOTO L1


and this is the "catch" part

L3 (11)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "catch"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
L4
GOTO L1


Notice any similarities? What is at "L1"?

L1 (14)
JSR L6


JSR is a jump instruction. So all this does is just to location L6. As you would suspect, it is the finally block...

L6
ASTORE 2
L7 (15)
GETSTATIC java/lang/System.out: Ljava/io/PrintStream;
LDC "finally"
INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V


Voila. Mystery solved!

I have to say that the bytecode is NOT the most diffcult thing in the world to interpret. A lot of it is pretty self-explanatory. I realize this is a real toy example and it gets more complicated, but it looks like something one can pick up. It's the same situation with IL code in the .NET world. I think maybe IL is a bit easier to read.

Maybe not the most important thing, but something that's interesting and nice to know.

The essential Java language library

The essential Java language library

Seems like a decent list. Of the books mentioned, I can vouch for "Effective Java". Haven't read Bruce Eckel's "Thinking in Java", but he's a good writer... "Thinking in C++" was a good read and we've included him in many of our discussions! And I know Rahul is a big fan of "Design Patterns". As far as sites are concerned, onjava.com and theserverside.com have decent articles. onjava.com is part of oreilly which I really respect.

What are some of your fav books? We discussed books we'd LIKE to read long back, but what about books you've already read? I'll mention three - "Applied .NET Framework Programming", "Effective Java" and "The C++ Object Model". I really like books that go into detail and explain HOW things work, you know what's going on underneath the covers or talk about best practices rather than just talk about syntax. I think all these three do that and more.

Java turns 10

See James Gosling (and friends) celebrate his kid turning 10.

Warning - celebration is pretty pathetic.