Sei sulla pagina 1di 8

6/9/2011

THE .NET REVOLUTION A Brief History of Visual Basic


• BASIC, a simple teaching language that
• This chapter presents the “big picture” of Visual programmers once learned before graduating to
Basic and the .NET Framework. more serious languages like C.
• You’ll get an overview of what has changed, why • Visual Basic inherited at least part of the BASIC
legacy, beginning its life with the goal of being the
it’s different, and just what life will be like in the easiest way for anybody to program . . . anything.
.NET world. Along the way, we’ll sort through • VB version 1.0, which introduced the easiest way
Microsoft’s newest jargon, demystifying : to create a graphical user interface;
– the Common Language Runtime (CLR), • VB version 4.0, which provided the easiest way to
– “managed” code, and the talk to a database;
– .NET class library. • VB version 5.0, which gave us the easiest way to
go “object-oriented.”

A Brief History of Visual Basic Enter .NET


• Visual Basic.NET 1.0.
• VB versions
– That’s because VB .NET 1.0 was the first version of
• 1991 VB 1 (May) Visual Basic that broke language compatibility.
• 1992 VB 2 (Fall) – Traditional VB programming tricks and hacks
• 1993 VB 3 (Summer) either failed or risked serious side effects.

• 1995 VB 4 (August) • Visual Basic 2005 is VB .NET 2.0.


• 1997 VB 5 (February) – Microsoft marketers decided that the .NET name
was confusing so they named it VB 2005.
• 1998 VB 6 (Summer)
– Didn’t change the language to make it one bit
• 2001 VB.Net? closer to classic VB.

1
6/9/2011

Enter .NET The Limitations of “Classic” Visual Basic


• Visual Basic 2005 differences are :
• Visual Basic’s Quirky (odd) Mix
– a few new language frills (many of which are
introduced in Chapter 3), • Isolated Languages
– a revamped design environment (which is Visual • Enterprise Development Headaches
Studio see Chapter 2), and • DLL Hell
– a return of the long-lost (and much-loved) run- • Incomplete Support for Object-Oriented
edit-and-continue debugging feature (Chapter 8).
Programming
• VB .NET may pose a migration challenge and a whole
new learning curve, but it also represents a major
redesign and refinement of the Visual Basic
language.

Visual Basic’s Quirky (odd) Mix Isolated Languages


• Visual Basic last ver. (6.0) was a mixture of cutting- • Each programming language does things a bit
edge features and old throwbacks. E.g. a great
framework for creating a graphical user interface differently.
with configure controls and windows just by setting • Windows programming without .NET, where:
properties. – C++ uses the MFC library,
• Problems
– J++ uses WFC, and
– Need of Windows API, a library of perplexing C
routines. – Visual Basic uses its own framework (with sprinkles of the
– “evil” type-conversion mechanism, Windows API thrown in for good measure).
• easier by letting you convert data types without following • Programmers suffered endless headaches trying to
the proper rules thus allowing you to overlook serious
errors. understand each other, and they had to consider the
– Ancient practice of referring to open files with difference and customs of every language .
numbers.
• And even if a problem was solved in C++, Visual Basic
– World-class object-oriented programming language
still has the Goto command? developers usually still needed to solve it all over again.

2
6/9/2011

Enterprise Development Headaches DLL Hell


• Three-tier design. Distributed objects. Load balancing. • DLL Hell is a particularly ugly example of the problem with component-
It all sounds good on paper. based programs.
• Most Visual Basic programs rely heavily on specialized components and
• Data objects reading and writing to the database, controls, sometimes without the programmer even realizing it.
business objects processing the results, and a Windows • These programs work fine when the correct version of every dependent
application displaying the results, with everyone talking file is present on the system,
together using the Component Object Model (COM). • but if
• But if you’ve ever tried to create a distributed program, • mistakenly some .dll is overwrites
you’ve probably discovered that : •
• strange problems start to come out of the woodwork.
– setting it up, •
– registering your components, and • Such problems are a nightmare to try and identify, and the worst part is,
– maintaining version compatibility they usually appear long after a fully functional application has been
• add a whole new set of painful problems that have installed.
nothing to do with programming • The end result?
• Fragile programs that can easily be disrupted when other applications are
updated or uninstalled.

