Sunday, March 30, 2008

Code Review: Removing the need for FoxTools

In a recent code compile of a client's application, I noticed some immediate compilation warnings pop up. The application ran fine but the errors were related to functions that exist in the ever popular FOXTOOLS library.

As some background, FoxTools is a FoxPro API library that provide a wide variety of functions (mostly found in the Windows DLL) that, at one point, were not available in FoxPro (going back as far as FoxPro 2.6). Since then, every edition of Visual FoxPro has introduced new functions replacing the need for using Foxtools (to give you an idea about some of the functions that exist in the FOXTOOLS.FLL, check out this post but you can also see it by opening FOXTOOLS.CHM in your VFP Home folder).

Now, when some of the functions were added into VFP, they were added using the same syntax as in the library, thereby requiring no code changes (yeah!). However, others were renamed to be more VFP like.  The one that immediately comes to mind is GETFILEVERSION() and AGETFILEVERSION (the native VFP function).

Most VFP array functions all accept the array as the first parameter (examples: ASCAN(arrayname,search), APRINTERS(arryname), ADIR(arrayname,skeleton). The FoxTools.fll GETFILEVERSION() function passed the array as the second parameter:

DIMENSION la(1)
IF GETFILEVERSION("MyAPP.EXE",@la)>0

ENDIF

The VFP native function is much more standardized:
IF AGETFILEVERSION(la,"MYAPP.EXE")>0

ENDIF

So it's a one character change - (not necessarily trivial if you have a lot of updates to make) - pretty straightforward.

But the code I came across used two of the other FoxTools functions that many developers like to use that have been upgraded in recent versions of FoxPro: WORDS() and WORDNUM().

From FoxTools, WORDS( ) returns the number of words in a particular string and includes a second parameter for the delimiters available. WORDNUM() returns the actual word requested. Example (and yes, note there is no space after the first comma).

lcText = "The name is Bond,James Bond."
? WORDS(lcText)

returns 5. Wait, you say, there are actually 6 words in there. Well, by default, WORDS() only treats spaces and tabs as delimiters so it misses that comma. So let's do:

? WORDS(lcText,CHR(9)+" ,")

With the second parameter, all of the characters that would delimiter a word are passed. This can go one step further with WORDNUM.

? WORDNUM(lcText,4)

returns "Bond,James" whereas:

? WORDNUM(lcText,4,CHR(9)+" ,")

returns simply "Bond"

The VFP functions are similar and perhaps make the code a little more readable (a subjective distinction to be sure). Otherwise, the functions are identical:

? GETWORDCOUNT(lcText) && Returns 4
? GETWORDCOUNT(lcText,CHR(9)+" ,") && Returns 5

? GETWORDNUM(lcText,4,CHR(9)+" ,") && Returns "Bond"

A quick note - the delimiter parameter is simply a list of characters are used. I put the CHR(9) in there so you can see the "tab" instead of the other chars. A great opportunity to use the #DEFINE statement.

#DEFINE _worddelims CHR(9)+" ,"

Changing the WORDS and WORDNUM functions in the code to the VFP internal functions removed the annoying compile time errors (a nit-picky issue to be sure) but also can make the code a little easier to read for VFP developers who may not be familiar with the Foxtools functions.

Why Get Rid of FoxTools?

So is this really necessary? After all, if Foxtools is available - why not use it?

1. Fewer files to distribute and variables to deal with. If you can do it from within VFP, why not? In addition, if you forget to say SET LIBRARY TO - you get errors (ugh!).

2. Performance. OK - this may be squabbling over tenths of seconds - but in my quick test (using War and Peace as the great example), the FoxTools functions were slower than the VFP counterparts. Not by much (less than a tenth of a second) but still there.

(Aside: for a great article on neat tricks with VFP and War and Peace, I point you to Steven Black's  much reprinted article on text)

These functions were added to FoxPro with version 7 - so unless you're still working in VFP 6, there is no good reason - or is there?

Ok, there may be one argument for keeping Foxtools around in the above scenario - variable length.

WORDS and WORDNUM are not as big as GETWORDCOUNT() and GETWORDNUM(). Is that a real reason? I don't think so but you might. 

Do you have any others?

Thursday, March 13, 2008

Flock Wins

Flock Browser - Flock Wins Web Award at SXSW Conference | Flock

I'm not sure how many people are aware of Flock but after using version 1.1 for the past few weeks, I'm hooked.  So Congrats on winning the web award at SXSW.

Yes - Flock is simply Firefox with a bunch of extensions and some additional toolbars but I do find it makes the web browsing experience a much better place. I know I typically use this blog for VFP and FoxPro items but I figure, if you're using a tool that you find useful, share it.

Some key takeaways that I find extremely valuable:
1. Built-in blogging support (as I'm doing now)
2. My World - which is just like having your own home page on a portal, only it integrates with your RSS feeds, News stories, Twitter and others.
3. Built-in email. While I typically have a web email page open at all times, the email link lights up to tell me when I've got new email.
4. The People sidebar - full access to Twitter, Facebook and other services.
5. Delicious built in.

Now some things I don't use:
it's RSS feeds - I'm still using Newsgator.
Media bar - just not that into YouTube or Flickr on a daily basis

And I wish it would allow additional accounts and services but then that might be an integration nightmare.

That said, there is only one extension I always install - the HTML Validator (you can find it under Firefox extensions). This is one useful tool for any one who does any kind of web work - it identifies all of the potential "offs" - such as missing tags, warnings for improper or proprietary (non-standard) tags and more.

Flock - if you're using Firefox, check it out. PLUS it gives you one more browser that you can test your site's compatibility with.

Sunday, March 09, 2008

Working with VFPX and CodePlex Source Control

Many developers who want to get involved with VFPX face a bit of a challenge, especially if they've never used Source Control. (What!?!?! You've never used source control)

When I started working on the Code Analyst, I used the SCCI provider within VFP but it always conflicted with my own SSC tool (SourceOffSite). There's also a TeamPrise Explorer or one built directly into Visual Studio but within VFP, I wanted something a little more, um, basic.

So there's a CodePlex SC command line click, that's really easy to work with.  I'm still experimenting with it - but in the end, I think it may be the way to go. One thing to realize though is that it will give you FULL access to the VFPX project, which includes LOTS of sub-projects. I only wanted to work on the Code Analyst but as a result, I ended up getting everything. I don't think that's a bad thing because it makes it easier to really appreciate the entire scope of the VFPX project. After all, this IS the future of Visual FoxPro.

It's useful to read the post below because as it explains the Command Line client works in a different mode than what you may be used to with Visual Source Safe ( I believe however it's closer in nature to other approaches).  From the introduction on the site, Source Safe and Team System operate on a "checkout-edit-checkin" approach whereas CodePlex client works in a "edit-merge-commit" approach. For VFP developers, this might actually work out better.

My big problem with using Visual Studio is that for some reason, it's gotten confused and thinks that SourceSafe is my ONLY client and thus I can't connect to the CodePlex team system. In addition, if you're pretty much living in VFP, why do you really want a 400 MB client (for the Team Explorer ALONE) when you're used to working with the relatively small development IDE of VFP (150 MB).

CodePlex Source Control Client - Home

To maintain compatibility with the "checkin/checkout" style approach, you may want to run DO HOME()+"SCCTEXT" WITH <filename> every now and then to make sure the SCA, VCA,MNA files are running, although for the record, I noticed that some of the projects do NOT include those pieces in there.

What tools are you using for working with CodePlex? If there's enough need, it might be worthwhile to create a little VFP wrapper for this little gem.

Friday, March 07, 2008

The Top Mistake of public speaking

Craig has a fun little post about his experience speaking at MS Launch last week.
"I suddenly relapsed into making the fundamental public speaking mistake: I thought it was about me!"

TIP: The Top Mistake of public speaking

Tuesday, March 04, 2008

Are you ready to Rockx?

Doug Hennig gives some of the latest news about FoxRockx , along with showcasing the splashy new logo.

At 99$ a year online and only $138 for printed and online, definitely a bargain for news and articles by some of the best writers in the community.

Can't wait for the web site to be live!

Browser Wars...revisited?

Remember the Browser wars? Jeez, back then, it really did seem like IE was the only tool that got new things done on it. (update: another interesting post back from 2003 on the whole item from Eric Sink(

Nowadays, I've even foregone FireFox in favor of Flock

When I see a site that only supports IE, I don't think of it as an advanced site but rather a site where the homework wasn't done properly. I still have a few sites like that and I hate them.

But why Flock?
a) instant blogging
b) instant delicious
c) built in twitter/social networking
d) great way to ensure a site's compatibility
e) email-link (with 1.1)
f) My World home page

