Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,902 members, 7,828,183 topics. Date: Wednesday, 15 May 2024 at 04:46 AM

Pthe Latest Rogamming Language[get Update Here] - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Pthe Latest Rogamming Language[get Update Here] (1109 Views)

(2) (3) (4)

(1) (Reply)

Pthe Latest Rogamming Language[get Update Here] by AGBAMA(m): 6:35pm On May 19, 2007
Visual Studio .NET -- The Latest Microsoft .NET Component- Developer Zone - National Instruments

Related Links - Products and Services
NI Measurement Studio Professional Edition - Products and Services - National Instruments

NI Measurement Studio Enterprise Edition - Products and Services - National Instruments

Microsoft's Latest Programming Language: Visual C#
32 ratings | 3.47 out of 5 | Print Document
Overview
Microsoft Visual C# .NET, a new programming language based on Microsoft .NET technology, claims faster and easier development that saves time and money. This article gives an introductory, practical look at programming in C#. To fully utilize the C# language capabilities for test and measurement, you need to have a good understanding of how this language interacts with the Microsoft .NET framework. With a thorough discussion of C# and the object-oriented approach, this article explores how Microsoft C# impacts Visual Studio programming and whether or not it's right for your test and measurement application development.



Table of Contents
The .NET Framework: Background Information
What is C#?
Object-Oriented Programming
Reliability and Optimization
Debugging and Data Types
Managed Code and Additional Features
Save Time Over Previous Visual Studio Versions
More Powerful and Safer Programming than Previous Visual Studio Versions
Potential Obstacles
Conclusion
The .NET Framework: Background Information

The .NET Framework, made up of the Common Language Runtime (CLR), the .NET Framework Class Library, .NET languages, and Visual Studio .NET, supports multiple languages, which allows for cross-platform applications. In order for this to work, a common element must exist through all .NET languages. The Common Language Specification (CLS) is an agreement that encompasses the rules, or specifications, of .NET languages. To be considered a .NET language, a language must comply with specifications set in the CLS agreement. Microsoft provides four CLS-compliant languages, including Visual Basic .NET, Visual C# .NET, Visual C++ with managed extensions, and Jscript. The goals of the CLR are:

Simplified application development
Multiple programming language support
Good performance and scalability
A safe and reliable execution environment
Simplified deployment

The CLR consists of an execution engine, a garbage collector, just-in-time (JIT) compiler, a security system, and the .NET Framework fundamentals.



All of the CLS-compliant -- or .NET -- languages, have managed code compilers that generate Microsoft Intermediate Language (MSIL). MSIL is machine-independent and can offer benefits including just-in-time compilation, metadata, and more. All .NET applications are constructed from Assemblies, a compiled (and versioned) collection of code and metadata that forms a functional unit. All Assemblies contain information stored in something called a Manifest, which contains the Assembly name, version, dependencies, associated files, and exported features for more informative versioning.

Another feature of Microsoft .NET technology that directly relates to C# is the .NET Framework Class Library. This library consists of more than 2,500 classes whose functionality you can access from all of the .NET languages. The library is made up of four main parts:

Base Class Library (networking, security, diagnostics, file I/O, and OS services)
Data and SML classes
Windows user interface
Web services and Web user interface

C# is a high-level language that hides much of the .NET framework details, while permitting access to system-level functions if the developer needs it. Because Microsoft created C# specifically for .NET, it inherently takes advantage of the .NET Framework features.
What is C#?


C# is an object-oriented language that enables programmers to develop applications with the power of C++ and the ease of Visual Basic. Microsoft built C# from the ground up with the .NET framework and Object Oriented Programming (OOP) in mind. However, C# expands OOP even beyond Visual C++ concepts. It is a strongly typed language in which everything is an object.

The core features of C# were derived from C-like languages. Therefore, if you have experience with C, C++, or Java, you will have a head start in C# development.
Object-Oriented Programming


C# extends the definition of a object-oriented language from the typical C++ definition. C# unifies the type system by defining every type in the language as an object. Whether using a struct, a class, or an array, the developer will use it as an object. Think of an object as a way to describe a relationship. For a real-world example, think of a ball. A ball has certain characteristics as well as behaviors. A ball has a color, shape, and size that can be thought of as characteristics or variables. A ball also has associated functions, or behaviors, such as bouncing and rolling. Similarly, in C# .NET, objects have characteristics and behaviors.

