Category Archives: Rants

A GOSUB By Any Other Name

3
Filed under .NET, Rants, VB Feng Shui

imageI’ve been using VS2010 for a while now, and there’s definitely a lot to like in this release. Granted, the UI is a little slower than 2008, but that’s mostly because of all the new WPF goodness baked into every nook and granny of the IDE now.

One thing that I’d been looking forward to is multi-line lambdas in VB. C# has had that since 2008 (or possibly before), but VB was always limited to a single line or (more typically) a call to a function, which could be multiline.

Still, when you’re talking about lambdas, you’re typically talking about small chunks of code that you almost never really want to be a separate function, Private or not. It’s just that much more clutter.

VB2010 finally addresses that disparity and you can now do multi-line lambdas in VB.

Dim MyLambda = Function(arg As String) As String
   arg &= ","
   arg &= "More"
   Return arg

'And to call it
Debug.Print(MyLambda("TestArg"))

Now, technically speaking, you might argue that “MyLambda” is an anonymous method. And you’d be right. Anonymous methods, delegates, and lambdas are, essentially, different names for the same thing. Basically, they’re all just ways of “embedding” code into a variable, and then being able to call that code.

In the olden days, you’d use pointers for such folderol, but this is managed .net code, and pointers are all but verboten in these parts.

But wait!

The thing is, it struck me at one point, while recently describing how you might actually use a delegate to a colleague, of the similarities between anonymous functions like the above, and the much maligned VB GOSUB statement (GOTO’s less recognized little brother).

Dim Arg as string = "testArg"
Gosub MyLambda
Debug.print(Arg)
Return

MyLambda:
   arg &= ","
   arg &= "More"
   Return

Don’t get me wrong, I never found GOSUB to be particularly all that clean a construct. I used it on occasion, but not often. You couldn’t pass explicit arguments with GOSUB, and executing a variable GOSUB required the ON x GOSUB statement, which was pretty abysmal to use.

Still, all the makings of a lambda were right there, all along.

Get Out The Vote!

3
Filed under Rants

image Or rather, Get out AND vote!

I’m not going to get up on any soapboxes here about politics. That’s not what this blog is all about. But whatever your inclinations are, at least get down to the polls this Tuesday and put your vote in!

Now, back to hacking at a generic interception framework!

Old School Advice That Still Rings True

1
Filed under Rants

Earlier today, I was reading an excerpt from an interview with Dan Bricklin (the guy that invented the spreadsheet, for those that might not know).

He was asked about his approach to building programs back in the day (the mid 80’s, all legwarmers and The A Team).

His response was quite interesting, very “agile” when agile only meant an adjective to describe gymnasts.

One thing I’ve always done, for many years — I know Bob Frankston did, too — you have to figure out a path through the whole thing and implement that first. And then you go back to add more. Getting the path through is like building a scaffold. A lot more is put on [the application] before it’s a real product, but you have the critical path in place. It’s always building off something that’s working.

I thought that was fantastic. Yet another example of how programming seems to be a lot of doing the same thing over and over, just with each generation coming up with trendy new names for it all in the process.

Phillips Comes Through

0
Filed under Rants

image It’s been almost two months since we got hit by lightning that took out almost all the electronics in the house. A very looonnnngggg two months. Far more time that I would ever want to spend hassling with insurance adjusters, repairmen, UPS vendors, etc.

Still, it could have been worse.

Fortunately, a little good news came in the mail today.

I’d built a very custom computer to power a gaming rig I’m building. It was connected to a Philips Surge suppressor with a “master” outlet, basically, a surge suppressor power strip with one plug that is the “master” plug. When whatever is plugged into that plug is turned on, all the other plugs come on. When turned off, all the other plugs completely power down. They’re a great way to cut down on vampire devices that suck energy even when “off”.

Well, the computer was fried by the lightning. As was the Altec Lansing speaker/subwoofer system connected to it.

I’d called Philips to try and file a claim against their “25,000$ connected equipment guarantee”. Obviously, my losses weren’t that much but every little bit would help.

They sent out a UPS mailing label to return the surge suppressor (it still worked but they wanted engineering to investigate it).

So I boxed it up and shipped it, along with the rundown the the fried equipment.

It took about 2 weeks, but today I get a package in the mail. They sent me a new surge suppressor (not sure how much the old one helped, as it was fried and my PC was fried, but that’s another story) and a check to cover the damages.

I’d had my doubts whether anything would come of that guarantee, but they did indeed come through, so hats off to Philips!

HP G85 and JetDirect for the Win!

2
Filed under Hardware, Rants

image I’ve always been a bit of an HP fan when it comes to their printers. Ages ago, my dad bought a LaserJet that worked for what seemed like forever.

So, back when I first started telecommuting, when I needed a printer, I naturally thought of HP and ended up with a G85 Inkjet/Copier/Scanner.

I also picked up a JetDirect box to let me hook it up directly to an ethernet network. This was all circa 2000. Yep, seriously olden days.

