I recently had the thought that VF could use a date literal and (maybe) a Date type. A date literal would add consistency by allowing the compiler to check for correctness instead of relying on opaque string literals, as LB does.
Visual Basic also has a date literal, but I'm sure that many people find it odd because it insists on using the US-centric mm/dd/yyyy format for dates and assumes a 12-hour time format. For example, the current date and time here is #7/22/2014 8:43 PM#.
The format I propose for VF would be a bit more internationalized. The same value from above would be represented as @2014-7-22:20:43:00.
The date parts could also be separated by slashes (@2014/7/22) or dots (@2014.7.22). The time part can be left off a date and defaults to 00:00:00.0. Or the literal can leave the date part off and just represent a time value; the date part defaulting to 0001-01-01 (or whatever is appropriate).
A Date type would almost certainly be represented with a 64-bit integer, given the looming Y2038 problem. But then I have to consider how much resolution to have in the time. VB's Date type uses 64 bits with a 100 nanosecond resolution and a range between #1/1/0001# and #12/31/9999#. I suppose that would be alright.
Do you have any comments or questions?
Subject: Experiment - Date literals and data type
Subject: Re: Experiment - Date literals and data type
I like the approach of using the sortable date format, which makes it much easier to understand the parts of it.
How about using a semicolon to separate the date from the time?
This would make it easier to parse the string and split it up into date and time.
In general time resolution of milliseconds should be sufficient, so 100 nanoseconds would be enough.
How about using a semicolon to separate the date from the time?
This would make it easier to parse the string and split it up into date and time.
In general time resolution of milliseconds should be sufficient, so 100 nanoseconds would be enough.
Subject: Re: Experiment - Date literals and data type
I'm not sure about people's ability to distinguish a semicolon from a colon in unspaced text. I'd guess that many people would see colons instead, and get syntax errors.
My reason for using a colon is because the Apache Web server's logs use a date/time format like 26/Jul/2014:12:34:56. Of course that isn't exactly the same format as I suggested and might confuse people as well.
I wonder how you all think about a format like
@2014-07-26@12:34:56
?
It sounds pretty natural if you read it out loud in English IMO.
STPendl wrote: |
How about using a semicolon to separate the date from the time?
This would make it easier to parse the string and split it up into date and time. |
I'm not sure about people's ability to distinguish a semicolon from a colon in unspaced text. I'd guess that many people would see colons instead, and get syntax errors.
My reason for using a colon is because the Apache Web server's logs use a date/time format like 26/Jul/2014:12:34:56. Of course that isn't exactly the same format as I suggested and might confuse people as well.
I wonder how you all think about a format like
@2014-07-26@12:34:56
?
It sounds pretty natural if you read it out loud in English IMO.
Subject: Re: Experiment - Date literals and data type
Here's an example that uses a couple Dates in a struct.
Note that when a Date is converted into a string, it is automatically formatted for the user's locale.
Code: |
Struct person
name As String birth As Date death As Date End Struct Dim US_presidents() As person = { _ { "George Washington", @1732-02-22, @1799-12-14 }, _ { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _ { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _ } Dim randDate As Date = RandomDate() For Each prez In US_presidents() If prez.birth <= randDate <= prez.death Tol @12:00:00 #out "President " & prez.name & " was alive in " & randDate & "." End If End For End |
Note that when a Date is converted into a string, it is automatically formatted for the user's locale.
Subject: Re: Experiment - Date literals and data type
Just tried to run the example, but failed to get it run correctly with the latest VF.exe
May be the debug output could contain the version number of the VF.exe to make sure the latest version is used for testing.
It seems that struct is not a recognized keyword.
May be the debug output could contain the version number of the VF.exe to make sure the latest version is used for testing.
Code: |
require IO #out Struct person name As String birth As Date death As Date End Struct Dim US_presidents() As person = { _ { "George Washington", @1732-02-22, @1799-12-14 }, _ { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _ { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _ } Dim randDate As Date = RandomDate() For Each prez In US_presidents() If prez.birth <= randDate <= prez.death Tol @12:00:00 #out "President " & prez.name & " was alive in " & randDate & "." End If End For End |
Quote: |
C:\Users\Stefan\Documents\Prog\ViviFire>VF.exe -v2 "Date Sample.txt" 138:require 24:IO 26:#out 1:?-- line 3 col 1: invalid UserModule 141:Struct 24:person 1:? 24:name 89:As 122:String 1:? 24:birth 89:As 132:Date 1:? 24:death 89:As 132:Date 1:? 48:End Struct 1:?-- line 8 col 1: EOF expected -- 2 errors |
It seems that struct is not a recognized keyword.
Subject: Re: Experiment - Date literals and data type
Hi Stefan,
The root of the problem is that the code I posted is unlabeled pseudocode.
So far, STRUCTs (and several other declarations) are legal only within LIBRARY modules. However, after giving it some thought, I can see that this was a rather arbritrary decision on my part. Most people would be annoyed to have to create a new source file just to declare a tiny STRUCT. So, expect to see this corrected in the next release.
EDIT
So, now I go look at the grammar and I see that STRUCTs are allowed inside user modules, but only after the END statement. If you simply move the STRUCT in the code to the end, it should parse with no errors.
Would you prefer the ability to place STRUCTs wherever you want? Or at least wherever you want at the module level?
The root of the problem is that the code I posted is unlabeled pseudocode.
So far, STRUCTs (and several other declarations) are legal only within LIBRARY modules. However, after giving it some thought, I can see that this was a rather arbritrary decision on my part. Most people would be annoyed to have to create a new source file just to declare a tiny STRUCT. So, expect to see this corrected in the next release.
EDIT
So, now I go look at the grammar and I see that STRUCTs are allowed inside user modules, but only after the END statement. If you simply move the STRUCT in the code to the end, it should parse with no errors.
Would you prefer the ability to place STRUCTs wherever you want? Or at least wherever you want at the module level?
Subject: Re: Experiment - Date literals and data type
The following is now parsed without error.
I would appreciate being able to place the declaration wherever I want in the module.
I usually prefer to place variable declarations at the beginning of the code for global variables and at the beginning of a procedure for local variables.
It is strange to have a variable or custom type used before its declaration.
Having procedures declared after the main code looks familiar, even so many languages force declaration of procedures before their use too.
Code: |
require IO #out Dim US_presidents() As person = { _ { "George Washington", @1732-02-22, @1799-12-14 }, _ { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _ { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _ } Dim randDate As Date = RandomDate() For Each prez In US_presidents() If prez.birth <= randDate <= prez.death Tol @12:00:00 #out "President " & prez.name & " was alive in " & randDate & "." End If End For End Struct person name As String birth As Date death As Date End Struct |
I would appreciate being able to place the declaration wherever I want in the module.
I usually prefer to place variable declarations at the beginning of the code for global variables and at the beginning of a procedure for local variables.
It is strange to have a variable or custom type used before its declaration.
Having procedures declared after the main code looks familiar, even so many languages force declaration of procedures before their use too.
Page 1 of 1
You can post new topics in this forumYou can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum