Archive

Posts Tagged ‘SmartMS’

TIOBE isn’t the only index that needs fixing

June 13th, 2013

404Worst thing in popularity is not being considered, or found.

Looks like TIOBE is not alone in differentiating Delphi and Pascal, other popularity indexes share the same issue:

More indexes I looked at didn’t show the “runners up”, only the top 5 or top 10, but they may as well have differentiated.

For lang-index, merging Pascal (rank 11) and Delphi (24), would be enough to reach rank 10, ahead of Ruby, just shy of Perl.

Read more…

News , , , ,

Fixed TIOBE index

June 12th, 2013

For some unfathomable reason, the TIOBE index distinguishes between “Pascal” and “Object Pascal”, and the “Pascal” category is seeing growth:

tiobe-pascal

So it can’t be the old classic procedural Pascal, can it? That leaves only Object Pascal dialects (FreePascal the largest, but also Oxygene and SmartPascal/DWScript). Pascal programming isn’t dead or dying.

Read more…

News , , , ,

Smart Contest 2013 – Round #2

May 6th, 2013

wartrailThe second Smart Context 2013 has been announced! As with the previous round, first prize is a tablet device of your own choice (up to USD 750). This time the theme is “Game Development”

The rules are as follows:

  • Registration before the 13th of May (registration at contest@smartmobilestudio.com)
  • Deliver your contribution before 3rd of June
  • The source code will be shared in our show case area
  • Preferable that it can run in the integrated IDE browser (but not mandatory)
  • No restrictions w.r.t game genre
  • No restrictions w.r.t project type (canvas, sprite, console, VCL)
  • You can use the trial version to make your entry

The registration date limit is not intended to be binding, but more like an “Hey I’m in”, and for the previous contest latecomers were accepted as well.

For this round I’ll be one of the judges alongside Jon Lennart Aasenden, who recently posted two articles about game development, see part1 and part2.

For more details, head to the announcement page.

News ,

Publishing pictures from an HTML5 app

March 15th, 2013
Comments Off

imgur-logoThis is a belated followup to the L-System Fiddle series from last year (more like a forgotten article), which ended with a Pascal-based HTML5 app being used to generate fractals and publish them to imgur.

Why imgur? Well because they have a well-documented API and they don’t require registration, authentication or other personal data for uploads, making it a good candidate for a demo anybody can try online, and where you may not want to enter your personal credits.

L-System Fiddle

You can try the L-System web app for yourself, it comes with a few sample L-System fractals, and it allows tweak the grammar, iterations and basic simple rendering parameters.

 
Read more…

Tips , , , , , ,

Property expressions and statements

February 14th, 2013

Object Pascal does allow binding a property to a field for direct read/writer, but we all have seen properties that required a slightly more complex getter or setter, and that usually meant a method for both. DWScript (svn trunk) & Smart Pascal (1.1) now support property expressions and statements, so the syntax is extended to allow:

property Name : Type read (expression) write (expression|statement)

Under the hood, the compiler will generate an unnamed getter or setter method when appropriate.
Read more…

News ,

Graphics competition, two days left to register!

February 8th, 2013

..and maybe win first prize, which is the tablet of your choice?

SmartContest 2013 Round #1

This is the first competition out of four this year. So this is your chance to win some exciting prices by showing off your Object Pascal skills!

The topic of this round is: graphics programming (eg. demo-scene, fractal art, visualizations etc).

Registration is before the 10th of February, follow the link above for more details!

News , ,

Thirteen features of DWScript

December 31st, 2012

2013After having survived the Mayan apocalypse and just before the year ends, and the US economy falls from the fiscal cliff into the pit of recession, here is a quick look at thirteen features of DWScript, so you don’t come into 2013 unaware :)

1. Supercharged memory management

ARC is trendy, but introduces cycles and weak references hell, GC is cool, but garbage collections stalls aren’t, deterministic memory management is fast and deterministic, but verbose and error-prone.

Why not have them all at the same time work together instead? That’s what you get in DWScript: ARC for immediate releases in simple cases, GC to collect cycles and avoid the weak reference, and manual deterministic release when you need it.

2. First-class dynamic arrays

