In a paragraph how would you sum up Templates to someone?

Tags: #<Tag:0x00007f225948eae0>

Doing a little book on Templates, unironically called “Deciphering Templates”.

Would this be a fair assessment for an opening paragraph?

Templates are like the crown jewels of the Toolset. It is a macro language on SARM’s which takes programming to a higher level of abstraction and productivity turning months of coding into hours.

Templates in their simplest form can be a code template adding or modifying existing code generated by other templates. In a more complex form, they can accept input via a number of different #Prompts which enables customisation of code, typically OOP classes but also procedural code. The macro language is influenced by Modula-2 to provide direct language support for multiprogramming.

TL;DR Templates are an extremely powerful macro language which produces code for any language.

If not what would you put? :grinning:

Hi Richard

you might want to define what you mean by SARMs as I presume you are not referring to Selective Androgen Receptor Modulators!

interesting that you refer to the templates as the “crown jewels” as I recall Bruce Barrington referring to the then upcoming templates manual (which back then had to be bought at extra cost) as the “keys to the kingdom”.

The Clarion wikipedia entry

mentions “The templates are able to generate any text based file, and are not limited to Language statements” which is an important point so where you have

perhaps you should say something more like “which can produce code for any language”.

Robert Artigas at

https://github.com/RobertArtigas/DCT2CLASS_Docs/wiki/A]-Steps-of-Code-Generation

includes some good links to other developments in this area including artificial intelligence efforts: sourceai, copilot, deepmind, doublesvsoop, gpt3 which may be of interest to you (and others).