Incomplete Support for OOP The .NET Vision


• The Ingredients of .NET
• Before I even knew what polymorphism and • The Common Language Runtime (CLR)
inheritance were, I knew that classic Visual
• The .NET Classes
Basic didn’t have them. Never mind that VB
• Speaking the Same Language
had all the other tools needed to write elegant
• Deep Language Integration
programs based on objects; there was no
• Prebuilt Infrastructure
escaping the talk about its OOP limitations. No
• Web Services and the Next-Generation Internet
other limitation did more to crush the
• Open Standards: XML, SOAP, WSDL, and Other
personal self-esteem of the dedicated VB Letters from the Alphabet
programmer.
• Metadata: The End of DLL Hell?

3
6/9/2011

The Ingredients of .NET The Ingredients of .NET


• Like COM and ActiveX, the .NET Framework
means a lot of different things, depending on
whom you talk to in Microsoft’s marketing
department. On the programming side, .NET is
made up of the:
– Common Language Runtime (CLR)
– set of unified classes.
– The .NET Framework
• .NET framework sits on top of the Windows
platform, which provides its own set of services
(e.g., IIS server built into Windows for web server).

The Common Language Runtime (CLR) What does CLR code offer to your applications?
• prevents operations that could corrupt memory and
The CLR is a runtime environment that processes, executes, cause the system to become unstable.
and manages Visual Basic code.
It’s a little like the traditional Visual Basic runtimes (for • Automatically cleans up objects you don’t need.
example, VBRUN300.dll or MSVBVM60.dll), but with • Catches common mistakes & halts your program with
increased responsibility. an error, rather than letting it run on with scrambled
data.
• Compiles your code on the fly into native machine
code, ensuring optimum performance.
• Code that executes inside the CLR is called managed
code which works with CLR services & operates
under the CLR’s careful supervision.

4
6/9/2011

The .NET Classes The .NET Classes


• The .NET classes contain the tools to perform
all kinds of tasks, from writing to a database to
reading from a web page.
• In the past, these capabilities either were
hard-coded into the language with special
functions, or provided through separate
components.
• Think of the integrated class library as a
supremely well-organized programming
toolbox.

Deep Language Integration


Speaking the Same Language • The power of CLR integration extends beyond the way
you code. Behind the scenes, the same engine is
• Within .NET, each programming language still processing code from different .NET languages.
has its own syntax. For example, every line in a • deep integration means that we can inherit procedures
C# program ends with a semicolon (;), unlike and properties from classes written in C#, and that
Visual Basic. But these differences are really errors thrown from code written in C# can be caught by
just superficial. code written in Visual Basic.
• In fact, every CLR language compiles into same CPU-
independent byte code (creating .exe or .dll file) the
Microsoft Intermediate Language (MSIL or IL ).
• Different .NET languages have the same performance.
so programming in VB 2005 instead of C# 2005 is
nothing more than a lifestyle choice.

5
6/9/2011

Prebuilt Infrastructure
• Most internal business applications boil down to databases, web
development involves tackling site-management issues, & game
requires the traditional 3D-rendering engine.
• Microsoft has been successful designing some of the basic
infrastructure that we all need, creating such tools as ADO for
universal database access and COM+ for managing transactions. Web Services and the Next-Generation
• Microsoft’s philosophy is to supply the infrastructure, while the Internet
programmer writes the specific “business logic” that distinguishes
one project from the next.
• No Need to spend time wrestling with low-level details such as
state management, database-specific APIs, and messaging.
• The .NET Framework extends this philosophy with its common
class library. Here you can find cutting-edge tools for creating
everything from a Windows service to an ASP.NET web application
ready to serve thousands of eager e-shoppers.

Open Standards: XML, SOAP, WSDL, Metadata: The End of DLL Hell?
and Other Letters from the Alphabet

6
6/9/2011

