Category Archives: VB Feng Shui

Should Software Developers Know Hardware?

2
Filed under Hardware, VB Feng Shui

I’ve worked in a variety of positions over the years, including staffing up entire development departments.

One element I usually insist on in new hires is a reasonably solid foundation of knowledge of basic PC hardware and Windows setup (I’ve generally worked in Windows shops, hence the bias there). Things like hard drive setup, FDISK, formatting, all the way to assembling normal PC components (i.e. box of parts to a working PC).

Granted, these days, it’s not particularly cost effective to actually build out  developer machines this way, but it seems to me that generally speaking, developers ought to know their way around under the hood, maybe not at the circuit level, but at least the component level.

Is this expecting too much? Not enough? I could always wimp out and say that it all “depends on the situation.” But I’m not talking about specialized hardware or device drivers. I’m talking about general business applications.

Or have computers become more like commercial airliners or helicopters, where the pilots fly, the mechanics fix, and never the twain shall meet?

Sucking up 80 Columns of Code

3
Filed under VB Feng Shui

There’s an interesting discussion on SlashDot asking the question of whether we collective programmers should drop the old “80 column” standard that’s still so prevalent and go with some larger number, say 132, or, possibly something even bigger.

With the new widescreen displays, this would almost seem to make perfect sense.

But I think I’d side with the majority of posters that 80 columns is more than enough in most situations. Besides that, there are very good reasons that newspapers and magazines don’t print articles the full width of the page, but instead create columns. The eye just has a hard time sucking up that much stuff .

In the typical programming book I have, I counted an average of about 74 chars per line (proportional, so the number could vary, though not by much). In the paper back books I checked, I see about 54 chars per line. These are single column books.

80 would seem just about right. Long enough to deal with the typical indentation of a programming language, but short enough to keep you from getting lost on the line.

Besides, other than those lines with long tables or strings of text, why would you create a very long line of code? C is pretty notorious for allowing such nonsense with it’s ? operator and inline assignments, but there’s very few that would argue those things make the code more readable. VB has it’s “:” statement separator, but there are very few instances where I’ve seen it put to particularly good use.

Convention generally holds that you want to stick to one statement per line. And typical statements should be far less than 80 chars long.

On a related note, I have a few other questions to throw out

  • How many spaces should a tab comprise?
  • Is it better to program black on white or white on black?
  • Do color coded syntax highlighting editors actually help or just distract?
  • Should web pages go columnar when the chars per line exceed some number (for instance, browsing full screen on a widescreen monitor)?

