Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 20, 2023 at 01:32:22PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/20/23 07:01, torhu wrote: > > > But why not have drawLine just be a free function? > > Exactly. > > If I'm not mistaken, and please teach me if I am wrong, they are > practically free functions in Java

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ali Çehreli via Digitalmars-d-learn
On 1/20/23 07:01, torhu wrote: > But why not have drawLine just be a free function? Exactly. If I'm not mistaken, and please teach me if I am wrong, they are practically free functions in Java as well. That Java class is working as a namespace. So, the function above is the same as the

Re: vibe.d + mongoDB

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 18:58:16 UTC, seany wrote: Hi I am googling to find some vibe.d and mongoDB tutorial. Are their some available? Thank you There is a nice book, titled D Web Development, that despite being 6 years old, is still mostly applicable to using vibe.d. The only

Re: vibe.d + mongoDB

2023-01-20 Thread Ben Jones via Digitalmars-d-learn
On Friday, 20 January 2023 at 18:58:16 UTC, seany wrote: Hi I am googling to find some vibe.d and mongoDB tutorial. Are their some available? Thank you There's a couple of examples like this one in main vibe repo in the examples directory:

vibe.d + mongoDB

2023-01-20 Thread seany via Digitalmars-d-learn
Hi I am googling to find some vibe.d and mongoDB tutorial. Are their some available? Thank you

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: For what I want, `constraintsOf` may expect every template parameter to be a type and to have a constraint. If I'm not mistaken, the following will help: https://dlang.org/phobos/std_range_primitives.html SDB@79=

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? No, reflection over templates is very limited.

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 12:15 PM, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; //

Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Quirin Schroll via Digitalmars-d-learn
Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; // tuple(long, const(char)[]) ``` At the moment, I

Re: What is the 'Result' type even for?

2023-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 20, 2023 at 12:49:54PM +, Ruby The Roobster via Digitalmars-d-learn wrote: [...] > Thank you. I didn't know that there was such a property `.array`. It's not a property, it's a Phobos function from std.array. T -- INTEL = Only half of "intelligence".

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread torhu via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to)

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 6:28 AM, thebluepandabear wrote: This type of semantics is not possible in D, which sucks. Well, static methods do exactly this. If you want to disable class creation, then use `@disable this();`, if you want to make all methods static, put `static:` at the top of the class.

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:38:52 UTC, Hipreme wrote: On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: ... [snip] With a single file, you can do: ```d final class Algo { @disable this(); static: void drawLine(...){} } ``` This also works, but it

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:38:47 UTC, evilrat wrote: On Friday, 20 January 2023 at 13:17:05 UTC, Ruby The Roobster ... [snip] Also there is various import options such as renamed import or static import(doesn't add module to a scope thus requiring to fully qualify it) static import,

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Hipreme via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to)

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread evilrat via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:17:05 UTC, Ruby The Roobster wrote: On Friday, 20 January 2023 at 13:03:18 UTC, thebluepandabear wrote: ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:03:18 UTC, thebluepandabear wrote: ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static class` but I doubt it will happen. D isn't Java, and never will be.

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread thebluepandabear via Digitalmars-d-learn
ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static class` but I doubt it will happen.

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 12:55:37 UTC, Ruby The Roobster wrote: On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear ... There is no way to implement that functionality in D. `final` means that the class cannot be extended, and `abstract` requires that only an extension of said

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to)

Re: What is the 'Result' type even for?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:39:48 UTC, H. S. Teoh wrote: On Fri, Jan 20, 2023 at 03:34:43AM +, Ruby The Roobster via Digitalmars-d-learn wrote: On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: > On 1/19/23 10:11 PM, Ruby The Roobster wrote: > ... > > The point

Re: What is the 'Result' type even for?

2023-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 04:46:07 UTC, Ali Çehreli wrote: Different instantiations of templates are distinct types. For example, if I called 'alternate' with two 'long' values, both alternate!int (as instantiated by the code above) and alternate!long would have different MyResult struct

Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread thebluepandabear via Digitalmars-d-learn
Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to) { .. }; } ``` Class in use: ``` Algo.drawLine(new Canvas(), new