New language changes in Visual Basic. net

Source: Internet
Author: User

New language changes in Visual Basic. NET IntroductionTo quickly create enterprise-level Web applications, 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. The use of 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 simplify the development of enterprise-level Web applications, the next version of Visual Basic is 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 required to quickly develop key enterprise-level applications, while maintaining direct access to making it the world's most popular development tool. Visual Basic. NET provides first-class object-oriented programming language features, such as constructor for inheritance, overloading, and parameterization. In addition, developers can write highly scalable code through explicit free threads, and write highly maintainability code through other modern language concepts such as structured exception handling. Visual Basic. NET provides all the language features required by developers to create strong and Scalable Distributed Web applications: New Object-Oriented Programming featuresL inherits the l-loaded l-parameterized Constructor Other modern language featuresL free thread l structured exception handling L strict type check l shared member l initialization settings Language update historyThe Visual Basic language has a long update history, which is related to the basic changes of the Windows platform. For example, a significant change to quickbasic is to support GUI development in windows3.0 and generate the first version of Visual Basic. The transformation from visual basic4.0 to com-based programming produces the concept of creating a DLL language. In visual basic5.0, the language is developed to support the creation of COM controls. With each continuous modification, Visual Basic becomes increasingly popular. The new visual basic object-oriented language feature provides developers with the ability to create enterprise-level Web applications, which is bound to continue this trend. Object-Oriented ProgrammingIn traditional Structured Programming, data storage separation and program code have some drawbacks. All code is written into a structured structure, not a module. Because the data element can be accessed from any code, it may not be modified without the developer's knowledge. This may cause very difficult debugging runtime errors. In addition, program maintenance may become an important task. It is very difficult to understand the global impact caused by modifying a line of code in structured programming. Finally, relying on developers to control code and data results will lead to lower reusability. Object-Oriented Programming (OOP) solves these problems. It encapsulates data and the methods implemented on it into an independent unit called an object. Data of an object can be hidden to prevent unauthorized modification. In addition, an object exposes a set of public methods that can be operated on data. This concept is called encapsulation. Due to the separation of Implementation Details and interfaces, the underlying programming logic can be changed later without worrying about damaging the code of the called object. OOP also allows developers to reuse code and data through inheritance. By inheriting from previously determined objects, developers can more quickly construct complex applications. Since writing new code will always bring potential errors, reusing tested code can minimize the possibility of generating additional errors. To meet these needs, Visual Basic. NET will provide some new language features, these features can make it have the advantages described above, make it a first-class object-oriented programming language. InheritanceThe most popular requirement for Visual Basic features is the support for inheritance. In the Internet era, development requires rapid assembly and massive reuse. Visual Basic is now fully inherited, including the inheritance of Visual forms. Developers can use the new keyword Inherits to derive from an existing class. Class1Function GetCustomer ()... End FunctionClass2Inherits Class1Function GetOrders ()... End Function inheritance statements support all inheritance-related properties. The instance of the derived class supports all methods and interfaces supported by the base class. Of course, a derived class can extend the set of methods and interfaces supported by the base class. A derived class can use the Overrides keyword to replace the methods defined in the base class. To reduce programming errors, Visual Basic prevents unexpected replacement of a function. Only functions declared as "Replaceable" can be substituted in a derived class. Heavy LoadVisual Basic now allows function overloading, which enables developers to create a process or function with the same name but different parameter types. Inheritance is particularly useful when the object model specifies the process of using similar names but operating on different types of data. For example, a class that may be represented by several different data types may have such a Display process: Overloads Sub Display (theChar As Char )... overloads Sub Display (theInteger As Integer )... overloads Sub Display (theDouble As Double) if there is no inheritance, you need to use a different name for each process or use the Variant parameter. Overload provides a clearer and more effective way to process multiple data types. Parameterized ConstructorA parameterized Constructor (or "constructor" for short) allows you to create a new instance of a class and pass parameters to the instance. Constructors are required for object-oriented programming. Because it allows user-defined constructor code to pass parameters through the instance creator. They simplify the code of the client program by allowing a new object instance to be created and initialized in a separate expression. Other modern language featuresVisual Basic. NET adds new concepts that simplify strong and scalable application development. These features include free threads, structured exception handling, strict type security, and new features that can improve productivity, such as initialization settings and sharing members. Free threadNow, when developers create applications in Visual Basic, the code they write is synchronized. This means that each line of code is executed before the next line of code. Scalability is critical when developing Web applications. Developers must use parallel processing as a possible tool. With free threads, developers can generate a thread to complete some long-running tasks, execute a complex query, or run multiple computations, other parts of the application continue to be executed, providing asynchronous processing. Sub CreateMyThread () Dim B As BackGroundWorkDim t As ThreadSet B = New BackGroundWork () Set t = New Thread (New ThreadStart (AddressOf B. doit) t. startEnd SubClass BackGroundWorkSub DoIt ()... end Sub End Class Structured Exception HandlingDeveloping Enterprise applications requires the creation of reusable and maintainable components. In the past Visual Basic versions, a controversial aspect of the Basic language was its support for error handling. Developers have found that consistent error handling solutions mean a large number of value assignment codes. Using existing On Error Goto statements to handle errors sometimes slows down the development and maintenance of large-scale applications. The call reflects some problems, such as Goto. When an error occurs, the control is transferred to a marked position in the subroutine. Once the error code runs, it must always turn through another clearing position, while the latter must go through a standard Goto, and finally Exit the process through another Goto or Exit. Using multiple combinations of Resume and Next to handle several different errors will produce hard-to-understand code and cause frequent errors when the execution path is not fully considered. Use Try... catch... finally, these problems will no longer exist, and developers can nest them to handle exceptions. This is also a control structure used to write clean code execution under normal conditions and exceptions. Sub SEH () Try Open "TESTFILE" For Output As #1 Write #1, CustomerInformationCatch Kill "TESTFILE" Finally Close # 1End tryEnd Sub Strict type checkThe current Visual Basic language is free of charge for implicit type forced conversion. The Visual Basic compiler allows almost any data type to be forcibly converted to another data type during runtime for value assignment and parameter passing except the reference mode. If the value to be converted cannot be converted without data loss, the forced conversion during running may fail. By adding a new compilation option, Visual Basic can generate compile-time errors for any conversions that may occur during running. Option Strict improves type security by requiring a conversion that may fail at run time or an error such as automatic conversion between numeric and string beyond user expectation. Shared MemberShared members are data and function members shared by all instances of the class. A single instance that shares a data member or function among all instances of the class is required by the inherited Visual Basic application. A shared data member exists independently in each instance of the class. The sharing method is different from the common method. It is not an instance of the implicit transfer class. For this reason, unrestricted reference to non-shared data members is not allowed in the sharing method. Shared members can be indirectly accessed, and they can be bound from the instance of the class. Initialization settingsVisual Basic. NET supports initialization of variables in the Declaration line. The initialization settings can be used anywhere in the control structure. The semantics of a process-level declaration containing initialization settings is the same as that of a declaration statement followed by an assignment statement. In other words, the statement Dim X As Integer = 1 is the same As Dim X As IntegerX = 1. ConclusionVisual Basic is now a first-class object-oriented programming language. with Visual Basic. NET, developers can create highly scalable code through explicit free threads. The code they write adds the use of modern language concepts such as structured exception processing, which will have high maintainability. Visual Basic will create strong, Scalable Distributed Web applications for developers to provide all the language features required.

 

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.