Classes, the foundation of OOP support in C#, also are important C# elements. Each C# program has at least one class. This class encapsulates data (or variables), and behaviors (or methods). Related classes are grouped into namespaces. This grouping enforces organization and clarity. Objects are combined into namespaces as well. For example, instead of listing include files at the beginning of all of your programs like so:

#include <stdio.h>
#include <string.h>

you would include the namespace to access the classes and objects in the namespace.

using System;
(The System class includes output methods)
Reliability and Optimization


Many users are skeptical about the new .NET technology and want to know how .NET technology is improving Windows stability and Visual Studio reliability. In the past, it was quite difficult to manage a Windows PC because of the complexity of the applications. The introduction of shared DLLs and the ability to overwrite DLLs increased this difficulty. In addition, unclean uninstallations and associated, shared files caused headaches in the removal and inclusion of applications. Many of these activities caused an unstable PC and potentially resulted in a reinstall of the operating system.

Microsoft addressed many of these reliability and stability issues with .NET technology. Applications no longer rely on the registry information, removing registry-related headaches. In the .NET Framework, applications are self-describing and allow developers to run different versions of a DLL on the same machine, side by side. In addition, rather than the operating system, the CLR executes languages that produce managed code. Because of this, the CLR can perform many safety checks such as memory management, garbage collection, and type safety.

This layer adds a level to the programming platform, and this higher abstraction brings more safety and security. This results in more consistency because all languages use a similar class library which in turn enables multiple language interoperability.
Debugging and Data Types


While you can get around some of the new debugging features, you should build executables using a Debug configuration. You can either use Just-in-Time (JIT) Debugging or Standard Debugging. With JIT debugging, you can build and run without entering the debugger. If there is an exception, you can view where it occurs. However, at this point you cannot add break-points or step through the code. To typically debug, you can use standard debugging. This option allows breakpoints, variable watching, and single stepping.

C# is a strongly typed language, which improves reliability over other languages. With untyped programming languages, such as VBScript and other scripting languages, you do not declare data types for variables. With this syntax, you can check for runtime errors but will not find compile time errors. C# has addressed this lack of compile-time checking. The term "strongly typed" means that every variable in C# has an associated data type. This pertains to variables, globals, and constants. This strong type indicates an error if certain conversions are declared. For example, in C++ certain type conversions truncate the data without alerting the developer. C# takes the safe approach and alerts the developer when it makes assignments between two variables of different types.

In addition to explicit declarations, C# (as in Java) specifies the exact size of an integer type. This differs from C and C++. C and C++ do not specify the size of the integer as they conform to the size associated with a particular machine. This inconsistency can lead to unreliable behavior.
Managed Code and Additional Features


C# managed code improves reliability in the .NET Framework. Managed code is code that targets .NET technology and contains certain extra information, called metadata, to describe itself. Both managed and unmanaged code can run in the .NET runtime. However, only managed code makes it possible for the runtime to guarantee proper functionality, including safe execution and interoperability. With managed code, comes managed data. The CLR offers certain additional features to assist with cleaner programming, such as memory allocation and deallocation, as well as garbage collection. Some .NET languages, including Visual Basic .NET and JScript .NET, use managed data by default, while others, C++ for instance, do not. Note that the CLR safety checks and manages data to provide safer development and more meaningful debugging messages.

C# introduces new functionality in structures, arrays, and more. C# includes all of the usual structures: if, while, for, and do loops. However, C# also includes break, continue, and goto statements and introduces a foreach structure that Visual Basic programmers are used to seeing. This loop is used for iterating through collections and is convenient when iterating through arrays. C# views arrays as a special type of collection. The foreachstructure iterates through arrays with a very concise syntax, without subscripts. For example, to iterate through this array in C#, you may do the following:

,
int [] evens = {2, 4, 6, 8, 10};
foreach (int even in evens)
{
Console.Write (“{0} “, even);
}

C# also adds functionality to the Switch statement with improvements over C and C++ by adding debugging features to catch common C and C++ style switch statements. Many times, a developer forgets the break statement and the program flows into the next case. A C/C++ compiler does not throw a compiler error, where as the C# compiler will catch the mistake and does throw a compiler error. C# has additional features to catch common mistakes and save time in the long run.
Save Time Over Previous Visual Studio Versions


