4D finally did away with the Modified({fieldname}) command.

I’ve replaced it in our code base with


4D recommends using the Form Event and On Data Change event.

Can’t tell you how frustrating it is to find the context of a variable stripped away by a meaningless re-assgiment (login required).

From Clean Code: A Handbook of Agile Software Craftsmanship:

The name of a variable, function, or class, should answer all the big questions. It
should tell you why it exists, what it does, and how it is used

// doing this totally strips away any meaningful context
$my_temp_variable = $employee_salaries[$an_employee_name];
$gross_salary = $bonus_factor * $my_temp_variable;

// hopefully the language constructs allow full variable interaction
$gross_salary = $bonus_factor * $employee_salaries["Fred"]

Sending html e-mails opens a whole can of worms on the many ways e-mail can be viewed. There is also no guarantee your e-mail will look as intended.

Instead of linking to a remote css file that may be blocked, or prompt the user with a scary ‘prevented external content to load’ error message, we can use PHP to pull the file directly. This adheres to the DRY principle and keeps the code base clean.

Use the file_get_contents function in place of linking a style sheet via an html style element.

I would also recommend a try/catch block in case the file_get_contents command fails.


In head section:

<style type="text/css" media="screen">
	<!-- we do this to embed the file contents into the e-mail.
	<?php echo file_get_contents("../common/css/blueprint/screen.css"); ?>

Having not played around with CSS frameworks before I found this one very appealing.

Really, it accomplishes something I used to spend an inordinate time doing: creating a simple set of CSS rules that bring all browsers to a common level playing field.

My favorite aspect is the concept of 24 columns easily split into classes span-x where x is a number of columns.

Check out blueprintcss.com for more information.

This allows multiple data stores but without rewriting all sql queries. Note you have to create two functions, one to accept dates, the other to accept times.

Specifically the 4D SQL function DATE_TO_CHAR. Luckily PostgreSQL has the equivalent as a formatting function to_char.

For business reasons it’s not practical to replace all instances of DATE_TO_CHAR to to_char.


Create a function in the postgresql data base that maps the DATE_TO_CHAR function to to_char. Luckily the formatting options I need are available.

Now SELECT DATE_TO_CHAR(DateField1, "YYYY-MM-DD") FROM Table1 will return the correct value regardless of the database queried. It’s important to note this works great for getting integer values from dates and casting as date objects. If queries rely on returning non-iso formatting your mileage may vary.

-- Function: date_to_char(date, text)
CREATE OR REPLACE FUNCTION date_to_char(date, text)
       RETURN to_char($1,$2)::text;
  COST 100;
ALTER FUNCTION date_to_char(date, text) OWNER TO postgres;
-- Function: date_to_char(time without time zone, text)
CREATE OR REPLACE FUNCTION date_to_char(time without time zone, text)
       RETURN to_char($1,$2)::text;
  COST 100;
ALTER FUNCTION date_to_char(time without time zone, text) OWNER TO postgres;

Recently while importing a new physical schema from PostgreSQL 8.4 into Oracle Data Integrator(ODI) via JDBC driver all of the tables were reversing into the model without data types defined for text, double precision, smallint, integer and boolean.

If one or two fields are missing it’s easy enough to set the data type manually for the column, but for a whole mess of tables and thousands of fields it’s unrealistic.

The solution is to define the proper data types using the physical architecture tab with PostgreSQL internal names for the data types. Even though by default there is one for integer, looking at the data type definitions smallint maps to int2, integer maps to int4, double precision maps to float8, boolean maps to bool.

Using these aliases which are used internally by PostgreSQL for historical reasons in the ODI Physical Architecture will fix the missing data types during the reverse process.

Not really a big deal, but could save resources on larger arrays. Is also a clean code practice to avoid awkward traversing array and assigning to ‘itself’ from what is essentially a sub routine.

Does it really matter? Likely not. Using the below script on my 2.66 Core i7 with 8gigs of ram passing by reference is roughly 3-4 times faster. At 100000 array key value pairs the difference is still in microseconds (less than half a millisecond).

More information here: http://php.net/manual/en/language.references.pass.php


// want to loop over an array
$an_array = array();

// lets populate it with random values
for ($i=0; $i < 100000; $i++) { 
	$an_array[$i] = md5(uniqid(uniqid("",true),true));

// start

// now lets maniuplate the 'old' way
foreach ($an_array as $key => $value) {
	// this modifies the value at the index using the array and key
	$an_array[$key] = "ref original array and key";


// lets do it the 'new' way, notice we are passing &
foreach ($an_array as $key => &$value) {
	// $value is a reference to the $an_array[$key]
	$value = "changes source array";
// finish


Sample Executions

Object Pass reference
445 123
455 122
443 122
452 119
446 129

*Note* times in microseconds

%d bloggers like this: