Enhancement
Add format function to the Tobject API
Issue description
Many times a statement is simply written out (transformed into a string). The code becomes complicated on optional statements. This could be simplified by using a format function. It would get a format and an optional string that gets printed if there is no statement.
Developer comments
Currently the code looks like this:
[%$date = $something->get_start_date();
$date_str = $date !== null ? $date->format("d.m.Y") : "Open"; %]
This could be:
[%$date_str = $somthing->format_start_date("d.m.Y", "Open"); %]
Many times even variable assignment could be omitted, since the purpose of the code frament is solely the output of the statement.
This would make the service code look much better:
* The code of the computational component would be freed of code fragments like the above. These are too complicated and are put in the computational component solely, because they would have a negative effect on the legebility of the presentational (markup) component.
* The code of the presentational component would be clearer since a functional call expression is more meaningful, where as in the case of the variable name, there is a chance that the coder assigns a "bad name".
The format argument is interpreted in relationship to the kind of occurrence that is retrieved. Would calls on names or associations make sense? Initially it seems no, but if you allow the format argument to be a function (which returns a string in all cases) … who knows, might have some benefit.
It is the responsilbility of the coder make sure the format parameter matches the statement retrieved.
Rejection comment
This is no longer an issue with the nullsafe operator. The code will look like this:
[% $date_str = $something?->get_start_date()?->format("d.m.Y") ?? "Open" %]
Good enough.
|
|
We are sorry
This page cannot be displayed in your browser. Use Firefox, Opera, Safari, or Chrome instead.