Learning Smart Pascal, a primer
One of the questions I get the most when it comes to Smart Pascal and Smart Mobile Studio, is “how do I learn the language?”. The short answer to this question is, if you know Delphi or Freepascal, that you already know it.
Linguistically Smart Pascal is more or less identical to ordinary Object Pascal (Delphi and FreePascal). So as a Delphi programmer you can jump straight into it and start coding – as long as you remember the following:
- You don’t need to postfix your event declarations with “of object”
- Interfaces are supported by TObject
- Threads are written in separate units (web workers)
- Sets are not supported, but easily emulated
- Generics is not supported
That really is everything you need to know, taking for granted naturally -that you already know Delphi or Freepascal and are not afraid to write code. I must admit that I did not expect people to be so dependent on the visual designer as they clearly are – but linguistically Smart Pascal is just “Delphi with a twist”. I don’t mean anything negative about that, I was just surprised that so many programmers are like fish out of water when you remove the visual aids. I rarely use the visual designer, except for form layout. Everything else is written in code, class by class, hierarchy by hierarchy.
The single most powerful difference is probably array operations. Under Delphi you are used to TList, TObjectList and lately, generics (not to mention stacks and queues). Under Smart Pascal arrays are more evolved and replaces these concepts. All arrays, regardless of type, support a wide range of operations. Once you understand how flexible and fast this is – it will change how you write your code profoundly. You might even end up missing these features in Delphi and implement a helper for it (like I have done).
Procedure TForm1.playValues; var mItems: Array of Variant; begin mItems.add(1200); mItems.add('this is a string'); mItems.add(12.5); mItems.push(19.22); writeln(mItems.pop); end;
Check out Array Operations on wikipedia for a list of methods supported by all arrays.
Where to begin
The reason we did not supply documentation is twofold: when I started the project I designed it to be a Delphi only tool, meaning that you were supposed to simply write ordinary Delphi (hence the link to Delphi Basics in the application). SMS was initially a utility by Delphi programmers for Delphi programmers. Sadly, Embarcadero has made it perfectly clear that they regard us as a threat rather than friends so we had no choice but to abandon VCL emulation and focus on our own, proprietary run-time library.
This attitude still baffles me because it represents a great loss of income and opportunity for Delphi programmers worldwide. Object Pascal as a language is the bread and butter of the Delphi community, and the more people use our language – the greater the interest and investment in Delphi there will be.
A brand new run-time library for a brand new platform, boldly taking Object Pascal where no compiler has gone before.
I am probably the first human being to compile an Object Pascal program and executing it on my Smart TV. Never before has Object Pascal run on a Phillips TV with an embedded browser — and never before have Object Pascal been used to control micro-processors. It was not Embarcadero that delivered this — it was us.
Real code, real work
You are also expected to tailor custom-controls yourself and adapt the standard controls and classes to your solution. This is how real software is made in all other languages, including Objective C, C# and C++. And while Delphi still retains it’s Visual Basic like, RAD, event driven development interface –Object Pascal is just as capable as C# and C++ for serious development. But the visual design tools quickly go out the window when you want to write rock-solid applications, be they for the mobile platform or not.
So in short: If you know Delphi and are not afraid of writing your own classes, which I really regard as a primer for calling yourself a programmer, then Smart Pascal will be mastered in a couple of days. You can also cut the learning curve even more by getting a book on Smart Pascal.
If you are new to Object Pascal then a quick visit to Delphi Basics will help you learn our language quickly and effectively.
And just like Delphi – we provide a “Demos” folder when you install Smart. This really is the #1 place to find example code. Everything from touch management, scrolling, hardware GPU powered sprites and more is covered here. A wast tome of knowledge ready to be played with and learned from.
If I was to learn Smart Pascal today, I would get the following:
Knowing that you can use Smart Pascal to control hardware, like the new JS based controllers which is making their entry into the embedded marked, hard-core HTML5 mobile applications, games, multimedia and serious business applications — it’s more than worth the couple of days it takes learning the ropes.