News for hackers. Stuff that matters.
Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @04:46AM (#19746199)
I don't like how people on the internet hate on C all the time. To me C is a wonderfully simple and elegant language that I can most of the time very clearly express my thoughts in. I find that this not the case with many other languages. This is the reason I use C. Of course compiler writers are trying to sabotage this but I don't write any critical code so if I get hit by an occasional bug it's not a big problem. I think C is misunderstood, perhaps because it is used everywhere and standards for critical pieces of software are applied to non-critical ones. E.g. never freeing memory, even leaking it by destroying all references to it, can be totally fine if your program just runs for a few seconds. Just allocate what you need, throw it away, and let the OS clean up when you're done. This is perfectly fine but I feel like many people wouldn't accept this kind of code because it's not acceptable in other circumstances.

Anyway, the author makes a few good points that are important but often overlooked, but I don't think I'd agree with him on the safety aspect in section 6. Making a safe C implementation doesn't really appear possible. If you allow casting integers to pointers, how do you implement these saftey checks he's talking about?

Re:Some Were Meant for C (2017) [pdf] by johannes1234321 on Thursday April 25, 2019 @05:55AM (#19746507)
"There are only two kinds of languages: the ones people complain about and the ones nobody uses." (Bjarne Stroustrup)

I guess that doesn't only apply to C++, but also C. :)

Re:Some Were Meant for C (2017) [pdf] by drb91 on Thursday April 25, 2019 @05:01AM (#19746268)
I stopped writing C because string manipulation sucked.
Re:Some Were Meant for C (2017) [pdf] by ChrisRR on Thursday April 25, 2019 @07:56AM (#19747103)
I agree with that. Recently I started reading "Writing an interpreter in Go" and thought I'd follow along using C.

From the first chapter, the Go code starts using strings as a short-cut to represent tokens . In other languages this is trivial because strings are very easy to create, resize, change, etc. Using C, this became an issue though, as using strings became a roadblock where I started having to implement different solutions rather than focusing my attention on the contents of the book.

Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @09:37AM (#19747908)
Using strings for tokens is probably not how you would ever do this in C. Make the tokens enums.
Re:Some Were Meant for C (2017) [pdf] by drb91 on Friday April 26, 2019 @10:51AM (#19758118)
Oddly this is also true for go....
Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @05:17AM (#19746351)
I never really got that complaint, I'd like to see some examples of what people consider so ugly about C strings.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @05:53AM (#19746499)
1 - string contents and actual length are handled in separate variables without correlation

2 - no enforcement that a null terminator actually exists in the string

3 - C brags about performance and is probably the slowest language to compute string length

4 - manipulating strings requires very carefull handling of buffers, usually forcing everyone to use the heap as easier way out

Re:Some Were Meant for C (2017) [pdf] by abmackenzie on Thursday April 25, 2019 @06:11AM (#19746579)
Storing the length of a string alongside the string is a viable option in C, it's up to you to do it yourself though (whereas Java and almost every other language does it for you). See https://github.com/phusion/nginx/blob/master/src/core/ngx_st..., used by NGINX.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @08:16AM (#19747237)
Which breaks down every time a C API needs to be called, and that linked API still has plenty of functions with separate pointer and length parameters.
Re:Some Were Meant for C (2017) [pdf] by badsectoracula on Thursday April 25, 2019 @08:34AM (#19747369)
You can do it like in Free Pascal/Delphi: store the string both length-prefixed (for fast length access and bounds checking) and zero terminated (for passing to functions that expect zero terminated strings).
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @09:49AM (#19748043)
And then the callee corrupts it.
Re:Some Were Meant for C (2017) [pdf] by badsectoracula on Thursday April 25, 2019 @11:41AM (#19749290)
If the callee is meant to corrupt it then it is your fault for misusing it (unless the corruption is intentional and you plan to recalculate the length after calling it). If it wasn't meant to corrupt it then it is a bug and if it is in your code then it is your fault for not using the string functionality that you already have in place to avoid the bug in the first place. If it is not in your code, as long as you had to use it you'd have that bug regardless of what language or framework you used since it is out of your control and there isn't anything you can do about it.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @12:16PM (#19749631)
Aka, C's community version of "you are holding it wrong".
Re:Some Were Meant for C (2017) [pdf] by badsectoracula on Thursday April 25, 2019 @12:57PM (#19750092)
Is there a language that doesn't allow any abuse of an API, including APIs that were not written in that language?
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @01:35PM (#19750518)
Yes, any system languages that doesn't need to depend on the existence of C.

If you are going to mention Assembly as possibility, check ClearPath where there is no Assembly, NEWP has full control over the hardware stack.

Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:03AM (#19748195)
>Storing the length of a string alongside the string is a viable option in C, it's up to you to do it yourself though

Obviously, since many other languages that do so are implemented in C.

Re:Some Were Meant for C (2017) [pdf] by tyingq on Thursday April 25, 2019 @07:14AM (#19746893)
Also sds, used by redis: https://github.com/antirez/sds
Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @06:10AM (#19746575)
I was actually more looking for practical issues. Usually the code that I write doesn't even handle strings a lot. Maybe I'm just using other languages for when I do that or maybe I'm using other approaches where others would use strings or maybe I just subjectively don't find them so bad as others. I'd just like to see exactly what people are complaining about so I could find out why I usually don't.
Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:05AM (#19748225)
>I was actually more looking for practical issues.

Those are not practical? Billions of dollars have been wasted on issues stemming from this...

Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @10:23AM (#19748424)
I'd just like to see a concrete example for once.
Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @11:02AM (#19748886)
Like, apart from tons of well known bugs, and vulnerabilities caused from string manipulation? How exactly did you miss news items, reports, posts, university lectures, books, and even your own personal experience, on them?

Or is the insinuation that we are hand-wavy about it, and you doubt the existence and scale of the problem? It's a well researched, well established problem, known for almost half a century.

https://en.wikipedia.org/wiki/C_standard_library#Buffer_over...

https://security.web.cern.ch/security/recommendations/en/cod...

http://www.informit.com/articles/article.aspx?p=430402&seqNu...

https://randomascii.wordpress.com/2013/04/03/stop-using-strn...

https://courses.cs.washington.edu/courses/cse341/04wi/lectur... (null termination)

https://www.geeksforgeeks.org/why-strcpy-and-strncpy-are-not...

https://www.owasp.org/index.php/Reviewing_Code_for_Buffer_Ov...:

And let's not even get into format string issues...

Re:Some Were Meant for C (2017) [pdf] by owl57 on Thursday April 25, 2019 @06:50AM (#19746769)
3 - C brags about performance and is probably the slowest language to compute string length

I have a feeling that of all axes of performace C cares the most about memory overhead. Then the obvious idea is to have it at exatly one byte per "simple" string, and you get to pick the class of programs that can't get away with that default string type:

• One-byte terminator: complicated text-handling application with a lot of (longer than a couple of pointers on average) string slices.

• One-byte length: anything that needs strings longer than 255 chars.

And then of these two solutions you pick the obviously more general one. What could possibly go wrong?

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @08:19AM (#19747261)
Anything that needs strings longer than 255 chars already had a solution in existing systems programming languages back when C was born.

Character arrays with open length, bound checked.

Naturally it requires better compiler support than C authors were willing to implement.

Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:05AM (#19748218)
>Naturally it requires better compiler support than C authors were willing to implement.

Which is still the case with many things in Go, a language of close origin to C (though this time not about strings).

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @11:08AM (#19748956)
It is interesting how in both cases they disregarded what was being made around them.
Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @01:24PM (#19750392)
What was made around them was only ever the gorilla with jungle thing. Fine for small programs, or larger ones within walled gardens. But not fine for infrastructure work.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @01:38PM (#19750551)
Yet Multics was deemed safer than UNIX as per DoD security assement.

I guess security is not relevant as infrastructure work.

Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @01:46PM (#19750653)
Oh, and what do they use today?

> I guess security is not relevant as infrastructure work.

...

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Friday April 26, 2019 @04:08AM (#19755597)
Ada and even Java (PTC/Aonix) when security matters.
Re:Some Were Meant for C (2017) [pdf] by marmaduke on Thursday April 25, 2019 @06:23AM (#19746636)
these seem like tradeoffs which are straightforward to understand, which allow for simpler ABI & runtime. sure, the "UX" of the language suffers compared to e.g. Python, but at least the mechanics are easier to understand. If you want Python style string handling in C you could just use the Python C-API.
Re:Some Were Meant for C (2017) [pdf] by sureaboutthis on Thursday April 25, 2019 @08:40AM (#19747415)
And yet I'm betting your language is run through a C program on its way to being interpreted or compiled.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @11:10AM (#19748971)
That is the unfortunate reality of having UNIX being widespread.
Re:Some Were Meant for C (2017) [pdf] by AnimalMuppet on Thursday April 25, 2019 @01:54PM (#19750750)
Windows is the fault of UNIX? I'm skeptical.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Friday April 26, 2019 @04:10AM (#19755605)
Windows is not a pile of C code, rather C, C++ and .NET.

And nowadays C code is considered legacy, with C#, Rust and constrained C++ as the road to the future.

Re:Some Were Meant for C (2017) [pdf] by sureaboutthis on Thursday April 25, 2019 @01:20PM (#19750336)
It's not unfortunate. If it was a bad thing, UNIX wouldn't be so widespread.
Re:Some Were Meant for C (2017) [pdf] by ernst_klim on Thursday April 25, 2019 @01:33PM (#19750497)
>If it was a bad thing, UNIX wouldn't be so widespread.

Strange argument. Javascript is widespread, COBOL was widespread, Windows is widespread, X86 is widespread. Widespread doesn't mean good. UNIX was a disaster, and the whole family of UNIX-like OS spent decades just for mitigate its errors and faults.

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @01:40PM (#19750579)
I guess we have someone here that enjoys using PHP, JavaScript and Perl.
Re:Some Were Meant for C (2017) [pdf] by sureaboutthis on Thursday April 25, 2019 @03:25PM (#19751631)
As a UNIX professional programmer, no. Other than Perl, which I don't use, why would you think that?
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Friday April 26, 2019 @04:11AM (#19755609)
Same set of language design qualities and being widespead due to historical accident.
Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:06AM (#19748237)
And our money go to some Cobol program on their way to our bank/insurance.

And our data through some JS monstrosity.

So?

Re:Some Were Meant for C (2017) [pdf] by johannes1234321 on Thursday April 25, 2019 @06:01AM (#19746535)
About point 3: Computing the string length is fast in C. The point is: In other languages you always have the length around, so you never count it up.

All the listed weaknesses also have benefits. For instance it is easy to get a substring without need to copy.

But yes, many bugs in C software originate from spring buffer overflows.

Re:Some Were Meant for C (2017) [pdf] by v_lisivka on Thursday April 25, 2019 @06:10AM (#19746572)
> All the listed weaknesses also have benefits. For instance it is easy to get a substring without need to copy.

To make substring in some other languages, you need to store pointer to beginning of the substring and length of substring.

To make substring in C, you need to store pointer to beginning of the substring and put '\0' into original string.

Re:Some Were Meant for C (2017) [pdf] by johannes1234321 on Thursday April 25, 2019 @06:18AM (#19746618)
> To make substring in some other languages, you need to store pointer to beginning of the substring and length of substring.

Plus a pointer to the beginning, plus a reference counter as the user expects it to manage lifetime. In C this is the user's job. Where they know the life time is guaranteed they can optimize.

Re:Some Were Meant for C (2017) [pdf] by Nursie on Thursday April 25, 2019 @09:56AM (#19748117)
I coded in C for over a decade. Never did I need a reference counter.
Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @11:25AM (#19749116)
No, you store offset + length.
Re:Some Were Meant for C (2017) [pdf] by adrianN on Friday April 26, 2019 @09:39AM (#19757323)
You can't use any of the stdlib string functions if you don't have that \0 at the end though, right?
Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Friday April 26, 2019 @09:44AM (#19757371)
Is there any function you would miss? Of those, which one couldn't you recreate in 5 straightforward lines of code?
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @06:03AM (#19746543)
O(N) is not the same as O(1).

That substring won't remain valid without copying it.

Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @11:20AM (#19749070)
> That substring won't remain valid without copying it.

Unless it's not modified? And unless, when modified, that shouldn't be its new value?

C Strings (nul-terminated) are the right approach for static storage of small static strings (like strings literals in the source code) since they have low overhead, and "substrings" aren't second-class citizens.

For dynamically allocated strings that won't be modified after creation, the right approach is using a large memory chunk that is shared between many such strings, plus two indices for offset / length (or just offset if it's text that can be terminated with a sentinel).

Having a short string of about 10 characters allocated as a dynamic object in its own allocation is wasteful. Slow to allocate and has about 2x to 3x overhead. This approach isn't good for applications that store a large amount of data.

> O(N) is not the same as O(1).

Don't call strlen() in situations where the strings are large and you need to know the length ahead of time, and running time is paramount. Instead, store the length.

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @12:19PM (#19749660)
The typical micro-optimization while typing without any profiler feedback, just gut feeling, as prevalent across the community.
Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @01:11PM (#19750247)
You don't need profiler feedback for these things, just back-of-the-envelope calculations. How much data you would like to store and process is not something a profiler can answer for you.

I can tell you that in one of my programs, the difference between garbage collected strings and optimized ones (actually, strings converted into unique integer handles immediately) for one of my projects (SAT solver in Java), handling a few million variables, was something like a second until completion vs a couple of minutes before the garbage collector finally dies due to lack of oxygen, losing all data computed up to that point.

Re:Some Were Meant for C (2017) [pdf] by flohofwoe on Thursday April 25, 2019 @05:44AM (#19746456)
I agree, but C (the language) doesn't even have the concept of a 'string'. It's just the convention how some C standard library functions interpret an array of bytes with a zero at the end.

At least in C it's quite obvious that strings are not trivial if you want both an intuitive way to work with strings, and high performance. The C++ std::string type is neither intuitive to work with, nor does it allow to write high-performance code.

For string processing it's really better to use another language with different trade-offs.

Re:Some Were Meant for C (2017) [pdf] by atilaneves on Thursday April 25, 2019 @07:55AM (#19747089)
> I agree, but C (the language) doesn't even have the concept of a 'string'

It has string literals, so yes it does.

> The C++ std::string type is neither intuitive to work with

Many would disagree.

> nor does it allow to write high-performance code

True, but only due to backwards compatibility with C - std::string operations have to add a null terminator for no other good reason.

Re:Some Were Meant for C (2017) [pdf] by badsectoracula on Thursday April 25, 2019 @08:36AM (#19747378)
> Many would disagree.

Many would also agree, that means nothing. Personally i dislike C++'s strings... and the rest of STL, which i view as one of the worst standard library APIs in wide use.

Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @11:07AM (#19748935)
> True, but only due to backwards compatibility with C - std::string operations have to add a null terminator for no other good reason.

That's about the least reason why std::string is inefficient.

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @05:54AM (#19746504)
C++ std::string is better and more secure and anything that C ever produced.

As for string processing in general, I do agree that other languages are better suited.

Re:Some Were Meant for C (2017) [pdf] by aap_ on Thursday April 25, 2019 @05:54AM (#19746505)
More often that not I find myself missing C-type strings in other languages. Being able to just walk through the characters and manipulating them is something I found rather ugly in python for instance. The NUL character is in my experience not so terrible, you typically have null pointers at the end of a linked list or whatever as well and nobody complains about that. Now I have to admit I had a bug recently that took me longer to fix then I would like to admit because I wasn't walking a string right, but usually I have very little trouble with them.
Re:Some Were Meant for C (2017) [pdf] by adrianN on Thursday April 25, 2019 @06:48AM (#19746759)
What's a character? UTF-8 makes that a bit difficult to answer. If you want arrays of ASCII bytes, you can have those in most programming languages.
Re:Some Were Meant for C (2017) [pdf] by lugg on Thursday April 25, 2019 @08:12AM (#19747204)
1 to 4 bytes.

How does utf8 make that difficult to answer?

When was the last time you iterated over a string of unicode points and said you know what would be handy right now? If these code points were split up into arbitrary and unusable bytes of memory.

Re:Some Were Meant for C (2017) [pdf] by adrianN on Thursday April 25, 2019 @08:29AM (#19747322)
Well, ä is a character in German. You can either write it as LATIN SMALL LETTER A WITH DIAERESIS, or you can use COMBINING DIAERESIS and a. When you iterate over the German word Mädchen as Unicode code points you might be confused. Other languages do much crazier things.
Re:Some Were Meant for C (2017) [pdf] by lugg on Friday April 26, 2019 @01:38PM (#19759966)
That doesn't make it hard..
Re:Some Were Meant for C (2017) [pdf] by olau on Thursday April 25, 2019 @06:34AM (#19746682)
It's been a long time since I wrote C, but the main problem in my recollection is that the standard library is not intuitive. Something simple like take a couple of arbitrary strings, concatenate them and return the result without leaking memory and not causing buffer overflows is not as trivial as it should be.

I don't think is a huge problem per se, though, you can just use a string library.

See the confusion here for an example: https://stackoverflow.com/questions/308695/how-do-i-concaten...

snprintf looks like it is the easiest way out.

Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:15AM (#19748336)
>More often that not I find myself missing C-type strings in other languages. Being able to just walk through the characters and manipulating them is something I found rather ugly in python for instance

If what you say if you want mutable strings, many languages have those and you don't need anything like "NULL" to have them (and you can use a bytearray of the string in Python, though Unicode complicates this).

>The NUL character is in my experience not so terrible, you typically have null pointers at the end of a linked list or whatever as well and nobody complains about that

That's not the same thing at all. The linked list is comprised of structs with next fields, that can be null or point to something. Your program can handle either just fine, as both are valid cases (a linked list expects to find the NULL guard at the end but also expects a non-NULL next pointer if the node is not the last one, so will handle both).

OTOH, if an incoming string doesn't have a NUL byte your program will crash/corrupt memory/worse. On top of that, you need to remember it to add it/make space/for most string manipulations. Strings are not expected NOT to end with NUL, and when they don't there's no way you can mitigate it, except to set arbitrary limits to how many characters you consider.

Re:Some Were Meant for C (2017) [pdf] by leetcrew on Thursday April 25, 2019 @08:39PM (#19753861)
> OTOH, if an incoming string doesn't have a NUL byte your program will crash/corrupt memory/worse.

how are linked lists different? if the last node contains garbage for its next pointer, the outcome will be exactly the same. it's a bit more rare to encounter an "unterminated" linked list, but I've seen it happen plenty of times deserializing a linked list from disk or if the programmer just forgot to initialize the pointer. c strings basically are linked lists with an implicit next pointer.

Re:Some Were Meant for C (2017) [pdf] by sureaboutthis on Thursday April 25, 2019 @08:38AM (#19747394)
This is why I don't like other languages. They have no concept of functions to interpret an array of bytes with a zero at the end.
Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:16AM (#19748345)
Actually (and I know this is a lame troll), it's trivial to make such functions in most non-C languages.
Re:Some Were Meant for C (2017) [pdf] by dgellow on Thursday April 25, 2019 @05:43AM (#19746452)
Why is this comment being down voted? Not everybody here is familiar with C string manipulation, if you down vote or complain at least give more detail that "it sucks".

@aap_, I asked a similar question some time ago and got some answers, you can check the thread here: https://news.ycombinator.com/item?id=19302581

The direct answer I got was:

> I'm guessing because an off-by-one or an extra skip might mean you miss the end of the string and go off into la-la land feeding whatever garbage happens to be in memory to your parser? That would mostly be a C issue (as it has no string abstraction at all).

Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:17AM (#19748360)
>Why is this comment being down voted? Not everybody here is familiar with C string manipulation, if you down vote or complain at least give more detail that "it sucks".

Well, if someone is not familiar, why do they read a subthread on the matter?

Shouldn't they better start with a tutorial on C/C strings?

Even if people on this thread gave arguments, how would they (not familiar with C and C strings) would evaluate them? They could be totally bogus.

Re:Some Were Meant for C (2017) [pdf] by drb91 on Friday April 26, 2019 @10:56AM (#19758171)
I am finding hard to imagine not seeing the difficulty here, so instead I’m just gonna point out simple operations like stripping whitespace, splitting strings on a character pattern, changing case, dealing with character encodings, regex matches all require manually iterating and mutating or copying strings and in the case of regexes require compiling and auditing various libraries. The abstractions other standard libraries have used, such as rust, make it much easier to simply express the string operations as high level operations and spend your time elsewhere while retaining relatively high levels of performance. Often, string processing is not in the inner loop and does not benefit from things like combining multiple string operations into a single pass, traditionally a thing that might make c perform better all other things being equal.
Re:Some Were Meant for C (2017) [pdf] by coldtea on Thursday April 25, 2019 @10:02AM (#19748181)
If this a joke?

Length not known, so prone to overflows at anytime, atrocious standard library, ... (and let's not even go into the Unicode situation).

Re:Some Were Meant for C (2017) [pdf] by mhh__ on Thursday April 25, 2019 @11:18AM (#19749057)
You basically have to write your own high level string library just to approximate the features of just about any other language...
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @05:49AM (#19746486)
C was already hated on BBS and USENET during the early 90's.

You will find my nick on those archives at the C++/Pascal trenches side.

Re:Some Were Meant for C (2017) [pdf] by xva100 on Thursday April 25, 2019 @08:40AM (#19747411)
Mysteriously, whenever I'm forced to work on an existing C++ code base, it has far more bugs than all C code bases that I've worked on.

And yes, apart from the myriads of usual C++ leaky abstraction bugs that "just" cause wrong results, this includes segfaults.

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @10:04AM (#19748214)
And how many of those are actually caused by features inherited from C copy-paste compatibility?
Re:Some Were Meant for C (2017) [pdf] by ChrisRR on Thursday April 25, 2019 @07:58AM (#19747120)
Fads have always come and gone. C was already 20 years old in the 90s so it was a fair target for hating in favour of something newer and shinier.
Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @08:13AM (#19747210)
In the early 90's C was still hardly a thing outside the UNIX computer lab.

Mainframes were written in a mix of Assembly and safe system languages (IBM i, z and Unysis ClearPath are the survivors).

8 and 16 bit home micros OSes were largely written in Assembly, and all system languages were in equal footing as platform guests.

Re:Some Were Meant for C (2017) [pdf] by jasode on Thursday April 25, 2019 @08:28AM (#19747317)
>In the early 90's C was still hardly a thing outside the UNIX computer lab.

That's not what I remembered. Back in 1989, I bought the very popular Microsoft C 5.1 compiler (in shrinkwrapped box) from the Egghead retail store. Egghead was basically a smaller version of CompUSA.

Also, non-UNIX publications like PC Magazine and BYTE had ads for Borland Turbo C. Watcom C was also a competitor.

In the late 1980s and early 1990s, if one wanted to write COTS software for DOS on IBM PC compatibles, it was either assembly or C Language. Other languages like dBASE/Clipper/4GL were for LOB apps instead of COTS. In 1985, both Lotus 123 v3 and MS Excel were written using C.

It was more like the early 1980s before the personal computer revolution when the C Language was mostly tied to UNIX.

Re:Some Were Meant for C (2017) [pdf] by pjmlp on Thursday April 25, 2019 @09:56AM (#19748126)
It was very regional.

Back in the Iberian Penisula, Turbo Basic, Turbo Pascal, TASM, NASM reigned on the PC for COTS.

Amiga demoscene was all about AMOS and 68000 Assembly.

I code since 1986, touched my very first C compiler in 1992.

By then I already had used Timex 2068 Basic, 48+ Basic, CP/M on +3 A, Z80, Turbo Basic, Forth, Turbo Pascal 3 - 6, Dbase III Plus, 8086 with TASM.

Thankfully also in 1992, I got hold of Turbo C++ 1.0, and I was settled on my opinion about C.

Re:Some Were Meant for C (2017) [pdf] by GlennS on Thursday April 25, 2019 @06:40AM (#19746716)
I feel like C has to go in the bucket of 'bad languages' these days, because it doesn't have sensible unicode support built in.

But that doesn't mean you can't have fun with it, or write good computer programs.

It just means that user inputted text is always going to be a pain.

Re:Some Were Meant for C (2017) [pdf] by Nursie on Thursday April 25, 2019 @06:45AM (#19746741)
To be fair it doesn't really have strings 'built in' particularly well either. It directly manipulates memory patches, and the string support that is there is mostly a very simple abstraction on that.

If you want support for unicode etc, there are libraries.

Re:Some Were Meant for C (2017) [pdf] by solarkraft on Thursday April 25, 2019 @08:38AM (#19747395)
But then that brings you compatibility issues, overhead ...
Re:Some Were Meant for C (2017) [pdf] by Nursie on Thursday April 25, 2019 @09:22AM (#19747767)
If you want to avoid development overhead, absolutely, C is a terrible language to pick.

I'm not sure what you mean by compatibility issues in this context?

Re:Some Were Meant for C (2017) [pdf] by solarkraft on Friday April 26, 2019 @11:08AM (#19758284)
I'm thinking about differen string representations used by different libraries. Is this not true?
Re:Some Were Meant for C (2017) [pdf] by Nursie on Friday April 26, 2019 @12:29PM (#19759234)
Honestly all I've encountered default strings (and people shy away from those now) and LibICU stuff. I think ICU has become a defacto standard but I have been out of C for a few years.

This tends to be important for strings you're going to show to the user (or input you gather from them), maybe most of the C in the world isn't aimed at interfaces like that...

Re:Some Were Meant for C (2017) [pdf] by jstimpfle on Thursday April 25, 2019 @10:46AM (#19748690)
Actually the best way to deal with unicode in almost all situations is to use UTF-8, and dealing with UTF-8 in C is trivial.

For other encodings, well you need to decode explicitly (or just go for wide chars). Shouldn't come as a surprise, and not a big deal either.

Re:Some Were Meant for C (2017) [pdf] by atilaneves on Thursday April 25, 2019 @08:05AM (#19747162)
Everybody's brain works differently. Maybe C is the language for you. Maybe your tradeoffs are different from mine and you're ok with dealing with segfaults and security exploits. AFAIC if I never again have to write string handling code in C it'll be too soon."|"|"|"|
Re:Some Were Meant for C (2017) [pdf] by sureaboutthis on Thursday April 25, 2019 @08:35AM (#19747373)
There are standard C libraries that handle strings very well. Are you saying other languages don't have security exploits? And in 35 years of writing in C, I have only had a very few segfaults while writing new code but never in production so I don't know why you think it happens so often unless your knowledge is only from reading reddit headlines.
Re:Some Were Meant for C (2017) [pdf] by atilaneves on Thursday April 25, 2019 @09:27AM (#19747816)
> There are standard C libraries that handle strings very well.

I'm not aware of any. I've never encountered a language that is more frustrating than C to manipulate strings in.

> Are you saying other languages don't have security exploits?

No, I'm saying they have fewer. Far fewer.

> And in 35 years of writing in C, I have only had a very few segfaults while writing new code but never in production

Good for you. In 25 years of writing C and working with dozens of other programmers writing C in that time, I've lost count of how many segfaults and memory corruption errors I've had to debug.

I don't miss those days and never want to go back.

> unless your knowledge is only from reading reddit headlines.

It is not. See above.

[dead]
Re:Some Were Meant for C (2017) [pdf] by sangnoir on Thursday April 25, 2019 @11:45AM (#19749326)
> Yeah, language without ... decent comprehensive library

I'm sorry, did you just say C doesn't have a comprehensive library?! I agree with your other points (but posit that they are not always negative; some of the 'flexibility' is useful in the domains where C dominates. Most of the shortfall can be covered by tooling, linting and standards.

It's been almost a decade since I last used C, but I think the complaints are overblown. Some tools have sharper edges than others, but there are there to accomplish a goal.

Re:Some Were Meant for C (2017) [pdf] by ernst_klim on Thursday April 25, 2019 @01:27PM (#19750420)
>I'm sorry, did you just say C doesn't have a comprehensive library?!

Data structures? Lists, Hashtables, Maps, Strings, Refcounted pointers, Weak pointers, Ephemerons, iterators for mentioned? C library is a joke even by 1970 standards.

>Most of the shortfall can be covered by tooling, linting and standards.

The amounts of CVEs prove you wrong. Besides, a typical C-coder considers himself smarter than type checker, otherwise he would be using another language (ML, Rust, Ada, C++).