Visual Basic. The language innovation in net

Source: Internet
Author: User
Tags error code error handling exception handling goto new features object model variable thread
Visual Visual Basic. The language innovation in net
Introduction

To quickly create an enterprise Web application, developers must rely on scalable, robust, reusable business logic. In the past few years, object-oriented programming has become the primary technology for creating systems that meet these requirements. The use of Object-oriented programming languages can make large systems easier to understand, easier to debug, and faster to update.

To enable Visual Basic developers to benefit from object-oriented design, simplifying the development of enterprise Web applications will be in the next version of Visual Basic-Visual Basic. NET support includes the implementation of all object-oriented language features within the inheritance. Using these new language features, Visual Basic. NET will quickly and efficiently provide all the power needed to develop enterprise-critical applications while maintaining the instant accessibility that makes it the world's most popular development tool.

Visual Basic. NET will provide a first-class object-oriented programming language with new features, such as inheritance, overloading, and parameterized constructors. In addition, developers will be able to create highly scalable, threading code with clear free threads, as well as to incorporate modern language constructs such as highly maintainable code for structured exception handling. Visual Basic will provide all the language features that developers need to create robust, scalable, distributed Web applications by using the new features below:

New Object-oriented Programming features

Inherited
Overload
Constructors with parameters
Other modern linguistic features

Free thread
Structured exception handling
Strict type checking
Shared members
Initialization tool
The history of language innovation

The Visual Basic language has a long history of updates that reflects fundamental changes in the Windows platform. For example, the significant changes made by QuickBasic to support the development of Windows 3.0 GUI led to the first release of Visual Basic. In Visual Basic 4.0, the transfer to a COM-based program design resulted in the appearance of the language structure used to create the DLL. In Visual Basic 5.0, language development supports the creation of COM controls.

With each successful revision, the popularity of Visual basic has grown rapidly. The new Object-oriented language feature provides the startup capabilities of developers who create enterprise Web applications, and will most likely continue this trend.

Object-Oriented Programming

There are several drawbacks to the traditional structured programming (data and program code stored separately). Any code written as a structured code is not modular. Because data elements can be accessed from any code, it is not possible to modify the data without the knowledge of the developer. This can result in a very difficult debugging run error. In addition, maintenance may also be a substantive task. Trying to understand the global impact of changing a line of code with a program design can be very difficult. Finally, relying on programmers to manage code and data leads to very low reuse rates.

Object-oriented Programming (Oop,object-oriented programming) solves these problems. It packs the data and the methods that act on the data into a unit called an object. The data for an object can be hidden to avoid unauthorized modification. In addition, this object provides a set of common methods for manipulating this data. This concept is called encapsulation. Because the implementation details are decoupled from the interface, the underlying program design logic can be modified at a later date without fear of destroying the code that invokes the object.

OOP also allows developers to reuse code and data through inheritance. By inheriting predefined objects, developers can build more complex applications more quickly. Because it is often possible to add errors to writing new code, reusing code can minimize the chance of additional errors.

To address these requirements, Visual Basic. NET will provide these additional language features, which will make it known as a first-class object-oriented programming language with all of the above benefits.

Inherited

Consistently, the most prominent request for Visual Basic is support for implementation inheritance (Implementation inheritance). program development in the Internet age requires rapid compilation and a lot of reuse. Visual Basic now includes all implementation inheritance, including visual form inheritance.

Developers can use the New keyword inherits to derive from an existing class.

Class1
Function GetCustomer ()
...
End Function

Class2
Inherits Class1
Function getorders ()
...
End Function

The Inherits statement supports all the visual properties associated with inheritance. An instance of a derived class supports all the methods and interfaces supported by this base class. Of course, derived classes can extend the collection of methods and interfaces supported by the base class.

Derived classes can use keyword overrides to overload the methods defined in the base class. To reduce programming errors, Visual Basic prevents you from accidentally overloading a function, and only the "Overridable (overloaded)" function can be overloaded in a derived class.

