The new changes of language in Visual Basic.NET

Source: Internet
Author: User
Tags exit error code error handling exception handling goto new features object model thread
Introduction to Visual

To quickly create an enterprise-class Web application, developers must rely on business logic such as scalability, robustness, and reusability. In the past few years, object-oriented programming has become the primary approach to systems that meet these requirements. Using object-oriented programming languages helps make large-scale systems easier to understand, easier to debug, and faster to upgrade.

To enable Visual Basic developers to benefit from object-oriented design and to simplify the development of enterprise-class Web applications, the next version of Visual Basic--visual Basic.NET will support all object-oriented language features, including implementation inheritance. With these language features, Visual Basic.NET will have all the capabilities needed to quickly develop enterprise-class critical applications while maintaining direct access to the world's most popular development tools.

Visual Basic.NET provides best-in-class object-oriented programming language features, such as constructors that implement inheritance, overloading, and parameterization. In addition, developers can write highly scalable code with an explicit free thread, while writing code with high maintainability through other modern language concepts such as structured exception handling. Visual Basic.NET will provide all the language features developers need to create robust, scalable, distributed Web applications:

New Object-oriented Programming features

L Inheritance

L Overload

L Parameterized Constructors

Other modern linguistic features

L FREE Thread

L Structured Exception handling

L Strict type checking

L Shared Members

L Initialization Settings

History of the language renewal

The Visual Basic language has a long history of updates, which is related to the fundamental changes in the Windows platform. For example, a significant change to QuickBasic is to support the development of Windows3.0 GUI and produce the first version of Visual Basic. The transition to COM programming in Visual Basic4.0 produces a language concept for creating DLLs. In Visual Basic5.0, its language evolved to support the creation of COM controls.

With each successive modification, Visual Basic is becoming more popular. The new Visual Basic object-oriented language feature provides developers with the ability to create enterprise-class Web applications, which is bound to perpetuate this trend.

Object-Oriented Programming

In the traditional structured programming, data storage separation and program code, there are some drawbacks. All the code is written into a structured, not a module. Because data elements can be accessed from any code, they may not be modified without the knowledge of the developer. This can cause Run-time errors that are very difficult to debug. In addition, program maintenance can become an important task. It is very difficult to understand the global impact of modifying a line of code in structured programming. Finally, relying on developers to control code and data results can lead to lower reusability.

Object-oriented programming (OOP) solves these problems by wrapping the data and the methods implemented on it as a separate unit called an object. The data of an object can be hidden to prevent unauthorized modification. In addition, objects expose a set of public methods that can operate on data. This concept is called encapsulation. Because implementation details and interfaces are separated, the underlying programming logic can change at a later stage without having to worry about breaking code that invokes the object.

OOP also allows developers to reuse both code and data through inheritance. By inheriting from previously identified objects, developers can build complex applications more quickly. Since writing new code always has the potential to be brought into error, reusing the tested code minimizes the likelihood of additional errors.

To accommodate these needs, Visual Basic.NET will provide some additional language features that enable it to have the benefits described above and make it a first-class object-oriented programming language.

Inherited

The most vocal requirement of Visual Basic features is support for inheritance. Development in the Internet age requires rapid assembly and a lot of reuse. Visual Basic now fully implements inheritance, including visual form inheritance.

Developers can derive from an existing class by using the New keyword inherits.

Class1

Function GetCustomer ()

...

End Function

Class2

Inherits Class1

Function getorders ()

...

End Function

Inheritance statements support all inheritance-related properties. An instance of a derived class supports methods and interfaces supported by all base classes. Of course, derived classes can extend the collection of methods and interfaces supported by the base class. Derived classes can use the Overrides keyword to override methods defined in the base class. To reduce programming errors, Visual basic prevents accidental substitution of a function. Only functions declared as "replaceable" are allowed to be substituted in the derived class.

Overload

Visual Basic now allows function overloading, which gives developers the ability to create a procedure or function that has the same name but different parameter types.

Inheritance is especially useful when the object model provides procedures to use similar names but operate on different types of data. For example, a class that may behave in several different data types can have such a display process:

Overloads Sub Display (TheChar as Char)

...

Overloads Sub Display (Theinteger as Integer)

...

Overloads Sub Display (thedouble as Double)

If you don't inherit, you need to use a different name for each procedure or use a Variant parameter. Overloading provides a clearer and more efficient way to handle a variety of data types.

Parameterized constructors

A parameterized constructor (or "constructor") allows you to create a new instance of a class and pass arguments to the instance. Constructors are required for object-oriented programming. Because it allows user-defined construction code to pass parameters through the creator of the instance. They simplify the client program's code by allowing a new object instance to be created and initialized in a separate expression.

Other Modern language features

Visual Basic.NET adds a number of new concepts that simplify the development of robust and scalable applications. These features include free threading, structured exception handling, strict type safety, and new features such as initializing settings and sharing members that can increase productivity.

Free thread

Now when developers create applications in Visual Basic, the code they write is synchronized. This means that each line of code is to be executed before the next line of code. Scalability is critical when developing Web applications. The developer needs to be a tool for parallel processing to be possible.

With free threading, developers can generate a thread that completes long-running tasks, executes a complex query, or runs a multiple-part calculation, while other parts of the application continue to perform and provide asynchronous processing.

Sub Createmythread ()

Dim B as BackgroundWork

Dim T as Thread

Set B = New backgroundwork ()

Set t = new Thread (new ThreadStart (AddressOf b.doit))

T.start

End Sub

Class BackgroundWork

Sub DoIt ()

...

End Sub

End Class

Structured exception handling

Developing an enterprise-class application requires that you create reusable, maintainable parts. In previous versions of Visual Basic, one of the controversial aspects of the basic language was its support for error handling. Developers have found that a consistent error-handling scheme means a large number of assignment codes. Error handling using existing On Error Goto statements sometimes slows the development and maintenance of large-scale applications. The name reflects the problem that, as Goto implies, when an error occurs, control is transferred to a marked position in the subroutine. Once the error code is run, it must often be turned over by another clearing position, which is to go through a standard Goto, and finally exit the process with another goto or exit. Using multiple combinations of resume and next to handle several different errors results in unreadable code and causes frequent errors when the execution path is not fully considered.

Use Try ... Catch... Finally, these problems will no longer exist and developers can nest their exception handling, which is a control structure for writing clean code under normal and exceptional conditions.

Sub SEH ()

Try

Open "Testfile" for Output as #1

Write #1, Customerinformation

Catch

Kill "Testfile"

Finally

Close #1

End Try

End Sub

Strict type checking

The current Visual Basic language is very free when it can produce implicit type casts. For assignment and parameter passing other than references, the Visual Basic compiler can allow almost any data type to convert to other data types through run-time coercion of type conversions. If the value to be converted cannot be converted without data loss, then the Run-time cast may fail. By adding a new compilation option, Visual basic can produce a compile-time error for any conversion that may occur at run time. Option Strict improves type safety by requiring a transformation that may fail at run time or when an error occurs, such as an automatic conversion between numeric types and strings that is not expected by the user.

Shared members

Shared members are data and function members that are shared by all instances of the class. Sharing a single instance of a data member or function in all instances of a class is required by using an inherited Visual Basic application. A shared data member exists independently in each instance of the class. A shared method is different from a normal method, and is not an implicit pass-by-instance of a class. For this reason, unrestricted references to unshared data members in a shared method are not allowed. Shared members can be accessed indirectly, and they can be bound from the instance of the class later.

Initialization settings

Visual Basic.NET supports initialization in the declaration line of a variable. Initialization settings can be used anywhere, including the control structure. The semantics of a procedure-level declaration with initialization settings are the same as a declaration statement immediately following an assignment statement. In other words, the statement

Dim X as Integer=1 and

Dim X as Integer

X=1 is the same.

Conclusion

Visual Basic is now a state-of-the-art object-oriented programming language, and with Visual Basic.NET, developers can create highly scalable code from an explicit free thread. The code they write increases the use of modern language concepts, such as structured exception handling, and is highly maintainable. Visual Basic provides developers with all the language features they need to create robust, scalable, distributed Web applications.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.