But, that printer is still going strong. Absolutely no problems with it. I’ve dropped it. Moved twice. And most recently, the house got struck by lightning. I lost computers, a SAN drive, network switches, hubs, a TIVO, even UPS’s and my AC units.

But that printer and the Jet Direct box survived unscathed.

So what?

Here’s the thing. The G85 is a great scanner, BUT, the software is hopelessly outdated and HP hasn’t updated it since the XP days. So running it under Vista or Win7 has been a pain.

After the lightning, I was re-setting up new machines, when I happened to try browsing over to the printer’s IP address, basically on a whim.

Guess what I found?

image

That JetDirect box has a webserver built into this WHOLE TIME!

Not just that, but check that scan button…

Click it, and it leads you to this page…

image

Yep, that’s right, you can initiate a scan right here, from the browser, then download the resulting image. No drivers to load, no compatibility issues. Nothing but good ol’ fashioned sweetness.

I’ve had this thing literally ten years and never knew that was there. Certainly never came across it in the docs or any online info.

Turns out you can teach an old dog new tricks (or get him to do tricks you’ve never seen before <g>)

Lightning Strikes

2
Filed under Rants

And let me tell you, in this day and age, lightning can just plain suck.

Garage Door opener, AC units, all my computers, UPS’s, TIVO, home audio, phone systems, NAS drives, cable box. You name it, it got smoked.

I’ve spent the last three weeks scrambling to get new machines setup, get backups restored (fortunately, I had recent ones), get repair techs out for the big stuff, and take care of the smaller stuff myself.

And I had a whole house surge suppressor, and well as UPS units on all my machines and some of my audio gear. Smoked them all as well.

So, any lessons learned? Oh yeah.

  1. Make SURE you know what’s covered by your UPS “connected equipment guarantee”. Keep all that paperwork filed somewhere for quick retrieval.
  2. Keep good records of purchases of anything you plug in. I keep mine in Quicken. Then keep backups of your Quicken data and the program disks so you can install to another machine and retrieve the data.
  3. You’ll typically have about 10 days to file a claim. So keeping recent backups of that data will help immensely with quickly pulling together all your records of what you had, when you bought it, and how much you paid.
  4. Check with your homeowner’s insurance. You likely have a 1% or 2% deductable. If your house is 250,000$, that’s a sizable chunk of change you’ll be out. And keep in mind, the insurance companies will depreciate the value of your equipment by how long you’ve owned it, so it might be even tougher to get up to that 1 or 2%.
  5. UPS’s can protect equipment but they won’t always work. Have backups. Make sure they’re restorable.
  6. You can almost be guaranteed that it’ll cost you more to replace all the equipment that you lost than it did to buy it in the first place. Why? Because if it’s computer stuff, you’re not going to go out and buy an exact replacement, you’ll buy something more modern, more harddrive space, bigger monitor, faster CPU, more memory, etc. Prices have come down since you bought, after all.

With the backups I had, it took a while, but I’m back online, and with almost my complete previous setup. Still lots of little stuff to take care of, but it’s getting there.

The good news is, we weren’t home, and there was no damage to the house itself, short of a few blown circuit breakers, and a blown GFCI.

In other words, lucky!

The Ian Knot

1
Filed under Misc, Rants

imageOk, so it’s completely unrelated to VB in every conceivable way <g>.

I just came across a very nifty way to tie your shoes. It’s called the Ian Knot and there’s a very good pictorial writeup (and video) about it here.

I’m not going to repeat his pictures here, but it’s essentially, just:

  1. make a crossover knot, the way you would normally start to tie your shoes.
  2. In the right hand, make a loop exactly like you normally would, with the string going up, over your finger and down.
  3. In the left hand, make the same loop, but with the string starting below your finger and coming up over your finger towards you.
  4. then just push the two loops through each other and tighten.

Check out the site above for pictures. It’s easier to see it than describe it.

But, it IS amazingly fast, and easy.

Agile Development

1
Filed under Rants, VB Feng Shui

Billy Hollis has out an interesting article in the latest Visual Studio Magazine about the possible destiny of Agile Development.

(sidenote: what the hell has happened to VBPJ VSM? Am I the only one that remembers the days when that mag was just shy of a phonebook and literally every article was worth the read? This latest issue is barely enough paper to wipe your a$s! Seriously. It’s sad).

Anyway, Hollis calls out Agile Dev fans, sort of. He takes a bit of a middle of the road stance, which, actually, I find quite refreshing. To me, Agile has always seemed more like a tactic to avoid really learning to improve your craft and rather, just plowing forward, balls-to-wall to get something working, dammit! It kind of reminds me of a quote I once read supposedly from Steven King. When asked what his process was for writing books, he said something like “I just keep flailing away at the damn thing till I have something I like.”

Now, don’t get me wrong. Getting something working is important. But the more I look at the tenets of Agile, the more I wonder whether it’s really the consultants recommending it and the experts teaching it for 1000$ a day that stand to gain anything from it. It just sounds like yet another in a long line of silver bullets.