So, how do all of these new features, frameworks, and improvements apply to the test, measurement, and automation industry? A few of the Microsoft .NET Framework components, such as server technology, do not directly affect the typical test and measurement developer, while others, such as the Visual Studio .NET environment, may change the existing Microsoft Visual Studio developer’s programming style.

As many of the features below help the test and measurement developer, you should note that C#, as well as the other .NET languages, is a general-purpose programming language. For test and measurement specific applications, add-in components, such as NI Measurement Studio, are recommended for more efficient development.

Shorter DevelopmentTime
Microsoft not only designed C# to take advantage of the .NET Framework, but also to decrease development time. To achieve this goal, Microsoft modeled it after Visual Basic. C# and Visual Basic .NET contain almost 90 percent identical feature sets.

Simpler Deployment
One time-saving feature of C# is how applications are deployed using the language. The CLR causes applications to become an assembly rather than an executable (exe) or DLL. This assembly is self-describing and contains all the information, which is typically stored in the registry, in a single place to ensure that the code and its description information do not lose conformity. These assemblies use versioning so you can enhance your applications while maintaining older versions. Another benefit with versioning is that you can execute both versions simultaneously without interfering with one another.

Less Code Writing
In addition to the Visual Basic-like methodology, C# presents another time-saving feature. C# is an attribute-based programming language. First introduced in Microsoft Transaction Server, an attribute-based language implements complex tasks such as distributed transaction. The developer simply declares general requirements. The benefit is that these attributes implement the task for the developer -- attribute-based programming eases much of the complexity and actually creates code for the task. Without C#, the attributes are separate from the program source code. Thus, when the source code is modified, the attribute information may become out of sync with the code. With C#, and other .NET languages, attributes are part of the source code, eliminating incompatibility issues. In C#, when a developer compiles these attributes into intermediate language, the attributes become part of the metadata. The .NET Framework actually provides several attribute types, including the synchronization, serializable, and custom attributes for a flexible solution.

For building test and measurement applications, you can add NI Measurement Studio .NET-compatible components for integrating data acquisition, instruments, analysis and visualization more rapidly.
More Powerful and Safer Programming than Previous Visual Studio Versions


Multithreading
Because the .NET Framework provides extensive support for multiple thread programming, C# is a well-designed tool for these applications. You can program with multiple threads in many programming environments today, such as Visual C++, NI LabVIEW, NI LabWindows/CVI, and more. The idea of multithreading is the same in C# -- to allow multiple concurrent execution paths with multiple CPUs, to achieve parallel processing, and to gain greater efficiency on single processor machines. However, there are some drawbacks associated with multi-threading. For example, certain multiple threaded applications can result in more complex applications and race conditions. With C#, you use the system threading namespace for greater simplicity. The setup is organized in the thread class, which encapsulates a thread of extension. This organization helps with the complexity of the application as the information is contained in the core thread class. To address the race condition issue, you should serialize access to the shared data or synchronize with the C# join method. Again, these two options are available in the system-threading namespace.

Reuse Existing Applications -- Migrating from Microsoft Visual Studio 6.0
Visual Studio .NET provides an Upgrade Wizard to help you migrate your Visual Studio 6.0 applications to the new ADE. For example, when you first open a Visual Basic 6.0 project file (.vbp) in Visual Studio 7.0 (.NET), the Upgrade Wizard appears. Microsoft also provides a command-line tool for upgrading projects outside of the Visual Studio environment. The upgrading tools modify the code within your project to comply with Visual Basic .NET syntax and replace any forms and controls with Visual Basic .NET equivalents. Due to the differences between Visual Basic 6.0 and Visual Basic .NET, some things in your project may not map directly. In these cases, Microsoft provides an upgrade report to guide you through the modification of your application. For this reason, Microsoft offers white papers on how to prepare your legacy applications for upgrading. Keep in mind, upgrading to Visual Basic .NET may not benefit all Visual Basic 6.0 applications.


COM
It is possible for .NET components to interoperate with COM components. In other words, you can call a COM component from a .NET language and vice versa. To call a legacy COM component from a .NET language, you can use the Type Library Importer tool, which imports a type library for a COM component and generates a .NET proxy for calling that component. C# automatically calls this tool when you add a reference to a COM component. There are many similar benefits between COM and .NET technology, but many differences in the implementation of those technologies. For example, with COM, you must provide an elaborate infrastructure to implement the component. You must implement a class factory to create COM objects, implement the methods to dynamically check the interface, and manually implement the proper memory management. With C# the CLR automates these processes. You create the object with one command, check for an interface, and the garbage collector takes care of memory management for you, simplifying COM component creation.

