Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C++] delete considered harmful

Name: Anonymous 2016-01-02 14:13

The unbridled use of the delete statement has as an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress. ... The delete statement as it stands is just too primitive, it is too much an invitation to make a mess of one's program.

Never use delete, use smart pointers, memory pools, stack allocations. Don't break RAII.

Name: Anonymous 2016-01-11 13:54

>>80
please italify your !s

Name: Anonymous 2016-01-11 21:13

>>80
O(1) length
Any data structure can have O(1) length.

Name: Anonymous 2016-01-11 21:20

>>82
A plain C string passed to your function.
Describe the O(1) way of computing its length:

Name: Anonymous 2016-01-12 0:16

>>83
Passing it with it.

Name: Anonymous 2016-01-12 5:37

>>84
Do you also pass it to strlen?

Name: Anonymous 2016-01-12 7:41

>>86
Why would you call strlen if you already know what it will give you back?

Name: Anonymous 2016-01-12 8:09

>>86
Thats the point: you need to calculate it somewhere, and C strings require O(n) length computation.

Name: Anonymous 2016-01-12 8:23

>>87
Check 'em

Name: Anonymous 2016-01-12 8:30

>>88
I see you've got dbus there

Name: Anonymous 2016-01-12 12:51

>>87
printf("%u\n", sizeof("hello I'm a C string") - 1);

Name: Anonymous 2016-01-12 14:03

>>87
As opposed to C++ strings, which magically know their length before they are even created? IHBT

Name: Anonymous 2016-01-12 14:19

>>90
%zu

Name: Anonymous 2016-01-12 15:22

Name: Anonymous 2016-01-12 16:13

I think what >>82 was trying to say is that you can add an O(1) length field to any datastructure, maintaining it in all mutating calls.

However, that means that you must perform all mutations via a single root object per data structure, and any structure sharing will probably ruin it.

Name: Anonymous 2016-01-12 22:13

Just use Java and don't think about that shit.

Name: Anonymous 2016-01-13 0:01

"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
- Bjarne Stroustrup

Name: Anonymous 2016-01-13 2:12

>>95
because the computational cost of calculating the length of ArrayList vs LinkedList isn't the same fucking issue, right?

Name: Anonymous 2016-01-13 2:36

>>87
you need to calculate it somewhere
No, just keep track of it.

Name: Anonymous 2016-01-13 9:09

>>97
Most Java programmers have no clue about the difference and the software they write still works fine.

Name: Anonymous 2016-01-13 9:33

>>9
C programmers could also do the same, but they're too wrapped up their asshole to realize that their efforts are pointless.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List