For me, it’s:

  • 3 (2 is too few to be visually distinct, and 4+ takes up too much line space),
  • White on Black (with a white background, there’s just too much light coming at me. It’s almost blinding to run an editor full screen on a 24″ widescreen with a white background.
  • Not much, although I do tend to color comments in a dimmer color than the rest of the code. Everything else I tend to leave as white text, unless it’s a very specific file format. For instance, I have coloring rules for INI files and XML files to highlight the sections, keynames, and element tags.
  • Up in the air on this one. On slashdot, maximized, I count about 230 chars per line on my widescreen monitor. They run as a single column and just stretch it out to accommodate the browser. Many news pages simply limit the max width of the page to somewhere around 1024 pixels or so. Here’s a typical MSN page maximized on my system:

image

That seems like a waste to me.

VB Finally Gets Real

0
Filed under VB Feng Shui

Bill McCarthy has written a very revealing “What’s Hot” for the July Visual Studio Magazine. First off, the name of the “version after the next version” of VB (VB 10) is apparently VBx. I have to believe that that’s some small homage to VB3 (for those that were around, that was the summer of ’93, I still have the 5.25″ floppies of the beta)  and the .VBX custom control that was the precursor to VB’s OLE custom controls (OCX’s) and in many ways, VB’s entire concept of classes.

I suppose if it was less than 14 years ago, there might be some confusion over the naming, but, hey, it was 14 years ago, so I’ll let that slide<g>.

One minor note here. Bill’s article indicates that VBx is the “next version of the VB compiler”, which isn’t quite true according to this posting on the VB Blog.

Bigger news is that the VB team is rolling out the Interop Forms Toolkit 2.0, which allows you to create OCX controls and integrations with VB6, in VB.NET. Now, as intriguing as this nugget is, it makes me wonder. VB6 is scheduled for End-of-Life in 2008. Introducing such a toolkit so close to that end-of-life would seem to be an implicit acknowledgement that, well, somebody screwed the pooch. This is a pretty clear indicator that, as much as Microsoft would love to see VB6 die, they’ve come to a realization that maybe, just maybe, people have very good reasons to continue using code that works. Maybe this realization will be the kick in the pants for Microsoft to not pull stupid semantic tricks with future VBs that break all sorts of backwards compatibility, again. Hmmm, and maybe Chuck E. Cheese will one day be a fun place for adults to hang out, too.

But, by far the biggest news to hit me square in the jaw was the VB group’s plans to have VB10, er, VBx written in VB itself! For me, this is simply huge. I’ve always said there are a certain fundamental class of problems a compiler presents that a good language should be able accommodate, and finally, VB will become one of those languages. I for one, have heard one too many times “If VB was any good, it’d be written in VB.” ‘Bout damn time!

Of course, there’s this troubling passage on the blog

“Currently VBx is in very early stages, and is a long way off from production. In fact, most of our development team is actively working on VB 9.”

Doh. Well, so VB get’s real when I finally get my flying car (that’s this one, not this one)

VB8 to have Runtime Agility

1
Filed under Software Architecture, VB Feng Shui

Leave it to MS to come up with the phrase Runtime Agility, but the concept, if I’m understanding it right, is very intriguing.


The post is here, but to summarize, Paul Vick is a lead on the VB team, and is discussing some of the items on the block for VB8.


He off hand mentions this…


Runtime agility. The ability to compile without a VB runtime, or targeting another VB runtime.”


Now, if I’m reading that right, this would seem to be huge. The idea of VB being able to “compile in” the runtime is something I know I’ve been asking for since VB3. Does it waste a little space? Sure. But it means you can truly have a single EXE “copy and deploy” type scenario.


And does this mean the .NET runtime bits that are necessary will get baked in as well? Too early to tell, I suppose. Still. Something very interesting to watch in the coming months.

The VS Shell and Extension Methods

5
Filed under Software Architecture, VB Feng Shui

Here’s an interesting read on something coming down the pike with Visual Studio. Basically, it’s a customizable shell of VS that would theoretically allow you to build you’re own Visual Studio, language and all.


Likely, it’ll be on a complexity scale of integrating VBA into your app (anyone remember that 300-armed, greased-up monster squid?), but still, very interesting.


Another interesting read on Extension Methods coming in VB9. I’ve wondered why something like this hasn’t been in VB since the very early days of classes (anyone remember VB4?). Why, oh, why have I never been able to create a method like:

Public Function MyOwnReplace(Self as string, Arg as string) as String Extends String
Return Blah(Arg)
End Function

and then use it by calling the function method off of any ol’ string variable…

Debug.Print MyString.MyOwnReplace(Arg)

Maybe this is a contrived example, but the Dynamic languages concept of extending existing objects is something that just belongs in VB.


 

No one’s competent

2
Filed under Software Architecture, VB Feng Shui

There’s an interesting opinion piece by Kathleen Dollard in last month’s Visual Studio magazine. The latest issue has another piece by Kathleen that is very similar. There’s no link to the latest one, because that issue has just come out (I got mine not 30 minutes ago).

In them, she’s essentially saying that the .NET framework, and all the various supporting enterprise frameworks, have become so large that no one can hope to be competent enough in them to be able to intelligently determine what to use, when to use it and when to stay away.

I couldn’t agree more. But despite comments in the article that she is “more optimistic today” and that “the revolution has begun”, I still come away from the articles sensing a muted dread. Fear that suddenly, skills you possess today and have honed over the years will become worthless. The value of the knowledge you currently have is drying up like last weeks doughnut holes.

And I’m just not down with that.

The fact is, my experiences seem to suggest that the less you know about these high level frameworks, the better off you are. I’m not saying don’t get familiar with them. I’m saying that if you spend time to learn the basics of computer functionality, hardware, interfaces, binary, and object oriented principles like encapsulation, polymorphism and inheritance, details of specific frameworks just tend to come out in the wash.

On the other hand, if you spend all your time focusing on a specific framework, when it’s no longer de rigeur, you’re screwed.

Microsoft has created some great stuff, to be sure, and some of the newest bits out of the pipe certainly seem compelling, WPF probably more so than anything else. But it’s also thrown out plenty of red herrings, costing companies untold money before people realized that “the silver bullet of the day” probably wasn’t a good idea after all.

Back to the knowledge issue though. When VB1 came out, and only a bit later VB3, everyone exclamed at how great it was because “you didn’t have to know the nuts and bolts of the Windows API to get something built for Windows”. Which was true, unless you wanted to build an program you could actually do something with.

The fact is, VB was like that first step down into the pool. It lets you get your feet wet and get used to cold water before you dive in headfirst. Plus you get to feel for sure whether there’s any water in the pool.

But eventually, you either dive in, or you decide you don’t like programming.

VB.Net has always been more like the diving board. You either walk away, or you dive in, and you won’t know if there’s water in the pool till you feel it or you bash your skull on the gunite.

I think there’s a bigger issue here, though. Emphasizing all these layers of Linq, Sharepoint, WPF, WF, WCF, Ajax, and blah blah blah, won’t help encourage anyone to dive in, and that’s what VB.net needs to be doing. Instead we get, what, the MY classes. Puh..leaze! At least edit and continue finally came back with VS 2005. Where’s the genius that decided it’d be a good idea to leave it out in the first VS releases, anyway?

Don’t get me wrong. You can create some hardcore stuff with VB.Net, a lot easier than was ever possible in VB. But you get some hardcore baggage coming along for the ride too. And that’s unfortunate, because falling CS enrollments may mean a pretty sweet employment future for me, but it bodes some not so sweet prospects for our long term technological advancement as a nation.

And dammit, I want my flying car before I GOTO END !

Monolithic, Client-Server, 3-Tier, n-Tier

0
Filed under Software Architecture, VB Feng Shui

You are writing all your applications with a Client-Server architecture, right?

Oh, wait, this isn’t the late 90’s.

You are writing all your applications as 3-Tier assemblies, right?

Oh, wait, this isn’t the early 2000’s.

You are writing all your applications… Oh, to heck with it.

What’s the architecture du jour these days, anyway, n-tier? x-tier? SOA? XYZ-PDQ?

So what’s all the hubbub?

I propose something radical. Logically tier your code based on functionality, not locality. If you do that properly, monolithic, Client-Server, 3-tier, n-tier, x-tier, tears for fears, it won’t matter.

Why not?

Because if the code is properly organized and logically tiered, you’ll be able to easily move it wherever it needs to go to create (and remove) whatever tiers become necessary.

For example, I once worked for a company building a sizable billing package based on SQL Server. We wanted it 3 tier (Presentation, Business Logic, and Data Access), but we also needed it to be:

  1. easy to debug and maintain, and I mean easy, not the “learn how to jump through hoops faster” easy, but really easy. The dev team was small. This was a requirement.
  2. easy to deploy in a demonstration mode. If a prospect couldn’t fire up a CD install and in 5 minutes or less be playing with it, it wasn’t going to fly.
  3. capable of scale-out deployment to accommodate multiple report generation servers, data analysis servers, etc.

In the end, we designed a server app as the BLL (it actually ran as a service), a database chock full of highly optimized stored procs as the DAL, and a fat client that contained not only the user-facing interface but also the entire server app internally. And the key to all this was that the code for the server was exactly the same code as was in the client. The code was literally shared between projects in our VCS.

When connected to an actual server component, it got all the benefits thereof. But for debugging, it was unbelievably efficient to have both the client and server right there running at one time not only in the same IDE, but actually as part of the same executable. And deployment was a snap because the demo install didn’t have to bother with a server installation, it just created the DB and dropped the client on the machine.

If we’d needed to split functionality out farther, it would have been a very straightforward process because internally, everything was already split out.

The bottom line is:

Get the logical tiers right and encapsulate with a vengence.

Note to self: Vengeful Encapsulation. Sweet band name!

Bad, Bad, Naughty UI

1
Filed under VB Feng Shui

Ok, how hard is it really to use a standard Windows button control on a form?

Apparently, for this app, it’s pretty difficult (and this is a big name Document Management app):

BadUI

Notice the FIND and PROFILE SEARCH buttons. They’re some kind of odd “flat button” thinggees, but right next door are two standard Windows OK and Cancel buttons (hopefully, the grokked down capture still shows this).

Maybe I’m just nitpicking here, but if you’re gonna skin an app and give it new button styles, shouldn’t you do all of them? Or just leave em alone?

My question is, Why stop at button styles? Why not make some labels bold, and others italics, just for the heck of it. Consistency is the mother of derision, right? Oh, and throw in some good colors while you’re there. It’ll help. Trust me.

Error Handling Strategies

0
Filed under Software Architecture, VB Feng Shui

I once wrote an article about error handling in VB6 for Visual Basic Programmer’s Journal (Sept 2001, jeez that seems like a long time ago! {edit} and it would appear that that link is long since dead 🙁 ). It was born out of the need for a comprehensive framework for handling errors in an app I was working on at the time.

Since then, I’ve expanded the framework several times and it’s grown into something quite handy. Once I get it cleaned up a bit for public consumption, I’ll make the new and improved version available.

I’ve since been looking at the .NET error handler framework, and while it’s certainly much improved over the VB6 days, it still leaves a lot to be desired.

At the very core of handling errors is the division of error types into two distinct classes:

  • Expected Errors
  • Unexpected Errors

In a perfect world, every possible error is an Expected Error and there are no errors that can occur within your program that the code isn’t written to intelligently deal with.

At the other end of the spectrum, is, of course, where most textbook and magazine article sample code lies; where every error is an Unexpected Error that will crash the program.

Unfortunately, real world limitations on time, money, manpower, etc tend to force all code somewhere south of Nirvana.

The .NET fanclub used to decry VB’s on error goto as antiquated technology, and trumpeted try catch as the silver bullet of the day. And I suppose:

On Error Goto Catch
Try:
...code to try...
Goto EndTry
Catch:
...code to handle any error in the try block...
EndTry:

is quite different from

Try
...code to try... 
Catch ex as exception 
...code to handle any error in the try block... 
End Try

as long as you’re only looking at their checksums<g>.

Sure .NET incorporates a wealth of metadata about the exception. The module, function, line number, etc are all available directly while handling the error. But something’s missing.

Oh, yeah, What about those Unexpected Errors?

.NET does have the Exception Handling Application Block and it looks very promising, although it also looks very involved. And do you really want to be able to configure exception handling policies via config files? I mean, beyond indicating the level of logging you want (verbose, medium, low, off), and the email address to send exception report to (unluckysupporttech@mycompany.com), I’m having a hard time coming up with anything else I’ve ever needed to dynamically configure in my apps for exception handling. But, I won’t say it couldn’t be useful.

In the end, I suppose the thing that bothers me most about the EHAB, and the whole structured exception movement in general, is that it really does nothing to address the Unexpected Errors in an application. You still have to wrap your entire procedure in a TRY block in order to be sure that you catch any exception raised in that procedure. Otherwise, the exception is simply propagated up the call stack to the first point that is covered by an exception handler. The good news about .NET, though, is that at least, in those cases, you can still retrieve a call stack back to the real source of the exception and log it. With VB6, no such luck without some sort of framework.

My other issue is that Try Catch style exception handling forces the declaration of how you intend on handling errors to the END of the function you’re looking at. In this age of declarative programming and metadata-attributed interfaces, that just seems so…yesterday.

Take my above comparison of try catch and on error. What actually happens to the error is stated down at the end of the procedure in both styles. Now. I can understand that approach if you have code dedicated to handling specific errors, but then, those are Expected Errors. For the Unexpected Errors, I’d rather know, declared right up front, how the prodecure intends to handle them.

That was the impetus of my article way back when:

  • Provide a framework that could provide a call stack that VB6 was lacking
  • Provide a means of clearly declaring how the procedure intends on handling Unexpected Errors.

Compare a typical Try Catch structure:

Public Sub Test()
   Try                                          
   .....Lots and lots and lots of code....
   Catch Ex as Exception
   ....how to handle specific exceptions, plus how to handle general exceptions...
   End Try
End Sub

with a prologue style declaration like I use in my error handling framework for VB6:

Public Sub Test()
'############### ERR HANDLING #############
Dim Err As CErr: Set Err = New CErr: On Error GoTo Problem
Problem:
Select Case Err.Handle(EHF_PRESENT or EHF_ALLOWRETRY, MODULE, "Test")
Case EHE_NONE: Case EHE_RETRY: Resume: Case EHE_PASS: Resume Next: Case EHE_RESET: Resume Problem
End Select
'##########################################
   .....Lots and lots and lots of code....
End Sub

The code states right up front how unexpected errors are handled (in this case, EHF_PRESENT or EHF_ALLOWRETRY indicates that the user will be shown a dialog and allowed to retry the operation). There’s a bit more verbiage here because of the requirements of VB6, but that’s not the point.

Personally, I’d prefer it if every routine in .NET could be (or maybe even had to be) attributed as to how unexpected errors are to be handled. Those that need to show a dialog would do so based on one or more “predefined” dialogs that depended on where in the app the error was thrown.

And for those apps that you never want to show an error dialog, you could instead indicated that any unexpected errors should be logged to the Event Log (or somewhere else) and then press on as best as possible.

Unlike the implications in so many magazine articles, error handling is hard. Proper error handling is like a prostate exam; you know you have to do it, but you’d really rather not bother.

VB and Resource Files (Part 3)

1
Filed under Resource Files, Utilities, VB Feng Shui

In case you’ve missed the first 2 posts in this series, I’m discussing the concept of using Resouce files with Visual Basic 6.

In the first part, I talked about how to compile arbitrary information into a resource file and reference it from VB.

In Part 2, I discussed a technique for compiling a VersionInfo resource and writing it into your VB executable, thus replacing the incomplete VB provided VersionInfo resource.

In this installment, I wanted to share a little trick for defining the elements of the “Version number” in a resource (RC) file such that you only have to enter the version number once.

If you recall, I presented a sample RC file the last time, looking like this:

1 VERSIONINFO
FILEVERSION 1,2,3,4
PRODUCTVERSION 1,2,3,4
FILEOS 0x4
FILETYPE 0x1 //// 2 for dll, 1 for exe
{
BLOCK "StringFileInfo"
{
BLOCK "000004b0"
{
VALUE "CompanyName", "MyCompany"
VALUE "ProductName", "MyProduct"
VALUE "FileDescription", "MyFileDesc"
VALUE "LegalCopyright", "MyLegalCopyright"
VALUE "LegalTrademarks", "MyLegalTrademark"
VALUE "OriginalFilename", "MyOriginalFilename"
VALUE "ProductVersion", "1.2.3.4"
VALUE "FileVersion", "1.2.3.4"
VALUE "Comments", "MyComments"
VALUE "InternalName", "MyInternalName"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0000 0x04B0
}
}

If you’ll notice, there is one thing about this script that no lazy programmer worth a macro recorder would tolerate. The Version Number is duplicated several times, and what’s worse, in several different formats.

First, we have the FILEVERSION and PRODUCTVERSION entries, with comma separated numbers.

But then we also have the stringized version of those two elements, that must be specified as period separated elements within quotes.

I don’t have an alcohol fueled Code Sync 5000 robot to keep those numbers straight so I figured I’d just use macro substitution. Right. Turns out, the Resource compiler (RC.EXE) is a mighty fickel beast.

What I envisioned was a simple block to define the version number:

#define MAJOR          1
#define MINOR          0
#define REVISION       0
#define BUILD          116

and then use those definitions further down in the file, like so

FILEVERSION MAJOR,MINOR,REVISION,BUILD

and similiarly

VALUE “ProductVersion”, “MAJOR.MINOR.REVISION.BUILD”

But obviously, there’s a problem; actually, more than just one.

I won’t dwell on the details, but after much head scratching (polite euphimism), I ended up with this joyous concoction:

#define COMMAVER(mj,mn,rv,bl)        mj,##mn,##rv,##bl
// Commaver yields x,y,z,a  (necessary for the numeric versions)

#define PERIODVERPT2( mj )           #mj ""
#define PERIODVERPT3( mj,mn,rv,bl )  PERIODVERPT2( mj ) "." PERIODVERPT2( mn ) "." PERIODVERPT2( rv ) "." PERIODVERPT2( bl )
#define PERIODVER                    PERIODVERPT3( MAJOR,MINOR,REVISION,BUILD )
// PeriodVer yields x.y.z.a (necessary for the stringized versions)

// define the two numeric versions
// always make them the same                    
#define FILEVER        COMMAVER(MAJOR,MINOR,REVISION,BUILD)
#define PRODUCTVER     FILEVER

// define the two stringized version numbers, we just make them the same
#define STRFILEVER     PERIODVER
#define STRPRODUCTVER  PERIODVER

Then you can use them like so

....
FILEVERSION FILEVER
PRODUCTVERSION PRODUCTVER
....
VALUE "ProductVersion", STRPRODUCTVER
VALUE "FileVersion", STRFILEVER

Get clever with the #include directive and you can easily keep the version numbers of all the separately compiled VB components of your project synchronized and only have to set the version number in a single place.

If there’s a simpler way, I’d love to hear about it. But this works, and it keeps all my version numbers straight.