Safer Programming
With safer programming and less run-time errors, you can save development time and decrease maintenance costs by shipping your application with fewer bugs. With the managed code in C#, the CLR can perform checks for type safety, memory overwrites, memory management and garbage collection. This results in a reduction of memory leaks and related issues. The CLR performing the memory management prevents your code from accessing memory directly, eliminating pointers, and greatly reducing crashes or other memory-overwrite behaviors. With the abstraction layer that the CLR adds, programming in C# is easier than programming at the lower level of the Win32 API or COM. The CLR also can enforce security, safeguarding against poor programming.

Type safety is another feature that promotes robust, safe programs. Microsoft incorporated several features to promote proper code execution in C#. For example, all dynamically allocated objects and arrays are initialized to zero. Although C# does not initialize local variables automatically, its compiler warns you. When you access an array, the software automatically checks the application's range. In contrast to C/C++, you can not overwrite unallocated memory in C# or create an invalid reference.

Potential Obstacles


There are a few features that may present some challenges for you if you are not properly prepared. Many of the features of C# will benefit your application develop only if you know how to use them properly. Other features, such as the conversion Wizard, work only in certain cases.
Unmanaged Code -- Overhead, Memory Management, Pointers
We have discussed the benefits and methodology to using managed code in C#. However, it is possible for a C# program to call unmanaged code, which can cause many of the issues C# and the .NET Framework were designed to fix. Any time you call legacy code without converting it to a managed environment, you are calling unmanaged code that runs directly on the operating system. If you transition from a managed to an unmanaged environment and back, there is associated overhead. However, if you don’t, you run the risk associated with calling unmanaged code. C# provides a utility to avoid overhead, which allows you to bypass the .NET memory management and receive memory directly. By doing this, you forfeit the benefits of using CLR’s memory management. To avoid this issue, you must port all of your applications to the .NET Framework, a potentially time consuming process that may or may not uphold your legacy application functionality.

Supporting Legacy Applications/COM
Earlier we discussed the Type Library Importer tool for calling COM components from C#. Because Microsoft now considers COM a legacy technology, it is not a native component in the .NET Framework. Thus, when calling COM components, Visual Studio simply creates a wrapper for the assembly. When using non-native components in any language, you see some performance declines. Calling legacy components in Visual Studio .NET is no different; occasionally, you run into performance penalties for COM interoperability. In addition, when COM objects use VARIANTs, they may translate the VARIANTs to a .NET object, making it is difficult identify which types are valid for specific properties and/or parameters.
Conclusion


If you are comfortable with the development environment that you currently use, I recommend continuing with that environment. However, if you are a Visual Basic 6.0 or Visual C++ 6.0 user, you soon will have to make a choice. I see C# as an attractive alternative to Visual C++, but only if you do not need to directly access the operating system memory or use unmanaged code. If you are a Visual Basic 6.0 developer, this may be an opportunity for you to explore your programming options. While C# was designed with the ease-of-use of Visual Basic in mind, the many syntactical changes may be challenging to learn. This may be a good time to evaluate a graphical development environment such as NI LabVIEW. However, if you’re ready to move forward to Microsoft’s latest version of Visual Studio, we suggest evaluating Visual Studio .NET and starting to develop some simple C# applications. You will find some challenges, but also some pleasant surprises.

For further investigation of Microsoft’s latest language, there are many resources available that you can find from Microsoft MSDN.
See Also:
Microsoft MSDN
NI LabVIEW
NI Measurement Studio


Related Links:
Know the Basics of Microsoft.NET
Visual Studio .NET -- The Latest Microsoft .NET Component

32 ratings | 3.47 out of 5 | Print Document
Reader Comments | Submit a comment »


Legal
This tutorial (this "tutorial"wink was developed by National Instruments ("NI"wink. Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).


My Profile | Privacy | Legal | Contact NI © 2007 National Instruments Corporation. All rights reserved. | E-Mail this Page

(1) (Reply)

Embed Native Components In Your Java Apps / Play Mp3 File In Visual Basic 2008 / Can You Imagine The Insult?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.