Dynamic arrays are strongly typed, first-class dynamic arrays have methods to Add, Delete, etc. like a (T)List<T>.

And where automatic memory management absolves you from destructors most of the time, true dynamic arrays absolve you from requiring constructors for list and LIFO queues.

3. Type-inferenced variables

Why manually specify the type when the compiler can infer it for you and you get a strongly typed variable?

“var a := 2;” is the same as “var a : Integer; … a := 2;” would be in Delphi.

4. Combined field declaration and initialization

Also type inferenced, fields default values can absolve you from having to write a constructor in trivial cases.

5. Multiple helpers per type

Helpers aka extension methods can be a powerful way to add functionality to existing types. Having a limit of one-helper-per-type hamstrings them.

6. Multi-line strings

Whatever your strings or constants are used for, sometimes they need to span more than one line. When that happens, being able to absolve yourself from concatenating an obscure #13#10 is nice. Having a syntax that will allow you to properly indent those strings without introducing spurious indentation in the string is even better.

7. Lambda syntax

This applies to SmartPascal, where closures and anonymous methods are common, by leveraging type inference and a less verbose, yet not operator-soupy syntax, you can have a syntax far more compact, yet still statically and strongly typed. Enough to make one happy.

8. Custom language extensions

Sometimes it would be nice to introduce custom construct into your source code, with DWScript’s language extension mechanism you can do just that and take over the parser for a section of code, can be used to introduce asm or JSON capability.

9. Unicode-safe strings and iterations

Because sooner or later you’re going to end up parsing Chinese and your 16-bit-characters assumption are going to haunt you. Having Unicode-aware loops and no 8-bit or 16-bit Char type in the language avoids that.

10. Unified function pointers / delegate

Because life is too short for procedure vs procedure of object vs reference to procedure. Let the compiler figure it out.

11. Compile-time function evaluations and constant expressions

When something is constant, it’s constant, no? DWScript lets you use constant expressions to define constants, so that you can have a constant defined by just “Sin(PI/4)” rather than a magic number plus a comment to explain what that magic number is.

12. Partial classes

Partial classes allow you to support automatically-generated code more easily, including code generated from compile-time type information, or just make your classes more extensible, by design.

13. Deprecated

Feature #13 got deprecated and isn’t available anymore.

14. Being able to compile to HTML5+JavaScript

With SmartMobileStudio, Make your business logic cross-platform, cross-terrain and as ubiquitous as  it can get these days. Run in mobile or desktop browsers, run server-side with node.js, or client-side with node-webkit as runtime environment.

Tips , , ,

Re-rooting Object Pascal

October 3rd, 2012

A while ago I asked about the name of TObject ancestor, well, it’s now live in the SVN and its name is ‘Object‘.

Object is thus the new root class, above TObject. Eventually, it’ll be the ancestor for every other type.

JObject

The earliest need for migrating to a rooted type system was to unify TObject and the new JObject, which is is the new root class for all “prototypal inheritence” JavaScript classes in SmartMS (while TObject remains the root for classical Pascal classes).

Subclasses of JObject are either purely external classes (implemented on the JS side, in the DOM, etc.) or Pascal classes compiled to JavaScript, but that follow the JavaScript “object” conventions rather than the Pascal conventions, ie.

  • methods are resolved through prototype (they can be resolved either statically or via a VMT for TObject)
  • field and method names are not obfuscated
  • no smart-linking or de-virtualization can occur
  • they are globally scoped in JS
  • marking methods as “virtual” is an error (they are dynamic, which is a bit like being implicitly “virtual” and “overridden”)
  • visibility isn’t supported (on the JS-side)
  • ClassType, ClassName, etc. don’t exist

These classes are intended primarily for consumption by “external” JavaScript libraries.

They’ll look and behave like “pure” JavaScript classes, so will share their downsides (no obfuscation, no whole-program optimizations, no elimination of unused methods by the smart-linker, etc.); Still, they retain some Smart Pascal advantages (strong typing, local optimizations, obfuscation of method implementations, case insensitivity on the Pascal side).

News , ,

Debugging PhoneGap/Cordova apps on the Desktop

September 11th, 2012