If you are specifically referring to Clarion’s templates (which perhaps you are given your reference to #PROMPT) then perhaps some mention could/should be made to the relationship to and the use of the dictionary which is a repository of information regarding data structures and their presentation.

hth

Geoff R

Actually I was!

So normally to emphasise strength, it would be common to say “X on steroids”
ON STEROIDS | meaning in the Cambridge English Dictionary

but SARM’s are like the next generation of steroid, and the younger generation who are going to the gym, may well know about SARM’s being a next generation steriod (menshealth.com), its actually part of chemo due to its anti cachexia properties (30:1 ratio where as Testosterone is only 1:1) amongst other things, although I know that in SA they use testosterone (androgel) for dementia treatment, so for the younger generation gym going coder’s who take their productivity and earning abilities very seriously, this statement should catch their attention if the search engines are any good! :stuck_out_tongue_winking_eye:

Although I have heard that the pressure to perform for a FAANG in Silicon Valley is so bad, many have taken to micro dosing (LSD) to keep up their creativity!!! I think thats holding on too tight imo.

And thats true, but something I forgot, yet I’m working on it right now, we have #RunDLL and #Run so we can also call or trigger additional functionality from the templates, beit calling some windows api’s, other dll’s, so they can actually do way more than just generate source code for any language, we can call external compilers, build own our frameworks for different platforms, we are limited by our imagination and time as to what else these templates can do.

This point Robert mentions in his link

Might have been too early in computer history for the idea of code generation to flourish.

Its so true, it is a bit of a running joke amongst coders to automate themselves out of a job, yet Clarion just lets you get closer to that point than any other language. I remember trying to get my Computer Science tutors into Clarion cpd2.1 and they couldnt get their heads around it. You know the biggest problem in the other languages? Its that they have too many libraries of varying standards of quality to the point its become a bit of a full time job tracking down the best library to use, just like its a full time job trying to lock down your computer & network for security reasons.

Yeah thats another good point, the templates work with the data, something again I’ve forgotten to mention, and yet the whole world revolves around data, its what every business, govt, non-profit, household, everyone needs data and yet so many people havent heard of Clarion which has been handling data since the dos days, and yet more people have Heard of Amber Depp a toe in Johnny. :wink:

Maybe people listen to FAANG’s too much or their advertising pays for good headlines!?!

OK that surprised me - thanks for explaining it.

Another issue you might have is that people coming from a C++ background will have a different idea about what templates are.

1 Like

Yep, now that you mention it, so would it be fair to say C++ templates are like the Clarion built in (data) Type conversion which then allows a degree of Procedure/(class) Method overloading to take place?

I can see what is put here
Template (C++) - Wikipedia

or would you word it differently?

I was thinking about whether it could be trademarked just to have it stand out. :rofl:

Edit. Didnt take the Daily Heil long to react eBay selling prohibited steroid-like muscle building tablets | Daily Mail Online

For as long as people have been programming computers, programmers have been creating libraries of reusable code, providing features they use over and over again. Over time there have been several steps forward in make reusable code better.

What has not progressed as quickly are techniques to make actually using resuable code easier. For most mainstream systems it take a programmer to integrate reusable components together to make a functioning program. They integrate at the “how” level - how does this library work? how do I make it do what I want.

The goal of the Clarion Template Language is to bridge this gap. This layer provides a visual interface which can be used by a non-programmer (a “developer” if you like.) This interface allows the developer to quickly and easily select from a predetermined range of options moving their program forward.

In addition to the developer input, the template language is tightly bound to a dictionary of data declarations - primarily database tables. Thus a developer is able to take those data declarations, and develop programs based around them; the templates then acting as the user-interface-glue between the developer and the existing reusable components.

The templates thus ask the developer “what” to do, not “how” to do it. The developer creates a program specification and allows the system to generate the desired program from that specification.

While all of this is laudable inevitably the developer will discover a need for a feature not yet available via the template interface - they want to do something not yet exposed by the programmer - and at this point they are free to inject (or “embed” in Clarion parlance) their own code into the system. In this way developer turns programmer and writes code to add their own specific flavour to the mix. The templates do the bulk of the work, the developer adds the touches of spice as needed.

Some changes made in this way are generically useful. And so that code makes its way into reusable code, and can then be exposed via a template. Next time this feature is needed it’s as simple as asking for it. In this way a programmer doesn’t just move this project forward, but also all future projects as well.

Of course this approach is not limited to the Clarion language, templates can be written to generate the glue for any language, and indeed over the years templates have been written to support output other than Clarion code. BAT files are common, but in some cases PHP, ASP or even JAVA code have been generated. There are even templates that can write templates.

In themselves however templates do nothing. Glue in a tube is just glue. Ultimately to be useful they need reusable code, however that appears. Once they have that, templates can provide that interface-glue, which makes that reusable code easy for a normal human to use.

So with 3rd party code used in whatever form it comes in, be it a COM object, DLL, OOP class, REST service, library, or Template, there is always an element of trust which has to be given, the other point is the template’s are not black box technologies, anyone can read or debug them, unlike COM objects, or DLL’s, so to use the word “developer” in the context of a “non-programmer” whilst valid perhaps does not highlight the productivity gains the templates can deliver if trust is implicit.

Unlike other languages, the Clarion community is smaller and that means more accountability because with Open Source or big entities like MS, Google, Facebook, there are a higher number of programmers involved and the churn is higher, the same with many open source projects.

However from a hacking perspective, Clarion templates are an excellent phishing ground :nerd_face: If anything the technical or required entry level knowledge to write programs is lower if someone is to use Clarion because it can do so much more for you, than someone attempting to write a program using C/C++ or even Assembler.

So the choice of programming language highlights the attack vectors that are best suited for the language. For example, in Clarion the EXP file exposes many classes when compiling a DLL, so whilst the Topspeed stack is unconventional because its not the major stack used on Windows, that inability to call a Clarion DLL in another language highlights a lack of knowledge that is useful for mitigating an attack vector and I know its your bug bear of “there is no security from obscurity”, but its still a hurdle which takes an amount of time to get past. At the same time, if someone is aware of the Topspeed stack then the current toolset practice to expose every thing isnt ideal. Ideally we can perhaps show this with the use of Ordinals instead of @F, and certainly restricting the exposed properties (variables/types) and methods (procedures/interfaces) to restrict this attack vector in our own DLL’s.

At the same time, its not a requirement to have a dct being used with the templates, the templates work with the local procedure and global data declarations which invariably will have to be used for any sizable program, and if user input is provided then the templates handle the control events.

If anything the templates are well suited to the loop based (window/control) event driven interface seen in Windows and other operating systems which makes them perhaps the ideal tool for writing bug free software across a variety of platforms.

So yes your point is fair when you say a non-developer can run with Clarion with just a few template inputs like a manager or CEO in a business directing staff lower down in the hierarchy, it doesnt highlight what else the templates bring to the table which is not seen in any other programming language and IDE.

I suppose in a way, using templates is like your famous saying “work smarter, not harder” because the Templates are like Boss level programming! :sunglasses:

Is that a fair assessment? :smirk:

Templates are just glue to reusable code. That reusable code could be black-box or not. So the trust issue is orthogonal to templates - trust revolves around the nature of the reusable code, not the template.

I would suggest that reusable code, in the form of CLW’s and INC’s (ie classes) is more trustworthy because the code is simpler to read, and more people are capable of reading it. Template code is obtuse at the best of times, and a much smaller number of people are experienced in being able to read it. Equally templates that make use of #SERVICE, #RUN or#RUNDLL become less trusted because they are calling out to other (presumably?) black boxes.

It is possible for a template to include the reusable code buried inside itself. The Clarion (Legacy) Chain is an example of that. However this approach is weaker than using classes for code, and template for glue (as say ABC does). Ultimately of course it’s the quality of the reusable code, wherever it is, that is the biggest factor in success or fail. The template layer is not a huge part of that equation (to me anyway.)

Agreed. Equally there’s no requirement for the template to have a programmer interface. But more useful templates tend to take advantage of both forms of input.

Templates are suitable for writing code against any language or platform, since, by definition all they produce are text files, and equally pretty much any compiler on any platform takes text files as input.

Whether the interface has a windows-style ACCEPT loop or not is somewhat irrelevant. I’m using templates to generate procedures that generate HTML (ie a web server) and there’s no ACCEPT loop in any of those procedures.

I’m not sure templates offer anything apart from a “developer” interface to reusable code. But that in itself covers a lot of ground. Yes, productivity goes up because it’s fast to turn things on and off. Yes it allows developers to create program with little or no programming experience. But these are side effects of the UI.

It also allows you to take the same input (dict and template prompts) and generate different output. In the same way a compiler might create a windows exe, or a linux exe from the same code base. So you might define say a web app with one template, but then click a checkbox and instead of creating Clarion code, now it’s creating JavaScript. An example of this is turning a NetTalk Web App (Clarion) into a PWA (JavaScript.) We take the “what you want” and use a different “how to get it”.

But again this is a side effect of the “input” (the “what”) which is disconnected from the output (“the how”).

So why don’t we have templates to generate Linux programs? or Mac programs? or iOS apps? Ultimately because writing the reusable code that underpins the “how” is a monster amount of work. There is no technical reason that the ABC template chain could not spit out a program written in c#. But that implies the ABC framework translated into c#. It’s do’able, but a lot of work. [And as an aside, to literally take an ABC program, you would need to have database access code, window management code, and so on. So you need to accumulate reusable code not just to match the ABC classes, but all the Clarion RTL in terms of functionality.]

Writing templates is not hard, but it is different. It takes a bit of getting used to because it’s not like writing clarion code, or pascal or whatever. It’s a different kind of programming. Maybe not as much as say List to C, but the same kind of idea. It takes practice and experience to be able to read template code and predict what it is going to do. It takes time and effort to learn that, and as you note, the community of people with that skill is small. It is not hard though, one just has to get started.

Of course as you know I’m lazy. Which means I naturally gravitated to doing work once, which for me means writing classes with template wrappers. This is “boss level” in the sense that I’m building reusuable code, which then means my eventual output is magnified.

However, it’s “developers” who get paid, not “programmers”. Programming is a cost. Developing is the skill of creating solutions, which are valuable to people, getting that out the door and getting paid. (hopefully some of that trickles down to the programmers.) The ideal company has a small number of people creating value, and a large number getting that value into the hands of paying customers. Programming is a small part of that chain - template writing is a very small part of that chain, but it’s a small part that can have a big impact on value.

Black box can also be legal black boxes, even classes/source can be legal black boxes, ie you can look but not touch.

I wouldnt call template code #Obtuse, perhaps the docs, examples over and above the shipping templates and lack of out-the-box debugging tools dont help but I would not call them obtuse or obfuscated. Everyone can read so templates arent really any harder than reading clw & inc’s.

On the point of #Service, #Run & #Rundll, how is that any different to using a class which links in a dll/com object to the main app on the trustworthiness front?

How is it weaker? Templates and classes can be considered identical in that they can have no input to produce code but can also expose inputs via a template prompt or a public class property.

In practice, templates are often used to include classes because the templates provide a better interface (GUI) with the AppGen, enhanced design time rule enforcement and a class is just text which makes its interface a good as using Notepad with the added weakness that the customer might have to do the testing because its a post compile time thing.

Yeah HTML (without javascript) is just a sequential stateless bit of code, much like the earliest computers were when it was still punch card. But nearly all modern computing devices (smart phones, laptops, smart tv’s & computers) do use a loop based processor of sorts, and they do offer a better experience, even the web browser needs a loop based processor in order to display the stateless sequential HTML much like a PDF viewer displays PDF’s. The point is Templates are designed to cater for the loop based processors and AFAIK no other programming tool exists with Templates, but I could be wrong?

Clojure (Lisp) is different like SQL is different to Clarion or Pascal or Assembler, but its something we can produce in Clarion, because programming languages are also interfaces to the OS and/or cpu instruction set.

Yeah but the templates make it easier to use the classes in whatever shape or form otherwise why do you use the templates to get your classes to work in an app?

looking is 90% of the upside. Certainly you can gain trust by looking.
And you can always touch if you want to. (It just makes updates a bit more work.)

It’s no different. If a library ships as a compiled DLL, or an OLE or whatever then it is trusted less. Not necessarily untrusted, but trusted less. The ideal is all source - in whatever form that comes. Which is why trust is orthogonal to templates - templates are either trustworthy or not, just like every other bit or reusable code.

It is harder because templates are different in that they mix “code” with “output”. When reading a class I’m just reading code - all the code, nothing but the code. When reading templates my brain is having to distinguish between two different programs at the same time - the template program that is running, and the program output it is creating.

Like all tasks this becomes easier with practice, and is a lot easier in the new IDE with the color syntaxing, but it still takes time for the brain to catch on. It’s not “hard” but it is “harder” in the same way that 2 is not large, but 2 is categorically greater than 1.

It’s weaker for a number of reasons;
a) Classes can be used in hand-code projects, whereas templates are limited to being used in an app.

