Thursday, February 23, 2012

Some useful Pragma commands

The Real Studio mailing lists are always a source of lively discussions.  A recent thread started with a suggestion to allow commented code to retain its formatting for readability.  This brought up a long discussion about ways to disable code.

Disabling Code
Like many of you, when I need to disable a block of code I'm working on, I will select it in the code editor and then click the Comment button on the toolbar (or press Command-').  This loses the code formatting structure (indentation), which I never really considered an issue.

It turns out there is already a way to disable code and keep your formatting: use conditional compilation.

Although you may never have done it in this manner, code like this will disable everything within the #If/#Endif:

#If False Then
  Anything can go here, whether it is code or plain text.

  Dim count As String
  For i As Integer = 1 To 100
    count = count + Str(i)

#If commands are parsed before the compiler does its magic.  Since #If False is never true, these commands are stripped from your code before being sent to the compiler.

Of course, it is less convenient to disable code this way because you actually have to type in the commands.  A contextual "Wrap this" menu might be useful here.  I created a Feedback case for this: 20397

Errors and Warnings
The discussion brought up a couple other useful Pragmas: Warning and Error.  To be perfectly honest, I never noticed that these pragmas even existed!  It turns out they were added years ago (Real Studio 2008, according to the Language Reference).

Something that I do often is mark code that I need to go back to for some reason.  Typically, I add a comment at the top and put TODO in it with a description:

// TODO: Fix this nasty hack

I think that usage stems from my Visual Studio days.  I would then periodically search the project for TODO and would have a list of things I need to address.

It turns out you can get even better behavior using #Pragma Warning:

  #Pragma Warning "Update this code to use Menu.Clone."
  Dim selectedMenu As MenuItem
  selectedMenu = EditMenu.PopUp

Your project runs just fine, but when you Analyze Project (or Item), this warning is displayed in the Warnings List.  I really like this and will start making more use of it.

The related Error pragma generates a compile error:

#Pragma Error "Stopped the compile."

I haven't thought of a good use for this yet, but I'm sure someone can enlighten me!

Tuesday, February 21, 2012

Mountain Lion and GateKeeper

Last week, Apple surprisingly announced the next release of Mac OS X: Mountain Lion. They also officially dropped the "Mac" part, so it's actually: OS X Mountain Lion.

Not only did they announce Mountain Lion, they also made it available for members of the Mac Developer Program for testing.

Like everyone else, I was quite surprised to see a new version of OS X announced by Apple so soon after Lion, which was only just released in July 2011.  In fact, I only just upgraded my main Mac to Lion about a month ago!

With this progress comes questions and for Real Studio developers, some of those questions are about the new GateKeeper feature.

GateKeeper is a newish security feature that aims to prevent users from launching compromised applications.

In Mac OS X Lion, the first time you launch an application downloaded from the Internet, you are prompted with a warning:
This is called "File Quarantine" and was introduced in Mac OS X Leopard.

GateKeeper extends File Quarantine to do a few other things.  Essentially, GateKeeper really wants you to only run applications that have been digitally signed to ensure their authenticity.  Why?  Because if a signed application is hacked (to add malware, for example) or otherwise modified, then the signature is invalidated and OS X will not run the app.  A valid signature tells the user that this app has not been modified by anyone other than the original developer.

This is all controlled with a new System Preference containing three options:
  1. Run Mac App Store Apps only
  2. Run Mac App Store Apps and Apps that have been digitally signed
  3. Run any app

Option 3 is the same as things are now with Lion (and Snow Leopard and Leopard).  Option 2 is going to be the default with Mountain Lion.  Option 1 is for your parents.

A digitally signed application is an application that has been signed using a certificate provided by Apple to you.  So what does it mean for Real Studio developers?

If you are already submitting apps to the Mac App Store, then you are a member of the Mac Developer Program and can sign your applications using the certificate you already have.  The command-line tool (codesign, provided with Xcode) is used to sign your apps with your certificate using syntax like this:

codesign -f -s "3rd Party Mac Developer Application: Your Company Name" --entitlements entitlements.plist ""

You can start signing apps not submitted to the Mac App Store at any time; they will work fine in Lion, Snow Leopard and Leopard.

For those that are not members of the Mac Developer Program, you do not yet have a certificate to use.  According to John Gruber's post about Mountain Lion, Apple will not require you to pay to get a certificate.  But they have not yet specified what this free method will be, so we have to wait and see.  It is really in Apple's best interest to have the certificates be freely available, so I'm confident a free way to get them will appear soon.

GateKeeper Limitations
There has been much concern that GateKeeper will completely prevent some apps from running at all and that it gives Apple the ability to remotely "kill" applications.  Both of those concerns are false.

First, GateKeeper only runs when the app is first launched.  If the certificate is proven valid at that time, then the app will launch.  The certificate is not checked again.

Apple can certainly invalidate certificates, but that will only prevent the app from being run on someone else's Mac, someone who has not already run it.  Invalidating a certificate does not give Apple the ability to "kill" or remove previously installed applications.

Secondly, even with the most restrictive setting of "Mac App Store Applications only", you can still force an app to run by right-clicking on it and selecting Open.  This will display a warning that lets you override the restriction and run the application.  Again, you only have to this the first time you run the app.

Final Words
I hope this helps you understand GateKeeper a bit better.  And rest assured, the team at Real Software is investigating Mountain Lion further.  But due to NDA, we won't be able to comment on specifics until it is released.

Thursday, February 16, 2012

Strategies for Mobile Enterprise Development

In SD Times on January 30th, Larry O'Brien writes about Strategies for mobile enterprise development in his Code Watch column.

He talks about three different types of mobile apps: web-based, cross-platform and native.  What's the difference?  Web-based is as you might think: HTML5-based web application that can run on any device, including mobile.  Cross-platform apps are apps that use languages and/or tools that can also be used to create apps for other platforms, such as Mono with its MonoTouch and MonoDroid products or Corona.  And native is when you use the tools provided by the mobile device platform manufacturer, such as Xcode/Objective-C/Cocoa for iOS devices.

Larry talks a little about using MonoTouch for iOS app development and notes that it works well, even if you still have to use Xcode and learn a lot about Apple's Cocoa framework API.  Having looked at MonoTouch myself, I don't see the point.  Why bother to attempt to shoehorn Cocoa into C#, something it was never design to work with?  You might as well take the next step and use Objective-C.

But in the end, he suggests that "the wisest strategy for the majority of enterprises is to make their first mobile projects web-based." His reasons (risk management, speed and simplicity) make a lot of sense.

Risk Management
As Larry notes, there are risks when creating a native application for mobile devices.  After all, mobile devices are in their early stages and change is constant. Going with a web-based technology is more proven.

Here, mostly Larry is referring to the speed of development and deployment.  With a web application, you are already familiar with the technology.  Plus you can roll out changes quickly and easily.  With a native app, you typically have to submit it to a marketplace for review or use their enterprise tools to deploy it to your users.  Either way is less convenient and you probably won't get the level of control you want.

Because web apps won't have direct access to all the bells and whistles of the mobile platform, it forces you to simplify you app.  You can instead focus on what your customers really need, rather than waste time "chasing new platform features."

Keep in mind that Larry is discussing enterprise software here, not consumer software.  For consumer software, a native or cross-platform application is still your best option.  But for enterprise software, think web first.

Wednesday, February 15, 2012

How to be lazy, productive & successful

I came across this link on GeekWire, which offers some great tips on how to stay productive.  I think it applies to everyone, including software developers.  It's worth a quick read:

GeekWire: How to be lazy, productive & successful

Monday, February 13, 2012

Resources for Developers, Part 2

Last week I talked about some of the free resources that we offer to Real Studio developers. This week, I'd like to talk about some of our paid offerings.

Technical Support and Customer Service
We provide web-based and email support to all customers that have a current (not expired) Real Studio Profesional, Enterprise, Web, or trial license. Simply log into your account at our website and visit our Technical Support webform. If you have an Enterprise license, you automatically receive our highest support plan, Premier Priority Support.

If you have a specific question about how to use Real Studio or what level of support you are eligible for, you can send an email to Customer Service at any time:

As I'm sure you know, Real Studio is sold using a renewal model. With a current license, you get all updates released during your renewal period, access to technical support, the ability to file Feedback cases and the ability to join the beta program.

Now of course, you do not have to keep your license current; the version of Real Studio that you are currently using will continue to work even if your license expires. But we really feel that the best way to get the most out of Real Studio is to keep your license current.

As a development tool, Real Studio is a complex project. It is constantly evolving and improving and if your license expires you do not get access to these improvements. If you haven't lately, check out the What's New in Real Studio page in the Documentation Wiki. It details all the new features and bug fixes implemented in each release for the past two years.

We are particularly proud of the Cocoa support progress that was made in Real Studio 2011 Release 4. If you create Mac applications, you owe it to yourself to check it out!

Another benefit of a current license is that you can file Feedback cases using the Feedback application. Do you have a suggestion for a new feature? Have you found a bug? Either way, the best way to let us know is to file a Feedback case. All feedback gets reviewed by someone on the team. I'd also like to point out that historically, bugs that are submitted with an example project demonstrating the bug have a much higher fix rate. Since you are all developers, I'm sure you know how much easier it is for you to fix a bug that you can replicate. It's the same thing for us.

The last benefit of a current license that I want to mention is the Beta Program. If you have a current license, you are eligible to join the beta program, which gives you early access to the next release so that you can help us make it better. To join the Beta Program, sign into your account on the Real Software web site, choose My Account and then choose Beta Program.

As a Beta Program member, you get to see what it is we are working on before it is released. This can help you better plan your projects for the future. At some point, members of the Beta Program will get to see and test the new IDE that's been in development for over a year. This alone might be reason enough for you to make sure your license is current. And since beta testers are expected to test the beta with their projects, we get the benefit of having more people testing Real Studio. The Beta Program really is win-win!

Developer Referrals Program
Did you know that there is quite a bit of Real Studio consulting work looking to get done? I should know, I did full-time Real Studio consulting for more than four years before I joined Real Software. And I'm not the only one. There are a lot of people out there that are looking to hire Real Studio developers to create their software.

If you join the Developer Referrals Program, you get access to people and businesses that contact us looking for Real Studio developers.

Ask Me
Again, I'd like to remind you that you can just ask me.  Whether you are evaluating Real Studio and have some questions, need some help trying to write up a Feedback case, are considering upgrading from an older version, have a question about consulting or just have a general question about Real Studio, I'd love to hear from you:

Friday, February 10, 2012

Real Studio and 64-bit Linux

