Will “Effectively Work with Legacy Code” help someone working with an application ported from VB6 to VB.NET?

I would like to reorganize a large legacy application originally written in Visual Basic 6.0 and subsequently ported to .NET. To do this with confidence, I want to have unit tests around existing code so that I can compare before and after. What is the easiest and most effective way to do this?

There is a book there called Effective Work with Obsolete Code that seems to help me. However, it seems to deal only with object-oriented languages, and Visual Basic 6.0 is not necessarily OO. Can this book help me? I hope that someone who reads it can vouch for it.

In particular, this application does not use classes other than the forms themselves. It accesses the database directly from forms and not sequentially. There were several people in this project who used their own styles without any standards.

As I said, this project has been ported to VB.NET. However, it is portable only in the sense that it compiles for Visual Studio 2008. All coding concepts are Visual Basic 6.0.

+6
refactoring vb6-migration legacy
source share
7 answers

It concerns not only object-oriented (OO) languages. Large sections focus on how to work with legacy code in C.

So yes, buy it!


There is a whole chapter (chapter 19):

My project is not object oriented. How to make safe changes?

There is also vbUnit , xUnit , which can help you use TDD with Visual Basic 6.0 .

Actually, I misunderstood the question and thought that you were going to the port, and not what you had already ported. In this case, you have a ton of "legacy" VB.NET , which is completely designed for you. You can use the capabilities of VB.NET OO and use the rest of the book.

I really can't recommend this book anymore.

+7
source share

Yes; book concepts are great and strong and go beyond the OOP. And VB6 can be object oriented, although it is not as thoroughly object oriented as some.

Among the strongest concepts in the book are “seams,” mainly places where you can break your code, enter tests, or isolate or abstract a bit of functionality. This is just one of the concepts that apply even to procedural code.

+1
source share

You can ask more specific questions.

Although VB6 is not a pure OO language as such, there are enough OO elements that things should be familiar with; In addition, there are several unit testing modules for the VB6 IDE.

But consider some of the high-level components of VB6:

  • Forms ARE objects (you can create new instances).
  • Modules behave like classes using only static methods.
  • Classes and UserControls are as close as possible to objects. The lack of a constructor makes things rude, but I hope that the original developer stayed with initialization or wrote a consistent Init.
  • Events in VB are odd; this is also what is likely to suit you the most. The hidden status code, which depends on the particular order of events, is undoubtedly scattered throughout the place.
  • Property Pages. Well, that's what it is.

Start with VB best practices. If the application was not written with the best practice code in mind, I think taking this step will save you from many problems.

+1
source share

You definitely have some work cut out for you, but here is a strategy to consider before doing ANY .NET work.

Extract as much of the base FORM code as possible into the class: one class file for each form at the beginning. In fact, form event handlers should do nothing but proxy method calls in an instance of the base class; it is obvious that all user methods can be transferred to the class file.

After reading the best practice guide (etc.) from Microsoft and others to help you get ready for the .NET port, you are mostly tuned to small pieces of hell that you will have to transcode / refactor: annoyances such as error handling, event ordering, late related objects / options, collections, etc.

Word for error-processed code: it is especially difficult to duplicate spaghetti errors, especially because the average Visual Basic encoder had poor ability to use it as a flow control logic. It is almost worth breaking each On Error block into separate subroutines if there are more than two .

After clearing the code, you can also consider refactoring Visual Basic code into reasonable abstractions (e.g., one data adapter class and connection, etc.), but you will be the best judge of this.

You may not like this approach, so definitely check out one form of water.

+1
source share

I have a copy that I bought to try to control our C / C ++ project. Since I missed the functionality of C # / .NET , it can offer.

Books are very C / C ++ ish, but, as John says, there is a chapter to working without objects.

But, if, as you say, your code is ported to .NET, it is no longer Visual Basic 6.0..NET code, it has many Visual Basic / C # features that allow you to connect to your code and test it. But this suggests that the book will give you a good overview of the various ways to connect to the application and strategies for managing a large old project.

+1
source share

I would suggest taking a look at Martin Fowler Refactoring: Improving the design of existing code , which is an excellent compulsory read.

You might be looking for something like Professional Refactoring in Visual Basic . I have not read it, but it seems to be applicable.

0
source share

I think you will find performance tests the most useful. They must be automated. Without performance checks, you will be left to manually test your application / code, actually launching it. It’s so easy to skip critical function testing when adding new code. This comes from my own experience.

Effect Sprout and Sprout Class are important when adding new code.

0
source share

All Articles