Monday, July 24, 2006
Java Generics FAQ
Java Generics FAQs - Frequently Asked Questions - This is a collection of answers to frequently asked questions (FAQs) about Java Generics, a new language feature added to the Java programming language in version 5.0 of the Java Standard Edition (J2SE 5.0).
Sunday, July 23, 2006
midday
I've always liked Mid-Day. I was pretty happy to find their site. But the format they have is pretty sucky. They provide a pdf for each page. So to read the entier paper, each page has to be downloaded separately. Not the most convenient thing.
I had started looking at Python a bit (going from the previous post). This seemed to be a pretty good project to use it for. The script - midday - automates the process. Given the paper you want (sunday|mumbai|vashi), it downloads each paper's pdf pages to your machine. It also uses a third party app - pdftk - to combine all the pages into one pdf. It needs to be downloaded and the location it was installed in needs to be passed into the script, but its not necessary. The script still works w/o it, but the pages are in separate pdfs. Should work on both Windows and Linux, but I've tested it only on Linux.
Overall, I liked Python quite a bit. Definitely more productive that Java... for something like this. Less upfront design needed, but is still structured. All the data structures mentioned in the last post came into play. Also, being interpreted, it's pretty easy to make it work on multiple platforms. The library is pretty extensive and with the easy ability to call other programs (especially in the linux environment where the culture is to create small programs that can be stiched together), python can be used for a wide range of applications.
I had started looking at Python a bit (going from the previous post). This seemed to be a pretty good project to use it for. The script - midday - automates the process. Given the paper you want (sunday|mumbai|vashi), it downloads each paper's pdf pages to your machine. It also uses a third party app - pdftk - to combine all the pages into one pdf. It needs to be downloaded and the location it was installed in needs to be passed into the script, but its not necessary. The script still works w/o it, but the pages are in separate pdfs. Should work on both Windows and Linux, but I've tested it only on Linux.
Overall, I liked Python quite a bit. Definitely more productive that Java... for something like this. Less upfront design needed, but is still structured. All the data structures mentioned in the last post came into play. Also, being interpreted, it's pretty easy to make it work on multiple platforms. The library is pretty extensive and with the easy ability to call other programs (especially in the linux environment where the culture is to create small programs that can be stiched together), python can be used for a wide range of applications.
Re: One Array to rule them all
Pretty late reply... I've been doing a bit of python of late. And although there isn't 'one array to rule them all' there are some similarities. In python there are three main data structures - lists, dictionaries and tuples. Lists are growable arrays (ArrayList in Java) and Dictionaries are associative arrays (HashMap in Java). Tuples are just containters to hold other objects (No equivalent in Java). They are immutable.
People always talk of productivity with dynamic languages. These built-in data structures are one of the main reasons for it. Sure Java has an amazing collections framework, but it's not a language feature. It's a framework built on top of the language. In python, these are part of the language... [] creates a list, {} creates a dictionary and () creates a tuple.
Having these be part of the language makes a huge difference. In Java, if you want to return multiple values from a method... either do something ugly like return an array with the values (the values have to be of the same type) or define a new class to hold the values and return an instance of that class. Quite a pain. In python, you just put the values (of any type) inside a tuple and return. As simple as that. And as you can imagine, lists are used a lot to hold collections of data. But probably the most used data structure is the dictionary. It's a dumping ground in all sorts of situations. You would think it would be a readability nightmare but it isn't. It's almost a convention in python and when you come across code, it is immediately recognizable. And these ds's combined make for more productivity gains. Tuples, being immutable, can be used as keys. Also, python has support for sets as well.
People always talk of productivity with dynamic languages. These built-in data structures are one of the main reasons for it. Sure Java has an amazing collections framework, but it's not a language feature. It's a framework built on top of the language. In python, these are part of the language... [] creates a list, {} creates a dictionary and () creates a tuple.
Having these be part of the language makes a huge difference. In Java, if you want to return multiple values from a method... either do something ugly like return an array with the values (the values have to be of the same type) or define a new class to hold the values and return an instance of that class. Quite a pain. In python, you just put the values (of any type) inside a tuple and return. As simple as that. And as you can imagine, lists are used a lot to hold collections of data. But probably the most used data structure is the dictionary. It's a dumping ground in all sorts of situations. You would think it would be a readability nightmare but it isn't. It's almost a convention in python and when you come across code, it is immediately recognizable. And these ds's combined make for more productivity gains. Tuples, being immutable, can be used as keys. Also, python has support for sets as well.
Wednesday, July 19, 2006
Saturday, July 15, 2006
Right to Information
The Right to Information Act (RTI) was passed in 2005 which empowers Indians to ask the Government about anything that concerns them. You can ask questions like why the road outside your house is not repaired or why some facility is polluting your city. The official is under an obligation to respond to your query within a stipulated period.
Now things are amazing on paper. I doubt that information comes so fast and easily. There are a few sites, organisations which assist in this.
See http://www.righttoinformation.org/
Maybe such a wiki like community site would better serve this purpose
Now things are amazing on paper. I doubt that information comes so fast and easily. There are a few sites, organisations which assist in this.
See http://www.righttoinformation.org/
Maybe such a wiki like community site would better serve this purpose
Thursday, July 06, 2006
[Trackback]How to concentrate on writing
Something to think about..
<quote>
When I am up against a deadline and I absolutely, definitely have to get on with my work, I use a few tactics to force myself to concentrate:
1. Switch off email. I don’t start Outlook (or if I do, I disable all the notifications that tell me I have new mail).
2. Isolate myself. I use Bose noise-cancelling headphones but don’t plug them into anything. The silence really is golden.
3. Greed and guilt. I remind myself how much money I’m getting paid for a particular assignment and how ashamed I will be if I miss the deadline. This actually works sometimes.
4. Stop with the blog already. When I’m pressed for time, distractions like blogging and hoovering become very compelling. Knowing this makes it easier to resist.
5. Get up early. 6am is the most productive time of day for writing. No distractions. It also feels more virtuous than staying up late with work.
6. Little treats. I bribe myself: ‘Matthew, if you write another 500 words, you can have a cup of tea and a biscuit.’
7. Chunking. Setting a timer or alarm clock for 15, 20, 30, 50 minutes and doing nothing but writing until it goes off and then taking a break seems like a good way to make progress.
8. Go full screen. Switching Word into full screen mode (from the view menu) eliminates all distractions but the piece I’m working on.
9. Shitty first draft. Splitting the work into distinct writing and editing phases breaks the job down nicely and it takes off some of the pressure to ‘get it right first time’.
10. Change location. Sometimes, if I’m really struggling to get started, taking a laptop or my notebook to a cafe and scribbling out something there - a fresh new location - is a good way to jolt-start an assignment.
</quote>
<quote>
When I am up against a deadline and I absolutely, definitely have to get on with my work, I use a few tactics to force myself to concentrate:
1. Switch off email. I don’t start Outlook (or if I do, I disable all the notifications that tell me I have new mail).
2. Isolate myself. I use Bose noise-cancelling headphones but don’t plug them into anything. The silence really is golden.
3. Greed and guilt. I remind myself how much money I’m getting paid for a particular assignment and how ashamed I will be if I miss the deadline. This actually works sometimes.
4. Stop with the blog already. When I’m pressed for time, distractions like blogging and hoovering become very compelling. Knowing this makes it easier to resist.
5. Get up early. 6am is the most productive time of day for writing. No distractions. It also feels more virtuous than staying up late with work.
6. Little treats. I bribe myself: ‘Matthew, if you write another 500 words, you can have a cup of tea and a biscuit.’
7. Chunking. Setting a timer or alarm clock for 15, 20, 30, 50 minutes and doing nothing but writing until it goes off and then taking a break seems like a good way to make progress.
8. Go full screen. Switching Word into full screen mode (from the view menu) eliminates all distractions but the piece I’m working on.
9. Shitty first draft. Splitting the work into distinct writing and editing phases breaks the job down nicely and it takes off some of the pressure to ‘get it right first time’.
10. Change location. Sometimes, if I’m really struggling to get started, taking a laptop or my notebook to a cafe and scribbling out something there - a fresh new location - is a good way to jolt-start an assignment.
</quote>
Thursday, June 29, 2006
One Array to rule them all
I've been coding in php of late. So some thoughts on that...
Most languages have a few Data Structures (ds). Java has the excellent Collections framework which contains quite a few types of ds as shown in the figure

