Compile time vs run time -- what is the difference?

2022-12-27 Thread thebluepandabear via Digitalmars-d-learn
I am reading through the free book on learning D by Ali Çehreli and I am having difficulties understanding the difference between compile time execution and run time execution in D language. What I do understand is that compile time and run time are the two processes that your code goes

Re: Compile time vs run time -- what is the difference?

2022-12-28 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 28 December 2022 at 09:10:38 UTC, areYouSureAboutThat wrote: On Wednesday, 28 December 2022 at 02:31:45 UTC, thebluepandabear wrote: .. Other errors are only able to be spotted during run time such as exceptions, dividing by zero, assert blocks. With regards to the 'assert

Re: Is there such a JSON parser?

2023-01-01 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 1 January 2023 at 23:28:12 UTC, torhu wrote: I need to parse some JSON data into various data structures, so I'm looking for a parser based on events or ranges. One that doesn't just load the file and build a data structure that represents the whole thing. So not std.json, at least.

Re: Is there a way to enforce UFCS?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though.

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
``` These two solutions should compile to approximately the same runtime code, with optimizations enabled. So, it's really down to personal preference; the former is more explicit about what the computer is to do, while the latter is more concise. Thanks! Works great.

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
On Thursday, 5 January 2023 at 17:36:55 UTC, H. S. Teoh wrote: On Thu, Jan 05, 2023 at 11:55:33AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] ```D foreach (BoardSize boardSize; arr) { Button button = new Button(); button.text = format("%sx%s", boardSize[0], b

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
Have fun reading this : https://issues.dlang.org/show_bug.cgi?id=21929 Thanks for the code suggestion although it still doesn't fix the bug. I am curious as to what those brackets do as well.

Re: Coding Challenges - Dlang or Generic

2023-01-09 Thread thebluepandabear via Digitalmars-d-learn
I know. Someone's going to say why don't YOU do it:) regards, The official book on D by Ali has many coding challenges. There isn't any need to create a website for D coding challenges or incorporate it into an existing website since D has under 1% of the market share.

Re: Is there a way to enforce UFCS?

2023-01-04 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo,

How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
I am using CSFML D bindings and I have created my own sort of UI library for drawing elements onto the screen. One of the classes I've created is a `Button` class, which contains a delegate called `onButtonClick` which is called when the button is clicked on by the user. Up until now,

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
Update some time later: the only way (oof!) around this seems to be using a `static foreach` with arrays: ```D Button[3] b; static foreach (indx, BoardSize boardSize; arr) { b[indx] = new Button(); b[indx].text = format("%sx%s", boardSize[0], boardSize[1]); b[indx].onButtonClick

(Noob question) Should subclasses be defined in separate modules?

2023-01-12 Thread thebluepandabear via Digitalmars-d-learn
(Sorry if this is a duplicate.) If I have the following code inside of a module: ```D class Obj { private { string name = "Hi"; } } class ObjDerived : Obj { } ``` Is it best practice to define `ObjDerived` inside another module, since `ObjDerived` can still access the

Why does this code only work with `std.conv.to` whilst not with `cast`?

2023-01-08 Thread thebluepandabear via Digitalmars-d-learn
I've been writing some code and I have been experimenting with casting. I've found that sometimes only `std.conv.to!` does the job over casting, and I am unsure why this is the case as I assumed that they are both the same. I have the following interface: ```D interface ICustomDrawable {

Re: Why does this code only work with `std.conv.to` whilst not with `cast`?

2023-01-08 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 8 January 2023 at 12:35:38 UTC, matheus wrote: On Sunday, 8 January 2023 at 11:29:10 UTC, thebluepandabear wrote: ... There is an explanation here: https://forum.dlang.org/post/tqukutfzeaxedunuv...@forum.dlang.org But in any case I'd like to point it out that I think you could

Is there a way to enforce UFCS?

2023-01-03 Thread thebluepandabear via Digitalmars-d-learn
Say you have the following class which represents a dog : ```D class Dog { @property { string name(); void name(string name) { _name = name; } } private { string _name; } } ``` And you have the following code with constructs a `Dog`

Why does this code only work with `T` and not `typeof(T)`?

2023-01-03 Thread thebluepandabear via Digitalmars-d-learn
I am using the CSFML D bindings, and I am creating my own `draw` template function. I first check that the object passed in is of the appropriate type, and if it is, I call the appropriate function: ```D template isDrawable(T) { enum isDrawable = is(T == sfCircleShape*) || is(T ==

Re: Why does this code only work with `T` and not `typeof(T)`?

2023-01-03 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 04:42:08 UTC, Ali Çehreli wrote: On 1/3/23 20:11, thebluepandabear wrote: > if I replace the `isDrawable` template with the > following (using `typeof`), the code does not compile: It must be because T is already a type. It's the same reason why the following

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread thebluepandabear via Digitalmars-d-learn
That's not a utf-8 code unit. Hm, that specifically might not be. The thing is, I thought a UTF-8 code unit can store 1-4 bytes for each character, so how is it right to say that `char` is a utf-8 code unit, it seems like it's just an ASCII code unit.

Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread thebluepandabear via Digitalmars-d-learn
Hello (noob question), I am reading a book about D by Ali, and he talks about the different char types: char, wchar, and dchar. He says that char stores a UTF-8 code unit, wchar stores a UTF-16 code unit, and dchar stores a UTF-32 code unit, this makes sense. He then goes on to say that:

Re: Confused about something in the D book relating to precision

2022-12-04 Thread thebluepandabear via Digitalmars-d-learn
I have to agree. Nobody really knows these by heart. Once you know what's available, you just come back and pick what you need for that occasion. Ali Thanks for your effort :-) It helped clear things up.

Confused about something in the D book relating to precision

2022-12-04 Thread thebluepandabear via Digitalmars-d-learn
Hello guys, (Noob question.) I would appreciate some help. I am reading Ali's book on D language, and I am up to page 127 -- talking about format specifiers. He says the following about the '%e' (exponent) specifier: "e: A floating point argument is printed according to the following

Re: Graphical progressive fill

2022-12-11 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 11 December 2022 at 06:50:44 UTC, Joel wrote: I've been trying to fill in areas with a colour but can't work it out. I want something like the effect where it fills with diamonds. Not all at once but building up in the main program loop. # # # #

Is there such concept of a list in D?

2022-12-09 Thread thebluepandabear via Digitalmars-d-learn
In most languages there is some sort of `List` type, is that the same for D?

Re: Is there such concept of a list in D?

2022-12-09 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 10 December 2022 at 05:54:09 UTC, Steven Schveighoffer wrote: On 12/10/22 12:46 AM, thebluepandabear wrote: In most languages there is some sort of `List` type, is that the same for D? D doesn't focus on interfaces, we have concepts, like ranges. Sorry, it's hard to answer your

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread thebluepandabear via Digitalmars-d-learn
:-D (Exercise for the reader: what's the Hausdorff dimension of the set of strings over Unicode space? :-P) T Your explanation was great and cleared things up... not sure about the linear algebra one though ;)

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread thebluepandabear via Digitalmars-d-learn
On Friday, 2 December 2022 at 23:44:28 UTC, thebluepandabear wrote: :-D (Exercise for the reader: what's the Hausdorff dimension of the set of strings over Unicode space? :-P) T Your explanation was great and cleared things up... not sure about the linear algebra one though ;) Actually

Re: How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
T Thanks, I've tried to mark it with `@safe` and it did give me a warning. I was also wondering, why is this code valid? ```D int[] numbersForLaterUse; @safe void foo(int[] numbers) { numbersForLaterUse = numbers; } ```

How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
I am reading the fantastic book about D by Ali Çehreli, and he gives the following example when he talks about variadic functions: ```D int[] numbersForLaterUse; void foo(int[] numbers...) { numbersForLaterUse = numbers; } struct S { string[] namesForLaterUse; void foo(string[]

Re: Is there such concept of a list in D?

2022-12-18 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 18 December 2022 at 22:17:04 UTC, j wrote: On Saturday, 10 December 2022 at 05:46:26 UTC, thebluepandabear wrote: In most languages there is some sort of `List` type, is that the same for D? What you're probably talking about is called a union in the C world. There is a nice

Re: Is there such concept of a list in D?

2022-12-19 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 19 December 2022 at 22:07:15 UTC, Ali Çehreli wrote: On 12/19/22 13:45, thebluepandabear wrote: > On Monday, 19 December 2022 at 21:41:45 UTC, thebluepandabear wrote: >> Why did my replies here to someone else get deleted? > > Myself and this other person's reply to this thread

Re: Is there such concept of a list in D?

2022-12-19 Thread thebluepandabear via Digitalmars-d-learn
No worries, hopefully a mod will explain why. I don't like when posts get removed for no reason :|

Re: Is there such concept of a list in D?

2022-12-19 Thread thebluepandabear via Digitalmars-d-learn
Why did my replies here to someone else get deleted?

Re: Is there such concept of a list in D?

2022-12-19 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 19 December 2022 at 21:41:45 UTC, thebluepandabear wrote: Why did my replies here to someone else get deleted? Myself and this other person's reply to this thread randomly got removed for no reason, I would appreciate an explanation 

Does 'ref' turn into a pointer during compile time?

2022-12-21 Thread thebluepandabear via Digitalmars-d-learn
Say you have the following function that takes in a `ref` parameter: ```D void modify(ref int num) { num += 5; } ``` Does the compiler turn that into the code below? ```D void modify(int* num) { num += 5; } ``` I was just wondering whether or not this is the case because I don't

Why can't rvalues be passed to a 'ref' parameter?

2022-12-10 Thread thebluepandabear via Digitalmars-d-learn
Hello, I am not really understanding why rvalues cannot be passed to a 'ref' parameter, the explanation in the book about D I am reading was not clear: "The main reason for this limitation is the fact that a function taking a ref parameter can hold on to that reference for later use, at a

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread thebluepandabear via Digitalmars-d-learn
On Tuesday, 22 November 2022 at 00:46:34 UTC, Siarhei Siamashka wrote: On Monday, 21 November 2022 at 23:41:22 UTC, thebluepandabear wrote: But why give a C++ code example? 廊 It's a D code example and it even can't be compiled by a C++ compiler. Just add the missing main function: My bad.

Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 23 November 2022 at 13:52:18 UTC, ryuukk_ wrote: On Thursday, 17 November 2022 at 04:39:35 UTC, thebluepandabear wrote: I am creating a TUI library and I have a class with the following constant fields: ``` class Label : Renderable { const string text; const

Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread thebluepandabear via Digitalmars-d-learn
I broke a forum rule by critically analysing your blog? Wow. Erm... You went off topic.

Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread thebluepandabear via Digitalmars-d-learn
That the D module dissolves that perimeters of my types - in relation to other code in the same module, is a really odd design decision that I cannot, as yet, get my head around. That is, I can see no possible way in which this design decision can enhance my coding, even after having given if

Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread thebluepandabear via Digitalmars-d-learn
've modified the code since then so that `private` isn't used, etc. Also thanks for that code improvement that you did, quite nice.

Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: A question I have been thinking about whilst using D is how often I should be using const. Many people claim that all variables should be const by default, but whether or not it is really needed is debatable and oftentimes

How often I should be using const? Is it useless/overrated?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
A question I have been thinking about whilst using D is how often I should be using const. Many people claim that all variables should be const by default, but whether or not it is really needed is debatable and oftentimes making everything const could cause readability issues and make the

Re: Is defining get/set methods for every field overkill?

2022-11-20 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 21 November 2022 at 00:29:12 UTC, thebluepandabear wrote: .. not to mention, I'd be out of job if I stopped writing getters/setters ;-) I value your input in this discussion, you have brought some good points. Out of interest, what type of industry-level software are you

Re: Is defining get/set methods for every field overkill?

2022-11-20 Thread thebluepandabear via Digitalmars-d-learn
.. not to mention, I'd be out of job if I stopped writing getters/setters ;-) I value your input in this discussion, you have brought some good points. Out of interest, what type of industry-level software are you creating with D? I don't know much companies using D commercially.

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
If you only want to add setters: ``` class Rect2D { int _width; int _height; void width(int width) { writeln("SET"); this._width = width; } void height(int height) { writeln("SET"); this._height = height; } } ```

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:52:41 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:39:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
A better example of a code refactor after adding getters/setters is changing the names of the fields like so: ``` class Rect2D { int _width; int _height; ``` or ``` class Rect2D { int width_; int height_; ```

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
oh. so i get it now. you have to refactor your class (change member variable names and also do it in all places where they are used througout the class. then add new methods, overloading them in this way and that way, all because you're initial design never factored in the possibility of

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:04:41 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 00:25:57 UTC, Gavin Ray wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
It likely already does something, in that- >'it allows for change to occur without having to break the clients interface'. That too is the 'point' missing from that rant. With all due respect, I think your point is mostly invalid due to the point that Dukc made.

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:39:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:27:14 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 04:19:01 UTC, thebluepandabear wrote: oh. so i get it now. you have to refactor your class (change member variable names and also do it in all places where they are used througout the class. then

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229042(v=vs.100) Thanks, I'll think about it more -- I am a noob so I may be wrong in what I am saying. Of course in C# this argument wouldn't exist because you could just do `{ get; set; }`, and I really wish D

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 00:25:57 UTC, Gavin Ray wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a member

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:14:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:08:05 UTC, thebluepandabear wrote: It likely already does something, in that- >'it allows for change to occur without having to break the clients interface'. That too is the 'point' missing

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 05:42:03 UTC, []() {}() wrote: those public Get/Set members functions are exactly what you get in C#, except the compiler does it for you, behind the scenes, saving you the keystokes.. but the end code is just as if you had typed them out yourself. I know...

Re: Is defining get/set methods for every field overkill?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
classes, and as such you will have a good chunk of code that is practically useless and doing nothing. Meant *fields not variables, excuse my terminology.

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread thebluepandabear via Digitalmars-d-learn
Best regards, Alexandru. Thanks but I haven't reached that yet.

Is there a formula for overflow?

2022-11-29 Thread thebluepandabear via Digitalmars-d-learn
I am reading through Ali's book about D, and he gives the following examples for an overflow: ```D import std.stdio; void main() { // 3 billion each uint number_1 = 30; uint number_2 = 30; } writeln("maximum value of uint: ", uint.max); writeln(" number_1: ", number_1);

Re: Is defining get/set methods for every field overkill?

2022-11-17 Thread thebluepandabear via Digitalmars-d-learn
(and will never need) that controlled access. Thanks. BTW the code is not Java, it is 100% D.

Is defining get/set methods for every field overkill?

2022-11-16 Thread thebluepandabear via Digitalmars-d-learn
I am creating a TUI library and I have a class with the following constant fields: ``` class Label : Renderable { const string text; const TextAlignment textAlignment; const Color color; this(Dimensions dimensions, string text, TextAlignment textAlignment, Color color) {

Re: How often I should be using const? Is it useless/overrated?

2022-11-22 Thread thebluepandabear via Digitalmars-d-learn
So the answer to your question is, use it when it has a payoff - for you. If that's the case, I've probably come to my own conclusion: that it's not worth it as it's not giving me any payoff for the extra code. Thanks.

Re: How often I should be using const? Is it useless/overrated?

2022-11-22 Thread thebluepandabear via Digitalmars-d-learn
On Tuesday, 22 November 2022 at 22:40:54 UTC, []() {}() wrote: On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: As a newcomer, I'd be interested in hearing everyones thoughts. Everyones thoughts? You sure about that ;-) anyho To Const or Not to Const?

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:26:49 UTC, Andrey Zherikov wrote: On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here 

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 21 November 2022 at 23:25:21 UTC, []() {}() wrote: On Monday, 21 November 2022 at 11:56:59 UTC, Ali Çehreli wrote: .. You took the question as whether to define them for class hierarchies, safety-critical systems, etc. Ali Or even in a very, very simple counter class: public

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 22:57:36 UTC, [] () {} () wrote: On Thursday, 17 November 2022 at 04:39:35 UTC, thebluepandabear wrote: ... I am debating whether or not I should add getter methods to these properties. On one hand, it will inflate the codebase by a lot, on the other hand --

Re: Is there a formula for overflow?

2022-11-30 Thread thebluepandabear via Digitalmars-d-learn
then the narrower value is converted to the wider type **C.** If the signed type is wider than the unsigned type, then the unsigned value is converted to the signed type **D.** Otherwise the signed type is converted to the unsigned type SDB@79 I didn't ask about casting...

How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
If I have the following code: ```D class X { private int num; struct Y { // how to access num? } } ``` How would I access `num` from `Y`? Whenever I try to I get a compilation error. I believe that it's possible for nested/inner classes, but I don't know if it's possible

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:37:43 UTC, Paul Backus wrote: On Sunday, 15 January 2023 at 12:26:15 UTC, thebluepandabear wrote: If I have the following code: ```D class X { private int num; struct Y { // how to access num? } } ``` How would I access `num` from `Y`?

Re: Are there more up-to-date D template tutorials?

2023-01-19 Thread thebluepandabear via Digitalmars-d-learn
roduct/learning-d/9781783552481?_ga=2.241359490.1811075590.1674153096-1605518740.1674153096 or Adam's book https://www.packtpub.com/product/d-cookbook/9781783287215?_ga=2.198287279.1811075590.1674153096-1605518740.1674153096 They're older than 2019, but I don't think much of the material

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

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: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-24 Thread thebluepandabear via Digitalmars-d-learn
On Tuesday, 24 January 2023 at 06:32:35 UTC, Christian Köstlin wrote: On 24.01.23 04:59, thebluepandabear wrote: Regards, thebluepandabear Btw I understand this question is extremely complex, don't want to pressure anyone to help me because of that... but any sort of assistance or leads

Re: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-23 Thread thebluepandabear via Digitalmars-d-learn
Regards, thebluepandabear Btw I understand this question is extremely complex, don't want to pressure anyone to help me because of that... but any sort of assistance or leads would be greatly... greatly apprecaited...

Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-23 Thread thebluepandabear via Digitalmars-d-learn
Hello everyone , hope everyone is having a good day. Hopefully I am allowed to ask technical questions here, if not please tell me and I will remove this. I am trying to create object oriented wrappers around `bindbc.sfml`, this is because I don't like the C-style syntax of CSFML. The

Re: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-24 Thread thebluepandabear via Digitalmars-d-learn
The example shows calls to `update()` in the setters and in the constructor. The D method for binding this looks like `void sfShape_update(sfShape* shape);`. Ur a legend bro... It fixed it... Calling this in the `Rectangle` constructor: ```D class RectangleShape : Shape { this(Vector2f

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

2023-01-24 Thread thebluepandabear via Digitalmars-d-learn
symbols. So let the users use them that way. There's no need to force them to type out the namespace all the time. It's certainly not an OOP vs. procedural issue, as namespaces have nothing to do with OOP. Thanks, appreciate your perspective.

Re: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-26 Thread thebluepandabear via Digitalmars-d-learn
On Thursday, 26 January 2023 at 11:46:07 UTC, matheus wrote: On Tuesday, 24 January 2023 at 03:42:34 UTC, thebluepandabear wrote: ... if not please tell me and I will remove this... How you would do that? Matheus. The forums don't have a delete feature. I am used to most forums having a

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

2023-01-29 Thread thebluepandabear via Digitalmars-d-learn
I hate a world with the classes. I can do almost anything I want without the classes. The software world soared above C without classes. SDB@79 As I said in my email to you -- each to their own. There's no point in arguing about whether OOP is the best method of doing things or procedural

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

2023-01-30 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 30 January 2023 at 21:50:03 UTC, thebluepandabear wrote: Use a struct and put `static:` after the opening brace. That's what GC is in core.memory. Using a `struct` for a purely static type would still allow the user to create instances of that `struct`. To bypass that, you'd have

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

2023-01-30 Thread thebluepandabear via Digitalmars-d-learn
Why do you want a type? I want a type because it gives clear context as to what family the method(s) belongs to, and helps make the code more idiomatic and easy to understand.

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

2023-01-30 Thread thebluepandabear via Digitalmars-d-learn
Use a struct and put `static:` after the opening brace. That's what GC is in core.memory. Using a `struct` for a purely static type would still allow the user to create instances of that `struct`. To bypass that, you'd have to disable the default constructor -- that then becomes ugly,

Re: How to a link to a C library to create static bindings?

2023-01-27 Thread thebluepandabear via Digitalmars-d-learn
When I do run with dub I just get: ``` Program exited with code -11 ```

How to a link to a C library to create static bindings?

2023-01-27 Thread thebluepandabear via Digitalmars-d-learn
Hello, I am wanting to create my own C bindings to CSFML, and I have been extremely struggling with this. There is no resources or tutorials for how to do this so I am basically on my own. First thing I looked at was `dstep` which helps translate C header files to D language, so I ran

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 15 January 2023 at 13:23:20 UTC, matheus wrote: On Sunday, 15 January 2023 at 12:44:51 UTC, thebluepandabear wrote: ... How will the variable `outer` become the reference to the current `X` object (if that makes sense?). Does the compiler do it automatically? I think you'll need

Are there more up-to-date D template tutorials?

2023-01-18 Thread thebluepandabear via Digitalmars-d-learn
Hello, The GitHub repo which helps introduce new users about D templates (https://github.com/PhilippeSigaud/D-templates-tutorial) seems to be quite outdated. As a beginner to D I have been struggling to learn about D templates, I haven't been able to find any up-to-date D template

Re: Are there more up-to-date D template tutorials?

2023-01-18 Thread thebluepandabear via Digitalmars-d-learn
Help would be appreciated. Regards, thebluepandabear A bit off topic/ranty but I did find the book by Ali on D extremely useful, but it was good as an 'introduction'. I feel like when it comes to more advanced features (such as templates, mixins, ranges, concurrency, etc) there are no

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-08 Thread thebluepandabear via Digitalmars-d-learn
A nested function (or perhaps an inline lambda) is needed to force the allocation of a dynamic context for the capture. This is an embarrassment. Why hasn't this been fixed yet? :-( T I agree that this needs to get fixed immediately, it seems to be bugging me another time as well. I

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-08 Thread thebluepandabear via Digitalmars-d-learn
Fixing this will improve the quality of the language for newcomers such as myself greatly. This not only confuses newcomers but it gave a false illusion of a bug within the code :/

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-08 Thread thebluepandabear via Digitalmars-d-learn
: create a copy of the value that is currently present in one particular iteration of the `foreach` by creating a function literal that takes your `struct` as a paramter. This works because structs are value types, so passing it to the function creates a copy. Thanks, your solution seems to

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

2023-01-22 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 22 January 2023 at 18:30:59 UTC, ryuukk_ wrote: On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: D is not java/C#, it's better than that! ```D // api.d void draw(){} // app.d import API = api; void main() { API.draw(); } ``` Sorry don't like that

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

2023-01-22 Thread thebluepandabear via Digitalmars-d-learn
// app.d import API = api; void main() { API.draw(); } ``` Another thing that I don't like about that solution, is that it doesn't 'force' the user to write in a namespace-like style. C++ `namespaces` force you to (I believe), and so does `static class` from Java/C#. D is both an

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

2023-01-22 Thread thebluepandabear via Digitalmars-d-learn
Something interesting. I know that D has C++ SFML bindings, although they are unmaintained. I was interested to see how they would 'implement' the C++ namespaces of SFML, and - boy was I surprised. Reading through `DSFML`, I see `final abstract class` getting used to implement SFML's

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

2023-01-22 Thread thebluepandabear via Digitalmars-d-learn
That way of naming a global function is essentially a poor man's^W^Wexcuse me, I mean, C's way of working around the lack of a proper namespacing / module system. In D, we do have a proper module system, so you could just call the function `drawLine` and put it in a file named Algo.d, then you

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

2023-01-22 Thread thebluepandabear via Digitalmars-d-learn
On Monday, 23 January 2023 at 00:27:29 UTC, Adam D Ruppe wrote: On Monday, 23 January 2023 at 00:21:12 UTC, thebluepandabear wrote: there's nothing in the language currently that would 'force' the user Why do you hate freedom? It's not a freedom issue, it's a library-design issue. Some

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

2023-02-18 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 19 February 2023 at 00:21:42 UTC, ProtectAndHide wrote: On Saturday, 18 February 2023 at 21:23:24 UTC, ProtectAndHide wrote: The more I look at D, the more I like C++. I should correct that. The more I look at D, the more I like C++, C#, Java, Kotlin, Swift, Javascript .. and

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

2023-02-18 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 19 February 2023 at 00:21:42 UTC, ProtectAndHide wrote: On Saturday, 18 February 2023 at 21:23:24 UTC, ProtectAndHide wrote: The more I look at D, the more I like C++. I should correct that. The more I look at D, the more I like C++, C#, Java, Kotlin, Swift, Javascript .. and

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

2023-02-19 Thread thebluepandabear via Digitalmars-d-learn
But in any case, it should be class private. There have now been three pages produced by three people all agreeing with each other. At what point does it start being spam? Having a discussion !== spam.

  1   2   >