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.


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 the list goes on..


All D needed to provide, was a way to let the programmer 
declare a private member inside a class. But that is too much 
for the language to handle, and so objectionable to many D 
users, that it will never happen. I have no problem with that, 
because, i really do have many other options - as do all the 
C++, C#, Java, Kotlin, Swift, Javascript .. and the list goes 
on..that you supposedly want to attract to D (although, I 
suspect nobody actually wants to attract them, since they'll 
expect to be able to declare a private member within a class.


So.. good luck with the .. ummm.. D thing.


Even if D did have the private feature, the ecosystem and 
community is too small for this language to be a viable option. 
Also D is not used on the job market, so good luck finding a D 
job.


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 the list goes on..


All D needed to provide, was a way to let the programmer 
declare a private member inside a class. But that is too much 
for the language to handle, and so objectionable to many D 
users, that it will never happen. I have no problem with that, 
because, i really do have many other options - as do all the 
C++, C#, Java, Kotlin, Swift, Javascript .. and the list goes 
on..that you supposedly want to attract to D (although, I 
suspect nobody actually wants to attract them, since they'll 
expect to be able to declare a private member within a class.


So.. good luck with the .. ummm.. D thing.


Based. I've already switched to TypeScript, Java, etc. Goodbye D.


Re: ELIZA Chatbot Implementation From C to D Lang

2023-02-18 Thread thebluepandabear via Digitalmars-d-learn

On Friday, 17 February 2023 at 17:03:34 UTC, ron77 wrote:
Hello, I succeeded in converting an ELIZA code from C to D, and 
here are the results. although I'm sure there are better ways 
to code it or to convert it...


this is nothing compared to chatgpt ;)


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

2023-02-16 Thread thebluepandabear via Digitalmars-d-learn
So let me just say: I think D does it right. D does not have 
class encapsulation; it has module encapsulation. This is by 
design, and the design is good.


The design is terrible...


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

2023-02-16 Thread thebluepandabear via Digitalmars-d-learn


But at stop mispresenting what I'm saying. What I've stated 
above, is what I'm saying.. no more.. no less.


Well said.

Its not that hard to understand, folks.


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

2023-02-15 Thread thebluepandabear via Digitalmars-d-learn

On Wednesday, 15 February 2023 at 20:06:18 UTC, bachmeier wrote:
On Wednesday, 15 February 2023 at 07:13:41 UTC, 
thebluepandabear wrote:
Time to move on to OCaml programmers telling us D doesn't 
have floating point arithmetic because there's no `+.` 
operator.


that's not the same thing though, you've created a great false 
equivalence! Congrats.


Only if you don't understand D's encapsulation. You're going on 
at length (apparently under multiple names in this thread) 
because you don't like D's implementation of encapsulation. 
That's no different from complaining that the `+` operator 
should be `+.`, and until D makes the change, it doesn't 
support floating point addition.


There are reasonable arguments for changing and not changing 
D's implementation of encapsulation. Your claim that D doesn't 
support encapsulation is false.


'under multiple names'... You can clearly see I have the same 
name, simply different profile pictures.


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

2023-02-14 Thread thebluepandabear via Digitalmars-d-learn

On Wednesday, 15 February 2023 at 02:14:30 UTC, Mike Parker wrote:
On Wednesday, 15 February 2023 at 01:16:00 UTC, 
thebluepandabear wrote:




I think what you could say is that D lacks _encapsulation_ 
which is also an OOP concept. So D is partially OOP but not 
fully OOP due to there being no encapsulation in the language.


D does not lack encapsulation, it's just that the unit of 
encapsulation is the module. Everything private in a module is 
encapsulated from the perspective of the public API.


If you really want to prevent anything inside a module from 
accessing the private parts of a class, you can put the class 
in its own module.


Must we continue beating this horse?


Why is the unit of encapsulation the module though? Makes no 
sense.


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

2023-02-14 Thread thebluepandabear via Digitalmars-d-learn
Time to move on to OCaml programmers telling us D doesn't have 
floating point arithmetic because there's no `+.` operator.


that's not the same thing though, you've created a great false 
equivalence! Congrats.


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

2023-02-14 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 01:15:09 UTC, thebluepandabear 
wrote:

On Tuesday, 14 February 2023 at 15:34:17 UTC, bachmeier wrote:
On Tuesday, 14 February 2023 at 10:16:47 UTC, ProtectAndHide 
wrote:


In any case, there is nothing 'picky' about wanting to be 
able to explicately 'declare' a member of my class type as 
being private. That to me, is what a programmer should expect 
to be able to do in a language that says it supports OOP.


What you are saying is that you want an implementation of a 
particular language that calls itself an OOP language. [There 
is a lot of controversy about the definition of 
OOP](https://wiki.c2.com/?NobodyAgreesOnWhatOoIs). I do not 
think the explicit ability to declare a member of a class 
private in a particular way has anything to do with it. You 
are certainly entitled to your opinion, but it doesn't help to 
say D is not an OOP language because you don't like some of 
the design decisions.


D is still an OOP language, as long as it has classes, 
inheritance, and polymorphism, though it's certainly not a good 
one if any class can acccess private members from the module, 
that's just horrid.


I think what you could say is that D lacks _encapsulation_ which 
is also an OOP concept. So D is partially OOP but not fully OOP 
due to there being no encapsulation in the language.


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

2023-02-14 Thread thebluepandabear via Digitalmars-d-learn

On Tuesday, 14 February 2023 at 15:34:17 UTC, bachmeier wrote:
On Tuesday, 14 February 2023 at 10:16:47 UTC, ProtectAndHide 
wrote:


In any case, there is nothing 'picky' about wanting to be able 
to explicately 'declare' a member of my class type as being 
private. That to me, is what a programmer should expect to be 
able to do in a language that says it supports OOP.


What you are saying is that you want an implementation of a 
particular language that calls itself an OOP language. [There 
is a lot of controversy about the definition of 
OOP](https://wiki.c2.com/?NobodyAgreesOnWhatOoIs). I do not 
think the explicit ability to declare a member of a class 
private in a particular way has anything to do with it. You are 
certainly entitled to your opinion, but it doesn't help to say 
D is not an OOP language because you don't like some of the 
design decisions.


D is still an OOP language, as long as it has classes, 
inheritance, and polymorphism, though it's certainly not a good 
one if any class can acccess private members from the module, 
that's just horrid.


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

2023-02-14 Thread thebluepandabear via Digitalmars-d-learn
On Tuesday, 14 February 2023 at 10:16:47 UTC, ProtectAndHide 
wrote:

On Tuesday, 14 February 2023 at 08:15:37 UTC, Kagamin wrote:

My point is you know you're just picky.


Well.. it seems to me, that your 'point' is to just have a go 
at me.


In any case, there is nothing 'picky' about wanting to be able 
to explicately 'declare' a member of my class type as being 
private. That to me, is what a programmer should expect to be 
able to do in a language that says it supports OOP.


Further nonsense towards me will be ignored ;-)


fight fight fight fight

jk


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn
For a language that claims to supprot OOP, and does public by 
default, and no way to declare type private... I mean... wow!


agree, it should definitely be `private` by default... if 
`private` was implemented properly lmao


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn


What attracts me to D, is the inability to program outside of a 
class in C#. I think they are trying to find ways to make this 
happen, but I wouldn't hold my breath.


programming outside of a class is overrated though in my opinion. 
i've never seen a usecase for it in an object oriented language. 
Of course Kotlin can do this, which is good, but you can just 
create utility classes (i.e. `static class` in C#, `final class` 
in Java with a private ctor, or Kotlin `object`.)


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn

That's not entirely correct.

I don't use any Apple hardware products. Never have, and never 
will.


I use Swift on Linux only.

There are of course some library features of Swift tied to 
Apple products. But I have no need for those library features.


As a standalone language, Swift can (IMO) already out compete D.


Swift on Linux? Interesting...

what is the use case?


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn
I'm not an advocate of any style in particular. I'm happy to 
use any style that is clear to understand and use, suitable, 
and can provide reasonable guarantees around memory safety and 
correctness.


But a language that claims to support OOP but doesn't even have 
type privacy, is a bit of joke IMO.


agreed, the current behaviour of `private` is inexcusable, and 
it's something newcomers need to be warned about.


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn
I think the 'real' problem, is that some core D people just 
refuse to allow D to provide such an option to the programmer.



I think a lot of it has to do with the fact that heaps of D 
programmers write procedural code and don't care about any object 
oriented features, that's because they're 'old-school' 
programmers, whereas OOP is 'new-school'.


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn
A good example of a language that does everything right is C#. If 
C# wasn't tied to Microsoft, it would honestly be pretty much the 
perfect language. Java is also pretty good, but it has its 
downsides.


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

2023-02-10 Thread thebluepandabear via Digitalmars-d-learn
I think the 'real' problem, is that some core D people just 
refuse to allow D to provide such an option to the programmer. 
For what reason, I cannot fathom, since Swift can do this just 
fine. I think it's some kind of bias against a particular style 
of programming that some don't want to see occuring when people 
use the D programming lanuguage. i.e. It has nothing at all to 
do with implementation, since it's already been demonstrated 
that it can be implemented, very easily.


Again, in this particular area, Swift is way ahead of D.


Sorry, but I do not believe Swift is near to the level of what D 
is, it's a language that's tied - like jail - to Apple's 
ecosystem, and its only real use is for iOS apps. They're two 
completely different languages in general.


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn
In contrast, I use D every day and love its relaxed attitude 
towards private.


the fact that private stuff is accessible from other classes in 
the same module is really really bad, and it's pretty detrimental 
to the language.


let's actually think about what `private` means.

when you come back from work, arrive home, and you close the 
curtains and want some alone, you want to be private to everyone.


you wouldn't want your neighbours (the module) to peek at what 
you're doing.


your neighbours aren't your friends in real life, and they (the 
module) aren't your friends in code -- just because they are in 
your vicinity doesn't mean they have a right to violate your 
privacy.


tbh this whole private behaviour should be changed, it's just so 
weird


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn
btw. When a newbie to D raises ideas, suggestions, etc... and 
you counter them with (in essence) 'we don't need that in D, 
but go write a dip if you think we do' attitude, is a real turn 
off.


yeah it seems like the community is closed off for feedback, 
which is concerning. namespaces/static classes are a net positive 
for the language, and they've been shown to be an extremely good 
features, being implemented in Kotlin, C#, and C++.


if the language wants to gain more people it needs to evolve


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn

On Thursday, 9 February 2023 at 19:17:15 UTC, Adam D Ruppe wrote:
On Thursday, 9 February 2023 at 13:00:04 UTC, thebluepandabear 
wrote:
For my school I am commissioned to create many types of 
software. I tried to have a look at some of the gui kits in D 
but there was no tutorial for how to use them and they seemed 
as if they are lacking features in comparison to Qt/JavaFX.


So your objection is one of newbie documentation. That's fair. 
Qt I always thought had nice docs, they're hard to beat. I've 
been slowly adding more to my stuff but it is a slow process.


idk about features though, you saying "seemed" means you 
probably don't even actually know what they have so that's not 
as actionable.


it's not anything personal, it's just that the current gui 
libraries for D are only around 1/100th of the size of other ones 
such as Qt/JavaFX, it's not really on the same wavelength, and 
there's nothing wrong with that specifically, it's very difficult 
to make an enterprise level gui library from scratch


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn

On Wednesday, 8 February 2023 at 12:07:35 UTC, zjh wrote:
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear 
wrote:

Hi,

In Java/C# you can create purely static classes.
...




Last time, someone proposed to add `private` like `C++'s`, and 
then it was the same,they are always unwilling to add 
facilities useful to others, and then he left `D`.


yeah the whole module behaviour with `private` is just a massive 
turn off tbh, it needs to be changed to match the Java style


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn
On Thursday, 9 February 2023 at 12:55:41 UTC, Guillaume Piolat 
wrote:

On Wednesday, 8 February 2023 at 12:10:59 UTC, zjh wrote:

On Wednesday, 8 February 2023 at 12:07:35 UTC, zjh wrote:

they are always unwilling to add facilities useful to others,



`D`'s community is small, this is the reason!


yeah right let's implement everything that people propose


that's not the point of this thread here :P Of course you dont 
add stuff on the whim if one person says you should, I am just 
encouraging open ended discussion.


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn

On Thursday, 9 February 2023 at 12:50:48 UTC, Adam D Ruppe wrote:
On Thursday, 9 February 2023 at 12:31:03 UTC, thebluepandabear 
wrote:
I am actually taking a computer science class and I need to 
create desktop apps to pass and get through school.


This is pretty easy in D. Like what specific kind of desktop 
app?


For my school I am commissioned to create many types of software. 
I tried to have a look at some of the gui kits in D but there was 
no tutorial for how to use them and they seemed as if they are 
lacking features in comparison to Qt/JavaFX.


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

2023-02-09 Thread thebluepandabear via Digitalmars-d-learn

On Wednesday, 8 February 2023 at 13:32:46 UTC, zjh wrote:
On Wednesday, 8 February 2023 at 12:12:57 UTC, thebluepandabear 
wrote:

but I still think the language has potential in the future



I don't know if they have a sense of crisis. Now `D` in tiebo 
ranks `50`.


I wouldn't say they have or should have a sense of crisis, the 
language itself is improving on a day-to-day basis but it isn't 
gaining popularity. I initially came in excited learning D 
because I thought that having a small ecosystem would just be a 
minor pain, but now I realize it's not minor -- it's pretty 
major. This is not to say D isn't a good language, it certainly 
is pretty good, but it just needs a bigger ecosystem. The 
community itself is great, no weirdos in it like Rust, but it 
just needs to be bigger.


I am actually taking a computer science class and I need to 
create desktop apps to pass and get through school. I thought 
this would be possible with D, but it has turned out to be a 
massive pain, so this is why I am switching to Java.


I think D may be one of those languages that eventually blows up 
like Rust because it's honestly great (it feels like a native 
Java some times), they just need to work on _marketing_ and 
_strengthening_ the ecosystem.