What I found in php was the array();
It can be used like...
$pasta = array('spaghetti', 'penne', 'macaroni');
In this case the array can be compared to a List or an Array.
You can also add an element to the end of an existing array with the array_push() function or remove an element from the end by using the array_pop() function.
Using the array_shift() and the array_unshift() function removing or adding elements to the beginning of the array can be done.
So now the array can work both as a Queue and a Stack.
Additionally it is possible to declare an array like..
$menu = array('breakfast' => 'bacon and eggs', 'lunch' => 'roast beef', 'dinner' => 'lasagna');
Here 'breakfast' is a key and 'bacon and eggs' is the value. Usually keys are numbers from 0 onwards. In effect our innocent array is now a Map as well.
All this is extremely great for learners. A few thoughts ..
1. The array exposes an API for all these ds'es. How can I enforce an array to act only as a Queue? Is the leakage of the abstraction too much.
2. How do they optimize? In Java I know the costs when I create a LinkedList or an ArrayList. Or use a TreeMap or HashMap. How is it done in php?
3. Also are there Sets in php where one object cannot be added twice. Maybe I am missing some ds library in php ;)
Most languages have a few Data Structures (ds). Java has the excellent Collections framework which contains quite a few types of ds as shown in the figure

What I found in php was the array();
It can be used like...
$pasta = array('spaghetti', 'penne', 'macaroni');
In this case the array can be compared to a List or an Array.
You can also add an element to the end of an existing array with the array_push() function or remove an element from the end by using the array_pop() function.
Using the array_shift() and the array_unshift() function removing or adding elements to the beginning of the array can be done.
So now the array can work both as a Queue and a Stack.
Additionally it is possible to declare an array like..
$menu = array('breakfast' => 'bacon and eggs', 'lunch' => 'roast beef', 'dinner' => 'lasagna');
Here 'breakfast' is a key and 'bacon and eggs' is the value. Usually keys are numbers from 0 onwards. In effect our innocent array is now a Map as well.
All this is extremely great for learners. A few thoughts ..
1. The array exposes an API for all these ds'es. How can I enforce an array to act only as a Queue? Is the leakage of the abstraction too much.
2. How do they optimize? In Java I know the costs when I create a LinkedList or an ArrayList. Or use a TreeMap or HashMap. How is it done in php?
3. Also are there Sets in php where one object cannot be added twice. Maybe I am missing some ds library in php ;)
Friday, June 23, 2006
Wednesday, June 21, 2006
Binary Search is broken
Courtesy Joshua Bloch (aka Java god) - Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken
Can be filed for the next edition of Java Puzzlers.
Can be filed for the next edition of Java Puzzlers.
Tuesday, June 20, 2006
Get Functional
This article - Functional Programming for the rest of us - is like Argentina's performance against Serbia-Montenegro... beautiful.
Wednesday, June 07, 2006
Re: Have you ever felt this?
The "there's got to be more to life than this" deamon thread gets activated often. It's still at a way low priority level as compared to that dude but dunno for how long.
Saturday, June 03, 2006
Sunday, May 21, 2006
Is India at the Tipping Point?
Here's the article... http://www.alwayson-network.com/comments.php?id=15024_0_38_0_C. It's by a Microsoft employee, but talks generally about whats good/bad about the Indian market. He covers pretty much the entire spectrum. Specifically, I thought this statement holds very true...
"It's also interesting to note that many Indians from the Valley are returning to India to set up their startup companies as well as to leverage the engineering/labor-cost advantages. While many startups we talked with have big ideas, they will need coaching to pitch ideas for funding and must be willing to accept possible failure, a normal part of the entrepreneurial culture.".
I've been following a few blogs by Indians who worked in software companies in the US and have gone back to start companies (startups) of their own. These are proper software companies, products based not services/bpo companies, targeting the Indian market. I feel this is an important trend. The backbone of the Indian IT industry is services, but it probably won't be able to sustain the growth in the years to come especially as salaries increase.
But at the same time, there are challenges. You have to think differently from if you were starting a co in the US because the market is so different. Broadband penetration is not high, payment procedures are different... credit card usage is not that common etc... But the guys who go back are smart and seem to take all this into account. Another thing is that the mobile market is booming and growing way faster than pc/broadband. So what about targeting mobile devices? That would be a huge market to target right off. I'm sure the big players like google, yahoo are already planning things, but there maybe opportunities to start some small super specific services?? What dyou think?
"It's also interesting to note that many Indians from the Valley are returning to India to set up their startup companies as well as to leverage the engineering/labor-cost advantages. While many startups we talked with have big ideas, they will need coaching to pitch ideas for funding and must be willing to accept possible failure, a normal part of the entrepreneurial culture.".
I've been following a few blogs by Indians who worked in software companies in the US and have gone back to start companies (startups) of their own. These are proper software companies, products based not services/bpo companies, targeting the Indian market. I feel this is an important trend. The backbone of the Indian IT industry is services, but it probably won't be able to sustain the growth in the years to come especially as salaries increase.
But at the same time, there are challenges. You have to think differently from if you were starting a co in the US because the market is so different. Broadband penetration is not high, payment procedures are different... credit card usage is not that common etc... But the guys who go back are smart and seem to take all this into account. Another thing is that the mobile market is booming and growing way faster than pc/broadband. So what about targeting mobile devices? That would be a huge market to target right off. I'm sure the big players like google, yahoo are already planning things, but there maybe opportunities to start some small super specific services?? What dyou think?
Friday, May 05, 2006
Bruce Eckel interviews.....
Saturday, April 29, 2006
Cool Calendar - Javascript Web Based Calendar Application
Last term for a user interface design class, I made the a web-based calendar. The calendar was about 3000 lines of Javascript. It emulates Outlook in that you can drag and drop select and so forth. The calendar however was just built for the user interface and has no backend. Therefore any changes you make are only held in the client machine's memory. When you reload they are reset. Also its only Firefox 1.0* + compatible. To see pre-populated events , go back to Dec. 2005.Try it out here. -Pawan
Monday, April 17, 2006
Phew
I have been coding in JSP for a while now and worked on the Struts framework as well. The servlet API's allow adding of instances to various levels of scope within the webapp. Like Application scope for the entire webapp, Session scope for the user session, Request scope for a particular request. Request scope is useful as the particular request response can be generated in parts by chaining servlets together. Now these methods make life pretty easy. Something which will used throughout the webapp can be kept at application scope and similarly at varying degrees of granularity at other scope. Like on correct credentials for a login form, a String can be stored in session scope.
This would always disturb me. Simply because client specific data was being stored in-memory. Upto how many users can be supported in such an architecture? even if 10 bytes are stored per client, that can count to a lot of memory for say 10k users. Then the overhead of caching, maintaining state of live data and associating it with the client.
Initially storing stuff in scope would make me think of the size of the objects I used to store. Then I realised frameworks like Struts store huge amounts of data at various scope. Like the action form etc in the request scope. So that made me feel that this is not such an issue. If such relatively heavy objects can be stored then that must be fine. And now with JSF etc these object are just getting larger.
Then I read on the Php Share-Nothing architecture. So the Share-Nothing architecture advocates... simply sharing nothing about the client on the server. As simple as that. Instead of storing stuff in memory, store details in a DB and make DB calls always. Now I am not actually sure how performant this is. But DB's have been around for a long while and have been well tuned. Plus DB's can be easily made to work in parallel redundant mode and have very good features.
Again I know I am being premature to be so anti-in-memory stuff. Many large systems have been built, especially in the enterprise. But it just does not feel right. In the end it seems easier to scale horizontally with the Share-Nothing approach. The in-memory approach seems to force towards vertical scaling.
Some examples... Flickr and Yahoo are two php based webapps. And they dont get bigger than them. Ebay is the biggest java based webapp i know of. But Google for ebay architecture and they too have a custom Share-Nothing like system in place. Gmail too uses Java, but have some super optimizations in place.
Rails is one very hot webapp framework right now. This is one of the more intelligent discussions I have read. Coupled with this blog post Rails seems like something I would like to learn soon. These guys seem to be aware of both php and Java webapp dev. Any idea on their principles on this issue?
What dyu guys think? Any of you really stick to the Share-Nothing principle?
This would always disturb me. Simply because client specific data was being stored in-memory. Upto how many users can be supported in such an architecture? even if 10 bytes are stored per client, that can count to a lot of memory for say 10k users. Then the overhead of caching, maintaining state of live data and associating it with the client.
Initially storing stuff in scope would make me think of the size of the objects I used to store. Then I realised frameworks like Struts store huge amounts of data at various scope. Like the action form etc in the request scope. So that made me feel that this is not such an issue. If such relatively heavy objects can be stored then that must be fine. And now with JSF etc these object are just getting larger.
Then I read on the Php Share-Nothing architecture. So the Share-Nothing architecture advocates... simply sharing nothing about the client on the server. As simple as that. Instead of storing stuff in memory, store details in a DB and make DB calls always. Now I am not actually sure how performant this is. But DB's have been around for a long while and have been well tuned. Plus DB's can be easily made to work in parallel redundant mode and have very good features.
Again I know I am being premature to be so anti-in-memory stuff. Many large systems have been built, especially in the enterprise. But it just does not feel right. In the end it seems easier to scale horizontally with the Share-Nothing approach. The in-memory approach seems to force towards vertical scaling.
Some examples... Flickr and Yahoo are two php based webapps. And they dont get bigger than them. Ebay is the biggest java based webapp i know of. But Google for ebay architecture and they too have a custom Share-Nothing like system in place. Gmail too uses Java, but have some super optimizations in place.
Rails is one very hot webapp framework right now. This is one of the more intelligent discussions I have read. Coupled with this blog post Rails seems like something I would like to learn soon. These guys seem to be aware of both php and Java webapp dev. Any idea on their principles on this issue?
What dyu guys think? Any of you really stick to the Share-Nothing principle?
Friday, April 07, 2006
C# futures
Its been interesting to see the path static languages like C# and Java have taken over the past year with their 2.0 and 5.0 releases respectively. There has been a drive towards more 'staticness' with generics i.e. more type specification at compile time. This has generally been seen as a good thing... more descriptive, more type safe and more performant (in the case of C# ;-) code. But then you have dynamic languages like Python and Ruby which are essentially the complete opposite with no static type specification at all. All the variables only have dynamic types with everything being inferred.
What's even more interesting is that inspite of this core difference C# has borrowed features for its 2.0 release from dynamic languages with more on the way for 3.0.
Iterators are a well known design pattern for traversing collections. They are a good way to loosley couple collections from the actual iterating process. So one can have multiple iterators, iterating collections in different ways. Iterators are sprinkled all throughout the Java Collection Framework and similarly C# has Enumerators having pretty much the same interface. Creating these iterators/enumerators invovles creating classes which keep track of state. Thats pretty much all they do... some logic to know where you are and to provide the next element. C# 2.0 introduced the yield keyword which generates iterators dynamically that manage the state automatically. Ruby and Python both have it. Here's a simple ex...
class MyCollection {
private int[] myElements;
public IEnumerator GetEnumerator() {
foreach ( int i in this.myElements ) {
yield i;
}
}
}
Thats it. No creating a class which implements IEnumerator. It's all generated automatically dynamically. Huge productivity booster. Complements the foreach functionality nicely.
C# 3.0 which is a ways off from being released has a lot more in store. Probably the biggest annoucement was about LINQ (Language Integrated Query) which introduces new syntax within the language to work with datasets - collections, relational databases (DLINQ) and xml (XLINQ). This major feature brings with it many smaller ones which again seem to borrow a lot from dynamic languages...
Probably, the most surprising one is Implicit Typing. You can do things like
var i = 1;
var s = "string";
var d = 1.11;
var numbers = new int[] { 0, 1, 2 };
Surprising since it goes against what C#/Java type languages have been known for. But this is a feature needed to make LINQ work since you don't know the final type which will be the result of queries.
Another interesting one is Extension Methods. Ruby has this feature. You can add new methods to existing types without being part of any type hierarchy. You can even add methods to sealed classes like String. As an example, think about a method that checks if a string is a palindrome. Normally, one would create something like a Palindrome class which has a static isPalindrome method which takes a string... Palindrome.IsPalindrome( text ). Pretty inelegant. With extension methods, you can define a method like this
static boolean IsPalindrome( this string text ) { ... }
And call it like this
string text = "civic";
bool palindrome = text.IsPalindrome();
It's a pretty cool feature which, again, is needed to add some LINQ funtionality. But I think there is potential for abuse here and without proper documentation it might cause some confusion.
Lambda Expressions have been available in many languages for a while. C# is finally getting this feature in 3.0. These expressions are popular when filtering datasets and as you can imagine would be an integral part of LINQ. Here's a simple example...
List<int> numbers = new List<int>;
numbers.add( 0 );
numbers.add( 1 );
numbers.add( 2 );
numbers.add( 3 );
numbers.add( 4 );
List<int> evenNumbers = numbers.FindAll( i => ( i % 2 ) == 0 );
So FindAll() will filter the list based on the lambda expression. Syntax seems a bit strange.
A final interesting feature was Anonymous Types. Languages like Python and Ruby have this concept of a tuple which can hold multiple values. So you can have methods returning multiple values. In C# or Java this isn't possible. What many end up doing is to return an array with 2 or more values. Pretty inelegant. Or you have to actually define a type which just holds those values and return that. It's a hassle. With anonymous types you can again dynamically create types without (as the name would suggest) giving it a name...
var person = new { Name = "C Sharp", Age = 4 };
Console.WriteLine( "Name: {0}, Age: {1}", person.Name, person.Age );
Again, as you can guess this is another needed feature for LINQ.
I haven't mentioned much about LINQ itself since I've only read a little about it and seen a video by the man. So dunno a lot of details myself. What would be interesting is to see all the IL that is generated to make all these abstractions work.
Anyway, it's something to look out for. Maybe Java will also be including some data related features for their Dolphin release.
What's even more interesting is that inspite of this core difference C# has borrowed features for its 2.0 release from dynamic languages with more on the way for 3.0.
Iterators are a well known design pattern for traversing collections. They are a good way to loosley couple collections from the actual iterating process. So one can have multiple iterators, iterating collections in different ways. Iterators are sprinkled all throughout the Java Collection Framework and similarly C# has Enumerators having pretty much the same interface. Creating these iterators/enumerators invovles creating classes which keep track of state. Thats pretty much all they do... some logic to know where you are and to provide the next element. C# 2.0 introduced the yield keyword which generates iterators dynamically that manage the state automatically. Ruby and Python both have it. Here's a simple ex...
class MyCollection {
private int[] myElements;
public IEnumerator GetEnumerator() {
foreach ( int i in this.myElements ) {
yield i;
}
}
}
Thats it. No creating a class which implements IEnumerator. It's all generated automatically dynamically. Huge productivity booster. Complements the foreach functionality nicely.
C# 3.0 which is a ways off from being released has a lot more in store. Probably the biggest annoucement was about LINQ (Language Integrated Query) which introduces new syntax within the language to work with datasets - collections, relational databases (DLINQ) and xml (XLINQ). This major feature brings with it many smaller ones which again seem to borrow a lot from dynamic languages...
Probably, the most surprising one is Implicit Typing. You can do things like
var i = 1;
var s = "string";
var d = 1.11;
var numbers = new int[] { 0, 1, 2 };
Surprising since it goes against what C#/Java type languages have been known for. But this is a feature needed to make LINQ work since you don't know the final type which will be the result of queries.
Another interesting one is Extension Methods. Ruby has this feature. You can add new methods to existing types without being part of any type hierarchy. You can even add methods to sealed classes like String. As an example, think about a method that checks if a string is a palindrome. Normally, one would create something like a Palindrome class which has a static isPalindrome method which takes a string... Palindrome.IsPalindrome( text ). Pretty inelegant. With extension methods, you can define a method like this
static boolean IsPalindrome( this string text ) { ... }
And call it like this
string text = "civic";
bool palindrome = text.IsPalindrome();
It's a pretty cool feature which, again, is needed to add some LINQ funtionality. But I think there is potential for abuse here and without proper documentation it might cause some confusion.
Lambda Expressions have been available in many languages for a while. C# is finally getting this feature in 3.0. These expressions are popular when filtering datasets and as you can imagine would be an integral part of LINQ. Here's a simple example...
List<int> numbers = new List<int>;
numbers.add( 0 );
numbers.add( 1 );
numbers.add( 2 );
numbers.add( 3 );
numbers.add( 4 );
List<int> evenNumbers = numbers.FindAll( i => ( i % 2 ) == 0 );
So FindAll() will filter the list based on the lambda expression. Syntax seems a bit strange.
A final interesting feature was Anonymous Types. Languages like Python and Ruby have this concept of a tuple which can hold multiple values. So you can have methods returning multiple values. In C# or Java this isn't possible. What many end up doing is to return an array with 2 or more values. Pretty inelegant. Or you have to actually define a type which just holds those values and return that. It's a hassle. With anonymous types you can again dynamically create types without (as the name would suggest) giving it a name...
var person = new { Name = "C Sharp", Age = 4 };
Console.WriteLine( "Name: {0}, Age: {1}", person.Name, person.Age );
Again, as you can guess this is another needed feature for LINQ.
I haven't mentioned much about LINQ itself since I've only read a little about it and seen a video by the man. So dunno a lot of details myself. What would be interesting is to see all the IL that is generated to make all these abstractions work.
Anyway, it's something to look out for. Maybe Java will also be including some data related features for their Dolphin release.
Monday, March 27, 2006
Bombay
A podcast on the city I call home - Bombay, by Suketu Mehta Author, "Maximum City".
http://www.itconversations.com/shows/detail769.html
http://www.itconversations.com/shows/detail769.html
Wednesday, March 15, 2006
Java tip - Get the method call hierarchy
So here's a small tip I learnt recently which I find useful at times. Quite often it is a pain to debug an application. You just want to have a trace from where a particular method was called.
Simply use this
<code>
MyClass() {
myMethod() {
new RuntimeException().printStackTrace();
}
}
</code>
Now whenever myMethod is called; a stack trace will be printed. So you can easily get the hierarchy of the calls made to reach that execution point. Notice that the Exception was not thrown; hence no handling is needed.
Simply use this
<code>
MyClass() {
myMethod() {
new RuntimeException().printStackTrace();
}
}
</code>
Now whenever myMethod is called; a stack trace will be printed. So you can easily get the hierarchy of the calls made to reach that execution point. Notice that the Exception was not thrown; hence no handling is needed.
Monday, March 06, 2006
JUnit Revelation
I stumbled upon this post by Martin Fowler via another blog. It's a bit dated (2004), but interesting. It reveals that JUnit creates a new instance of TestCase for each test method defined within it. The primary reason for doing this is so that tests are isolated from each other. That is tests don't share the state of objects. So they can be run in any order needed.
JUnit has two special methods setUp and tearDown (these I guess can be called anything in the newer version using Annotations) that are automatically run (if defined) before each test method. I wondered how they did this. Now it makes sense.
JUnit has two special methods setUp and tearDown (these I guess can be called anything in the newer version using Annotations) that are automatically run (if defined) before each test method. I wondered how they did this. Now it makes sense.
Subscribe to:
Posts (Atom)