Hamza Khalid

Stay Agile, Expect Change

November 2006 - Posts

Server.CreateObject() in C# and VB

consider the following code written in C# that utilizes the classic ASP CDONTS Class to send email

Object obj=new Object();
obj=Server.CreateObject("CDONTS.NewMail");
obj.To ="
abc@xyz.com" ;
obj.From ="
abc@xyz.com" ;
obj.Subject="Test" ;
obj.Body="Test email message using CDONTS ";
obj.Send();


The above code will not compile in c# since type of Obj is not known. we need to reference
the Com component of CDONTS class and then explicitly type cast Obj. So instead of referencing, i found a quick solution that solved my problem and here it is.
 i just rewrote the above code in VB.NET


Dim obj as Object
obj=Server.CreateObject("CDONTS.NewMail")
obj.To ="
abc@xyz.com
obj.From ="
abc@xyz.com
obj.Subject="Test" 
obj.Body="Test email message using CDONTS "
obj.Send()  

and it worked like a charm.. without any Exceptions?? Strange for a C# geek. Thanks to VB.net's loose coupling.

Share this post:                                       
Posted: Nov 20 2006, 03:25 PM by hamza khalid | with no comments
Filed under:
How to Shoot Yourself in the Foot in Any Programming Language

The proliferation of modern programming languages (all of which seem to have stolen countless features from one another) sometimes makes it difficult to remember what language you’re currently using. This guide is offered as a public service to help programmers who find themselves in such dilemmas.

C
You shoot yourself in the foot.

C++
You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”

JAVA
After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes and methods of those classes needed, you’ve forgotten what the hell you’re doing.

Ruby
Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it.

PHP
You shoot yourself in the foot with a gun made with pieces from 300 other guns.

ASP.NET
Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.

SQL
SELECT @ammo:=bullet FROM gun WHERE trigger = ‘PULLED’;
INSERT INTO leg (foot) VALUES (@ammo);

Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you. (via Andy)

Javascript
YOu’ve perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.

CSS
You shoot your right foot with one hand, then switch hands to shoot your left foot but you realize that the gun has turned into a banana.

FORTRAN
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception-handling ability.

Modula2
After realizing that you can’t actually accomplish anything in this language, you shoot yourself in the head.

COBOL
Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER. on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be retied.

LISP
You shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds ….

BASIC
Shoot yourself in the foot with a water pistol. On big systems, continue until entire lower body is waterlogged.

FORTH
Foot in yourself shoot.

APL
You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.

Pascal
The compiler won’t let you shoot yourself in the foot.

SNOBOL
If you succeed, shoot yourself in the left foot.
If you fail, shoot yourself in the right foot.

Concurrent Euclid
You shoot yourself in somebody else’s foot.

HyperTalk
Put the first bullet of the gun into the foot of the left leg of you.
Answer the result.

Motif
You spend days writing a UIL description of your foot, the trajectory, the bullet, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.

Unix
% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm: .o: No such file or directory
% ls
%

Paradox
Not only can you shoot yourself in the foot, your users can too.

Revelation
You’ll be able to shoot yourself in the foot just as soon as you figure out what all these bullets are for.

Visual Basic
You’ll shoot yourself in the foot, but you’ll have so much fun doing it that you won’t care.

Prolog
You tell your program you want to be shot in the foot. The program figures out how to do it, but the syntax doesn’t allow it to explain.

Ada
After correctly packaging your foot, you attempt to concurrently load the gun, pull the trigger, scream and shoot yourself in the foot. When you try, however, you discover that your foot is of the wrong type.

Assembly
You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot. After that’s done, you pull the trigger, the gun beeps several times, then crashes.

370 JCL
You send your foot down to MIS with a 4000-page document explaining how you want it to be shot. Three years later, your foot comes back deep-fried.

Python
You try to shoot yourself in the foot but you just keep hitting the whitespace between your toes. (via Marco Azaro)

.Net
Microsoft shoots you in the foot.

Microsoft accidentally shoots you in foot. Promises service pack to reattach your foot sometime in the next year. 18 months later you get service pack that removes your colon along with the rest of your foot.

Java -

Build a well formed class with a well designed shootmyselfinthefoot method, start your program and hold your foot still for 40 minutes while your app loads.

For JAVA, I think it should have been:

You waste 2 hours trying to implement a generic foot shooting framework, solving classpath issues, profiling the bullet shooting algo (because at first the bullet is too slow and bounce off the foot), adding performance tweaks and reducing the memory usage (the gun is too heavy), adding try {shooting} catch(whatever could go wrong) to make sure you find out why it doesn’t work only to ‘finally’ figure out that you can risk moving your foot for an indefinite amount of time because the jvm is too slow to boot and shoot, and that the bullet pauses in mid air because of a garbage collection…

AJAX:

The gun makes an XMLHTTPRequest for the bullet which arrives some unspecified time later, killing a bird.

 

CSS:
You try to shoot your left foot, you miss 2 pixels. You try to shoot your right foot, you miss 1 pixel. Finally you try to shoot your head, you miss 10 pixels. Then you realize you’re using MS IE gun.

EJB

- Define a Foot interface
- Define a FootHome
- Define a FootImpl
- Define a Bullet interface
- Define a BulletHome
- Define a BulletImpl
- Define a Gun interface
- Define a GunHome
- Define a GunImpl
- Get the FootHome from the context
- Catch NamingException because you JNDI isn’t setup
- Get existing Foot from FootHome
- Fix error because you forgot to narrow the instance
- Create new Gun
- Be shocked that it actually worked successfully
- Create new Bullet instance
- gun.shoot(bullet, foot);
- Catch TransactionRolledBackException because your isolation level was incorrect
- rm -rf *.java *.class

Python:

gun.shoot(me.foot) works once you tell Python that you have a gun and a body, but you keep aiming at the whitespace between your toes because you never used any in Perl.


Hibernate / NHibernate
And in the last but not least  For hibernate users
You create Entities for Gun, Bullet and Foot and then create there Gun.hbm.xml, Bullet.hbm.xm and Foot.hbm.xml Mapping Files . and then..

Foot foot =new Foot();
Gun gun =new Gun();
gun.Bullets.Add(10);

gun.Fire(foot);

When you run it, gun drops a bullet very slowly, and nothing happens to your foot ???
then you suddenly figure out in hibernate mapping (Lazy=’true’)


#crossposted from
http://www.fullduplex.org/humor/2006/10/how-to-shoot-yourself-in-the-foot-in-any-programming-language/

Share this post:                                       
Posted: Nov 20 2006, 03:20 PM by hamza khalid | with 2 comment(s)
Filed under:
3-Tier, 3-Layer, MVC: a Trio of Famous Trios

Most of the people think that 3 Tier architecture, three- Layer architecture and MVC . all are same. i found a very nice article on msdn that discusses these three terminologies and their differences.

http://blogs.msdn.com/diegumzone/archive/2006/10/09/3_2D00_Tier_2C00_-3_2D00_Layer_2C00_-MVC_3A00_-a-Trio-of-Famous-Trios.aspx

by the way what do you people think?

Share this post: