* Kurtis Rader <
kra...@skepticism.us> [210505 23:35]:
The fact that this sort of confusion over the layout for Time.Format
occurs frequently is a good indication that the approach taken is not as
programmer-friendly as it ought to be. However, Time.Format has what I
consider to be a much more egregious design flaw; one that should have
ruled it out as the design for the standard library: the notation
cannot unambiguously represent any desired format containing literals.
If you want literal digits in the output, you are unlikely to be able
use a single call to Time.Format without additional string manipulation
afterward.
Try to code the Go equivalent of the Linux command «date +"%Y 4 %d"».
You either need two calls to Time.Format with string concatenation, or
you must manipulate the string result of Time.Format to insert the
literal "4".
The %x notation is used in Go's fmt package, so this syntax must already
be clearly understood by a Go programmer. This notation allows any
literal to be unambiguously contained within the format string. Why add
the cognitive overload of a completely different notation for time
formatting that many programmers struggle to understand? Also, I would
be very surprised if there were many Go programmers who never have to
look up which reference digit to use for day and which for seconds; the
order is arbitrary and not logical. It doesn't take much to remember
that %H %M %S is hours, minutes, and seconds, while %y %m %d is year,
month, and day.
I would be willing to bet that if a Time.Printf were added to the time
package, it would very quickly become the overwhelming favorite over
Time.Format. This would be a compatible change that could easily be
added without violating the Compatibility Promise.
If I were designing this, however, I would not just copy the Linux date
format. I would use format modifiers similar to the fmt package. E.g.
instead of %y for two-digit year and %Y for four-digit year, year would
always be %y with a way to indicate how it should be formatted.
...Marvin