Home » Archived » EGL Development Tools » Timestamps and nulls(Some notes on references, values, nulls and how they relate to timestamps)
Timestamps and nulls [message #760871] |
Mon, 05 December 2011 13:48 |
Joe Pluta Messages: 62 Registered: November 2011 |
Member |
|
|
This started out as a discussion of timestamps and why they have to have a question mark in a record. Here's what I learned about defining a timestamp: if it has a format, it's a value, if it doesn't it's a reference. Okya, fine, but I'm still wrapping my head around the fundamental difference between reference and value. This is the definition form the language reference:
Quote:A reference type defines an object, which is a value in a memory area that was separately allocated to hold the value. The object is referenced from some logic and is an instance of the type. In this case, the words "value," "object," and "instance" are interchangeable.
A value type defines a value that is embedded in an object.
From timestamp you get this:
Quote:A Timestamp with a format is a value. A Timestamp without a format is a reference, and it may point to any other Timestamp, with or without a format. It's not possible to create a Timestamp unless it has a format, i.e. new timestamp("yyyyMM") is valid but new timestamp is not.
If I work my way through this, what I get is this: a value is a distinct instance of a type, while a reference is a variable that refers to a type (and may or may not be null). That's not exactly how it reads; the idea of a value type being embedded in a reference type seems to overload the word "type" too much. But let me continue.
In Java, you can define a variable of type MyClass. That variable is a reference, and may contain either a null or an object of type MyClass (or its subclass, but that's irrelevant to this discussion). Object references (variables) are intrinsically null-capable. In EGL, nullability is an attribute; a variable can either be nullable or not. If it's not nullable, then when you declare the variable you are implicitly creating an object of that type.
And that's where the problem lies for timestamps. For reasons that aren't entirely clear to me, there is no default format for a timestamp and so you can't create a timestamp value without a format. You CAN create a variable of type timestamp without a format, but it cannot be implicitly initialized, because you can't create a value without a format. So, in order to declare a variable of type timestamp, you have to either declare it with a format or as nullable:
t1 timestamp ("hhmmss");
t2 timestamp?;
The former is initialized with a value of the current time in HHMMSS format, while the second is initialized with null.
See my next post for some interesting results of a test program.
|
|
| | |
Re: Timestamps and nulls [message #761695 is a reply to message #760899] |
Tue, 06 December 2011 22:34 |
Matt Heitz Messages: 36 Registered: July 2009 |
Member |
|
|
Hi Joe,
That's an awful lot to chew on. Can you point out the places where you have specific questions or concerns in your test programs?
Thanks,
Matt
P.S. Regarding your original post, it might help to think of a timestamp with a format as a record with two fields: its format and its value. Timestamp variables declared with the same format will have identical format fields, but their values may differ.
A timestamp without a format could be thought of as a pointer to that kind of record. The record it points to at one moment might have a different format and value from another record it points to later.
If a timestamp without a format is nullable, and you don't put an initializer on its declaration, its initial value is null because it has no timestamp record to point at.
ts timestamp?; // it's null
If you have a non-nullable timestamp without a format, you must initialize it, as in this example.
t1 timestamp("hhmmss");
t2 timestamp = t1;
It's an error to omit t2's initializer because t2 isn't nullable. That means it has to be pointing at some record, all the time.
|
|
| |
Re: Timestamps and nulls [message #762249 is a reply to message #762148] |
Wed, 07 December 2011 18:59 |
Brian Svihovec Messages: 55 Registered: July 2009 |
Member |
|
|
Joe,
Take a look at the function "asString(value ETimestamp in)" in the source code for EString.egl.
The comment for this function states:
/**
* {@Operation widen} Converts a timestamp to a string. The 26-character result
* will include all possible fields of a timestamp, from years down to fractions
* of seconds, in the format "yyyy-MM-dd HH:mm:ss.SSSSSS". Leading zeros are
* included in each field of the string when necessary, e.g. January is
* represented as "01" not "1".
*/
In the absence of a value for a field, it looks like the displayed value is using the 'initial values' for these fields.
If you want to display the value using a specific format, you can try:
Syslib.writestdout(StringLib.format(t1, "hhmmss"));
The functions provided by StringLib.egl can be found here.
I agree that this information needs to be made easily accessible, but hopefully we will be able to produce documentation from these comments in the future, without having to duplicate the information in the standard documentation.
-Brian
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 08:30:36 GMT 2024
Powered by FUDForum. Page generated in 0.02696 seconds
|