Monday, October 25, 2004

The Discussion continues...

This is what Khurram bhai had to say in my mails response...

hello Hammad,
Nice to hear your comments, let me assure you first that I am not
against .NET (I am MVP yaar :)) and just trying to compare the two
technologies objectively.
In my opinion there are few things Java is better and several other
things that can handle by .NET more nicely. e.g if we need Windows
only development with platform integration features etc.

Now let me answer your comments step by step ,

> 1- Language Design:
I agree with you, I think both Java and C# are equally capable
languages with beautiful syntax. (much better then VB that why I
didn't comments on language features )
But there is important diff. in Java and .NET, every function is
virtual in Java by default, but in .NET we have to explicitly mark the
function as virtual, although its increase the flexibility of the
system but I have to find its usage yet. it would be better in my
opinion if every thing is virtual by default in C# as well.

2- Persistence Frameworks:
I tried NHibernate, but it is in pre-alpha stage so it is not an
option to use in our production env. projects.

Let me explain my point of view regarding OR tools w.r.t your blog.

Q.1
How effective is O/R mapping when you don't look at single objects but
rather need to fetch sets of data (assume the price history for a
stock) based on certain criteria such as a certain time period?

I think OR mapping is useful in single object CRUD(Create, Read ,
Update, Delete) operation or when we have to manipulate the data
(usage of object operations), for reporting purpose or only displaying
data it does not make much sense, but if we are using any Object
Oriented Language like java / C# we have to make objects for data
manipulation in any case and for that OR tools are logical choice.

For Bulk Amount data access OR Tools should not be use. (Please see
also EJB Bulk Data Access pattern)

Q.2
How do you integrate with transactions and how do you assure that you
are in control of the order and locking hints of insert/update
operations to minimize deadlocks/lock contention?
In my JDO / Hibernate experience, OR tools use transaction of database
engine through JDBC or ADO.NET wrappers so it usually has not impact
on transaction handling. (just like simple JDBC or ADO.NET
applications)

Q.3 c)
How tight is the coupling between your relational model and your
objects? Can you change the table layout and indexing of the data
store flexibly as your data volumes change?

--- Most of the JDO and OR tools based on JDBC or ADO.NET
capabilities, table layout or indexing chg usually don't impact much
on simple JDBC/ADO.NET application so that is the case of OR Tools

Q.4
What is the net efficiency gain that O/R mapping gives you in
development? Is it actually making developers more productive in
creating *and maintaining* your software or is it merely "more
elegant"?

In simple operation I found OR tools are more efficient , since they
are using Cache mechanism of queries and results. Also JDO like tools
improve the developer productivity a lot since in most of our business
application CRUD operations contains around 30 to 40% of middle tier
development time. by using transparent persistence layers we can
reduce that time and guarantee the bug free data access layers
development.

In my experience I found JDO like tools much better then hand coded
data access layers , since it is very manual and repetitive tasks.
Also there are middle level between pure OR mappers and hand coded
database logic, you should check the
www.ibatis.com , it provide nice OR tools and must have tool for every
ADO.NET developer.


> 3- Custom Layout:
I was talking about the Winforms and not ASP.NET forms. I don't like
the idea of base Form which have layout functionality, instead design
wise I am more inclined separate Layout managers like in Java.
currently they are not supported.

4- As a side note , I want to see Dynamic proxy equivalent in C# as
well, it is must for any serious AOP programming, Java Dynamic proxy
implementation is cool. (I know there are independent dynamic proxies
exist for .NET , but they are based on remoting framework and I have
doubts in its performance.)

Just my quick thoughts :)

