473,419 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,419 developers and data experts.

PHP, Macros and COBOL Templates

1
I have been writing PHP for a good 20 years*, but before that I wrote COBOL, and I still write C after almost 40 years of it.

COBOL had a feature called templates - which could have been wonderful if it did what I thought it did, but it didn't.

The problem I want to address is that I quite often want to re-use PHP code for an application that is *almost* the same as another, but not exactly the same. For websites, this often includes an amount of (Postgre)SQL.

Consider, for example, code for a record collection - you have records, with titles, artists, Labels, release dates, Numbers, pictures of sleeve front and back, etc. You code up a page to list the catalogue, with filters and sorting, and a button to add a new record. Each entry has a button to select to see/edit/delete full details.

Now you want to do the same thing for a book collection. It is pretty much the same code, but the variable names are different. In some cases, there may be more or fewer fields, or the fields may be of different types, requiring different validation code, and the help and error messages need to be different.

It would be extremely useful to code up the basic functionality, and then have a facility to import it, translating the variable names, and other things using a definition process, so that these two things can be managed by different change management systems and maintained by different people. Also, the database record names, field names and types need to track the SQL code and that needs to map to the PHP names, type etc - which is not necessarily a 1-1 mapping. Sure you can skip this step, but then no human will be able to debug or maintain it.

Remember it might be highly desirable to have both the above implementations on the same website, in which case they might even share the same database server.

In the olden days, this is how we used Assembler, and those of us who were introduced to C as "the new PDP11 Assembler" (PDP11 was designed as a "hardware Fortran machine"), did this sort of thing as our normal work process.

Also remember that systems which auto-generate variable names like $V1002, $V1003, etc are not, in the real world, debuggable. Both originators and users are at risk of insanity. (I seem to remember Borland's drag-and-drop+ database stuff doing this, but it might have been someone else's). Oracle's PowerObjects was similar, until they discovered even Oracle's crack team could not make it Y2K compliant - possibly due to all the crack ( have no connection with Oracle other than them discontinuing PowerObjects killed my employer's factory work in progress management system, bankrupting the company).

It is possible I am going about this wrong, and should write the whole damn thing in C, but where the object is to produce a prototype, or code with a short expected life (eg "we have the contents of a library we want to sell like a garage sale") or similar,
the PHP is quite a good solution - build it, hack it till its more or less working, use it, and then throw it away). I do not recommend coding electronic power steering for cars, or railroad switching systems in PHP, but it does have good use-cases. Software for research projects might be one. The Uni could maintain a set of templates for an area of research, but individual projects could quickly create instances specific to their research project. The use of Uni-specific templates (written by IT professionals) making collaboration between teams easier, while the team could create project specific instances which support their workflow.

Yes, I know about frameworks, and this is similar in functionality, but significantly different in implementation and use.
My approach makes it possible to take the imported code, and give it a life of its own, rather than track changes in the template. While that would not be the primary deployment practice, there might be cases where it is the best option.

It should also be possible to use my approach to take a solution written in one Locale, and deploy it in another - or - potentially - automate systematically taking stuff from a popular locale (ASCII ?) and deploying it in a completely different locale.

* I am the person that suggested there is a Wii game that allows you to write PHP by throwing cow-pats at the screen with your Wii-mote - it might explain the quality of much PHP code.
+ a colleague of mine once said "the advantage of drag-and-drop is that you can drag it to the window and drop it onto the ground three floors below" (works best with punched cards).
Aug 15 '22 #1
0 2770

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Andreas Micheler | last post by:
Hi, I have several long complex C macros in the math module of aUCBLogo like #define _XFUNC_primitive(NAME)\ NodeP _##NAME(PairPP arg)\ { ((ObjectP)(arg))->var()->NAME( arg );\ return...
4
by: Robert Frunzke | last post by:
Hello, I need to implement a custom allocator to speed up the allocation of a specific class in my project and instead of hardwiring it, I would "templatize"(?) it. The allocator should have...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
11
by: San | last post by:
hi there, I am new to c++ and tryig to learn the basics of the c++ concepts. While I was reading the templates, I realize that the templates are a syntax that the compilar expands pased upon the...
27
by: Cephalobus_alienus | last post by:
Hello, I know that macros are evil, but I recently came across a problem that I couldn't figure out how to solve with templates. I wanted to create a set of singleton event objects, and wrote...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.