The best line from Hollis’s article is:

Most developers love to write code, and agile does a pretty good job of rationalizing why developers don’t need to do anything else.

Ouch!

If Programming Languages Were Religions

249
Filed under Rants

A friend of mine just pointed me to a pretty funny post about if programming languages were religions.

Can’t say I necessarily agree with his stand on Visual Basic<g>, but it’s a funny post, none-the-less.

Actually, that post has a link to a similar post about if languages were cars. Not quite as good, but worth the look. However, one comment there had me rolling. Best geek bumper sticker candidate I’ve seen in a long while!

FORTH LOVE IF HONK THEN !
                                          from a posting here

Shared Class Members or Modules?

0
Filed under .NET, Rants, VB Feng Shui

I ran into a chunk of code today that threw me.

The code was contained within a particular class definition.

Every member (properties and methods) were marked Shared.

Public Shared Sub MyMethod()
blah....
End Sub

The net effect was a class that, even if you could instantiate it, wouldn’t have any purpose as in instance. Its sole use was to provide essentially a dumping ground for a bunch of general purpose library routines.

At first, I just wrote this off as odd and continued on.

But, on further reflection, this just doesn’t seem right. As Scott Hanselman might say, it’s got a rather nasty Code Smell.

So, I did what any reasonable person would do; I googled it.

Apparently, there are more than a few people out there contemplating the same thing. What’s scary though, is that usually, the arguments end up along these lines:

  1. Modules in VB.Net are a throwback, a hack, and a nod to compatibility and should be avoided.
  2. Modules can’t be accessed from other .NET languages.
  3. Other .Net Languages don’t have modules, so you’re better off using shared members on a class definition.
  4. Modules aren’t OOP. Classes are. Use classes.

It’s already been proven that, internally, VB.Net modules compile to exactly the same code as a Class with shared methods. Further, the modules have been documented as a first class feature of VB.Net, the language, not some soon-to-be-deprecated nod to VB6 compatibility. And Modules CAN be accessed from other languages. So I’m not going to bother with any of those bits again.

Personally, I think in comes down to two simple concepts, syntactics and semantics.

The Syntactics

Syntactically, defining members in a Module allows them to be accessed without  qualifying the member with the module name. So, given this Module definition:

Public Module MyModule
   Public Shared Sub MyMethod()
      blah....
   End Sub
End Module

I can access the method MyMethod by simply invoking the name MyMethod(); I don’t have to qualify it, as in MyModule.MyMethod().

This is a minor issue, except that it effectively allows you to extend the VB language. You can add your own RIGHT() function or LEFT() function, etc. This can be a fantastic aid to code readability when used appropriately.

The Semantics

However, I believe the even bigger argument is semantics. A class, is, by its very definition, the definition of an object that can be instantiated. Even singleton classes can be instantiated at least once. But a class of shared methods is a class that has no reason to be instantiated. And that really isn’t a class, it’s just a set of loosely related, if even related at all, functions. And that is the definition of a Module!

Do you regularly create an integer type variable when what you really need is a DATE? Then why collect a bunch of shared functions in a class when a module is specifically intended for such purposes?

Discoverability

The only rational I can come up with is discoverability. Forcing developers to prefix shared methods with the class name provides a means (through Intellisense) of discovering the capabilities of that class. But, you can optionally prefix module members in exactly the same way, so again, shouldn’t we be using the features of the language as they’re intended?

Why Shared Members at all?

Given this, what benefit is there of using shared members at all?  I’ve seen a few examples for defining singleton objects where you retrieve the single instance via a shared member of the class. That certainly makes logical sense, but from a coding perspective, it seems ugly to me. Why ask the class for the single available instance of itself? Shouldn’t you ask something else for that instance? It also makes for some odd-reading code:

Dim TheOneInstance = MySingletonClass.GetTheOneInstance

And other than singletons, what other purpose is there for shared members?

(UPDATE 10/29/08: After further experiments and reading, it turns out that, as far as I can tell, the ONLY way to truly get a singleton object is to use a shared method within the object itself. Nasty, but that appears to be the only way to do it).

I know the .NET framework uses them extensively, but are they used effectively?

For example, take the String class. It exposes quite a few shared members, such as Compare and Copy. But in practice, using those shared members doesn’t quite make sense. If I’m comparing two strings, the object-oriented thinker in me naturally gravitates to:

If OneString.Compare(OtherString) Then

Not

If String.Compare(OneString, OtherString) then

The bottom line is, if I’m comparing two strings or copying a string, I’ll always be working with an instance of a string, so why shouldn’t those methods be instance methods and not shared methods?

I suppose String.Format() is a passable example, but even that would seem to make more sense as:

dim x = "Insert a parameter here {0}".Format(Arg0)

Do you have a good use for shared methods that you’d like to, uh, share?

Let me know!