News for hackers. Stuff that matters.
Re:Show HN by WalterBright on Saturday December 03, 2022 @01:49PM (#33846139)
> why they’re considered to be so difficult to manage?

Back in the 90s, I was very experienced with C strings and managing them. Then I chanced to look at BASIC again, and realized that strings in BASIC were so simple and intuitive. Why couldn't C be like that? When I started on the design of D, I decided that it had to make strings as easy to do as BASIC did.

And D does.

The trouble with C strings is the 0 termination of them. This means:

1. to get the length of the string, you have to scan it. This is expensive.

2. when manipulating strings, a common error is to get off by one in the storage because of the 0 termination

3. you cannot get a subset of the string without making a copy. Not only is a copy expensive, but then you have to keep track of the memory for it

4. there's no way to check for buffer overflows

D's design, which uses a phat pointer (length, ptr) for strings, solves these problems.

Re:Show HN by tored on Saturday December 03, 2022 @03:21PM (#33846908)
A year ago I picked up the BASIC dialect PureBasic. Pleasant surprise actually, the syntax of the PureBasic dialect is a bit archaic, but if you accept that it is much easier and faster to get anything done compared to C (and C++). Personally I find low level topics easier to grok in PureBasic than in C even though they mirror the same concepts. PureBasic has Unicode strings built in.

It is a bit shame that BASIC has such a bad reputation, there are many BASIC dialects that does the job well still today.

https://www.purebasic.com/documentation/reference/ug_string....