Why is `scope` planned for deprecation?

via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 17 13:08:17 PST 2014


On Monday, 17 November 2014 at 19:24:49 UTC, Walter Bright wrote:
> You're saying without evidence that sentinels are faster. They 
> are not.

You are twisting and turning so much in discussions that you make 
me dizzy.

I've been saying that for SOME OPERATIONS they are too, and that 
is not without evidence. Just plot it out for a 65xx, 680xx, Z80 
etc CPU and it becomes self-evident. Any system level programmer 
should be able to do it in a few minutes.

Using sentinels is a common trick for speeding up algorithms, it 
has some downsides, and some upsides, but they are used for a 
reason (either speed, convenience or both).

Pretending that sentinels are entirely useless is not a sane line 
of argument. I use sentinels in many situations and for many 
purposes, and they can greatly speed up and/or simplify code.

> You're saying without evidence that 0 terminated strings use 
> less memory. They do not.
>
> (It does not save space when "filename" and "filename.ext" 
> cannot be overlapped.)

0-terminated and shortstring (first byte being used for length) 
takes the same amount of space, but permanent substring reference 
slices are very wasteful of memory for low memory situations:

1. you need a ref count on the base buffer (2-4 bytes)
2. you need pointer to base + 2 offsets (4-12 bytes)

And worst is you retain the whole buffer even if you only 
reference a tiny portion of it. Yuk! In such a use scenario you 
are generally better of reallocation or use compaction. For 
non-permanent substrings you can still use begin/end pointers.

And please no, GC is not the answer, Simula had GC and the kind 
of strings and substrings you argued for but it was not intended 
for system level programming and it was not resource efficient. 
It was convenient. Scripty style concatenation and substring 
slicing is fun, but it is not system level programming. System 
level programming is about taking control over the hardware and 
use it most efficiently. Abstractions "that lie" mess this up.

Is wasting space on meta information less critical today? YES, OF 
COURSE! It does matter that we have 100.000 times more RAM 
available.


More information about the Digitalmars-d mailing list