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.