Ten Enhancements You Can’t Live Without Ten Enhancements You Can’t Live Without
1. Visual Basic is truly object-oriented—at last. 6. Method overloading now allows you to create different
2. The new Windows Forms model for programming a versions of methods with the same name, but with different
user interface is more powerful than ever, and arguments. Visual Basic 2005 will use the correct one
bundles convenient controls for everything from automatically.
system tray icons to print previewing to web browser 7. Even critics can’t deny that the new development
windows. environment is heart-stoppingly beautiful. Does any other
3. There’s no automatic type conversion: Option Strict language offer collapsible code, intelligent dynamic help,
lets you turn off this dangerous “convenience.” and an entire programming language for creating macros?
4. Structured error handling makes it as easy to trap an 8. A new event model lets you connect multiple event handlers
error in Visual Basic as in any other modern to a single control and store function references in special
programming language. variables, called delegates.
5. ASP.NET provides the easiest and most powerful 9. Initializes let you set the value of a variable on the same line
system to date for programming web applications. where it is declared.
10. Metadata means that DLL Hell may finally be a thing of the
past. You can now set up a program just by copying its
directory—a capability that hasn’t existed in the Windows

Ten Changes That May Frustrate You Ten Changes That May Frustrate You
6. Older database access methods, such as RDO and DAO, are not
1. Arrays must always have a lower boundary of 0. fully supported. (For example, they can’t be used for data
2. Existing Internet projects using Web Classes or DHTML aren’t binding.)
supported, so you will need to rewrite them from scratch as 7. Even if you use the upgrade wizard, a great deal of code may need
ASP.NET applications. to be rewritten, including routines for reading from and writing to
3. There are no more default properties, so you can’t abbreviate files, and for creating printouts. In fact, for complex applications,
Text1.Text as just Text1. you may have to abandon the whole idea of migration.
4. The techniques you used in the past to print documents, draw 8. There is no way of accessing pointers. In classic Visual Basic,
graphics, read text files, and provide context-sensitive help have pointer access was dangerous and unsupported, but could still be
changed—get ready to learn these basics all over again. done by those who knew the “secret” functions, such as StrPtr()
5. There is no deterministic finalization. That fancy jargon means and ObjPtr().
that when you’re finished with an object, it may still hang around 9. Goto, Gosub, and line numbers are no longer supported.
in memory for some time until it’s cleaned out. As a result, you 10. The model for drawing on a form has changed. If you did custom
can’t rely on events that take place when an object is unloaded, drawing in the past, you’ll need to rewrite it from scratch.
because they won’t occur at a predictable time.

7
6/9/2011

The Dark Side of .NET What About COM?


• COM is the Component Object Model, the fundamental technology that
• Not every Visual Basic programmer is happy with the radical allows programs to communicate together, and allows parts of programs
changes Microsoft made. To some critics, .NET’s drive to modernize (their components) to interact as well. Until now, COM was supposedly
the basis of Windows programming—so where has it gone?
programming has left Visual Basic 2005 looking more like Java than
.NET. • This is a question that’s bound to be asked again and again. As Microsoft
points out, there are hundreds of millions of COM applications, including
• They argue that years of Visual Basic legacy are being left behind, such heavyweights as Microsoft Office. COM will be around as long as
and that compatibility with old code is being rudely broken. There’s Windows is around; in fact, Windows won’t boot without COM.
more than a grain of truth to these complaints. • That said, .NET is not built on top of COM. Programs written in .NET
• So is .NET worth it? Yes. Visual Basic 2005 has changed enough to communicate natively; because their languages are all based on the CLR,
make life a little painful for developers, but once you understand they don’t need to work through obscure COM interfaces.
the new changes, your coding days will be easier and more • In fact, .NET is really a next-generation version of COM. (At one early
productive. In a sense, Microsoft is gambling that developers will be stage, parts of it were even called COM+ 2.0.) But don’t panic. Microsoft
so eager to program with an elegant, revitalized version of Visual has worked long and hard to make sure that COM applications can
Basic that they’ll sacrifice backward compatibility. Sometimes communicate seamlessly with .NET.
change hurts. • One day you may wake up to a world without COM . . . but it won’t be any
time soon.

Potrebbero piacerti anche