As you start to code all day, every day, you start to develop your own set of guidelines. I’d call them rules, but since I break them often enough I have to call them guidelines. Since I deal with my own code and Other Peoples Code (OPC) on a regular basis here are my guidelines (in no particular order):
- Name any control you reference in code. It needs to make sense to you. If you have a bunch of Pushbutton1, Pushbutton2, etc. pushbuttons you are causing yourself grief in the long run. You’re coding not only for right now, but for 5 years from now when you’re not intimately familiar with your UI and you want to make a change or fix a bug (or hand it off to a consultant).
- If you find yourself copy/pasting code over and over again you should think about a global method or perhaps a subclass. I’m talking about the MessageDialog alerts, the ComboBox helper code, etc. The reason this is a problem is that if you have the same code all over the place and you have to change it, you then have to change it everywhere. The chances of missing one hase big bug implications and your clients/customers may not appreciate the bug. This is called, by the way, refactoring and it’s not a bad thing to do.
- Big, huge, monolithic methods/functions are not good. My general rule is that if my method is over a screen length I start looking at ways to break it up into smaller chunks. This makes it easier to debug too since the runtime exception doesn’t have line numbers on where a bug occurred. All it can give you is what the error is and where it occurred (and even sometimes that’s not reliable).
- Name your variables something that make sense to you. You need to come up with your own guidelines, but the reason is the same as naming your controls. You should, at a glance have some level of understanding of what the variable is for. I don’t name loop variables (i, j, k, x, y, etc) unless I have nested loops. Some would argue that prefixing your variables is a dumb idea because RB is very strongly typecast and if you change the type you then have to change the prefix. Um…sure…that’s what global search and replace is for. But I can tell at a glance what type the variable is.
- Name your methods/functions something that make sense. Same reasons as above. If you can’t figure it out at a glance what it does, then you might need to rename it.
- One that keeps haunting me (in other words I haven’t always learned the lesson on this) is to use a thread whenever there’s a tight code loop. It always seems that during testing I have far less data than I will in real life so that tight loop that only takes a blink during development takes seconds in production and causes the app to ‘freeze’. Threads are a natural way to solve that problem. I urge you to not use refresh statements in your loops – instead use a thread. Of course threads aren’t perfect in that you then have to worry about how you update UI but if you have the Thread in the window you’re generally pretty safe.
- Test your cross-platform apps on each platform. Don’t assume that your Mac OS X application created in RB will look good on Windows and vice versa. Trust me on this one. Depending upon what you’re doing, Windows can be hugely different performance-wise than the Mac and Linux. Double-buffering is standard on Mac OS X and Linux but NOT on Windows so that really great looking custom control on Mac/Linux looks just awful on Windows because of flickering.
- Project organization is important. As your project gets bigger and more complicated having the big monolithic list of objects becomes harder to find things. I generally start with Application, BKS, Others, and Assets folders in my projects and put everything in those folders. The assets folder is icons and any other graphics for the projects. The application folder has all app object, all the windows and application specific objects. The BKS folder contains my own toolset of classes, subclasses, extensions, etc that I’ve written and use in most projects (I generally try to retain rights to any code in this folder). In the others folder is my toolset of objects that are from others and I don’t claim that I wrote. Some of these are encrypted and others are not. Keeping your project tidy is a good thing.
- Code first for functionality and once it’s working you can test for efficiency. I’ve found that some things I thought would be slow weren’t and some things I thought would be ok weren’t. Get it working first and THEN worry about it.
Those are mine off the top of my head. What guidelines would you share with someone new to coding and/or REALbasic?
Interesting little blurb at http://blogs.barrons.com/techtraderdaily/2010/05/26/apple-will-steve-ballmer-show-up-at-the-wwdc-keynote/ about Microsoft presenting at Apple’s World Wide Developer Conference (otherwise known as WWDC) to show off Visual Studio for iPad/iPhone and general Mac OS X development.
Geeze. How many levels of wrong is this rumor? You think Apple is going to trust Microsoft with the keys to their iPhone/iPad kingdom? I don’t think so. Apple has worked too hard building xCode and Cocoa Touch to let a 3rd party develop for iPhone/iPad. If this does happen, then Apple might as well give Adobe a call and let them know they can restart their iPhone/iPad programs too. And we all know where that feud isn’t over yet.
Where this might make sense is desktop applications. Microsoft, while doing all that work to write Microsoft Office for the Mac in Cocoa, wrote their own Cocoa libraries and other Mac GUI editors and put it into Visual Studio. Seems like an awful lot of work with minimal gain for Microsoft unless they’ve decided to make a push in REAL Software’s corner. They certainly have the knowledge and resources to do such a product.
While I don’t think this rumor has legs it does make you think. No doubt Microsoft is feeling the pinch of developers learning Cocoa which does nothing for Microsoft. If they developed a cross-platform Visual Studio it stems the bleeding because now developers don’t have an either/or decision to make. Learning a new development tool and frameworks suck and letting all those Windows developers develop for Mac and Windows using their tool keeps Microsoft in the game. It doesn’t help them with iPhone/iPad development (now) but in five years who knows. If it does happen it will generate some serious buzz which is something Microsoft wants (needs?).
What does this do, if true, to our favorite development tools company located in Austin? I don’t think it would be good news.
We (BKeeney Software) updated our REALbasic Training Videos today with H.264 video as the default rather than Flash. This allows access for iPad and iPhone users.
We have over a hundred videos and around 20 hours of training videos. Our Journal Entry project, a simply diary application, goes through the process of creating a REALbasic database application from start to finish. While we do all of the development on Mac OS X, we regularly go into Windows and Linux and explore the differences between controls and how to workaround those differences.
If you’ve ever wanted to see how other people use REALbasic, this is an excellent opportunity. We have around two hours of free video (with registration). Subscriptions are available and if you’re a student or educator, contact us to get up to 40% off full price. ARBP paid members can get a 20% discount.
So far we’ve been getting excellent reviews!
[Updated] Part of my motivation to moving to H.264 was to view the videos on my iPad. The iPad is a really good medium for video training because it can run beside the desktop/laptop computer and you can do the same things in REALbasic while I’m showing it to you in the video. Video on the iPad is gorgeous!
I don’t venture into Windows-land very often but I ran across a couple of articles today that gave me cause for concern.
http://www.microsoft.com/presspass/press/2009/jul09/07-24statement.mspx is talking about how European users might get to choose which browser is used by their machine.
The second is http://www.aeroxp.org/2009/03/ie8-functionally-removable/ is about how Internet Explorer is functionally removable from Windows 7. The article states that the procedure only removes the Internet Explorer executable and not all of the supporting libraries so it shouldn’t be much of a concern to RB developers. Or is it?
During the ARBP chat last week, REAL Software president and CEO, Geoff Perlman stated that he was unaware of any Windows 7 incompatibilities. No one asked specifically about what happens if the user uninstalls Internet Explorer in Windows 7 or a European users chooses FireFox, Safari, Chrome or Opera as their web browser rather than Internet Explorer.
Will the HTMLviewer still work? I think it will because it’s dependent upon the supporting libraries but it’s a question that I’d like reassurance on from RS. But perhaps the real question is whether the HTMLviewer.IsAvailable is an adequate check and it jumps into the libraries or if it’s simply a check on what version of Windows you’re running? After all, if you’re using Windows XP or Vista you HAVE TO HAVE Internet Explorer. But it seems like Windows 7 might be changing that rule.
I’ve been particular critical of the HTMLviewer control over the past several years. Yes, RS has worked some of the bugs out but it’s still not as stable as I’d like to see it. My biggest beef is that it’s not using the same supporting libraries on Windows, Linux and Mac OS X. On Mac OS X it uses WebKit. On Windows it uses Internet Explorer and on Linux it uses GTK. This leads to platform incompatibilities, instabilities and downright bugs between the platforms.
If you didn’t read the release notes for RB 2009 R3 you’ll find that RS isn’t shipping REALbasic with the Language Reference for Linux because HTMLviewer has too many issues so Linux users have to rely upon a PDF version. Ouch.
REALbasic’s strength is cross-platform so why not use a cross-platform web browser as the basis for HTMLviewer? Use Gecko (Firefox) or Webkit (Safari and Google’s Chrome)! We might need it for Windows 7 which is being released in October?
Thoughts?
More info on Cocotron can be found at http://www.cocotron.org/. Their stated goal is:
The purpose of the project is to provide an easy to use cross-platform solution for Objective-C development.
There’s a blog post at Mac Daddy World at http://macdaddyworld.com/2008/10/27/adventures-in-cocotron/
Now I can say with some certainty that xCode and Objective C isn’t as easy to learn and use as REALbasic but a programming language is a programming language and we can all learn “one more” language and IDE. Certainly one of the truths about REALbasic is that all of it’s controls are a compromise and not as feature rich as their .NET and Cocoa brethren. Cocoatron has the potential of changing some minds of people who might be looking at REALbasic and go with Cocoa if controls on both platforms are nearly identical.
It seems that Cocotron isn’t an officially supported Apple product but that might not matter in the long run if enough developers start using it. Stranger things have happened in other platforms where something becomes a de-facto standard. It wouldn’t surprise me either that Apple has a skunkworks project that does this as well so it’s possible that at any point Apple could go, “Because of demand, here’s the official Cocoa for Windows frameworks.”
One major issue I see with Cocotron is that you can only do code development on the Mac. That is certainly one of RB’s strengths where you can run on Windows, Linux or Macintosh OS X and compile and debug for the other platforms (Pro editions only).
One thing that is similar to RB is that it looks like you can debug your Windows app while running in the xCode IDE. I wonder how fast or slow that is? I might just fire up xCode this weekend.
Your thoughts?