Re: Effective String to Date conversion?

2024-01-28 Thread Mengu via Digitalmars-d-learn

On Monday, 22 January 2024 at 10:56:04 UTC, atzensepp wrote:

Dear D-gurus,

being new to D I am trying my first steps and the language is 
quite intuitive and appealing.
When reading a file and creating a hash for the reocrds I want 
to get only the most recent ones. For this I need to convert 
Date/Time-Strings to comparable DateTime-Objects.
The code below works but looks a bit clumsy. Is there a more 
efficient (shorter) way to accomplish this?


[...]


If your date conforms to an ISO or extended ISO format, you can 
use DateTime.fromISOString [0] or DateTime.fromISOExtString [1] 
functions.


[0] 
https://dlang.org/phobos/std_datetime_date.html#.Date.fromISOString
[1] 
https://dlang.org/phobos/std_datetime_date.html#.Date.fromISOExtString


Re: length's type.

2024-01-28 Thread mw via Digitalmars-d-learn

On Sunday, 28 January 2024 at 16:16:34 UTC, Olivier Pisano wrote:


If .length were to be an int, D could not handle array of more 
than 2G bytes. The whole language would be useless on 64 bit 
systems.



The array.length better to be *signed* `long` (signed size_t) 
instead of unsigned.


Can you guess what is the output of this array element average 
calculation example:


==
import std.algorithm;
import std.stdio;

void main() {
  long[] a = [-5000, 0];
  long   c = sum(a) / a.length;
  writeln(c);
}
==

See the result here:

https://forum.dlang.org/post/cagloplexjfzubncx...@forum.dlang.org


Re: length's type.

2024-01-28 Thread monkyyy via Digitalmars-d-learn

On Thursday, 18 January 2024 at 02:55:37 UTC, zjh wrote:
Can you change the type of 'length' from 'ulong' to 'int', so I 
haven't to convert it every time!


The devs are obviously very very wrong here I underflow indexs 
all the time


But this is a pretty dead fight, I'd aim for a smart index type 
thats a "checkedint" with underflow protection and can alias to 
int; cause maybe that could someday happen.


Re: length's type.

2024-01-28 Thread monkyyy via Digitalmars-d-learn

On Sunday, 28 January 2024 at 16:16:34 UTC, Olivier Pisano wrote:

On Sunday, 28 January 2024 at 08:55:54 UTC, zjh wrote:
On Sunday, 28 January 2024 at 06:34:13 UTC, Siarhei Siamashka 
wrote:


The explicit conversion `.length.to!int` has an extra benefit



I rarely use numbers over one million.

But do I have to consider numbers over `4 billion` every day?


If .length were to be an int, D could not handle array of more 
than 2G bytes. The whole language would be useless on 64 bit 
systems.


_Of bytes_ and if your messing with the type and still think 
that's an important concern you could make it a long for 63 bits 
and no silly 0-1 behavior


a signed index of a datatype that is 2 words will still compete 
with the mythical computer ram of a max ram 64 bit machine; if 
you have 64^2 ubytes maybe you should rotate your prospective and 
store 256 counts of each.





Re: length's type.

2024-01-28 Thread Olivier Pisano via Digitalmars-d-learn

On Sunday, 28 January 2024 at 08:55:54 UTC, zjh wrote:
On Sunday, 28 January 2024 at 06:34:13 UTC, Siarhei Siamashka 
wrote:


The explicit conversion `.length.to!int` has an extra benefit



I rarely use numbers over one million.

But do I have to consider numbers over `4 billion` every day?


If .length were to be an int, D could not handle array of more 
than 2G bytes. The whole language would be useless on 64 bit 
systems.





Re: length's type.

2024-01-28 Thread zjh via Digitalmars-d-learn
On Sunday, 28 January 2024 at 06:34:13 UTC, Siarhei Siamashka 
wrote:


The explicit conversion `.length.to!int` has an extra benefit



I rarely use numbers over one million.

But do I have to consider numbers over `4 billion` every day?