So it recently came to my attention that I'm a declare whore. There are some who are surprised by my proclivity for using declares at the drop of the hat, and I feel that I could probably shed some light on this subject.
First off, I'm a Win32 API programmer by trade, and have been for many years now. I started my journey down the pure Win32 path when Windows 95 was released and that's where I have the most training. So when a problem comes up on Windows, my immediate reaction is "how would I solve this using Win32 APIs?" And since you can do just about anything Win32 API related in RB using declares, it's the first solution that pops out for me (even if there's an easier way to do it in RB). So once I get ready to answer a question, I have to step back and figure out if there's a more RB-specific way to do it. And many, many times there is. But if it's at all sketchy, I just fall back on good old Win32 since that's what I know and love and I know it can get the job done.
So the second reason why I push declares a lot is because I push the envelope in my own projects. Part of my job is to come up with new things to put into REALbasic, and those new things will be using the Win32 APIs. So a lot of times, I spend a good part of my day architecting solutions using declares as a proof of concept for various things. For instance, the StatusBar that's in the WFS was made as a technology preview for adding it to the RB IDE. Because I spend so much time using RB to garner new functionality that the framework doesn't expose, I'm very used to using that as a way to solve problems. Goes back to the "initial reaction" thing from before.
The final reason, which is the most important one (to me anyways) is: I *am* using REALbasic. Declares are an integral part of the REALbasic toolkit, and anyone who shuns them on a whim is missing out on a ton of raw power. Using declares, you can do *anything* you want. Don't like large parts of the RB framework? Fine! Rewrite it using declares. It's certainly possible -- there are very few things you can't do using pure RB code (including declares) and we're continually working on the product to ensure that you will be able to do these things (eg: new data types, structures, soft declares etc). So why *not* use declares to solve a problem? The only valid technical reason is because they're not (generally) cross platform. And while this is certainly true, that doesn't mean it's not helping you solve your problem. It just means that your solution isn't complete.
So yeah, I do reach for declares frequently. It's a lot of fun to show people that they really can accomplish anything they need to in REALbasic, and so I doubt I'll stop using them any time soon. But just because I tend to reach for my Win32 APIs doesn't mean that you have to do that yourself. I push the envelope, which is something most people don't do. For most people's applications, they'll never need to touch declares or will only have to do so very infrequently. For instance, the RB IDE itself doesn't make use of declares nearly as much as you might think it does. I would say that declares and their usage make up under 1% of the entire code base for the whole IDE. And that's a professional application, not a trivial one.
So if you're scared of OS API calls and think that REALbasic isn't for you because you see me spouting off about all the neat declare stuff you can do, fret not. Declares are simply a power tool which you can choose to use as you need it. They're sort of like a jackhammer. They're not that hard to use once you get the hang of them, and you can use them to do some amazingly powerful stuff, but they're not something you use every day.
I just happen to enjoy using a jackhammer to pound in nails, that's all. ;-)
The funny thing is because I use RB to BE platform agnostic, I tend to try and do things in RB before I reach for a declare.
And the more I can do this way the less I reach for a declare but, like you said, there are things that you cannot do in pure RB without declares.
Yeah, when x-platform is important to your application, declares should be pretty far down on the list of tools (but still something you should consider).
I do use them (as my recent conrtibution the the WSF can attest to) but I cringe every time I have to read the header files to decipher what type things really are (OS X and Windows)
Though don't stop looking at declares for cross-platform either! Declares *are* cross-platform, it's just the libraries that may not be (say, OS libs). But there are *tons* of public libraries out there that can do all sorts of powerful things - just take a gander at sourceforge.net. Many of these libraries can be easily compiled on all the platforms supported by Rb, and the declares you write into them are cross-platform.
And even when you are talking declares to system libraries, there are still cases where it makes sense to use them in cross-platform apps. Lots of the functionality in the system libraries exists on all the platforms, though you will have to write different declares for them.
You forgot the obligatory link.
http://www.declaresub.com/iDeclare/
My PDF Classes have to get detailed font information - much more detailed than the "yes, this font exists, and 'yourstring' is X pixels wide " that RB provides! I use declares to accomplish this. While the declares aren't the same across platforms, they are parallel enough that it isn't much trouble to write for several platforms.
Brady Asher et al
Been there done my fair share of that and yes, there are ways to get similar information that you need cross platform. Reading an audio CD on OS X and Windows is radically different and one doesn't require declares where the other does. Try almosat anything to do with an audio CD on Windows and get ready for declares, and an enhanced CD is guaranateed to require them on Windows.
Or reading he CD TOC information which OS X happens to provide very nicely in how it mounts the CD, and Windows .. well ... lets say the SCSI command set, iotcl and ASPI may become your best friends.
I would just be nice to accomplish a lot more without having to resort to them, but for now it beats the butt off writing it in C as a plugin :)
Declares beat C plugins only when you don't have to add a bunch supporting code... recently I found it easier to write a plugin for some IOKit.framework code I needed than to create all of those classes!
Over the past couple of years so much work has been done making declares more and more usable. I think it is great.
What really gets me excited is that this means more and more of the RB framework, rather than just the IDE, can be written in RB. I'm sure that has already started in some places.
It is always of fun for me to show people some pretty tricky stuff and pull up the curtain and show what it was developed in. I've shocked a lot of people, and driven plenty of RB license purchases that way...