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
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
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.
them or remove them.
I agree, forbidding function call syntax would be a great usecase
for `@property`.
It will probably never get implemented though.
```
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.
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
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.
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.
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,
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,
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
(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
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 {
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
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`
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 ==
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
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.
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:
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.
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
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.
# #
# #
In most languages there is some sort of `List` type, is that
the same for D?
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
:-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 ;)
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
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;
}
```
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[]
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
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
No worries, hopefully a mod will explain why. I don't like when
posts get removed for no reason :|
Why did my replies here to someone else get deleted?
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
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
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
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.
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
I broke a forum rule by critically analysing your blog?
Wow.
Erm... You went off topic.
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
've modified the code since then so that
`private` isn't used, etc.
Also thanks for that code improvement that you did, quite nice.
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
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
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
.. 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.
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;
}
}
```
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
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_;
```
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
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
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.
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
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
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
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
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
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
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...
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.
Best regards,
Alexandru.
Thanks but I haven't reached that yet.
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);
(and will never need) that controlled access.
Thanks. BTW the code is not Java, it is 100% D.
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) {
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.
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?
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
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
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
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 --
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...
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
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`?
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
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
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.
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
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...
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
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
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.
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
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
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
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.
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,
When I do run with dub I just get:
```
Program exited with code -11
```
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
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
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
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
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
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 :/
: 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
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
// 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
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
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
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
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
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
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 - 100 of 140 matches
Mail list logo