b) Classes can be used directly in test code, and the code in those classes can thus be more reliable. The template layer can be unit tested as well, but that becomes more tricky the more possible inputs there are.

c) Clarion Classes are easy to use in any Clarion framework. plugging them into Legacy, ABC or NetTalk or whatever requires different template code for each framework - but by minimising the template code for each, it’s possible to easily create an maintain templates for any of the frameworks.

d) Classes are more extensible - in the sense that every virtual method call is an implicit embed point. This can be overcome in templates by adding lots of embed points, but that has to be actively done by the author, whereas with classes it comes for free (well, as long as ,VIRTUAL is used.)’

e) Someone can derive a class, add their own spin to it, but continue to use the existing template without change. In other words you might have a derived StringTheory class (say RichTheory) - which doesn’t need to alter shipping code (class or template) but which can be completely used by the StringTheory template.

f) Most of all though it’s better because it separates “clarion code” from “template code”. It lets the template do what it does best - provide the visual interface to the class. Reading the template is easier, the template itself is smaller and so on.

When I started writing add-ons they were naturally in the form of monolythic templates. That’s all we had to work with. The adding of OOP in C4 meant we could create classes, and let templates be just glue. I’ve found that the classes approach has meant a lot less work, and a lot easier work, and that’s the way I’ve been doing it ever since. We still have a couple old products which are “just templates” and they seem a bit strange to me now. I always want to go back and refactor them into classes, but time is limited.