Overload

Visual Basic now allows function overloading, which allows developers to create different versions of Sub or function with the same name but with different types of arguments.

Overloading is especially useful when your object model prescribes that a similar name is used for procedures that manipulate different data types. For example, a class that can display several data types might have a display procedure like the following:

Overloads Sub Display (TheChar as Char)
...
Overloads Sub Display (Theinteger as Integer)
...
Overloads Sub Display (thedouble as Double)

If there is no overload, you will have to use a different name for each procedure, or use a Variant parameter. Overloading provides a clearer and more efficient way to handle multiple data types.

Constructors with parameters

A constructor with a parameter (or simply called a constructor) allows you to create a new instance of the class while passing the variable to the new instance. Constructors are critical for object-oriented programming because they allow instance creators to pass parameters to user-defined construction code. They simplify customer code by allowing the creation and initialization of a new instance in a single expression.

Other modern linguistic features

Visual Basic. NET adds a number of additional constructs that simplify the development of more robust and scalable applications. These features include free threading, structured exception handling, strict type safety, and productivity features such as initialization tools and shared members.

Free thread

Today, when developers create applications in Visual Basic, they write code that is synchronized. This means that each line of code must be executed before the next line of code. Scalability is critical when developing Web applications. Developers need tools that support concurrent processing.

By including free threading, developers can produce a thread that performs certain long-term tasks, executes complex queries, or runs multiple-part computations, while other parts of the application continue to perform, providing asynchronous processing capabilities.

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 application requires the construction of reusable, maintainable components. One of the challenging aspects of the basic language in previous versions of Visual Basic is support for error handling. Developers found that a consistent pattern of error handling meant that a large number of copies of code could be replicated. Error handling with an existing On Error Goto statement slows the development and maintenance of large applications. Its name reflects some of the problems: as Goto implies, when an error occurs, control is transferred to the location of a tag in the subroutine. Once the error code is run, it must normally be transferred by a standard goto depending on another clearing position, which will eventually use another goto or exit to launch the process. Using a variety of resume and next combinations to quickly handle several different errors results in code that is difficult to read and causes frequent errors when the execution path is not fully considered.

Use Try ... Catch... Finally, these problems are solved, developers can nest their exception handling, and a control structure is used to write cleanup code that executes 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

Today, the Visual Basic language is very free in terms of the implied type of coercion it produces. For variables and parameter classes that are passed rather than referenced, the Visual basic compiler can convert almost all data types to any other type by generating a run coercion. If the value to be converted cannot be converted without data loss, then running the enforcement action will be effective. By adding a new compilation option, Visual basic can make any forced build compilation errors that might cause errors at run time. The option "Strict" improves type safety by converting a conversion that may fail at run time, or when an automatic type conversion between numeric types and strings is not generated by the user's expectation.

Shared members

A shared member is a data and function member of a class that can be shared by all instances of the class. Sharing an instance of a data member or function member between all instances of a class is required in the use of inherited Visual Basic applications. A shared data member exists independently of any particular instance of the class. A shared approach is different from a common method, and it is not implicitly passing instances of classes. For this reason, unqualified references to unshared data members are not allowed in a shared method. Public shared members can be accessed remotely, and they can be late bound from an instance of the class.

Initialization tool

Visual Basic. NET supports initializing a variable in a row that is declared. Initialization can be used in any location, including inside a frame structure. The semantics of the declaration that includes the process level of the initialization tool are the same as the declaration statement immediately following an assignment statement. In other words, this statement "

Dim X as Integer = 1

The following statements have the same meaning:

Dim X as Integer
X = 1

Conclusion

Visual Basic is now a first-class object-oriented programming language. With visual Basic. NET, developers will be able to create highly scalable, unambiguous free-Threading code. Their code uses a modern language structure, such as structured exception handling (structured Exception handling), which is highly maintainable. Visual Basic provides all the features that developers 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.