I know it has RSS Feed support but I rely on Newsgator for that.

What's really nice these days is that it isn't a Browser war. IE still owns 60% (updated - thanks Sergey80%) of the Browser world but these days, it's not about killing another browser, it's simply about a better experience. I love the fact that I can boot with Ubuntu from CD and everything worked perfectly. Or I can run my browsers in a variety of environments and it all works seamlessly. I still use IE for a variety of things but it's more to confirm compatibility. It isn't such a bad (Net) world after all.

Turning 50

No....not me (yet!)...but the FoxShow just turned 50!

After 49 not so regular episodes starting in March of 2005, we've hit 50 with hopefully the last of the rushed episodes (rootkit, rebuild, repeat as I mentioned earlier) but also with a great interview with Alan Stevens. (I had no idea he had worked with the JFAST project among others). We spoke about FoxPro, DotNet, VFPX, TDD among other things.  We had done the interview in the middle of February but because of the woes mentioned earlier, it was impossible to get a full episode out so now it's there.

Unfortunately, it was a rushed episode with very little other commentary but it still comes in around 40 minutes. Hope you enjoy.

Monday, March 03, 2008

Install, Upgrade, Activate ....and repeat

About two weeks ago, my laptop was a target of a rootkit attack and even though I got it completely cleaned up, everythihng on the machine just seemed sluggish and definitely not "work-worthy" (it was taking upwards of 2 hours to produce a 5 minute video).