Regards,
Khurram Shakir
MVP (Visual C#)

Sunday, October 24, 2004

Comparing .NET with Java 1.5

In response of my .NET vs Java 1.5 mail, our guru MVP Khurram Shakir made a few interesting points. This blog entry is my response to his mail ......


I also have a few points to make, please correct me if am wrong.

This discussion i belive is very important for all of us and this is not about a war between Java and .NET ... its just a comparison between technologies and tools available for us to use. We as programmers/ s/w engineers /(any thing else you can think of) use these technologies/tools as and when they are useful and "appropriate" for us. So in some sense we ought to be technology/tool independent to be more effective and useful to our organizations.

Now getting back to the discussion:

1- Language Design:
I personally believe Language design is one of the important considerations. If that wont be the case people wont love/like a particular language over the other. I mean alghough VB is a great tool, but I never really liked it as a programming language. (what do you say?). In this context I believe C# is a beautiful language, if not better then atleast as good as Java.

2- Persistence Frameworks:
NHibernate is being developed and it is in its Alpha release at the moment. I am my self unsure about ObjectSpaces. So this thing might be lacking with .NET, I agree. But, tell me what is the cost that we have to pay for these Object-Relational Mappings, you bet, its performance. Also from design point of view i have asked a lot gurus about this Object Relational Mappings, these ideas sound good when you have a stable data model and developing a small to mid-size application. Believe me for enterprise scale financial/ mission critical applications we simply are not looking for objects mapping table and helper classes for create, update, and retrieve functions. Sometimes when I have to initiate a business process flow (lets say by performing a transaction), the data that I require may not typically be mapped using Obect Relational mapping, because what I am trying to abstract is a process and it has its own state and its db status corresponds to and spans across multiple tables. I had this interesting reply from Clemens Vasters when i asked him about the same.

3- Custom Layout:
I completely agree with Khurram bhai that there is no such feature available for customizing layout. But with ASP.NET now we have Master Pages and themes that takes care of all such requirements, but still WinForms API is still lacking it.But as a work around either we can write generic event handlers (as in interceptors) that can dictate the look and feel of our forms. For even better, we can implement base class Forms with specific UI features (themes/layouts) and inherit our froms from them (i.e. Visual Inheritance)

4- UI/XML Mapping:
I will again agree with Khurram bhai that UI/XML mapping is som thing that is missing. We all will have to wait for XAML to get real.

I dont have experience of working with GDI+/ Java Imaging APIs so i cant comment on that.And for tools I believe Whidbey with its featurs like Team System, Visio Integration, Data base integration (drag drop features for SPs/ tables etc), Source Safe etc and all with its compoenent orientation stuff ... is a very powerful IDE. Havent seen eclipse 3.0 and JBuilder 2005 as yet so no comparison with them.

Thats all I had to say...

best regards,
Hammad.Rajjoub.
http://dotnetwizards.blogspot.com


khurram shakir wrote:
My few thoughs about Java 5.0 !!!
In general I am impressed with the features and quality of Java 5.0 !

Java 5.0 is now in production version, and .NET 2.0 will take at least
sixth month more to become production ready.

In general I am not much interested in language features of any of
these technologies, instead interested in the services they are
providing.

I found Java APIs are quite nicely design when compare to .NET APIs,
especially I am impressed with the availability of Java Persistence
frameworks like (JDO, OJB, Hibernate), The official counter part for
these frameworks are still missing in .NET (ObjectSpaces will ship in
2006, if it ever ship !).

Also for developing extensible UI applications, I found Swing APIs are
more flexible and feature rich(Although quite complex), e.g.
- WinForms has no official Custom Layout support (just one event for
which we have to do all layout stuff) and UI designing is heavily
dependent on Visual Studio IDE.
- Developing UI from XML based schema language is missing in .NET (may
be suppored in 2006, when XAML become part of Longhorn). Swing already
has Long term Persistance support (Xml based UI)

(I know there might some performance problems in Swing but I think
situation is change a lot in JDK 1.4 and now in Tiger)


Design wise I found Java 2D and Java Imaging APIs are more creative then GDI +.
There are few useful utility clases are still missing in .NET, e.g.
there is no BigInteger Counter part I found in .NET ( I need it when
developing RSA algo for 100 digits Prime numbers, for example )

By the way I also found the IDE Space in Java is much more advance
then compare to Visual Studio.NET (even VStudio 2005), JBuilder X/2005
and Eclipse 3.0 are far more feature rich then Widbly in their current
state.
Hoping things are changing rapidly in .NET Front as well.

Regards,
- Khurram Shakir
Microsot Most Valued Professioanl (MVP - Visual C#)

Wednesday, October 20, 2004

Iterators in C# 2.0

Iterators are some thing pretty cool, they get you to use foreach withouth explicitly implementing IEnumerator/IEnumerable.

Some facts about Iterators: (source MSDN)

An iterator is a section of code that returns an ordered sequence of values.
An iterator can be used as the body of a method, an operator, or a get accessor.
The interator code uses the yield return statement to return each element in turn.
Using iterators, it is no longer necessary to implement the interfaces System.Collections.IEnumerable and System.Collections.IEnumerator when creating a collection class that supports foreach. The compiler does this work for you.
The return type of an iterator must be System.Collections.IEnumerable, System.Collections.IEnumerator or one of the generic iterator interfaces.
Iterators can be named as well (as i have done in my example).


Yeild is a new key-word in C# 2.0 following are a few important facts about it: (source MSDN)

The yield statement can only appear inside an iterator block, which might be used as a body of a method, operator, or accessor. The body of such methods, operators, or accessors is controlled by the following restrictions:

Unsafe blocks are not allowed.
Parameters to the method, operator, or accessor cannot be ref (C# Programmer's Reference) or out (C# Programmer's Reference).
A yield statement cannot appear in an anonymous method.
A yield statement cannot appear in a finally block. When used with expression, a yield statement cannot appear in a catch block or in a tryblock that has one or more catch clauses.

Now its time to see the code:



#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace HelloIterators
{
#region Stack Class
///
/// My Simple Stack Class using Generics
///

/// Type Parameter
public class Stack
{
///
/// Top of the Stack
///

private int top;

///
/// Generic Collection to hold stack contents
///

private System.Collections.Generic.Collection data;


///
/// Stack Constructor
///

///
public Stack(System.Collections.Generic.Collection t)
{
data = t;
top = 0;
}

///
/// Default Constructor
///

public Stack()
{
data = new System.Collections.Generic.Collection();
top = 0;
}

///
/// Push
///

/// Item/Content to be pushed
public void push(T item)
{
data.Insert(top, item);
top++;
}

///
/// POP
///

/// Content / Item on stack top
public T pop()
{
if (top > 0)
{
top = top - 1;
return data[top];
}
else
{
throw new IndexOutOfRangeException(" Stack is already empty");
}
}

///
/// Iterator method
///

/// IEnumerable
public IEnumerable getAllItems()
{
for(int index=top-1; index>=0;index--)
{
yield return data[index];
}
}

}
#endregion
class Program
{
static void Main(string[] args)
{
// StackClassObject--See char as type paramter(this reminds me of
// C++ :))
Stack myStack = new Stack();

myStack.push('H');
myStack.push('A');
myStack.push('M');

// USING NAMED ITERATOR.
foreach (char ch in myStack.getAllItems())
{
Console.WriteLine(ch.ToString());
}

Console.ReadLine();
}
}
}

Monday, October 18, 2004

C# Generics

I recently installed Visual Studio Whidbey Beta 1 (which i recieved through MS Community Starter KIT) on my machine. It is kind of a cool ide with lots of enhancements like Refactoring and Expansions. I wrote my first program implementing the concepts of Generics. Generics are a new feature of .Net Framework 2.0. With Generics we can defer type specification of one or more type until the class is declared and instantiated by the client code. This effectively translates into Templates Concept of C++.

I implemented a generic stack class and the code goes like this:

public class Stack
{
///
/// Top of the Stack
///

private int top;

///
/// Generic Collection to hold stack contents
///

private System.Collections.Generic.Collection data;


///
/// Stack Constructor
///

///
public Stack(System.Collections.Generic.Collection t)
{
data = t;
top = 0;
}

///
/// Default Constructor
///

public Stack()
{
data = new System.Collections.Generic.Collection();
top = 0;
}

///
/// Push
///

/// Item/Content to be pushed
public void push(T item)
{
data.Insert(top,item);
top++;
}

///
/// POP
///

/// Content / Item on stack top
public T pop()
{
if (top > 0)
{
top = top - 1;
return data[top];
}
else
{
throw new IndexOutOfRangeException(" Stack is already empty");
}
}

}
#endregion

#region Testing Stack Class
///
/// Testing Stack Class
///

class Program
{
static void Main(string[] args)
{
// Stack Class Object -- See char as type paramter..
//(this reminds me of C++ :))
Stack myStack = new Stack();

myStack.push('H');
myStack.push('A');
myStack.push('M');

Console.WriteLine(myStack.pop().ToString());
Console.WriteLine(myStack.pop().ToString());
Console.WriteLine(myStack.pop().ToString());

// Index Out of Bound Exception
Console.WriteLine(myStack.pop().ToString());

Console.ReadLine();
}
}
#endregion
}


This code wont get me any accoldate, that I know :). But it still proves the point that Generics are simple and very useful in terms of re-usable data structures.

Portable.NET

Portable.NET is a free implementation of .NET; it is a complete suite of compilers, libraries and tools for running and developing .NET applications.

Download it from here: http://getdotgnu.com/downloads

Some cool snapshots:

Windows XP theme


MDI Text Editor



Java 1.5 vs C#

J2SE 5.0 specs are out. And you know what Java 1.5 has tried to catch up with C#.
Java 2 Platform Standard Edition (J2SE) 5.0 ("Tiger") is the next major revision to the Java platform and language; it is currently slated to contain 15 component JSRs with nearly 100 other significant updates developed through the Java Community Process (JCP).

According to this slash dot post, following is a summarized list of enhancements:

1- Generics (C# 2.0 already supports this)
2- Enhanced For-Loop (the foreach construct in C# 1.0, duh!)
3- Autoboxing/Unboxing (C# 1.0 already has this, everything is an object, even the primitives - not really, but they do it so well...)
4- Typesafe Enums (again C# 1.0 already implemented this, but I think they've added a little bit more twist in Java, that its actually a better implementation)
5- Varargs (C# 1.0's params construct, ellipsis construct in C++)
Static Import (I don't know if C# 1.0 has this, or C#2.0, but C# has a construct for aliasing your imports - which is way cooler. Static Import, actually promotes bad coding habits IMHO)
6- Metadata/Annotations (this is C# 1.0's Attributes, Sun's upturned noses just gave it a fancier name - also, C#'s implementation is better and more intuitive)

Monday, October 11, 2004

A talk on SOA at ProQuest 2004

Finally I got the chance to speak about SOA. It was a guest speaker session at ProQuest (A National Level Quiz and Programming Competition organized by ACM-CSKU ). My talk was sponsored by Phillips Pakistan (sounds good!). Agenda for this talk included a comparison of Service Oriented paradigm with other paradigms like Procedural and Object Oriented Paradigm. Then I talked about how Service Orientation fits into todays world and also discussed the tenets of SOA. I also discussed the relationship between Web Services and Service Oriented Architecture. Overall it was pretty good to talk about it!

Distributed Computing and XML Web Services

I was invited at MAJU to deliver a presentation to final year students. There I talked about "Distributed Computing", and how it was being done using technologies like CORBA, DCOM , RMI etc. I told them why do we need a paradigm for distributed computing that ensures loose coupling and is based on standards. I told them about XML Web Services and its underlying architecture. I also discussed find,bind and execute feature of service orientation. Students liked the stuff pretty much :)

Design Patterns and Application Frameworks

This event at KU went pretty fine. I told the audience about importance of re-usability, patterns and best practices. My discussion revolved around MVC framework and its facets Audience at KU was interactive as usual.

Thursday, October 07, 2004

Learning the lesson !

When I was speaking on "Design Patterns and Application Frameworks" at Dept Of Computer Science,Karachi University, couple of weeks back I learned a big thing. The big thing was
"Keep the questions for the end !"

I usually try to make sessions more interactive and dont do it the traditional teacher/student way. Rather I prefer to have a live audience that respond to pulses being generated. However having said that, too much of questions ( or may be discussion) during the talk can lead to time slip, lost focus, and irritated audience.

So whenever you make a presentation make sure that you either keep your questions for the end or keep numbers/durations of questions limtied during the talk.

Thats it for now!

Events Update!

It has been very tough couple of weeks, both in terms of work loads and emotional stress. However I was able to find some time to speak on .Net on a couple occassions.

Following is the summary for recently held events:

1. I hosted a session on Design Patterns and Application Frameworks at Karachi University on Saturday, 18th September, 2004. (I will update the event details in my next blog entry)
2. I was invited by Mr. Viqar of Microsoft Pakistan to deliver a presentation at MAJU last week (i.e. Saturday,2nd October, 2004) (I will update the event details in my next blog entry)
3. I was invited as guest speaker at ProQuest 2004 to speak on "Service Oriented Architecture (SOA)". (I will update the event details in my next blog entry)

Events to come:

1. I will be the guest speaker at AMI (Iqra University), Karachi Campus on coming Saturday (i.e 9th October 2004). There I will be talking about ASP.Net programming Model.This will be our first event at AMI so, we will also be launching our INETA user group there as well.

stay tuned for more!