Re: Setting field of struct object

2024-01-22 Thread Bkoie via Digitalmars-d-learn

On Monday, 22 January 2024 at 11:31:11 UTC, zjh wrote:

On Monday, 22 January 2024 at 08:54:54 UTC, zjh wrote:
C++ can achieve ultimate `simplicity` without violating `DRY`,
And here, D violates the `DRY` principle!
Moreover, as the `package level, module level, class level, 
member level`, D language violates integrity.

Because D has no `class level` limit.
These are all not `serious states`.


i think D module base system is fine wished some other lang had 
the same you can avoid circular import ref.


dry? well he can easily turn that into a generic config static 
factory which its look like hes trying to do.


D is totally different from C++ in D you usually you wont 
construct the struct directly use alias as.


Re: How to use ImportC to import WebGPU header

2024-01-12 Thread Bkoie via Digitalmars-d-learn

On Thursday, 11 January 2024 at 15:18:08 UTC, Sergey wrote:

On Wednesday, 10 January 2024 at 23:36:33 UTC, JN wrote:
I would like to use ImportC to automatically import a C header 
into my D project.


It was already done. Use it 
https://code.dlang.org/packages/wgpu-d

Don't reinvent the wheel :)


or if you push a package atleast document the code or give example
D is not like rust where you can just dive into a lib without 
docs or example


Re: D is nice whats really wrong with gc??

2023-12-22 Thread Bkoie via Digitalmars-d-learn

On Friday, 22 December 2023 at 12:53:44 UTC, bomat wrote:
I think the problem most "old school" programmers have with 
automatic garbage collection, or *any* kind of "managed" code, 
really, is not the GC itself, but that it demonstrates a wrong 
mindset.


If you use (or even feel tempted to use) a GC, it means that 
you don't care about your memory. Neither about its layout nor 
its size, nor when chunks of it are allocated or deallocated, 
etc.
And if you don't care about these things, you should not call 
yourself a programmer. You are the reason why modern software 
sucks and everything gets slower and slower despite the 
processors getting faster and faster. In fact, you probably 
should get another job, like flooring inspector or something. :)


and that's the reason why modern programs are getting bigger, 
slower and leaking memory. no one should be manually managing 
memory, rust is a prime example of that but now "barrow checker 
the issue" or "too many unsafe blocks", and as one guy said above 
you can avoid the gc in d so...


D is nice whats really wrong with gc??

2023-12-18 Thread Bkoie via Digitalmars-d-learn
just look at this i know this is overdesign im just trying to get 
a visual on how a api can be design im still new though but the 
fact you can build an api like this and it not break it is 
amazing.


but what is with these ppl and the gc?
just dont allocate new memory or invoke,
you can use scopes to temporry do stuff on immutable slices that 
will auto clean up

the list goes on

and you dont need to use pointers at all...!!

i honesty see nothing wrong with gc,

ofc d has some downsides,
docs not very good compare to some other lang.
ide support not great but it works sometimes
i use helix and lapce and maybe sometimes intellj
it works better in helix though.
and of d is missing some minor libraries

```
import std.stdio: writeln, readln;
auto struct Game
{
string title;
private Board _board;
private const(Player)[] _players;
final auto load(T)(T any) {
static if (is(T == Player)) {
_pushPlayer(any);
}
return this;
};
final auto play() {assert(_isPlayersFull, "require players is 
2 consider removing"); "playing the game".writeln;};

final auto _end() {};
auto _currentPlayers() const {return _players.length;}
enum _playerLimit = 2;
auto _isPlayersFull() const {return _currentPlayers == 
_playerLimit;}

import std.format: format;
auto _pushPlayer(T: Player)(T any) {
if (_isPlayersFull) assert(false, "require %s 
players".format(_playerLimit));

_players.reserve(_playerLimit);
_players ~= any;
}
}
private struct Board {}
enum symbol {none, x, o}
private struct Player {const(string) _name; symbol _hand; 
@disable this(); public this(in string n) {_name = n;}}

alias game = Game;
alias player = Player;
alias board = Board;
auto main()
{
import std.string: strip;
game()
.load(player(readln().strip))
// .matchmake
.load(player(readln().strip))
.play;
}
```