As a result, I decided this weekend to rebuild it from scratch ( a good practice especially on notebooks every now and then), using the original Dell CD (which was XP Home SP1). I then upgraded to SP2 and everything was good. I was going about upgrading to the Pro edition. OK - I have to activate Windows. Did that. I saw the lovely Windows hillside and ....nothing else. Reboot. You have to activate Windows....saw the lovely Windows hillside and ...nothing. Reboot. You have to activate Windows. I'm sorry you have to CALL Microsoft to activate Windows. What a joy that is. It's all automated but still what a painful experience.

Even after that, Windows is already activated but still nothing.

Argh! Let's retry this again. This time, I'll just reformat with my Windows XP Pro. You must activate Windows but this time, I had no network drivers loaded so I have to contact the automated service. Except...no installation ID appeared. Come on!

Let's try this one more time (still awaiting results) before I just say screw it - finally - after having to reformat the drive one more time, it comes up. Wow - there goes an entire weekend. What can I say except - not impressed.

For those of you who have been looking for the latest FoxShow, this is the main reason why I haven't been able to get another one up in February. I have a great interview with Alan Stevens on tap though so if this works, I'm going to get it out today.

So while I was doing this, I immediately thought "is there an open source (or free) version of a Virtual PC-type machine" that would let me a) better evaluate Linux (Ubuntu) and b) let me retain my Windows valid EULA by running it in a virtualized PC. That leaves WINE out, but what are the thoughts on VMWare (free), VirtualBox or QEMU?

Anything that works really well for the VFP developer?