Incidentally I don’t say classes + templates > templates to damn templates. On the contrary I say it to praise them. Templates are an integral part of the equation - and they are still the Clarion special sauce.

Exactly - 100% my point. Classes are great, template makes using them easier. This is the point of my original post. Writing reusable code has been getting steadily easier for decades now. Using reusable code has not. Templates are magic because they focus on making reusable code easier to use. That’s why I write them, that’s why I use them.

It’s not a question of “templates or classes”. Both are strong alone. But together you get the best of both, and the combination is worth a lot more than either alone.

I think this point is something of a digression. They weren’t really designed for loop based processing, they were designed to generate code. As such they generate any code just fine. You’ll find that they’re equally good at any code. I’ve been generating JavaScript functions with them and it generates fine. Obviously they are good at generating Clarion - I’m saying they are equally good at generating everything else.

To be honest Richard, I have not used C++ since the late 80’s and early 90’s. I initially used Zortech C++ and later Borland C++ but I think C++ templates were a later addition to the language - so I am probably the wrong person to ask.

But I think you are on roughly the right track in that you can define a generic function that can be used with different parameter types - perhaps a bit like using ANY in Clarion. I suspect at the object level though, instead of generating one generic function, C++ generates code for each possible parameter type. But that is more a guess based on my imperfect memory so take it with a bucket of salt.

