www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Type safety and time units in Go and D

reply "Atila Neves" <atila.neves gmail.com> writes:
My buddy Jeff never learns... he sent me a blog post link about 
Go development today and I ended up comparing how the bug 
mentioned in the blog post wouldn't happen in D:

https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/

Atila
Jan 20 2015
next sibling parent "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Tuesday, 20 January 2015 at 10:44:54 UTC, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link about 
 Go development today and I ended up comparing how the bug 
 mentioned in the blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/
FWIW this is type safe in a duck-typing language like Python too: from datetime import timedelta t = timedelta(10) assert( t + t == timedelta(20) ) t*t TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'datetime.timedelta'
Jan 20 2015
prev sibling next sibling parent reply "Paulo Pinto" <pjmlp progtools.org> writes:
On Tuesday, 20 January 2015 at 10:44:54 UTC, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link about 
 Go development today and I ended up comparing how the bug 
 mentioned in the blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/

 Atila
Just linked it on Reddit, http://www.reddit.com/r/d_language/comments/2t1kaj/typesafety_and_time_intervals_in_d_and_go/
Jan 20 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/20/15 3:56 AM, Paulo Pinto wrote:
 On Tuesday, 20 January 2015 at 10:44:54 UTC, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link about Go
 development today and I ended up comparing how the bug mentioned in
 the blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/


 Atila
Just linked it on Reddit, http://www.reddit.com/r/d_language/comments/2t1kaj/typesafety_and_time_intervals_in_d_and_go/
Better post in /r/programming. -- Andrei
Jan 20 2015
parent "Atila Neves" <atila.neves gmail.com> writes:
I went to post it but someone else already did:

http://www.reddit.com/r/programming/comments/2t25nx/typesafety_and_time_intervals_in_d_and_go_xpost/


Atila

On Tuesday, 20 January 2015 at 16:26:01 UTC, Andrei Alexandrescu 
wrote:
 On 1/20/15 3:56 AM, Paulo Pinto wrote:
 On Tuesday, 20 January 2015 at 10:44:54 UTC, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link 
 about Go
 development today and I ended up comparing how the bug 
 mentioned in
 the blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/


 Atila
Just linked it on Reddit, http://www.reddit.com/r/d_language/comments/2t1kaj/typesafety_and_time_intervals_in_d_and_go/
Better post in /r/programming. -- Andrei
Jan 20 2015
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/20/15 5:44 AM, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link about Go
 development today and I ended up comparing how the bug mentioned in the
 blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/
On the question of why that is the way it is, it's because we actually thought of all that shit when designing the time library :) I was a big proponent of not using the same type to mean duration and timestamp, and only allowing sane operations. Jonathan was the same way. You can see some if it here: http://forum.dlang.org/thread/340452.74950.qm web58008.mail.re3.yahoo.com http://forum.dlang.org/thread/201008141800.31122.jmdavisProg gmail.com http://forum.dlang.org/thread/201010081404.59147.jmdavisProg gmx.com Ah, the nostalgia :) -Steve
Jan 20 2015
next sibling parent reply Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Tuesday, January 20, 2015 08:24:34 Steven Schveighoffer via Digitalmars-d
wrote:
 On 1/20/15 5:44 AM, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link about Go
 development today and I ended up comparing how the bug mentioned in the
 blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/
On the question of why that is the way it is, it's because we actually thought of all that shit when designing the time library :) I was a big proponent of not using the same type to mean duration and timestamp, and only allowing sane operations. Jonathan was the same way.
That separation is one of the main reasons for introducing MonoTime recently as a replacement for TickDuration, because TickDuration conflates the monotonic timestamp and monotonic duration. With MonoTime, we end up with a separate monotonic timestamp and then use the same duration type that we've been using everywhere else (Duration), which then also has the benefit of reducing the number of duration types (which has caused far too much confusion). But TickDuration was a minimally changed version of SHOO's Ticks type, and I did a very poor job of integrating it into core.time and std.datetime when std.datetime was introduced. It's never really fit with the rest. - Jonathan M Davis
Jan 20 2015
parent "Laeeth Isharc" <Laeeth.nospam nospam-laeeth.com> writes:
  the question of why that is the way it is, it's because we
 actually
 thought of all that shit when designing the time library :) I 
 was a big
 proponent of not using the same type to mean duration and 
 timestamp, and
 only allowing sane operations. Jonathan was the same way.
That separation is one of the main reasons for introducing
I would like to express my appreciation to the implementors (I guess Jonathan and Stephen) as well as to the Phobos guardians for taking the pains to implement the datetime library in a thoughtful and conscious way. Dates are not conventionally the most glamorous part of a library, but they are very important in some key use cases for D. Much of finance is about net present value, and for that you need to get datetimes right. Every swap has a bunch of cashflows, and you need to apply various market conventions in generating these. Eg cashflows are every three months, and you roll forward if the payment day is a holiday, unless that would take you to the next month, in which case you roll backwards. Similarly for analyzing high frequency data, one needs to be able to work easily with timestamps. I was so frustrated by numpy's datetime64 that I ended up rolling my own, so it is encouraging that my new chosen platform (D) natively does a much better job. The level of attention to detail, high standards, and appreciation of beauty are some of the best things about the language and the people here. On a different note, and having read the discussion Jonathan linked to: bounded int, and better messages about template constraints would certainly be things I would find helpful.
Jan 20 2015
prev sibling parent reply "Atila Neves" <atila.neves gmail.com> writes:
The question about how it is the way it is was about why the Go 
library allows things like that since the Go team apparently does 
believe in type safety. Nevertheless, thanks for the links!

Atila

On Tuesday, 20 January 2015 at 13:24:34 UTC, Steven Schveighoffer 
wrote:
 On 1/20/15 5:44 AM, Atila Neves wrote:
 My buddy Jeff never learns... he sent me a blog post link 
 about Go
 development today and I ended up comparing how the bug 
 mentioned in the
 blog post wouldn't happen in D:

 https://atilanevesoncode.wordpress.com/2015/01/20/type-safety-and-time-intervals-in-d-and-go/
On the question of why that is the way it is, it's because we actually thought of all that shit when designing the time library :) I was a big proponent of not using the same type to mean duration and timestamp, and only allowing sane operations. Jonathan was the same way. You can see some if it here: http://forum.dlang.org/thread/340452.74950.qm web58008.mail.re3.yahoo.com http://forum.dlang.org/thread/201008141800.31122.jmdavisProg gmail.com http://forum.dlang.org/thread/201010081404.59147.jmdavisProg gmx.com Ah, the nostalgia :) -Steve
Jan 20 2015
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/20/15 10:34 AM, Atila Neves wrote:
 The question about how it is the way it is was about why the Go library
 allows things like that since the Go team apparently does believe in
 type safety.
Yes, I misread "I showed him the code and he seemed really interested in it, and also wondered which design decisions led to the current state of affairs." as the state of affairs in D. :) -Steve
Jan 20 2015