Evolving the Clarion Language

Nuts and bolts of the language changes made for .NET

<January 2008>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

News

Current news on the nuts and bolts of the language changes made for .NET

Navigation

Subscriptions

Clarion# Language features

In the early days of the Clarion# beta we had an ongoing discussion in the news groups focused on what changes we could make to Clarion# syntax to make it easier to read and write code. We've been busy implementing and testing those changes and we'll deliver them to you in the next release sometime next week.

Here is what's coming up:

We have removed the requirement to use & to declare a reference to an object in the data section. So instead of writing;

myString &String

you'll just write -
myString String

The & operator is still required when you want to declare a reference to a value type.  Value types are known as simple or primitive types and they include types such as Byte and Long, and by default, they are passed by value. Also GROUP, QUEUE, FILE, and ANY will require the & operator to declare as a reference.  But a reference type can be declared without the & and if the declaration doesn't have any parameters then the object will not be instantiated.

MyClass.P2 PROCEDURE()
A     MyCollection     ! just a declaration requires explicit instantiation
B     MyClass()        ! calls the default constructor
   CODE

This also means that you will use = operator for all reference types where now &= is currently required. For example:

Aa System.ICloneable
Bb System.ICloneable
CODE
Aa = Bb       ! whereas in the current version we write Aa &= Bb

That means we no longer have any need for the := operator, so its now removed from the Clarion# language.

However the &= operator is still needed to work with references to value-types (LONG, SHORT, DATE, GROUP, QUEUE, FILE, etc.)

Another change that was requested and implemented; no more automatic instantiation of objects, in other words all reference types are implicitly a TYPE.

Aa CLASS,TYPE

END
is now equivalent to:
Aa CLASS

END

The reasoning for this change was well explained by Dave Harms in a ClarionMag article which you can read here: http://www.clarionmag.com:8080/cmag/v9/v9n12instantiation.html

Automatic disposal of objects:
Since we now assign null to objects there is no sense to automatically call DISPOSE. Now it's the user's responsibility to create an object instance and thus it's user's responsibility to call DISPOSE if it's needed.

A word on constructors and declarations:

s     System.String('abc')
b     bool(True)

the compiler will generate for you as:
s = new String("abc")
b = new bool(true);

Another example to make this very clear:
S     System.String() ! parentheses means calling the default constructor
S     System.String  ! no parentheses so just a declaration without calling any constructor

With the described changes, given this code snippet:
A Aa
B Aa
CODE
A = B  

The statement A=B means assigning a reference.

So if the = operator is used to assign a reference, how do you copy content from one object to another?  Easy to do and required no language changes, the deep assignment operator :=: can be used for copying of content between like objects.

We have also introduced a new attribute AUTODISPOSE. If you mark a declaration with AUTODISPOSE then DISPOSE is called automatically on exit from the scope.

ZERO based indexes
We are changing Clarion# to use zero based indexes for all arrays and collections. But FILEs and QUEUEs will still use 1-based indexes. The rationale behind this change is that this makes it easier to work with the core Framework objects, 3rd-party .Net libraries, shared libraries you may write, as well as make it easier to translate code samples from C# or VB.

For those of you who have Clarion#, and those who soon will, we have also been looking into adding some features that will make it very easy to pass data back and forth from Clarion# and Clarion 7, so you'll be able to easily work side-by-side, .Net and Win32  Of course that can be done now but the idea is to make it much easier.

We have also been refining some of the UI features in the C7 RTL, and I'll post a blog on those changes later this weekend.

posted on Friday, January 25, 2008 9:06 PM by Robert Zaunere

# re: Clarion# Language features @ Saturday, January 26, 2008 8:28 AM

Bob,

Thanks for this. I do have a question about constructors. If you use the () meaning to call the constructor, and lack of them meaning to not call it, is there any value or rationale to having optional constructors? In the Clarion language, having a CONSTRUCT method is always called when the object is instantiated regardless how. I'm trying to imagine a scenario where optional constructor calls would make sense. Why the change?

I don't mind this, just trying to see the value and where and why I would use this.

AUTODISPOSE is a nice touch!

Russell Eggen

# re: Clarion# Language features @ Saturday, January 26, 2008 9:55 AM

Russ, the empty parentheses means call the default constructor, but you can also place parameters within the parentheses to call a specific constructor, which is often what you'll need.

Robert Zaunere

# re: Clarion# Language features @ Saturday, January 26, 2008 12:44 PM

More than one constructor?! Kewl! Indulge me with a follow up question please.

Can we expect to see constructors now accept parameters? Function overloading, etc?

Russell Eggen

# re: Clarion# Language features @ Monday, January 28, 2008 2:43 AM

Usual .NET powered programming languages automaticly dispose objects using GC. Can't completely understand what is AUTODISPOSE attribute for? Is it necessarily to mark all object variables with AUTODISPOSE if I do not wish to use DISPOSE???

Igor

# re: Clarion# Language features @ Monday, January 28, 2008 9:35 AM

Russ, we already support constructors with parameters.

Robert Zaunere

# re: Clarion# Language features @ Monday, January 28, 2008 9:44 AM

Igor, To answer your question: it is not necessary to mark any object with AutoDispose.

But AutoDispose is useful in cases where we want deterministic resource cleanup. Things like closing file streams, releasing bitmaps, etc. and any unmanaged resources should be disposed. For example, a Bitmap object that encapsulates a 4MB image file reports only the size of the managed object to the GC, but the GC doesn't know about the 4MB image, so it won't be garbage collected. When you call Dispose() on the Bitmap object it will release the image itself. So AutoDispose is just a shortcut, as the compiler will automatically generate the call to Dispose() for you.

Robert Zaunere

# re: Clarion# Language features @ Wednesday, February 20, 2008 7:24 AM

I just wanted to share with all of you some tips on migrating your existing projects to the latest language formats. We had to convert all of our existing Clarion# examples and samples in this latest release. Here are some tips to expedite this process:

Open your old project. Access the IDE Menu's Replace option (Search > Replace).

Replace the following:

Find what: ^
Replace With: (leave blank)
Look in: Whole Solution

Find what: :=
Replace With: =
Look in: Whole Solution

Find what: &System
Replace With: System
Look in: Whole Solution

Find what: &Clarion
Replace With: Clarion
Look in: Whole Solution

That will get you 99% along the way. The compiler will find the other 1%

Hope this helps

Bob Foreman

Powered by Community Server, by Telligent Systems