Some corporate backing (RedHat, for example) would also be great 
since many people are working on it for free, and thus lacking in 
motivation.


anyways I know nobody cares about my opinion, and hopefully this 
didn't come across disrespectful


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

2023-02-08 Thread thebluepandabear via Digitalmars-d-learn

On Wednesday, 8 February 2023 at 12:10:59 UTC, zjh wrote:

On Wednesday, 8 February 2023 at 12:07:35 UTC, zjh wrote:

they are always unwilling to add facilities useful to others,



`D`'s community is small, this is the reason!


yeah, I've already switched to Java because of this. but I still 
think the language has potential in the future


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

2023-02-08 Thread thebluepandabear via Digitalmars-d-learn
C# just makes it 'easy' for the programmer to define it as 
such, without all the nonsense other languages require. In 
addition, the C# compiler WILL prevent nonsense code, which is 
exactly what I want from a compiler ;-)


Java as well.



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

2023-02-08 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 8 February 2023 at 09:00:40 UTC, thebluepandabear 
wrote:
C# just makes it 'easy' for the programmer to define it as 
such, without all the nonsense other languages require. In 
addition, the C# compiler WILL prevent nonsense code, which is 
exactly what I want from a compiler ;-)


Java as well.


Wait nvm


Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn

Thanks.


update: just set up a Manjaro vm and it seems to work, I guess 
I'll have no choice but to switch to Manjaro then if I want to 
use sfml


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

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn


I do not agree, that a compiler that allows a programmer to 
misuse a type, should be seen as 'a feature'.


If that's the kind of 'power' D programmers want, then D is not 
for me.


Eh, I don't think I would _quit_ D because of this issue, but 
it's definitely something that bothers me (more so the lack of an 
ecosystem) especially since I come from a .NET/JVM background. 
I'm pretty shocked this isn't a feature tbh.


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

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn

On Sunday, 5 February 2023 at 23:53:35 UTC, Ali Çehreli wrote:

On 2/5/23 14:40, ProtectAndHide wrote:

> On Sunday, 5 February 2023 at 10:51:51 UTC, thebluepandabear
wrote:
>>
>> It's not a terrible workaround to be honest.
>> 
>
> The 'terrible' part is this:
>
> - the compiler will allow you to declare a variable of type
Algo
> - the compiler will allow you to declare an array with
elements of type
> Algo
> - the compiler will allow you to use Algo as a type argument
> - the compiler will allow you to use Algo as a parameter
> - the compiler will allow you to use Algo as a return type

I understand disabling the programmer to do certain things are 
beneficial e.g. to prevent bugs but those above can all be seen 
as features. What is so terrible about giving the programmer 
those powers?


Ali


I don't see why you'd want to expose a static class/namespace as 
a variable, or any of such similar things. That would give no 
benefits to the programmer?


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

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn

On Sunday, 5 February 2023 at 23:50:35 UTC, Ali Çehreli wrote:

On 2/5/23 02:57, thebluepandabear wrote:

> When dealing with contexts, or for when you want a clear
context in your
> codebase, namespaces can be a life saver

Can you give an example of a D problem that namespaces could 
solve? I have been with D for 14 years and haven't missed 
namespaces from C++ ever.


The reason I ask is, mentioning lack of features of other 
programming languages is not the right way to go. We have to 
understand what problem they were trying to solve with that 
feature and then see how D already tackels it.


In this case, it is namespacing and D solves it with the 
following feature and perhaps others that I can't think of:


- modules
- structs
- classes
- templates

I don't consider myself a maintainer of D but I don't agree 
that yet another feature for namespacing is needed. I feel that 
it would bring complications.


I don't think it is practical to bring all features of all 
languages into D or any other language.


> we've seen it used in the D
> library, so there's no excuse for why this shouldn't be
added, in my
> opinion.

If I'm not mistaken you've counted five such instances. Were 
they really necessary? Could they be coded in a different way? 
What is the cost of missing namespaces? I think you are the 
first person raising this issue.


You must have a strong case for this feature; so, I recommend 
you write a DIP for it. It is likely that the mere act of doing 
that will expose hidden costs and usage problems.


Ali


I'm not going to create a DIP when I've hardly even touched the 
surface of the language, this is a beginners forum. I would need 
to wait 3-5 years until I'd feel comfortable doing so. Right now, 
it's not my place to be doing such things; this is just an 
observation from a beginner (aka me).


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

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 5 February 2023 at 10:51:51 UTC, thebluepandabear 
wrote:

{
@disable this();

static this()
{
Message =  "Hello!";
}

static:

string Message;

void drawLine() {};
}


It's not a terrible workaround to be honest.

`static class` does have a use when it's nested, so it might 
create some conflicts if such a feature (like C# `static 
class`) were added.


Due to the mindset of the current maintainers of the language, 
I doubt we will see such a thing. Maybe in 10-20 years 
something will change and the language will add a static class 
or namespace feature, for now we'll have to deal with modules 
or using your way of creating a `static class`.


I don't like it when people see modules as a replacement for a 
namespace/static class, when that's not the case.


Rust has modules. It also has namespaces.

C++ will be getting modules, it also has namespaces.

When dealing with contexts, or for when you want a clear context 
in your codebase, namespaces can be a life saver, we've seen it 
used in the D library, so there's no excuse for why this 
shouldn't be added, in my opinion.


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

2023-02-05 Thread thebluepandabear via Digitalmars-d-learn

{
@disable this();

static this()
{
Message =  "Hello!";
}

static:

string Message;

void drawLine() {};
}


It's not a terrible workaround to be honest.

`static class` does have a use when it's nested, so it might 
create some conflicts if such a feature (like C# `static class`) 
were added.


Due to the mindset of the current maintainers of the language, I 
doubt we will see such a thing. Maybe in 10-20 years something 
will change and the language will add a static class or namespace 
feature, for now we'll have to deal with modules or using your 
way of creating a `static class`.





Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-04 Thread thebluepandabear via Digitalmars-d-learn

On Sunday, 5 February 2023 at 03:19:43 UTC, bachmeier wrote:
On Saturday, 4 February 2023 at 23:51:17 UTC, thebluepandabear 
wrote:
"Error: Missing Symbol, Message: sfText_getLineSpacing", 
"Error: Missing Symbol, Message: sfText_getLineSpacing"]


source/app.d:19 void app.loadDyn() [0x55d86edd1931]
source/app.d:24 _Dmain [0x55d86edd1954]
```


Oh yeah, that's another bug I had. You would need to downgrade 
the version to SFML_240.


Something of a puzzle that it works with Arch, though, but not 
Ubuntu/Mint. It doesn't sound like Arch has that problem.


What problem doesn't Arch have, the missing symbol or the shared 
library one?


If it's the missing symbol one, I suspect the reason Arch doesn't 
have that issue is because it has a more updated package on its 
repo (AUR).


Ubuntu has CSFML 2.5.0, not CSFML 2.5.1, which makes everything 
much more of a pain. That's exactly why you are getting those 
missing symbol issues, I believe. I did speak to the bindbc team 
about it, and that was the conclusion that we came to. In order 
to fix the issue and not have to downgrade, you would have to 
manually compile CSFML 2.5.1, which is a pain.


I'm wondering, after downgrading, do you get the shared library 
issue that I am currently dealing with?


Thanks.


Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-04 Thread thebluepandabear via Digitalmars-d-learn
"Error: Missing Symbol, Message: sfText_getLineSpacing", 
"Error: Missing Symbol, Message: sfText_getLineSpacing"]


source/app.d:19 void app.loadDyn() [0x55d86edd1931]
source/app.d:24 _Dmain [0x55d86edd1954]
```


Oh yeah, that's another bug I had. You would need to downgrade 
the version to SFML_240.


Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn


I have tested on arch linux and everything works fine, i'll try 
to setup a linux mint / ubuntu VM tomorrow


Thanks.

It seems like an issue with my system then. I've been stuck on it 
for a week or so, but haven't been able to find the root cause of 
the issue.





Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn
Could someone (that uses Linux) perhaps try and emulate my bug to 
see if it's an issue with the bindings or on my system? That 
would be greatly appreciated!


Steps:

1. Open up the terminal and type in `sudo apt-get install 
libcsfml-dev`


2. Create a new D project and add the following to `dub.json`:

```
"dependencies": {
"bindbc-sfml": "~>1.0.2",
"bindbc-loader": "~>1.0.1"
},
"versions": [
"SFML_Audio",
"SFML_Graphics",
"SFML_250"
],
```

3. Add the following code to `app.d`:

```D
import std.stdio;
import bindbc.sfml;
import std.string;
import std.exception;
import bindbc.loader;
import std.conv;

void loadDyn() {
if (!loadSFML()) {
string[] messages;

foreach (const(ErrorInfo) err; errors) {
string errorStr = to!string(err.error);
string messageStr = to!string(err.message);

			messages ~= format("Error: %s, Message: %s", errorStr, 
messageStr);

}

		throw new Exception(format("Fatal error(s) encountered whilst 
calling `loadSFML()` function: %s", messages));

}
}

void main() {
loadDyn();

	sfRenderWindow* renderWindow = 
sfRenderWindow_create(sfVideoMode(500, 500), "Snake Smooth 
Dynamics", sfWindowStyle.sfDefaultStyle, null);

sfEvent event;

while (renderWindow.sfRenderWindow_isOpen()) {
while (renderWindow.sfRenderWindow_pollEvent()) {
if (event.type == sfEventType.sfEvtClosed) {
renderWindow.sfRenderWindow_close();
}
}

renderWindow.sfRenderWindow_clear(sfYellow);
renderWindow.sfRenderWindow_display();
}
}
```

It should only take around 2-3 minutes.

Regards,
thebluepandabear




Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn

On Friday, 3 February 2023 at 19:44:07 UTC, bachmeier wrote:
On Friday, 3 February 2023 at 12:23:40 UTC, thebluepandabear 
wrote:
On Friday, 3 February 2023 at 11:43:46 UTC, thebluepandabear 
wrote:

On Friday, 3 February 2023 at 11:37:43 UTC, bachmeier wrote:
On Friday, 3 February 2023 at 10:15:37 UTC, thebluepandabear 
wrote:
I recently did a fresh install of CSFML and I am getting 
this errors when running my csfml D bindings program:


```
object.Exception@source/app.d(38): Fatal error(s) 
encountered whilst calling `loadSFML()` function:
 ["Error: libcsfml-system.so, Message: 
libsfml-system.so.2.5: cannot open shared object file: No 
such file or directory",
 "Error: libcsfml-system.so.2, Message: 
libcsfml-system.so.2: cannot open shared object file: No 
such file or directory",
"Error: libcsfml-system.so.2.0, Message: 
libcsfml-system.so.2.0: cannot open shared object file: No 
such file or directory"]

```


We don't have the full compilation and loading details, but 
this part of the message seems unusual:



"Error: libcsfml-system.so, Message: libsfml-system.so.2.5


One is `libcsfml` and the other is `libsfml`.


Hi,

It seems like it has changed since then, I am _no longer_ 
getting those conflicting errors, it's just 'libcsfml' for 
both instances.


I am thinking of compiling CSFML from scratch to see if it 
will help, but I'd rather not since it seems complex.


Furthermore, I would like to thank you for bringing up the 
compilation/loading details up. I'll send a snippet of that 
if I can figure out how to do so.


nvm, im getting that error again


It might be a bug in bindbc-sfml. The code is here: 
https://github.com/BindBC/bindbc-sfml/blob/master/source/bindbc/sfml/system.d#L231 Unbuntu stores the file in /usr/lib/x86_64-linux-gnu/libcsfml-system.so.2.5. Maybe the compiler doesn't know to look in /usr/lib/x86_64-linux-gnu.


I sent an issue request to bindbc-sfml and they could not 
reproduce my bug or figure out why it was happening, but I 
wouldn't be surprised if it is a bug.


Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn
On Friday, 3 February 2023 at 11:43:46 UTC, thebluepandabear 
wrote:

On Friday, 3 February 2023 at 11:37:43 UTC, bachmeier wrote:
On Friday, 3 February 2023 at 10:15:37 UTC, thebluepandabear 
wrote:
I recently did a fresh install of CSFML and I am getting this 
errors when running my csfml D bindings program:


```
object.Exception@source/app.d(38): Fatal error(s) encountered 
whilst calling `loadSFML()` function:
 ["Error: libcsfml-system.so, Message: libsfml-system.so.2.5: 
cannot open shared object file: No such file or directory",
 "Error: libcsfml-system.so.2, Message: libcsfml-system.so.2: 
cannot open shared object file: No such file or directory",
"Error: libcsfml-system.so.2.0, Message: 
libcsfml-system.so.2.0: cannot open shared object file: No 
such file or directory"]

```


We don't have the full compilation and loading details, but 
this part of the message seems unusual:



"Error: libcsfml-system.so, Message: libsfml-system.so.2.5


One is `libcsfml` and the other is `libsfml`.


Hi,

It seems like it has changed since then, I am _no longer_ 
getting those conflicting errors, it's just 'libcsfml' for both 
instances.


I am thinking of compiling CSFML from scratch to see if it will 
help, but I'd rather not since it seems complex.


Furthermore, I would like to thank you for bringing up the 
compilation/loading details up. I'll send a snippet of that if 
I can figure out how to do so.


nvm, im getting that error again


Re: SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn

On Friday, 3 February 2023 at 11:37:43 UTC, bachmeier wrote:
On Friday, 3 February 2023 at 10:15:37 UTC, thebluepandabear 
wrote:
I recently did a fresh install of CSFML and I am getting this 
errors when running my csfml D bindings program:


```
object.Exception@source/app.d(38): Fatal error(s) encountered 
whilst calling `loadSFML()` function:
 ["Error: libcsfml-system.so, Message: libsfml-system.so.2.5: 
cannot open shared object file: No such file or directory",
 "Error: libcsfml-system.so.2, Message: libcsfml-system.so.2: 
cannot open shared object file: No such file or directory",
"Error: libcsfml-system.so.2.0, Message: 
libcsfml-system.so.2.0: cannot open shared object file: No 
such file or directory"]

```


We don't have the full compilation and loading details, but 
this part of the message seems unusual:



"Error: libcsfml-system.so, Message: libsfml-system.so.2.5


One is `libcsfml` and the other is `libsfml`.


Hi,

It seems like it has changed since then, I am _no longer_ getting 
those conflicting errors, it's just 'libcsfml' for both instances.


I am thinking of compiling CSFML from scratch to see if it will 
help, but I'd rather not since it seems complex.


Furthermore, I would like to thank you for bringing up the 
compilation/loading details up. I'll send a snippet of that if I 
can figure out how to do so.


SFML D bindings: libsfml-system.so.2.5: cannot open shared object file:

2023-02-03 Thread thebluepandabear via Digitalmars-d-learn
I recently did a fresh install of CSFML and I am getting this 
errors when running my csfml D bindings program:


```
object.Exception@source/app.d(38): Fatal error(s) encountered 
whilst calling `loadSFML()` function:
 ["Error: libcsfml-system.so, Message: libsfml-system.so.2.5: 
cannot open shared object file: No such file or directory",
 "Error: libcsfml-system.so.2, Message: libcsfml-system.so.2: 
cannot open shared object file: No such file or directory",
"Error: libcsfml-system.so.2.0, Message: libcsfml-system.so.2.0: 
cannot open shared object file: No such file or directory"]

```

I am using SFML D bindings 
(https://github.com/BindBC/bindbc-sfml):


```D
void loadDyn() {
if (!loadSFML()) {
string[] messages;

foreach (const(ErrorInfo) err; errors) {
string errorStr = to!string(err.error);
string messageStr = to!string(err.message);

			messages ~= format("Error: %s, Message: %s", errorStr, 
messageStr);

}

		throw new Exception(format("Fatal error(s) encountered whilst 
calling `loadSFML()` function: %s", messages));

}
}

void main() {
loadDyn();

	sfRenderWindow* renderWindow = 
sfRenderWindow_create(sfVideoMode(500, 500), "Snake Smooth 
Dynamics", sfWindowStyle.sfDefaultStyle, null);

sfEvent event;

while (renderWindow.sfRenderWindow_isOpen()) {
while (renderWindow.sfRenderWindow_pollEvent()) {
if (event.type == sfEventType.sfEvtClosed) {
renderWindow.sfRenderWindow_close();
}
}

renderWindow.sfRenderWindow_clear(sfYellow);
renderWindow.sfRenderWindow_drawSprite(snakeHeadSprite, null);
renderWindow.sfRenderWindow_display();
}
}
```

Things I've tried:

- I found someone with a similar question: 
https://stackoverflow.com/questions/41516065/linux-sfml-cannot-open-shared-object-file, tried out some answers but to no avail


- I tried to `sudo apt purge` every CSFML dependency (graphics, 
audo, etc) and reinstall each component (`csfml-audio`, 
`csfml-graphics`) manually etc, to no avail.


- I tried to run `sudo ldconfig`... didn't work

- As a last ditch effort I tried to manually move the shared 
object files to the `/usr/local/lib` directory (to try and 
perhaps trick the compiler to run the program?) but to no avail.


- I tried to run on a new VM and still didn't work

- I tried to set `LD_LIBRARY_PATH` environment variable

The amount of layers I depend on make it impossible to find where 
the bug is from, there are a lot of separate things going on and 
it's very multilayered, I don't know where the issue is 
specifically coming from as it used to work just fine I ran the 
exact same commands to install CSFML previously,  now when I do 
it it just refuses to run.
The weird thing is when I ran a brand new virtual machine, 
installed those packages, still same issue.


I am running Linux Mint 21.1, Ubuntu based. Relatively new PC.

Help would be appreciated.



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
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 to disable the default constructor -- that then 
becomes ugly, hackish code.


Looking at the GC code found @ 
https://github.com/dlang/dmd/blob/master/druntime/src/core/memory.d, it seems like they have disabled the default constructor:


```D
struct GC
{
@disable this();
...
}
```

Interesting, so maybe there is a use case for a purely static 
type or namespace?


The standard library as well uses `final abstract class` a couple 
of times, which can also be thought as a type of namespace.


All these 'hacks' to workaround a namespace-like feature are ... 
interesting... So maybe such a feature would help the language?


Just askin questions!



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, hackish code.


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 is, it's up to the person's 
personal preferences.


Personally, I like interfaces, I like abstract classes, I like 
inheritance, I like polymorphism. A lot of things can be done 
with pure structs, but sometimes that extra OOP stuff is needed 
too.


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 `dstep` and translated the C 
header files to D language. This went well. I ended up wrapping 
all the code in an `extern(C)` call.


Now, I am trying to 'link' CSFML to my bindings but have been 
struggling to do so.


I tried to add the following to `dub.json`:

```
"libs": ["csfml-audio", "csfml-graphics"]
```

But it came back with an error:

```
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/out/production/sfmld-backend/obj/sfmld-backend.o: in function `_Dmain':

/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x3a): 
undefined reference to `sfRenderWindow_create'
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x58): undefined reference to `sfRenderWindow_isOpen'
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x69): undefined reference to `sfRenderWindow_pollEvent'
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x7c): undefined reference to `sfRenderWindow_close'
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x90): undefined reference to `sfRenderWindow_clear'
/usr/bin/ld: 
/home/tom/Desktop/sfmld-backend/source/graphics.d:(.text._Dmain[_Dmain]+0x99): undefined reference to `sfRenderWindow_display'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```

I am really confused as to how I even am supposed to get the 
library name in the first place, which is another thing that is 
confusing me.


Any help with this would be appreciated.







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 delete feature which is why I said that, I now realize I 
cannot remove posts on This forum.


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-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 size) {
_size = size;
setSize(_size);

ptr.sfShape_update();
}
```

It is my fault on this one.

Thank u sir.


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 would be greatly... greatly 
apprecaited...
I do not know anything about sfml, but could you try a simpler 
shape, e.g. circle (that is a primitive on the native side). 
perhaps the winding order of your vertices is wrong?


Kind regards,
Christian


thanks for the reply

That also - unfortunately - doesn't seem to work.

 I would love to see some proper examples for creating shapes but 
the docs for bind-bc didn't have any :|


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 C-style syntax is not right -- in my opinion -- for an object 
oriented language. Dealing with pointers all the time is also 
unsafe.


This is not to say that CSFML isn't good -- it's great, and I've 
made some apps using `bindbc-sfml`. I just want to extend it to 
my liking with object oriented wrappers that can more closely 
match the C++ SFML syntax.


For the wrappers, I created a `Shape` class. This `Shape` class 
is seen in the original C++ SFML implementation:


```D
class Shape : Transformable, Drawable {
void setTexture(sfTexture* texture, bool resetRect) {
ptr.sfShape_setTexture(texture, resetRect);
}

void setTextureRect(IntRect rect) {
ptr.sfShape_setTextureRect(rect.to_sfIntRect());
}

void setFillColor(Color color) {
ptr.sfShape_setFillColor(color.to_sfColor());
}

void setOutlineColor(Color color) {
ptr.sfShape_setOutlineColor(color.to_sfColor());
}

void setOutlineThickness(float thickness) {
ptr.sfShape_setOutlineThickness(thickness);
}

const(sfTexture)* getTexture() {
return ptr.sfShape_getTexture();
}

IntRect getTextureRect() {
return ptr.sfShape_getTextureRect().toIntRect();
}

Color getFillColor() {
return ptr.sfShape_getFillColor().toColor();
}

Color getOutlineColor() {
return ptr.sfShape_getOutlineColor().toColor();
}

float getOutlineThickness() {
return ptr.sfShape_getOutlineThickness();
}

size_t getPointCount() nothrow {
return ptr.sfShape_getPointCount();
}

Vector2f getPoint(size_t index) nothrow {
return ptr.sfShape_getPoint(index).toVector2f_noThrow();
}

FloatRect getLocalBounds() {
return ptr.sfShape_getLocalBounds().toFloatRect();
}

FloatRect getGlobalBounds() {
return ptr.sfShape_getGlobalBounds().toFloatRect();
}

private sfShape* ptr;
}
```

The `sfShape` pointer isn't currently initialized, I'll get to 
that issue soon.


As you can see, `Shape` extends the `Transformable` class and the 
`Drawable` interface. This again roughly matches what's seen in 
SFML. SFML.NET also did a similar wrapper for their CSFML C# 
bindings. What's great about SFML.NET is that you don't even know 
that you're using CSFML, this is because it feels just like C++ 
SFML.


Now, I will create a `RectangleShape` which will be a subclass of 
the `Shape` class:


(Btw I took a lot of inspiration from SFML.NET when it comes to 
these wrappers.)


```D
class RectangleShape : Shape {
this(Vector2f size) {
_size = size;
setSize(_size);
}

Vector2f getSize() {
return _size;
}

void setSize(Vector2f size) {
_size = size;
}

override {
size_t getPointCount() {
return 4;
}

Vector2f getPoint(size_t index) {
final switch (index) {
case 0:
return Vector2f(0, 0);
case 1:
return Vector2f(_size.x, 0);
case 2:
return Vector2f(_size.x, _size.y);
case 3:
return Vector2f(0, _size.y);
}
}
}

private Vector2f _size;
}
```

As you can see, the `Rectangle` class only overrides the 
`getPointCount` and `getPoint` methods.


**These are the methods that the superclass - `Shape` - will use 
to construct the shape object for it to actually be drawable.**


Now, let us add the following code to the `Shape` class so that 
we can construct a `Shape` via these two methods, which we assume 
that the child provides us a good implementation for:


```D
class Shape : Transformable, Drawable {
this() {
ptr = sfShape_create(, , 
cast(void*)this);

}

extern(C) private static ulong getPointCount(void* data) 
nothrow {

return (cast(Shape)data).getPointCount();
}

extern(C) private static sfVector2f getPoint(size_t index, 
void* data) nothrow {
return 
(cast(Shape)data).getPoint(index).to_sfVector2f_noThrow();

}
```

I hear you asking, what's going on here?

We are providing two callbacks to the `getPointCount` and 
`getPoint` methods via function pointers, and we're passing in 
the current object to the `data` `void*` pointer. It's kind of 
hard to understand, but if you read through it carefully you 
should get a rough idea of what's going on.


Now, when we create a new instance of `Rectangle`, I will assume 
that the constructor will be called, the `sf_shape` ptr will be 
initialized correctly (as it will be utilizing the crucial 
`getPoint` and `getPointCount` methods) and everything 

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 
libraries want to incorporate a namespace-like design to force 
the user to be more 'explicit' with what they want.


SFML has a `Keyboard` namespace which has a `Key` enum.

The user is 'forced' (although I am not sure if this is the case 
since it's C++) to use the `Keyboard.` declaration before using 
the `Key` enum. Looking at code block 1 and 2, which makes more 
sense?


```C++
Keyboard::Key.A
```

```C++
Key.A
```

The first one does, because looking at the second one, the person 
who will read the code might be confused what 'Key' means, is it 
a car key, a set of keys for unlocking something, etc?


Now, the user doesn't have to use the library if they don't want 
to. There will be plenty of libraries out there that don't have 
namespaces.


I haven't been programming for a long time, but most of the other 
languages I used had such a namespace feature. Kotlin has 
something called an `object` which is essentially a namespace and 
it is great. The benefits of adding a namespace-like feature 
outweigh its costs, imo.


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 can just 
use D's symbol resolution rules to disambiguate between 
Algo.drawLine and PersonalSpace.drawLine, for example. :-P



T


Again, stuffing it into a module is not the same thing as a 
namespace. The user can just bypass this by writing `drawLine`, 
there's nothing in the language currently that would 'force' the 
user to write in a namespace-like/static-class-like fashion, and 
that's the biggest problem.


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 `Keyboard` namespace:


`final abstract class Keyboard` at 
https://github.com/Jebbs/DSFML/blob/master/src/dsfml/window/keyboard.d


It seems like using `final abstract` is the best solution.




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 object oriented and procedural language, I would 
honestly love to see some sort of `namespace` or `static class` 
feature come into the language. I know that it's controversial 
here, but I would honestly think it would help develop the 
language in a good way. But that's just my opinion.


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 solution specifically. That's because it is 
a procedural implementation, not an OOP-style one. I don't know 
how much of the D community writes procedurally but I'm 
personally an OOP-type of guy.


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.


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 Pos(5, 3), new Pos(7, 9));
```

This type of semantics is not possible in D, which sucks.

After scouring the forums, the only workaround seems to be the 
following:


```
final abstract class Algo {
void drawLine(Canvas c, Pos from, Pos to) { .. };
}
```

This solution seems like a bit of a hack, which is why I don't 
like it.


Alternatively you could create a module, but then it would just 
be a function without a clear type.


Is anyone aware of a non-ugly way to implement a 'static' class 
or namespace?


Regards,
thebluepandabear



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 
they've covered is in any sense obsolete.


Mike's one is more of a learning one. I'll check out Adam's as it 
seems to be more geared toward learning the advanced stuff of the 
language, thanks!


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 resources out 
there, but I guess that's the 'cost' of picking a lesser-known 
language. Hopefully in the future there will be more books 
written on this language, if there was a book on the advanced 
features of D I'd happily purchase it :)


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 
resources so I can learn this concept, which sucks.


Is anyone on this forums aware of any up-to-date (preferably 
2019+) D template books/resources? I know C++ has many books on 
this topic, but less so for D.


Help would be appreciated.

Regards,
thebluepandabear


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 to do this:

class X {
private int num;

struct Y {
X outer;
int fun() { return outer.num; }
}

Y y;
this(){
y = Y(this);
}
}

void main(){
import std.stdio : writeln;
auto x = new X();
x.num = 10;
writeln(x.num);
writeln(x.y.fun());
}

Prints:

10
10

Matheus.


ah, that's annoying, but I guess it's the only solution as it 
stands.





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`?

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 for structs.


Help would be apprciated.


I don't think this works for structs. As a workaround, you give 
your struct an explicit reference to the outer class, like this:


```D
class X {
private int num;

struct Y {
X outer;
int fun() { return outer.num; }
}
}
```


Thanks.

How will the variable `outer` become the reference to the current 
`X` object (if that makes sense?). Does the compiler do it 
automatically?


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 for structs.


Help would be apprciated.




(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 members of `Obj` (since 
`private` is only applied to modules), or does this go against 
the intended use of the language?


As a beginner, I am having an extremely tough time understanding 
why you would want to place these two classes in the same module 
or even have this intended behavior of `private`. I am coming 
from Java/Kotlin which are both strictly OO language and have 
different ways of encapsulation.





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: 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 be the most elegant one yet, I 
recently came across the similar problem and I realized that the 
other answer was too long and verbose.


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
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 believe I saw a similar StackOverflow post about this issue for 
C#, and Microsoft did fix it, hopefully D can do the same. Fixing 
this will improve the quality of the language for newcomers such 
as myself greatly.


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 
do that foreach without casting or std.conv by just omitting 
the type of the variable you're iterating:


import std.stdio, std.conv;

interface IDog {
void bark();
}

class Dog: IDog{
string s;
this(string _s){s = _s;}
void bark(){writeln(s);}
}

class List{
IDog[] dogs;
void add(T)(T d){ dogs ~= d;  }
}

void main(){
auto d1 = new Dog("meaw!");
auto d2 = new Dog("wof!");
auto l = new List();
l.add(d1);
l.add(d2);

foreach(d; l.dogs){ // No type informed for "d"
d.bark();
}
}

Prints:

meaw!
wof!

Matheus.


The `foreach` worked for that case since `bark` is a method of 
`IDog`. `update` is not so a conversion to `Button[]` is needed.


I will look at your resource, thanks.


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 {
void render(sfRenderWindow* renderWindow);
}
```

And the following class that implements that interface:

```D
class Button : ICustomDrawable {
...
override void render(sfRenderWindow* renderWindow) {
...
}
}
```

And this class which uses `ICustomDrawable`:

```D
class StackLayout : ICustomDrawable {
   ...
void addChild(T)(T child) {
static assert(is(T : ICustomDrawable), "Invalid type T 
for child");

...
}
...
ICustomDrawable[] _children;
}
```

For some reason, when I want to cast the `children` (property), 
only the second example works:


1.

```D
foreach (Button button; cast(Button[])(_boardSizeRow.children)) {
button.update(event, _renderWindow);
}
```

2.

```D
foreach (Button button; to!(Button[])(_boardSizeRow.children)) {
button.update(event, _renderWindow);
}
```

When I run the first code example I get a black screen, whilst 
with the second I do not. I find this very strange as when I 
write to the console the 'type', it is the same for both 
scenarios.


Help would be appreciated as to why this is happening so I can 
better understand how D works.




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

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: 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], boardSize[1]);
button.onButtonClick = {
eventHandler.settingsWindow_onBoardSizeButtonClick(boardSize);
};
button.onButtonClick();
_boardSizeRow.addChild(button);
}
```


This is a classic D trap: the loop variable is only allocated 
once, and the closure captures the single location where the 
loop variable resides, thus every delegate from every loop 
iteration will see the same value when they are run later, 
i.e., the last value of the loop index. Do this instead:


```D
foreach (BoardSize boardSize; arr) {
Button button = new Button();
button.text = format("%sx%s", boardSize[0], boardSize[1]);
BoardSize size = boardSize; // force separate capture
button.onButtonClick = {

eventHandler.settingsWindow_onBoardSizeButtonClick(size);

};
button.onButtonClick();
_boardSizeRow.addChild(button);
}
```

This is arguably a language bug (I can't imagine any sane use 
case where somebody would actually want the current semantics). 
 But we have not be successful in convincing Walter about 
this...



T


Your code with the variable capture doesn't seem to work.


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 = {

eventHandler.settingsWindow_onBoardSizeButtonClick(boardSize);

};
_boardSizeRow.addChild(b[indx]);
}
```

Any other ways of fixing this annoying issue?




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, everything has worked fine.

I want to add a couple of buttons side by side to represent an 
element of a list and assign them each a unique lambda expression 
for that particular element in the list, this is the current code 
I have:


```D
foreach (BoardSize boardSize; arr) {
Button button = new Button();
button.text = format("%sx%s", boardSize[0], boardSize[1]);
button.onButtonClick = {

eventHandler.settingsWindow_onBoardSizeButtonClick(boardSize);

};
button.onButtonClick();
_boardSizeRow.addChild(button);
}
```

Running this code, I had expected that everything would work 
fine. Unfortunately upon running the code, tapping each of the 
buttons returned only the largest `boardSize` value, the one 
which is gets iterated last.


Note that I am still not totally sure why this is the case. At 
first, I was confused, but then I suspected that after the 
variable gets sent as a parameter to the 
`settingsWindow_onBoardSizeButtonClick` function, it gets changed 
again in the next iteration creating a sort of chain effect -- I 
may be wrong, but this is my suspicion.


Some of the things I tried was creating a new object each time, 
although it didn't work. I might have not done this properly as I 
am a beginner to D language. I saw someone else ask a similar 
question as to why this is happening but that was for C#, not D, 
so it wasn't that much of a use to me.


Help would be appreciated!


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, int value) {
  foo.bar = value;
}

void main() {
  foo.setBar(100); // UFCS
  setBar(foo, 100); // Non-UFCS (Above expands to this)
}
```

This is not UFCS but just class method calling:

```
class Foo {
  int bar;

  void setBar(Foo foo, int value) {
foo.bar = value;
  }
}

void main() {
  foo.setBar(100); // Not UFCS - just method call to the class
  foo.setBar = 100; // Not UFCS - simply a setter function call 
(equal to the above)

  setBar(foo, 100); // Error
}
```

Also note that @property doesn't really do anything now and 
there's even talk about deprecating it. Althought I personally 
still use it, then it doesn't have much of a function and none 
of your code is affected if you remove it.


Yeah I got mixed up.

I think a good use of `@property` is for code clarity, it makes 
it clear which parts of your code should be treated as properties.


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 code fails to compile:


void main() {
alias T = int;
alias TT = typeof(T);
}

Error: type `int` is not an expression

And the error message tells us typeof requires an expression. 
What you can do is to use T.init and the code should now work 
like the following does:


alias TT = typeof(T.init);

Ali


Ok, that makes sense now, my mistake. I seem to have gotten the 
wrong impression that typeof is more flexible than it is.


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 == 
sfRectangleShape*) || is(T == sfText*) || is(T == sfSprite*);

}

void sfRenderWindowExt_draw(T)(sfRenderWindow* renderWindow, T 
obj) {
static assert(isDrawable!T, format("Cannot call any draw 
method on type %s", T.stringof));


if (is(T == sfCircleShape*)) {

renderWindow.sfRenderWindow_drawCircleShape(cast(sfCircleShape*)obj, null);

} else if (is(T == sfRectangleShape*)) {

renderWindow.sfRenderWindow_drawRectangleShape(cast(sfRectangleShape*)obj, null);

} else if (is(T == sfText*)) {
renderWindow.sfRenderWindow_drawText(cast(sfText*)obj, 
null);

} else if (is(T == sfSprite*)) {

renderWindow.sfRenderWindow_drawSprite(cast(sfSprite*)obj, null);

}
}
```

For some reason, if I replace the `isDrawable` template with the 
following (using `typeof`), the code does not compile:


```D
template isDrawable(T) {
enum isDrawable = is(typeof(T) == sfCircleShape*) || 
is(typeof(T) == sfRectangleShape*) || is(typeof(T) == sfText*) || 
is(typeof(T) == sfSprite*);

}
```

This is really strange, as I assumed that the two pieces of code 
were essentially the same.


Any help as to why this is the case would be appreciated.


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` object:

```D
void main() {
Dog d = new Dog();

d.name = "Poodle";
writeln(d.name);
}
```

In the code we can see that we have utilized UFCS (universal 
function call syntax) to set the properties for the object. This 
feature is great. We have also used D's `@property` annotation 
which gives us some other advantages that you can see in the 
documentation.


The issue I have is that UFCS is not enforced, which I thought 
would be a rather good use for the `@property` annotation. This 
means that we can do the following in our code:


```D
void main() {
Dog d = new Dog();

d.name("poodle");
writeln(d.name());
}
```

I prefer the UFCS version over the non-UFCS version since it is 
more clear that it is a property and it matches closely with the 
official D style guide.


I am disappointed that `@property` does not enforce UFCS, as I 
believe that it would add to its usefulness. Sometimes throughout 
my codebase I get confused and write properties in non-UFCS 
syntax, which bugs me a bit.


My question is: is there a way to enforce UFCS-syntax?


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.


I'm new to D and also haven't found any solid JSON libraries. 
Unfortunately a massive downside for D is the fact that the 
ecosystem is very small when compared to other languages such as 
Java.


You might want to try the following:

https://github.com/libmir/asdf





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 blocks' you mention, D (like C++) 
has both static assert and runtime assert.


// ---
module test;
@safe:

import std;

void main()
{
  string val = "some string";
  static assert(is(typeof(x) : int)); // assertion fails at 
compile time.
  assert(val == "some other string"); // assertion fails at 
runtime.

}
// ---


Before even running the code I get an IDE warning (IntelliJ). 
Does IntelliJ compile the code in the background?


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 through to be executed 
natively. Compile time is the first stage. During compile time, 
the compiler checks for basic syntax errors such as a missing 
semicolon, typos throughout the codebase. Then the run time stage 
begins. Other errors are only able to be spotted during run time 
such as exceptions, dividing by zero, assert blocks.


In Java and some other languages, during compile time the code 
gets executed into Java bytecode. This also happens for C#. I 
don't know if there is an equivalent 'intermediate' language for 
D that your code gets translated to.


In general, I have a very vague understanding of these concept.s 
I don't understand the basics of how compile time and run time 
works in D language, it wasn't really explained in the book so 
when I see terms like 'compile time' and 'run time' I only have a 
very vague idea of what these things mean and how the process 
works for D language when compared to other high level languages.


Any help would be appreciated.



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 think this was touched in the book about D I am reading.




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

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 randomly
got removed
> for no reason, I would appreciate an explanation 

Are you sure it was this thread? What were in those posts? 
Perhaps they were posted on another thread?


I follow these newsgroups with ThunderBird, which naturally 
keeps local copies of the posts. I've just gone through all 
posts in this thread and I see no difference between 
ThunderBird's cache and the forum interface's cache.


Note that ThunderBird does not delete any post even if a 
moderator removes a posting from the newsgroup. For example, 
when a spam gets posted, my ThunderBird will show the post even 
after it's been deleted from the newsgroup server.


Ali


Yeah I am sure it was on this thread. One of the posts was at 
https://forum.dlang.org/post/kzvnajixjdnlcupsl...@forum.dlang.org, it now shows 'Not Found'. I just replied to this person who was asking whether or not I was talking about C's `union` type (I was not), and his post and my reply seems to have magically disappeared.


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 


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-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 (free) book by Ali that every Dlang 
beginner should probably read.


I am reading that exact book (halfway through), it's great. I 
wasn't talking about the `union` type (I am familiar with it), I 
was talking about Java's `ArrayList` / C++'s `std::vector` 
/ Rust's `vec!`.


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[] names...) {
 namesForLaterUse = names;
  }
}
```

He says that the code above is a bug because:

"Both the free-standing function foo() and the member function 
S.foo() are in
error because they store slices to automatically-generated 
temporary arrays that
live on the program stack. Those arrays are valid only during the 
execution of the

variadic functions."

The thing is, when I run the code I get absolutely no error, so 
how is this exactly a 'bug' if the code runs properly? That's 
what I am confused about. What is the D compiler doing behind the 
scenes?


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.



#  #
#  #
#  #  #
#  #
#  #



#  #
#  #  #
#   ####
#  #  #
#  #



## #
# ####
#  # #
# ###   #
## #



There should be some ANSI sequences that allow you to do such a 
thing (as in clearing the console and refreshing), not familiar 
with any though from the top of my head.


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 time 
when the rvalue

would not be available."

I didn't really understand what Ali meant by this statement, any 
help would be appreciated so this can be clarified.


Regards,
thebluepandabear


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 question without asking more 
questions: are you looking for a linked list? A list API? A 
specific list interface?


-Steve


I was wondering more if there is an object oriented way of 
creating arrays, like in Java there is an `ArrayList`, in C++ 
there is `std::vector`, etc.


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?


  1   2   >