Although Real Studio is not a 64-bit application (we're working on it), it works just fine on 64-bit versions of Mac OS X (Snow Leopard and Lion) and Windows (Vista and 7).  This is because both of those operating systems include the appropriate libraries for backwards compatibility with 32-bit applications.

With Linux, it is not as straightforward.  Most 64-bit Linux distributions do not include the 32-bit compatibility layer by default, which means Real Studio or apps created with it will not work.

The way to fix this varies from distribution to distribution, so it's a challenge for us to be able to provide guidance when this occurs.  Practically, it is best if you just try to stick with a 32-bit version of Linux for now.  I recommend Ubuntu 10.10 32-bit.

But if you need to use a 64-bit Linux, the first thing you want to do is make sure that these 32-bit compatibility libraries have been installed.  On Ubuntu (and other Debian-based versions), this Terminal command usually works:

# sudo apt-get install ia32-libs

You should also be able to do this using the Synaptic Package Manager (search for ia32):

Depending on the version of Linux, you may also need to do some other things in order to get the installers for Real Studio and Feedback to run.

Check out Christian Schmitz's post How to install Real Studio on 64 bit Linux for some additional tips.

Christian notes that he is still having trouble getting 32-bit versions of libwebkit and libgtkhtml to install, which breaks HtmlViewer.  I've seen the same thing.  Apparently, the install of ia32-libs does not include these libraries.  I ran into this with a client a year or so ago and I never found a way to get these libraries to installed on Ubuntu, so if there are any Linux experts out there with some suggestions, please leave a comment.

Thursday, February 9, 2012

Structure alignment

One of the great things about working in the Real Studio environment is that a lot of the nitty gritty details are handled for you, and if you ever need to branch outside this environment you can with declares. However, one very important detail needs attention if you deal with declares, especially those that accept a Structure as a parameter.

By default Realbasic packs Structures, which means the Structure doesn't take up any more space then what you defined. For example, take this structure:

This is an example of a packed Structure, where the two members take up a total of 5 bytes. That's great if this Structure never leaves Realbasic land, but if you plan on using it in a declare for example, that's when you'll need to worry about Structure alignment. Depending on how the shared library was built, the Structure alignment could vary, but the common alignment strategy is to align to the largest integral type or to the natural alignment (i.e. 4-bytes for 32-bit or 8-bytes for 64-bit), whichever is less. On Windows you'll find that their OS APIs always align to the largest integral type. Here's an example of the difference:
struct {
     int a;    // RB Integer (4-bytes)
     double b; // RB Double (8-bytes)
     short c;  // RB Int16 (2-bytes)

The default Structure alignment would typically be 4-bytes if calling a 32-bit OS API on OS X and Linux so the Structure above would take up 16 bytes. This is how it looks in memory:

If calling a Windows OS API the Structure alignment would be aligned to the largest integral type, and in this case we have a double which is an 8-byte integral so the Structure above would take up 24 bytes. This is how it looks in memory:

Notice the automatic padding that happens, wouldn't it be nice if Realbasic padded the Structures too? Well it can, if you specify the StructureAlignment attribute on the Structure. The only thing you need to make sure of is that the alignment strategy that you want to use as Realbasic does not assume anything. To specify the Structure alignment just right-click on the Structure to bring up the Attributes editor and enter the StructureAlignment.

Now our Structure will be aligned on a 4-byte boundary, which means the first member is padded with 3 extra bytes:

As you can see, the Structure alignment strategy changes the memory layout of the Structure so it's very important to understand the alignment strategy of the shared library that you are calling, otherwise you can run into some random memory corruption issues.

Tuesday, February 7, 2012

Resources for Developers, Part 1

One of my goals as Developer Evangelist is to ensure that everyone can use Real Studio as effectively as possible. I'd like to cover the resources we provide to you. In Part 1, I am covering the free resources that are available to all Real Studio developers.

Obviously if you're reading this post you know about our blog. But take a moment to make sure you have subscribed to the RSS feed with your favorite news reader. I use Google Reader on my Mac and Reeder on my iPhone and iPad.

Blog RSS Feed:

All our documentation currently resides on our Documentation Wiki:

The benefit of a wiki is that we can more easily update it.  Being web-based, you can also access it easily on your mobile devices.

For times when a local copy is more convenient, each release of Real Studio incudes a local copy of the wiki.  By default when you click on one of the Help topics in the Help menu of the IDE, you get the web-based help in the IDE's documentation viewer.  If you would rather see the local help, you can hold down Option (Mac-only) while clicking the menu.  There is also a Preference in the General section to select which version of the documentation you want to see by default.

Updating documentation is one of my primary responsibilities and you should see many changes in the coming weeks and months.

I realize that the wiki is not as usable as some people might like, but it still has a lot of useful content with more on the way.  I will be working hard to make the documentation as good as it can be.  If you do find problems with the documentation or have suggestions for improvement, please file a Feedback case on it the same as you would for Real Studio itself.

Example Projects
Many people prefer to learn from example.  Fortunately, Real Studio comes with a lot of example projects.  You can view all of these in the New Project window when Real Studio launches.  Expand the Examples item in the Listbox to quickly open any example project.

In the coming weeks, I wil be reviewing and updating all the example projects.  I also expect to add several new examples.  If you do find problems with the examples or have suggestions for new examples, please file a Feedback case the same as you would for Real Studio itself.

Community Discussion
Real Software has both discussion forums and a mailing list for our customers to communicate with each other. Personally, I prefer to use discussion forums rather than mailing lists, but we've kept both around because people often prefer one over the other.

You can visit the forums here:

You can subscribe to the mailing list here:

I will remind you that the forums and mailing lists are for our customers to communicate with each other. Although Real Studio employees often visit and reply to posts in both these areas, they are not official support channels. Personally, I try to read most forum and mailing lists posts, but I tend to post more on the forums than I do on the mailing lists.

Next Time
Next week, in Part 2, I will talk about our paid offerings that can enhance your Real Studio experience.

In the meantime, I'd like to point out that you can just ask me.  If you are evaluating Real Studio and have some questions, ask me. If you have a question about Real Studio, but don't think it's appropriate for the forums or NUG, ask me. Maybe I'll turn the answer into a blog post! If you need some help writing up a Feedback case, ask me. If you have an older version of Real Studio and are considering renewing or upgrading, ask me. If you have questions about consulting, ask me.

Wednesday, February 1, 2012

Hello from Paul Lefebvre

Hello fellow Real Studio developers! My name is Paul Lefebvre and I am the newest member of the Real Software team, taking on the role of Developer Evangelist.

In this position I will be responsible for many things that relate to educating prospective and existing customers about the best ways to get the most out of Real Studio. In particular, I will be focusing on documentation, tutorials, example projects, webinars, blogging, training and social web coverage.

I've been using Real Studio for over 10 years and have been programming professionally for nearly 20 years using other tools such as PowerBuilder, C#, VB.NET and Java.

I am extremely excited to be joining the Real Software team!

I love hearing from fellow Real Studio developers, so if you have any suggestions on how I can help you make better use of Real Studio, send me an email: