Emailid
Password
         
  
    Forgot password

New user Sign Up
 

Dissimilarities between Other Implementations and C# Generics

       Current Rating:  80%                                                     Total Members Rated:  1
                                                                     Send To Friend

  

Dissimilarities between Other Implementations and C# Generics

 

 

1. Sun Microsystems® has suggested the addition of generics in the next version of the Java language, code named "Tiger". Sun has chosen an implementation that does not require modifying the Java Virtual Machine. As such, Sun is faced with implementing generics on an unmodified virtual machine.

 

2. C++ templates cannot define constraints. C++ templates can only define constraints implicitly by simply using a member that might or might not belong to the type parameter. If the member does exist in the type parameter that is eventually passed to the generic class, the program will work properly. If the member does not exist in the type parameter, the program will fail and a cryptic error message will likely be returned. Because C# generics can declare constraints and are strongly typed, these potential errors do not exist.

 

3. There is noteworthy difference between C++ templates and C# generics. Where C# generics are compiled into IL, causing specialization to occur intelligently at runtime for each value type and once only for reference types, C++ templates are essentially template code expansion macros that generate a specialized type for each type parameter supplied to a. Therefore, when the C++ compiler encounters a template, such as a Stack of integers, it expands the template code into a Stack class that contains integers internally as its native type. Regardless of whether the type parameter is a value or reference type, unless the linker is specifically designed to reduce code bloat, the C++ compiler creates a specialized class each time, resulting in a significant increase in code bloat over C# generics.

 

 4. The planned Java implementation uses similar syntax to templates in C++ and generics in C#, including type parameters and constraints. However, because it treats value types differently than reference types, the unmodified Java Virtual Machine will not be able to support generics for value types. As such, generics in Java will gain no execution efficiency. Indeed, the Java compiler will inject automatic downcasts from the specified constraint, if one is declared, or the base Object type, if a constraint is not declared, whenever it needs to return data. Furthermore, the Java compiler will generate a single specialized type at compile-time that it will then use to instantiate any constructed type. Finally, because the Java Virtual Machine will not support generics natively, there will be no way to ascertain the type parameter for an instance of a generic type at runtime and other uses of reflection is strictly inadequate.

 

 

Conclusion

 

While some languages may implement this feature earlier than others, all of Microsoft's other three languages will contain support for generics. It is Microsoft's intent to support the consumption and creation of generic types in Visual J#TM, Visual C++, and Visual Basic. Meanwhile, the C# team is laying the groundwork for multiple language support by incorporating facilities in the underlying runtime for generics. Microsoft is working closely with third party language partners to ensure the creation and consumption of generics across .NET-based languages. And that is a fact.

 

Happy coding!


                           Rate This Article:   

Author is Offline
  Author: Konjanja Takeuchi
       


Comments Posted
Label
Subject Author Status Date

 

Post Comment

Related Articles
N-Tier in ASP.NET or other .NET apps
Make your web site ‘perfect and Search Engine Friendly for Google and Yahoo
On making your content neat and tidy
Web site templates and its uses
Web Traffic and Higher Page Rank



Home | About Us | Site Map | Privacy Policy