Is unix time function in wrong module?

2021-05-19 Thread Martin via Digitalmars-d-learn

Hi,

shouldn't the unix time functions be in std.datetime.Date and 
std.datetime.DateTime instead of std.datetime.SysTime?


The documentation states:
- "std.datetime.systime for a point in time with a timezone."
- "std.datetime.date for points in time without timezones."

Unix epoch is 00:00:00 UTC on 1 January 1970 - and UTC is a 
standard, not a timezone.
if i am not mistaken timezones getting applied on UTC - so i do 
not understand why the unix time functions are in the modules 
which are "timezone aware" and not in the modules without a 
timezone awareness.


Re: How do I create classes dynamically?

2021-04-15 Thread Martin via Digitalmars-d-learn

On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote:
I wanted to find out if it is possible to create classes 
dynamically.


out of curiosity: Why you would like to do this? I cannot think 
of a use case for this - this is why i ask.


null and initialized string comparisons

2021-02-17 Thread Martin via Digitalmars-d-learn

Hi,

is this how it supposed to be? (https://run.dlang.io/is/7B4irm)
---
string a = null;
string t = "";

assert( ! a );
assert( t );
assert( t == a );
---

I have not expected assert(t == a) to be true - i would like to 
know the argument for why this is correct when at the same time 
assert(!a) and assert(t) is true.. feels a litle bit js-ish to me


Tuple or struct as return type?

2021-02-06 Thread Martin via Digitalmars-d-learn

Hi,

lets say i want to create a function that returns multiple values 
- e.g. Tuple!(string,string).


Why/when i should prefer Tuple as a return type over returning a 
struct (or even string[2] in this case)?


Thank you



Re: why is "hello".writeln considered bad?

2020-11-20 Thread Martin via Digitalmars-d-learn

On Friday, 20 November 2020 at 10:03:18 UTC, Daniel Kozak wrote:
I remember days when I liked UFCS too . Unfortunately  it is 
not so awesome when you use it with IDE.


And I would like to add: if you use in a bigger team. It's 
annoying when every dev have a own taste.. And together with 
optional () it's hell - no joke.
The need to think about codeatyle definitions in such detail is a 
nogo for big projects.


Re: magically a static member on init?

2020-11-15 Thread Martin via Digitalmars-d-learn

On Sunday, 15 November 2020 at 00:29:41 UTC, H. S. Teoh wrote:
if you don't like the semantics, don't use it; always allocate 
the field in the class ctor instead.


Hi, i neither like it nor dislike it - it just caught me by 
surprise because i was under the impression that if i create a 
new instance then all members get initialized according to the 
declared optional default value.


I can see how this is a feature - but it is also of kind "expert 
knowledge" and i would argue that "expert knowladge" is a designs 
arch enemy.


Re: magically a static member on init?

2020-11-14 Thread Martin via Digitalmars-d-learn
On Saturday, 14 November 2020 at 23:30:58 UTC, Adam D. Ruppe 
wrote:

On Saturday, 14 November 2020 at 23:20:55 UTC, Martin wrote:

Is this intentional?

[...]


alright, thank you! :)


magically a static member on init?

2020-11-14 Thread Martin via Digitalmars-d-learn

Hi, i do no know if this is intended - but imo this is weird:
https://run.dlang.io/is/eBje3A

I expected that `c.a.str == ""` (just like `c.str` is). But 
instead `c.a.str` keeps the value of `b.a.str`.


Is this intentional? IMO this feels not consistent and its weird 
when a reference leaks into another instance without having 
declared it static member.


Greetigs


Re: vibe.d / experience / feedback

2020-10-03 Thread Martin via Digitalmars-d-learn

On Friday, 2 October 2020 at 09:46:09 UTC, Denis Feklushkin wrote:

Because standard implementation worse?


What do you mean with "worse"?
In my experience std.json is a very thin implementation of the 
JSON spec - without/very low "magic". IMO this is what one wants 
in a std lib. Its a good starting point for further simplfication 
wrappers or framework specific magic (what vibe actually do, if i 
am not mistaken


passing a parrameter read-only ref?

2020-09-13 Thread Martin via Digitalmars-d-learn

Hi,
i would like to create a function which takes the first parameter 
as a reference to a struct - but assure the calle that the 
reference is read-only. Can this be done?


If i am not mistaken, then the "in" Parameter Storage Class is 
what i want(?). But the documentation states that this feature 
should not be used.


For context: I want to write struct-methods outside the struct 
(like in golang).


Re: How to compile Windows exe files from this source

2020-08-12 Thread Martin via Digitalmars-d-learn

On Sunday, 9 August 2020 at 19:04:07 UTC, Marc wrote:
I don't know much more about D than creating a 'hello world' 
exe file with the DMD Compiler

but I'm interested in using the eBay/tsv-utils binaries.
Unfortunately, the author didn't create any MS Windows binaries:
https://github.com/eBay/tsv-utils/releases

Does anyone know how to compile this code into MS Windows 
binaries?


It is a bit off-topic but I strongly suggest that you take a look 
at the windows subsystem for Linux, that is a on-board feature in 
Windows 10 
(https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab)


It makes working with tools like tsvutils much more effective.


Re: Factory pattern for classes

2020-08-10 Thread Martin via Digitalmars-d-learn

On Sunday, 9 August 2020 at 15:56:31 UTC, Ali Çehreli wrote:

module deneme;

import std.stdio;

interface I {
  void methodName();
}
...
I getClassById(uint id)
{
if (id == 0) {
return cast(A)Object.factory("deneme.A");
} else if(id == 1) {
return cast(B)Object.factory("deneme.B");
} else {
return cast(C)Object.factory("deneme.C");
}
}

void main() {
  auto o = getClassById(1);
  o.methodName();
}


Why not simply do?

I getClassById(uint id)
{
   if (id == 0) {
   return new A();
   } else if(id == 1) {
   return new B();
   } else {
   return new C();
   }
}


Then you can also pass parameters to the constructors or call 
further factories to create them, as long as they return a 
`I`-compatible type.


Re: Polymorphism? Passing arguments

2017-11-03 Thread Martin via Digitalmars-d-learn

ok, thanks you very much for the information.




Re: Polymorphism? Passing arguments

2017-11-03 Thread Martin via Digitalmars-d-learn

Thank you for the answer

On Saturday, 4 November 2017 at 01:35:41 UTC, Adam D. Ruppe wrote:

Why are these ref?
Just taking ref away from both of those will likely fix your 
problems.


because without it i get the error "Program exited with code -11"

The thing is, somwhere deeper in `setRelation` i call two 
functions:

```
public void addChild(ref Node child) {
  this.children ~= 
}

public void setParent(ref Node parent) {
  this.parent = 
}
```




Polymorphism? Passing arguments

2017-11-03 Thread Martin via Digitalmars-d-learn

I have a interface
`interface Node {...}`

and some classes implementing Node:
```
class Text : Node {...}
class Element : Node {...}
```
and a function like this:
`public void setRelation(ref Node parent , ref Node child) {...}`

if i do this it works:
```
Node root = new Element("root");
Node text = new Text("blah");
setRelation(root ,  text);
```

but this does not:
```
Node root = new Element("root");
setRelation(root , new Text("blah"));
```
Error: function Nodes.setRelation (ref Node parent, ref Node 
child) is not callable using argument types (Node, Text)


Why is this? Text implements Node. This is how i do it in other 
Languages - How can would be this possible in D?


how to harvest the results of tasks from a taskpool?

2017-07-05 Thread Martin via Digitalmars-d-learn

Hi,

i have a coulpe of different machines with MySQL Servers running 
on it.
Now, i want to execute queries for all Databases at the same time 
and collect the Result to process it.


I am new to the parallelism - so maybe i understand something 
totaly wrong.

What i tring is something like this:


{
 auto tPool = new TaskPool();
 forach(server ; servers)
 {
  auto task = task!queryWorker(query);
  tPool.put(task);
 }

 tPool.finish(true);
//> how to collect the results now? <---

}

row[] queryWorker(string query) {

 //rows = result of the query

 return rows;
}


btw.. how to markup code in this forum?


Tuple/Typedef question

2015-01-11 Thread Martin via Digitalmars-d-learn

Is there a way to get Tuple (and Typedef) from the std.typecons
module to generate a new type that is unique on every
instantiation? What I mean is:

alias T1 = Tuple!(int, int);
alias T2 = Tuple!(int, int);

writeln(__traits(isSame, T1, T2)); // prints true

When using Typedef, the types are still the same:

alias T1New = Typedef!(T1);
alias T2New = Typedef!(T2);

writeln(__traits(isSame, T1New, T2New)); // still prints true

The documentation of Typedef says:
Typedef allows the creation of a unique type which is based on
an existing type. Unlike the alias feature, Typedef ensures the
two types are not considered as equals.

Shouldn't the second part at least print false then?


Re: Tuple/Typedef question

2015-01-11 Thread Martin via Digitalmars-d-learn
On Sunday, 11 January 2015 at 11:52:42 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Sun, 11 Jan 2015 11:41:08 +
Martin via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


Is there a way to get Tuple (and Typedef) from the std.typecons
module to generate a new type that is unique on every
instantiation? What I mean is:

alias T1 = Tuple!(int, int);
alias T2 = Tuple!(int, int);

writeln(__traits(isSame, T1, T2)); // prints true

When using Typedef, the types are still the same:

alias T1New = Typedef!(T1);
alias T2New = Typedef!(T2);

writeln(__traits(isSame, T1New, T2New)); // still prints true

The documentation of Typedef says:
Typedef allows the creation of a unique type which is based on
an existing type. Unlike the alias feature, Typedef ensures the
two types are not considered as equals.

Shouldn't the second part at least print false then?

as for `Typedef!` -- you can use it's third arg, cookie:

  import std.typecons;

  alias T1 = Tuple!(int, int);
  alias T2 = Tuple!(int, int);

  alias T1New = Typedef!(T1, T1.init, t0);
  alias T2New = Typedef!(T2, T2.init, t1);

  pragma(msg, __traits(isSame, T1New, T2New)); // false

there was a heated discussion about `std.typecons.Typedef`, 
built-in
`typedef` and other related things, but the decision was to 
keep the

status quo.


I can't believe I missed the cookie part. Thanks!


spawnProcess command-line arguments help

2014-08-03 Thread Martin via Digitalmars-d-learn
When I use the spawnProcess function in std.process, the command 
line arguments that I provide to the function seem to get 
quoted. Is there a way to tell the spawnProcess function that I 
want the command line arguments to be non-quoted?


Example:
spawnProcess([SomePath\\Test.exe], [-silent]);
and the command line becomes: SomePath\Test.exe -silent (with 
the quotes exaclt like shown).


Unfortunately (for some strange reason), the spawned process only 
responds to non-quoted arguments passed through the command line. 
So the command line should be exactly: SomePath\Test.exe -silent


Is there any way to achieve this?