I have always felt automatic type conversion, that you mention, is one of Clarion’s strengths although once in a while it can trip you up - but that is rare (at least in my experience).

It depends on how you update it, ie sticking within the OOP paradigm so using (derivation, inheritance) or instantiation or just modifying the source. However you modify the class, you can do the same with the templates, have a look at #Procedure ,Parent(name(family))

They are both the same, classes mix code with output as well and in C7+ you can have the text editor display different colours based on different conditions to make it easier to see the template code and the output, although I cant seem to get C11 to include the preceding # when I double click a template command but it works in C6.

So why go backwards to a text editor? Sure Templates can only be used in the AppGen, but thats why people use Clarion and not some other IDE or tool like Notepad.

Code is code, its either reliable or its not and last time I looked Templates still come with a windows handle and a handle to its controls displayed on them just like a clarion exe, making it possible to unit test templates as well. :yum:

What exactly do you mean by an implicit embed point? My understanding of virtual is its like having all the API prototypes from a DLL done for you automatically when called from a parent class. I’ve got libmaker and the source code from libmaker in the examples, if I wanted to automate the prototype of dll’s even more than whats already on offer. Loadlibrary also gives us the chance to load dll’s and api’s using their ordinals if we didnt want to use libmaker to make a lib file. Sure having a parent class call a child class makes the prototyping faster there, but it could be rivalled as I’ve mentioned above.

Yeah and you can also call Templates like that.

The template code is clarion code, its just happens to be prepended with a hash symbol and only works in the app gen, thats why we can use clarion code to extend template commands.

Tell me about it, I use #Include an awful lot.

Your focus or aim is end user code and I’m not saying use a template to generate a class, although you could, but for somethings the templates are better suited for, I’d use the templates.

But you only get “Boss mode” with the inclusion of the templates. What you call the special sauce or the glue, I call it Boss mode because no other programming tool has anything as developed as the Clarion templates AFAIK. Loads of programming tools support classes, but not many can say they have an interactive framework to make coding even easier, safer from bugs and more productive.

…on a loop based OS, or maybe that was a subconscious effect of making them operate on loop based OS.

My interpretation is its like procedure overloading like you see in Classes or Templates.

ie
MyProc (cstring voila)
MyProc (string voila)
MyProc (long voila)
MyProc (short voila)

So where it (automatic type conversion) tripped me up, was in a filter and Alexey suggested I used
condition = 0 * 1 but I was probably using the wrong data type anyway, a decimal instead of a long or something like that for a RecordID.

The do explain it though in the help doc, its titled
Simple Assignment Data Type Conversion

Some people use Clarion in hand-code projects as well. Obviously classes can be composed into other classes as well, so that’s also “hand-code” of a sort.

correct - which is why unit tests are so useful. They help ensure the code reliability. Unit testing templates is hard, unit testing template-generated code is also hard. Whereas unit testing class methods is easier.

I think this is perhaps core to us talking past each other here. Your understanding above is incorrect, and it’s critical because Virtual methods are pretty much the only reason to use classes. (Well, ok, there are others, but Virtual Methods is like 90% of it.)

It’s a tad difficult to explain in a simple forum post - it’s one of those “light bulb” things where it makes perfect sense once you get it, but it takes forever to “get” it - and it’s really hard to help someone get it. I’ve done a couple webinars on it, but I recommend coming to a OpenClarion Wednesday webinar and I can walk through it with you.

I’m not saying you’ll change your approach, but I think you might discover that classes offer another level of usefulness. Like I said above, templates are great, classes are great, but using them together is
magic.

,Parent is useful, but it’s not the same as derived classes. They are both useful in quite different ways.

Agreed. Templates take reusable code to the next level. I’m not saying they’re bad. And you can do a lot with them. I’m just saying that doing Templates and Classes together is more than templates. That doesn’t make templates bad.

I agree. For “developers” (and I use that term non-pejoratively) Clarion lets you pick from a menu of choices and that happens very quickly. And if the menu item you want is not there, then it can be added.

1 Like

Thats what I like about language, some words convey an idea that is unquantifiable.

So lets start with the first question, what is your definition of an implicit embed point?

Its not going to be 100% identical because #Procedure is not a class, but some of the OOP properties seen in classes has been translated to the #Procedure.

You were calling them glue or special sauce, earlier.

When you are inside the class, and you make a call to a method, you get two implicit embed points there, because the derived class (as generated by the template) allows you to embed code before, and after, the parent call. So effectively you are embedding in the called method, right before, and right after the code in the method.

As an example, take the ABC TakeEvent method. As you’d expect the WindowManager class takes events and “does things with them”. But you can embed before the parent call, and after the parent call to either suppress, or supplement the event handling code.

This approach works fine in template land (the template generates the derived method with just a parent call as a “possible code”) but it also works in hand-code land - a derived class gets the ability to embed at the start of the method, at the end of the method, or replace the method completely.

Exactly. If the generic, reusable code is in a class, then the template becomes a user-interface to using that class. So you get all the benefits of OOP code (faster compiles, smaller Exe’s etc), but with the high-productivity of a template interface.

Of course all the code that’s in the class could be inside the template, and the template author can add lots and lots of embed points, but it’s fundamentally easier to create reusable code as a class / template pair rather than having everything in the template. And the end result is smaller, and compiles faster, because you’re not regenerating reusable code in every procedure.

I believe that an important part of communicating a technical concept (such as brewing, Clarion templates, astrophysics, or diesel engine mechanics) to an audience with an unknown background requires that you avoid jargon, buzzwords, assumptions that people “know what I’m talking about” (eg: “SARMs”), while also not assuming they have specific skills (eg: C++) related to the subject matter, even if they have general knowledge, such as “I code in (whatever language)”. It feels like this text is moving that direction.

Phrases like “crown jewels” and “keys to the kingdom” beg for additional explanation, eg: why are these things categorized as such?

It’s really too bad there isn’t a publicly available clarion wiki that isn’t entangled in a non-standard UI and formatting tool. This thread, once curated / edited / whatever, would make a nice entry about templates.

Well I’ll check this out once I’ve finished my class writing template and look for it.

I know that method,Virtual enables some toing and froing with a parent class but I didnt know the appgen creates embeds automatically so I’ll check that out.

The use of the word SARM’s was deliberate, its something most people wont have heard of and might well have gone and looked it up, but the “on steriods” is a phrase more commonly used.

Generally I agree, the language used needs to be stripped back to a level which is understood by a wide audience, but that audience will still be in the IT domain, and most people will be familiar with the concept of Crown Jewels thanks to Disney & other storey tellers, Royal Families and history in general so will probably understand the concept of value and importance when something is expressed as important like Crown Jewels.

I dont understand what you mean with this, are you suggesting Wikipedia isnt standard or something else?

by “Appgen” I mean templates. It’s done in the ABC templates, and for non ABC templates we use a bit of shared template code (Cape01.TPW, Cape02.TPW) which is freely available. It’s like the ABC stuff, but a touch more flexible, and works on non-ABC classes.

Given the lack of resources from SV and small chance for payback to a 3rd party vendor, it seems unlikely that the basic shipping classes & templates will ever be revised/replaced. Nevertheless, I have to believe that a new, creative approach could reinvigorate a whole community of ideas & possibilities.