If you’ve tried building PhoneGap/Cordova apps, be it in Object Pascal via Smart Mobile Studio or directly in JS, you’ll quickly have realized that debugging on the devices, even with remote debuggers and emulators, isn’t always convenient.

Being able to debug in a desktop browser would be so much more convenient, eh?

The most commonly recommended way to do that is via Ripple, a Chrome plugin, which is indeed pretty, but IME proved quite buggy and heavy (meaning that Chrome debuggers would spend more time reporting stuff buried deep in ripple.js than in my own code).

Enter phonegap-desktop, an open source project by Jonathan Prince, which is essentially just a phonegap.js library that exposes the PhoneGap API, and allows you to provide fake device data just by writing in a json file. Simple, no-fuss.

To use it with a SmartMS project, just copy the “phonegap-desktop.js” file in the bin subfolder of a project, rename it to “phonegap.js“, et voilà! you can then run your app in Chrome or FireFox as usual. And when building the zip for Phonegap Build, just don’t include that file.

Tips , , , , ,

Fiddling with L-System (part 2)

August 13th, 2012


Part 1 left us with a large cryptic looking string (a recursively applied grammar applied to an axiom, for the purists).

In part 2 we’ll go from that big string to a visual representation, by making use of that string as a set of commands for a turtle language.

Turtle graphics came to fame in the days of Darwin’s voyage to the Galapagos the Logo programming language, and in many ways are the grand-daddy of vector graphics languages like SVG.

For more details, read the turtle graphics article in wikipedia, it’s (at the moment) short and to the point.

Turtle Graphics Language

In our case, the language is made up of the following basic commands:

  • F : go forward one step
  • + : turn left by a fixed angle
  • - : turn right by a fixed angle
  • [ : push current turtle state in the stack
  • ] : pop current turtle state in the stack

Those five commands allow to render any monochrome connected graphics. Of course the language can be extended to allow more operations: changing color, changing pen width, moving without drawing, specifying filled polygons, extending to 3 dimensions, etc.

Not that kind of turtle graphics

Not that kind of turtle graphics

Show me the code!

Implementing an interpreter for the above language is a smple affair. First, we define a structure to hold the current state of the turtle:

type
   TLSystemRendererState = record
      X, Y : Float;
      A : Float;
   end;

and the minimal renderer object with current state and stack would be

type
   TLSystemRenderer = class
      private
         FState : TLSystemRendererState;
         FStack : array of TLSystemRendererState;
      public
         procedure Render(canvas : TW3Canvas; const axiom : String);
   end;

The Render method is where everything happens:

procedure TLSystemRenderer.Render(canvas : TW3Canvas; const axiom : String);
var
   i : Integer;
   a : Float;
begin
   canvas.BeginPath;
   canvas.MoveToF(FState.X, FState.Y);

   for i := Low(axiom) to High(axiom) do begin
      case axiom[i] of
         'F' : begin
            FState.X += Cos(FState.A)*Size;
            FState.Y -= Sin(FState.A)*Size;
            canvas.LineToF(FState.X, FState.Y);
         end;
         '+' : FState.A += Angle;
         '-' : FState.A -= Angle;
         '[' : FStack.Push(FState);
         ']' : begin
            FState := FStack.Pop;
            canvas.MoveToF(FState.X, FState.Y);
         end;
      end;
   end;

   canvas.Stroke;
end;

Characters that are not commands are just ignored, this is quite important for L-System, as non-command characters are often used at the grammar level for the rule (the Penrose tiling being a good example).

The renderer leverages the stack-like pseudo methods of dynamic arrays along with the automatic record cloning, so the code is rather simple as you can see.

Not explicited above are the Angle is the angle parameter (in radians), which you’ll want to make a property of the renderer. Also Size is the standard step Size, for LSystemFiddle, 10 seems to look good for a line width of 1, but you may want to allow fiddling with it in a more complete renderer.

That’s all for the monochrome renderer, but that’s not all for this series ;-)

If you check again the Live Demo App, you’ll see a new “Publish” button was added since part 1 was… published (hit F5 if you don’t).
Feel free to use the new “Publish” button to share your creations!

 

News , , , ,