December 12, 2022

On Sunday, 11 December 2022 at 17:45:20 UTC, ryuukk_ wrote:

>

Why is it called DList and not just List, i have no clue

Probably because it is a Double-linked List :-)

December 12, 2022

On Sunday, 11 December 2022 at 17:45:20 UTC, ryuukk_ wrote:

>

There is: https://dlang.org/phobos/std_container_dlist.html

Why is it called DList and not just List, i have no clue

The D is to indicate that it is a doubly-linked list. It maintains a forward and backward pointer chain to support iteration in both directions. This is in contrast to SList (std.container.slist) that only has a forward pointer chain.

December 13, 2022

On Monday, 12 December 2022 at 07:57:28 UTC, TTK Ciar wrote:

>

On Sunday, 11 December 2022 at 17:45:20 UTC, ryuukk_ wrote:

>

Why is it called DList and not just List, i have no clue

Probably because it is a Double-linked List :-)

oh right, thanks, i never used that module before i should have read its content before asking lol

December 13, 2022
On Saturday, 10 December 2022 at 15:59:07 UTC, Ali Çehreli wrote:
>
> ... Object orientation don't go well with collections....

On what basis do you make that assertion?

i.e. Which aspect of OOP programming 'don't go well with collections'?

Is it encapsulation?

Is it inheritance?

Is it polymorphism?

Is it generics? (which is an integral part of OOP these days)

As evidence against your assertion (just to start with):
C# -> System.Collections
C# -> System.Collections.Generic
C# -> System.Collections.Concurrent

Only when you provide related proofs, can you come up with such an axiom.

December 13, 2022
On 12/13/22 14:21, areYouSureAboutThat wrote:
> On Saturday, 10 December 2022 at 15:59:07 UTC, Ali Çehreli wrote:
>>
>> ... Object orientation don't go well with collections....
>
> On what basis do you make that assertion?

You stripped my answer.

> i.e. Which aspect of OOP programming 'don't go well with collections'?
>
> Is it encapsulation?
>
> Is it inheritance?
>
> Is it polymorphism?
>
> Is it generics? (which is an integral part of OOP these days)

I am impressed with the questions. Waiting for your answers...

> As evidence against your assertion (just to start with):
> C# -> System.Collections
> C# -> System.Collections.Generic
> C# -> System.Collections.Concurrent
>
> Only when you provide related proofs, can you come up with such an axiom.

Or I can tell what I think, you counter, and we all learn. Proofs... Axioms... Pfft...

Ali

P.S. I apologize for everything I've done to you in the past. Don't forget: You can always forkit!
December 13, 2022
On Saturday, 10 December 2022 at 06:11:18 UTC, thebluepandabear wrote:
>
> 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.

of course there is - I mean just imagine if there wasn't ;-)

e.g (an note, it's called unsafeVector for a reason ;-)

// ----
module test;
import std;

void main()
{
    unsafeVector v = new unsafeVector(5);

    writefln("size of v is: %s", v.size());
    writeln;

    writeln("v contains:");
    for (int i = 0; i < v.size(); i++)
    {
        v[i] = i+1;
        writefln("v %s : %s", i , v[i]);
    }
    writeln;

    writeln(v[0..3]);
    writeln(v[0..$]);
    writeln(v[$-1]);
}

unittest
{
    unsafeVector v = new unsafeVector(5);

    assert(v.size() == 5);

    // NOTE: be sure to use the interface here
    // as D lets you shoot yourself in the foot
    // by giving you direct access to sz !!!
    for (int i = 0; i < v.size(); i++)
    {
        v[i] = i+1;
    }

    assert(v[0..3] == [1,2,3] );
    assert(v[0..$] == [1,2,3,4,5]);
    assert(v[$-1] == 5);

    v[2] = 999;
    assert(v[2] == 999);
}

class unsafeVector
{
  private:
    size_t *elem;
    immutable size_t sz;

  public:
    this(size_t s)
    {
        assert( isIntegral!(typeof(s)) );
        elem = cast(size_t*)new size_t[s];
        sz = s;
    }

    auto ref opIndex(size_t i)
    {
        return elem[i];
    }

    auto ref opSlice(size_t start, size_t end)
    {
        return elem[start .. end];
    }

    auto ref opDollar()
    {
        return sz;
    }

    auto size()
    {
        return sz;
    }
}
// ------------
December 13, 2022
On Tuesday, 13 December 2022 at 22:33:02 UTC, Ali Çehreli wrote:
>
> Or I can tell what I think, you counter, and we all learn. Proofs... Axioms... Pfft...
>
> Ali
>


"I suppose sir, you are going to explain your puzzling remarks."

December 13, 2022
On Tuesday, 13 December 2022 at 22:51:13 UTC, areYouSureAboutThat wrote:
> On Saturday, 10 December 2022 at 06:11:18 UTC, thebluepandabear wrote:
>>
>> 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.
>
> of course there is - I mean just imagine if there wasn't ;-)
>
> e.g (an note, it's called unsafeVector for a reason ;-)
>

We have nothing to do with unsafe stuff! Why do we waste time with unsafe things; To learn or to teach?

SDB@79
December 14, 2022
On Tuesday, 13 December 2022 at 23:34:45 UTC, Salih Dincer wrote:
>
> We have nothing to do with unsafe stuff! Why do we waste time with unsafe things; To learn or to teach?
>
> SDB@79

Really?

That example I provided was just to demonstrate that 'yes' you can implement a container using OOP. I mean why couldn't you?

I just used some basic encapsulation here.

It's pretty easy to make it 'safe'.

But if you want me to provide such an example, utilising all the tools of OOP, you need to first pay me ;-)

December 14, 2022
On Tuesday, 13 December 2022 at 23:34:45 UTC, Salih Dincer wrote:
>
> We have nothing to do with unsafe stuff! Why do we waste time with unsafe things; To learn or to teach?
>
> SDB@79

btw. I reject your axiom: 'We have nothing to do with unsafe stuff!'

It is demonstratably not correct, given the need for @safe.