News for hackers. Stuff that matters.
Re:Relive: 50 years of C, the good, the bad and the ugly by antirez on Friday December 30, 2022 @10:03AM (#34185630)
A different take on the matter: I write code mainly artistically, and I found that C is one of the best languages available to code as a form of art. It allows to be both brutal and honest, or abstract and deceiving. Not many languages are so semantically powerful.
Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @10:37AM (#34185956)
It’s mostly semantically very poor to be honest. C really is a nicer assembly in a lot of way. It’s extremely limited. You have branching logic, functions call, pointer arithmetic, a way to define data structures which are really memory layouts and that’s pretty much it. I guess you can appreciate that as an aesthetic statement but what you wrote would apply equally to any language with more complex semantics.
Re:Relive: 50 years of C, the good, the bad and the ugly by sn41 on Friday December 30, 2022 @10:59AM (#34186209)
> that’s pretty much it.

Only if you ignore

1. variadic arguments as in printf,

2. function pointers which are a very elementary (type-unsafe) form of closures,

3. a nice way of casting to void

4. setjmp and longjmp goodies (?) which allow you to code up co-routine libraries and exception handling mechanisms

I'm sure there are more such facets I am missing.

The elegance of the specification may be questionable, but the scope of what C tried to achieve is breathtaking. It actually is superior to most of its improvements.

Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @11:17AM (#34186411)
There is no elegance there. Casting to void is not a plus. That’s just C having no proper type system.

Function pointers as an elementary form of closures, come on, what’s next? Closures are defined by capture. It’s nearly as fun as pretending C as coroutines because of setjmp.

How can a statement like C being semantically poor even be seen as controversial? For god sake, we are talking about a language which semantically doesn’t even have proper arrays.

> The elegance of the specification may be questionable, but the scope of what C tried to achieve is breathtaking. It actually is superior to most of its improvements.

Seriously? It wasn’t even a good language when it was released. Lisp and Pascal were far better. It won because of compiler availability and adequate performance on limited platforms.

HN really is a joke sometimes.

Re:Relive: 50 years of C, the good, the bad and the ugly by youarethejoke on Friday December 30, 2022 @11:37AM (#34186642)
You really don't understand, but that's okay. C is a wonderful language, and that's the end of it really. You just try to think C as a language that SHOULD HAVE all the stupid bells and whistles you find convenient. Many of us more advanced coders have found that those stupid bells and whistles are, in fact, inconvenient. Casting to void is a powerful technique and the limits are literally endless. C is semantically rich, way beyond your dull imagination.
Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @12:32PM (#34187329)
The argument is not about what can and can’t be done in C. C is Turing complete and low level. You can do anything in C. The debate is not even about if it’s good idea (I don’t think it is but that’s separate).

The question is about C semantics. Given the reply I get it’s pretty obvious that most here don’t understand what a language semantic is. It’s about the amount of concepts you can express in the language. Haskell - a language I personally despise - is semantically very rich. So is modern C++ for what it’s worth. C simply isn’t.

It’s even deceiving sometimes because it has the apparence of having some semantic elements (arrays for exemple) which are not there in reality and are really only syntactic sugar on top of other semantic constructions(pointers).

Re:Relive: 50 years of C, the good, the bad and the ugly by eska on Friday December 30, 2022 @03:23PM (#34189612)
You’re whitewashing history if you think Pascal was superior to C. There was no conspiracy among compiler developers as you imply.

Also you complain about semantic richness of C, but then only point to semantically rich languages you despise. A curious reader would wonder: why care about semantically rich languages then? An observant reader would wonder: so aren’t there times where semantic richness is not useful?

Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @03:57PM (#34189989)
What conspiracies are you talking about? C won because its compiler was widely available for free. That’s pretty much a fact. Pascal was indeed a superior language but limited by the proliferation of extensions, paid compilers and its compiler performance.

I’m not even complaining about the semantic richness of C. I’m just stating the fact that it doesn’t really have semantic richness. Then again don’t get me wrong. I do think C is a terrible language and I say that having worked on a C static analyser. It’s full of avoidable undefined behaviours and silly sharp edges.

Thankfully, nice languages with rich semantic exist. I was just pointing some I don’t like to separate the issue of semantic richness from likability. I enjoyed working in Ada a lot. Ocaml is awesome. I have never used Rust but from what I have seen that seems nice.

Semantic richness is useful because it helps programmers express what they want to do in way which are clearer and therefore more likely to be correct.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:47AM (#34207904)
Pascal, at least the original specification, does have a few flaws. It was intended to run as P-code in a VM so you wouldn't expect it to be as good as running directly on the hardware.

The successor to Pascal, which fixed it's problems, was Modula-2, which is vastly superior to C. Unfortunately by the time it came out and started becoming available, it was too late for it to compete fairly with C. Ada is comparable to Modula-2, especially before Ada added OOP, but Ada was too late to compete with C as well.

It's taken 30 years but finally we are starting to see safe languages, eg. Rust, compete with C and C++. I don't know whether Rust will be the language that overtakes C and C++, but if not, I believe a successor to it will and C and C++ will become like COBOL, that no ones uses to write any new code.

Re:Relive: 50 years of C, the good, the bad and the ugly by Tozen on Monday January 02, 2023 @01:35AM (#34215039)
Pascal was and is continually evolving. A strong argument can be made that Object Pascal was the "successor" of Pascal, and that happened in 1985/86. After Apple and Wirth developed Object Pascal, Borland added the OOP extensions to their version soon afterwards. Turbo Pascal had quite a long run, and some are still using it. The Delphi dialect of Object Pascal came out in the early 1990s and Free Pascal came out in the late 1990s.

Many of the so-called issues with Pascal were resolved way back in the mid to late 1980s. In regards to Pascal's competition with C, this arguably evolves around AT&T and Unix. It's AT&T and their huge government, industry, and business influence that pushed C over the top.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Thursday January 05, 2023 @10:09AM (#34260636)
Modula-2 has many new features that make it better than Pascal. It is not merely a Pascal with some issues fixed.

One small thing I like about Modula-2 is an improvement in the syntax where BEGIN is not required after conditionals and loops.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @03:50AM (#34194766)
The first thing you need to learn about semantics is that it's a singular: "what semantics is", not "what semantics are".

The nice thing about C is that if you're opinionated about what you want your ideal language to look like, you can use C in that pursuit. You can write your run-time in C and parts of the implementation. C is good for interfacing with operating system platforms.

You can fully bootstrap yourself off C entirely, or stick with C for the run-time and perhaps other parts. If your language isn't very good at expressing low-level manipulations, you can keep C in there as an option for writing those kinds of modules.

Some languages have used C as a target language for compilation.

C can be an enabler in the pursuit of other languages.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:49AM (#34207935)
C is a garbage language. It has a lot of undefined behaviour. It isn't safe. It isn't even strongly typed. It's only marginally better than a macro assembler. C programmers consider that a virtue but programmers who want to write safe, robust code, know C is garbage.
Re:Relive: 50 years of C, the good, the bad and the ugly by Tozen on Monday January 02, 2023 @02:21AM (#34215267)
"One man's garbage is another man's treasure."
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Thursday January 05, 2023 @10:05AM (#34260553)
Those people are called hoarders.
Re:Relive: 50 years of C, the good, the bad and the ugly by WalterBright on Friday December 30, 2022 @12:46PM (#34187517)
Much of what you say is true. But I came to C from Pascal. Pascal circa 1982 was unusable without all the numerous extensions each vendor tacked on. C worked out of the box. I could get things done in C without constantly fighting the Pascal and Fortran compilers of the day. This was true despite the terrible C compilers of that time.
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Saturday December 31, 2022 @01:30PM (#34199212)
I remeber that Small-C and RatC were hardly usefull without tons of inline Assembly.

As proven by books like "A book on C" from 1984 (Robert Edward Berry and B. A. E. Meekings).

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:33AM (#34207721)
Pascal wasn't ready for real-world use because it came from an academic setting and was initially designed to run P-code in a VM. It's successor, Modula-2, fixed all of Pascal's issues and added a lot of great functionality.
Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Friday December 30, 2022 @03:20PM (#34189575)
> HN really is a joke sometimes.

A lot of what I'm seeing from your comments here is you can't handle people who have something positive to say about C.

They're not saying it's the one true way or something. Just that they like it in some respect.

And your attempts to dismiss that and call "HN" a joke for harboring someone who thinks this way look kind of childish to me.

Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @03:43PM (#34189873)
Then you are seeing what you want to see. People are straightforwardly arguing that C is semantically rich which is indeed laughable. I have addressed the point under but clearly a lot of you don’t understand what language semantics are.

Considering I was having interesting discussion about the subtleties of the Hindley-Milner type system on this same website a decade ago, yes, I do think HN is becoming a joke. The joke is on me however because apparently I keep commenting for reasons which are not always apparent to me I must confess.

Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Friday December 30, 2022 @03:54PM (#34189959)
There are plenty of interesting C works out there, as well as data structures or algorithms that C can express elegantly.

Small example, linked lists. I don't think non-C linked list code tends to be as straightforward as I've seen in C.

Or the character-at-a-time style of string processing. It's kind of unique to C.

You can say there is stuff about that you don't like. That's fine. Linked lists suck with modern CPU caches anyway. C strings have lots of misadventures in terms of buffer overflows. But it's unique and interesting. Lots of elegant things have been written this way. Your unfamiliarity with it doesn't make it "a joke" to point this out.

I have my own gripes with HN. Try mentioning politics and it brings out all sorts of fascist-sympathizing crazies. But saying good to neutral things about C (while not even universally praising it) is not one of those issues.

Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @05:16PM (#34190731)
> as straightforward as I've seen in C

To be fair, the most straightforward definition of the linked list is generic, and C completely lacks such facility.

> fascist-

Sounds familiar.

https://news.ycombinator.com/item?id=33478321

Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Friday December 30, 2022 @06:10PM (#34191221)
> C completely lacks such facility.

Generic linked lists can be done with pointer casts. See the way the Linux kernel does it.

The list manipulation routine takes a pointer to a member, and the more specific type is opaque. The code that knows what the actual structure is can derive it from a node pointer.

A structure can even have multiple node pointers in this scheme.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @03:36AM (#34194714)
* * *
Re:Relive: 50 years of C, the good, the bad and the ugly by imran0 on Saturday December 31, 2022 @08:11AM (#34196130)
> Sounds familiar.

I cannot decide whether it's an honor or an insult to be called a _fascist sympathizer_ for opposing the authoritarian suppression of speech.

Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Saturday December 31, 2022 @11:44AM (#34198134)
I didn't want to address this because it's a tangent, but I understand that free speech protects expressing fascist thought. I can still disapprove of it and not want to be around a lot of it, consider high concentrations of it to be a sign of an unhealthy community, without saying it should be somehow illegal.
Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Friday December 30, 2022 @06:51PM (#34191599)
I am extremely familiar with C. I used to work on a static analyser for it. The issue is that there is very little to like in how C is designed from a PL point of view.

You are confusing what the language can do and what is semantic is.

C strings are just a contiguous allocation of byte and a bunch of functions which interprets it as ascii characters and stop on a specific value. That’s literally the worst representation of a string you can have.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @12:01AM (#34193743)
I think it's a nice representation, allowing easy recursion.

   const char *my_strchr(const char *str, int ch)
   {
     if (*str == 0)
       return NULL;
     if (*str == ch)
       return str;
     return my_strchr(str + 1);
   }
It's a good format for storage and communication.

Name any other string data structure and I will cite you all the disadvantages compared to the C string.

- If the format contains pointers, you have to marshal it to a flat representation to communicate or store it. The C string is already marshaled.

- If the format contains size fields, their own size matters: are they 16, 32, 64. What byte order? Again, needs marshaling. You might think not if going between two processes on the same machine. But, oops, one is 32 bit the other 64 ...

I shudder to think of what FFIs would look like, if C strings were something else. It's the one easy thing in foreign interfacing.

C programs themselves sometimes come up with alternative string representations, for good reasons; but those representations don't interoperate with anything outside of those programs, or groups of closely related programs.

Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Saturday December 31, 2022 @06:56AM (#34195672)
C null terminated strings are not magic. Protocols between the sender and receiver have to be defined. You face exactly the same problem regarding byte order, size consideration and marshalling with C strings.

You are basically arguing that C strings are a good default because they are the default. If they were something else, well, we would have saner FFI in a lot of place.

C strings are a terrible default. They are fundamentally unsafe. Mishandle the null char for any reason and you now face a serious security issue.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @12:37PM (#34198640)
* * *
Re:Relive: 50 years of C, the good, the bad and the ugly by WastingMyTime89 on Saturday December 31, 2022 @01:09PM (#34198992)
> Not char/byte C strings. You might be thinking of wchar_t strings.

No I’m talking about the classic byte arrays C pretends are strings. If the receiver you are talking to is not expecting a chain of bytes where each byte is a character and one special value means the chain is over, well, you will have to transform what you are sending to what your receiver is expecting.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @07:12PM (#34202136)
If somebody's expecting something other than a C string then we unsurprisingly have gratuitous complications. If everyone agrees on the C string though, it just interoperates as-is. Code compiled for some 16-bit microcontroller can just shove the C string into its transmit buffer, and on the other end, code compiled for 64 bit big-endian Power PC receiver just uses it as-is.
Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:35AM (#34207747)
C is the biggest mistake in the software industry since the beginning of software. The people that worship C only do so because they haven't seen the better paths the software industry could have chosen.
Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Monday January 02, 2023 @12:15AM (#34214613)
E.g. Donald Knuth hadn't seen better paths.

"I think C has a lot of features that are very important. The way C handles pointers, for example, was a brilliant innovation; it solved a lot of problems that we had before in data structuring and made the programs look good afterwards. C isn't the perfect language, no language is, but I think it has a lot of virtues, and you can avoid the parts you don't like. I do like C as a language, especially because it blends in with the operating system (if you're using UNIX, for example).

All through my life, I've always used the programming language that blended best with the debugging system and operating system that I'm using. If I had a better debugger for language X, and if X went well with the operating system, I would be using that."

Dec 7, 1993, Computer Literacy Bookshops Interview.

Re:Relive: 50 years of C, the good, the bad and the ugly by asveikau on Monday January 02, 2023 @02:50PM (#34222748)
This is ridiculous hyperbole.

Nobody "worships" C and people who have positive experiences with C often have exposure to higher level languages.

You can find strengths or upsides in C and still acknowledge faults, and still acknowledge merits elsewhere.

Re:Relive: 50 years of C, the good, the bad and the ugly by andsoitis on Saturday December 31, 2022 @11:25AM (#34197875)
This routine only works with ASCII, yea?
Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @12:44PM (#34198732)
It will also find ASCII characters in UTF-8. That's a common situation because delimiting characters are often in the ASCII range.

We can make a more complicated example that nevertheless uses recursion and essentially the same way, which looks for a UTF-8 character. We can examine and decode a prefix of the string as a UTF-8. If there are bad bytes or the character doesn't match then we recurse.

We can also write a wide character (wchar_t) version of the function which looks the same. That will handle all of Unicode on sane platforms, and the basic multilingual plane (BMP) on Windows.

Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @12:44AM (#34193965)
If that static analyzer was itself written in C, you have one program's worth of C experience, which is very little.
Re:Relive: 50 years of C, the good, the bad and the ugly by enedil on Friday December 30, 2022 @12:10PM (#34187063)
Closure is not an anonymous function. It "encloses" variables that were in scope at the point of closure creation. Therefore function pointers cannot serve that purpose as is.
Re:Relive: 50 years of C, the good, the bad and the ugly by sn41 on Friday December 30, 2022 @12:30PM (#34187298)
I agree, I should have used anonymous function specifically instead of a closure (for example, Ruby/Smalltalk closures are blocks, not functions.) Thanks for the correction.
Re:Relive: 50 years of C, the good, the bad and the ugly by Someone on Friday December 30, 2022 @01:26PM (#34188103)
C is also relatively poor at providing “a way to define data structures which are really memory layouts”. Integer sizes (historically) and padding are implementation-defined, AFAIK bit fields are underspecified in that you cannot specify in what bits of a byte they end up.
Re:Relive: 50 years of C, the good, the bad and the ugly by thesuperbigfrog on Friday December 30, 2022 @01:50PM (#34188431)
So true.

I wish that C had a more rich way to define struct layouts and low-level representations for integral types.

I really like how Ada does it:

https://en.wikibooks.org/wiki/Ada_Programming/Representation...

If you need to read or write specialized hardware registers, being able to define a data structure with a custom representation is very nice and can save significant time and effort.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:50AM (#34207944)
I wish C had never been born.
Re:Relive: 50 years of C, the good, the bad and the ugly by titzer on Friday December 30, 2022 @12:51PM (#34187588)
C would be a better language if it really lived up to its old ideal of being a "portable assembly language". That stopped being true as compilers started optimizing undefined behavior (e.g. signed overflow). Instead of a "+" in the source code yielding an honest-to-goodness hardware add instruction, it could be "optimized"--i.e. constant folded, CSE'd, strength-reduced, value-range-analyzed, among others--by an optimizing compiler in ways that completely ignore what the hardware instruction actually does upon overflow. That meant the C language became more like a vague suggestion of assembly and it became pretty much impossible to code to the machine anymore.
Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Friday December 30, 2022 @01:00PM (#34187720)
In the absence of CPU instruction which does the saturated ADD, how do you solve the overflow problem in a bare-metal language without introducing the performance hit?
Re:Relive: 50 years of C, the good, the bad and the ugly by titzer on Friday December 30, 2022 @01:40PM (#34188289)
It depends on how you define your language semantics. If you choose 2's complement wraparound semantics, which is what nearly all CPUs in the world have standardized on, there is nothing for the compiler to do. It's a pure operation, a single instruction, and can be constant-folded, strength-reduced, CSE'd, moved, dead-code-eliminated, etc. If you want a different semantics at the source level, e.g. overflow is an exception, then the compiler needs to emit additional code.

For Virgil I chose to settle on 2's complement because it's what hardware gives and has no overhead. It comes with the full compliment of fixed-width integers of widths 1-64 and odd-width ones come with zero-extension or sign-extension as necessary to make the underlying hardware width unobservable.

Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Saturday December 31, 2022 @05:37AM (#34195235)
> If you want a different semantics at the source level, e.g. overflow is an exception, then the compiler needs to emit additional code.

Yes, and which is exactly what I hinted at with my question to your comment. With the HW we have today, implementing such semantics without an extra hit is not possible and which is why I thought your comment wasn't completely fair but more theoretical.

Re:Relive: 50 years of C, the good, the bad and the ugly by titzer on Saturday December 31, 2022 @03:06PM (#34200209)
Checking for overflow is basically adding a conditional branch (usually to out-of-line code) after arithmetic. It's very cheap, almost free, if there are enough execution units, I-cache isn't a bottleneck, etc etc. But yeah, it is theoretically an overhead, which is why I avoided it for Virgil.

I suppose range analysis can eliminate many overflow checks, e.g. in counted loops, but it's not completely zero cost.

Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Monday January 02, 2023 @06:34AM (#34216840)
> Checking for overflow is basically adding a conditional branch (usually to out-of-line code) after arithmetic.

Yes, but now as well you have to return a value to communicate the overflow to the call site. And call site has to check for that value and that's yet another and another ... and another branch. Depends how deeply you want to propagate that error and decide how (?) to deal with it, this will grow the code size, which can contribute to the higher frequency of I-cache misses and page-faults, but it can also inhibit compiler optimizations.

On the CPU level, I think there's an attached cost as well because each of those branches will occupy entries either in branch-target (BTB) or branch-order (BOB) buffers or both. Sizes of these buffers are quite scarce so ending up with the unfavorable ratio of check-for-overflow entries vs entries occupied by other type of branches found in the code is something that will put more pressure to our branch-prediction unit. More "important" branches will now more frequently start to lack their entry in the branch history simply because of the fact that we're now sprinkling our check-for-overflow if's all over the place. And we know that branch misprediction is the costliest operation (15-20 cycles) we can encounter in the CPU pipeline.

Also, I think a bigger picture must be observed in this context. E.g. what is the percentage of arithmetic operations some big real-world sized binaries contain? I'd figure that in average it would be a sizeable amount, and in ones with a lot of math even more so. And then I wonder what we could observe if we applied the check-for-overflow transformation to all such signed-arithmetic operations.

Re:Relive: 50 years of C, the good, the bad and the ugly by zozbot234 on Friday December 30, 2022 @01:27PM (#34188109)
The performance hit of overflow has nothing to do with lacking assembly instructions. It's all about having to preserve error states whenever overflow occurs and inhibiting optimization.
Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Saturday December 31, 2022 @05:28AM (#34195207)
I don't follow. If we had the saturated ADD instruction supported in hardware we wouldn't have to deal with saturation logic in software. Compiler would simply be able to emit SADD instruction whenever we asked for it to and would be given a chance to spit out more optimized code because that would essentially be a branchless code.

Reality though is that we don't have such hardware and we have to deal with it in software, so, instead of a single instruction emitted there will be a bunch of them, and of which there will be certainly branches involved.

Re:Relive: 50 years of C, the good, the bad and the ugly by tialaramex on Friday December 30, 2022 @02:05PM (#34188624)
> if it really lived up to its old ideal of being a "portable assembly language".

What "old ideal" ? Where do you believe this "ideal" was expressed? Should I expect to find it in the First Edition K&R perhaps? Or in the documentation for the original C compiler? In the ANSI standard ?

C was never this mythical "portable assembly language" that's just something people say about it, mostly to ridicule it, you are engaging in Nostalgia.

Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Friday December 30, 2022 @05:10PM (#34190692)
From Dennis himself,

"The language is also widely used as an intermediate representation (essentially, as a portable assembly language) for a wide variety of compilers, both for direct descendents like C++, and independent languages like Modula 3 [Nelson 91] and Eiffel [Meyer 88]. "

-- https://www.bell-labs.com/usr/dmr/www/chist.html

Re:Relive: 50 years of C, the good, the bad and the ugly by tialaramex on Friday December 30, 2022 @06:26PM (#34191388)
That same document claims, "C's approach to strings works well" which, I mean I admire Dennis Ritchie but he's just wrong.
Re:Relive: 50 years of C, the good, the bad and the ugly by pjmlp on Saturday December 31, 2022 @03:14AM (#34194626)
Moving goalposts, you were asking who said it, the language authors did.

If they are right or not, it is another matter.

Re:Relive: 50 years of C, the good, the bad and the ugly by timbit42 on Sunday January 01, 2023 @11:52AM (#34207964)
Regarding that matter, he was wrong. I wish he'd never written the garbage that is C. It's a stain on his reputation.
Re:Relive: 50 years of C, the good, the bad and the ugly by titzer on Sunday January 01, 2023 @05:27PM (#34211704)
I'm willing to forgive those who move on to better ideas, but we are really stuck with this 50 years later. When most of PL land knows better than to keep digging in this hole.
Re:Relive: 50 years of C, the good, the bad and the ugly by tialaramex on Sunday January 01, 2023 @06:19PM (#34212184)
But Dennis doesn't express it as an ideal, and that document is written really late -- it's citing a 1991 document in the part you just quoted, so that's after C89.
Re:Relive: 50 years of C, the good, the bad and the ugly by low_common on Friday December 30, 2022 @10:35AM (#34185929)
Can you share some examples of your "art"? I'm trying to wrap my brain around the concept of writing code for any reason other than work or trying to build something.
Re:Relive: 50 years of C, the good, the bad and the ugly by antirez on Friday December 30, 2022 @10:42AM (#34186027)
Some background here: http://antirez.com/news/133
Re:Relive: 50 years of C, the good, the bad and the ugly by nikbackm on Friday December 30, 2022 @10:32AM (#34185894)
C++ should be even better in those categories.
Re:Relive: 50 years of C, the good, the bad and the ugly by siftrics on Friday December 30, 2022 @10:38AM (#34185967)
This shouldn't be downvoted. C++ is a superset of C; it must be capable of being at least as "brutal and honest" and "abstract and deceiving" as C.

I would argue that C++ can be dramatically more deceiving than C --- see inheritance and operator overloading, just to name two.

Re:Relive: 50 years of C, the good, the bad and the ugly by AlexeyBrin on Friday December 30, 2022 @10:56AM (#34186167)
C++ is not a superset of C, there are plenty of legal C constructs that will trigger errors when compiled with a C++ compiler.
Re:Relive: 50 years of C, the good, the bad and the ugly by wiseowise on Friday December 30, 2022 @02:20PM (#34188830)
C++ is a sane defaults superset of C.
Re:Relive: 50 years of C, the good, the bad and the ugly by 3836293648 on Friday December 30, 2022 @02:42PM (#34189096)
C is not a superset of C either. C++ is a superset of a C version, even if they then went on to add stuff that wasn't added to the other
Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Friday December 30, 2022 @11:22PM (#34193534)
But most of them are new constructs, not found in the venerable C90.
Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @11:57AM (#34186911)
Operator overloading is the one thing that makes C++ strictly better than any language that does not allow it.
Re:Relive: 50 years of C, the good, the bad and the ugly by camel-cdr on Friday December 30, 2022 @12:12PM (#34187084)
How so? To me, operator overloading seems like a non feature, that at best create more ambiguity.
Re:Relive: 50 years of C, the good, the bad and the ugly by Conscat on Friday December 30, 2022 @12:34PM (#34187350)
Without it, you cannot express arithmetic wrappers or simd wrappers. So far, no language with any users has managed to provide adequate arithmetic and simd types built in, despite several attempts like Odin and CosmiC/HolyC. I'm not sure it's even possible to design such types that satisfy everyone, and they must be extensible somehow because satisfying anyone is a moving target.

Note how terrible doing any amount of math is in C.

Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Friday December 30, 2022 @12:52PM (#34187592)
Also without operator overloading, it wouldn't be possible to implement lazy evaluation, which along with the use of expression templates happens to be one of the most crucial aspects that any linear algebra library will want to take advantage of in order to generate the most optimal code.
Re:Relive: 50 years of C, the good, the bad and the ugly by Someone on Friday December 30, 2022 @01:18PM (#34187978)
> without operator overloading, it wouldn't be possible to implement lazy evaluation

I don’t understand that. You can have functions that return promises that then can get passed to other functions returning promises, and leave it either to the compiler or to an expression evaluator you write (that ideally runs at compilation time as much as possible) to optimize away anything not needed. For example (pseudo-code)

  vector3D a = …
  vector3D b = …
  promise<vector3D> c = addLazily(a,b)
  print c.x
in the end, could do the equivalent of

  print a.x + b.x
I think you could make a modern C++ compiler do that for this simple example.
Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Friday December 30, 2022 @01:49PM (#34188423)
Of course, you can do it that way as well. However the problem with promise approach is that it is introducing extra dynamic memory allocations beneath and these cannot be optimized out or elided. At least, not to my knowledge. With expression templates and operator overloading you're basically avoiding exactly that as much as possible.
Re:Relive: 50 years of C, the good, the bad and the ugly by Someone on Friday December 30, 2022 @03:15PM (#34189503)
Where do you see dynamic memory allocations being needed in that example? I only see locals that a good compiler can fairly easily optimize away.

Also, there’s a simple bijection between expressions with operators and two-argument function calls:

  a + b * c
  +(a, *(b,c))
  plus(a, times(b,c))
Because of that, I don’t understand why operator overloading should give better optimization opportunities than function calls.
Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Saturday December 31, 2022 @05:02AM (#34195089)
Unless you're talking about some theoretical promise, C++ promise implementation imposes dynamic allocation.
Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Friday December 30, 2022 @11:24PM (#34193541)
Operator overloading is syntax; lazy evaluation is semantics.
Re:Relive: 50 years of C, the good, the bad and the ugly by menaerus on Saturday December 31, 2022 @05:19AM (#34195170)
That is true but a little bit unfair comment because I expanded with the context in the very next sentence. Or perhaps you're aware of alternative way of how to implement lazy evaluation without expression templates and operator overloading with all of its advantages?
Re:Relive: 50 years of C, the good, the bad and the ugly by tialaramex on Friday December 30, 2022 @01:32PM (#34188178)
Overloading is miserable. C++ has to provide this as an overload because it still, decades after standardisation and half a lifetime after it was created, doesn't have a way to just extend types.

If you can just extend the types then you can provide operators that way and there's less opportunity for ambiguity. See Rust.

Also so many of the C++ operator overloads are broken instead of just not existing, which tempts you to overload things instead of saying "Nope, that's a bad idea" and just walking away altogether.

Example, boolean short-circuiting AND and OR. If we write

    if (this() || that()) foo();
in C++ then that OR is short-circuiting, so that() won't get called if this() is true.

But if the return type used overloads the boolean OR operator, short-circuiting is disabled, and now both this() and that() are always called...

Re:Relive: 50 years of C, the good, the bad and the ugly by colanderman on Friday December 30, 2022 @10:49AM (#34186105)
Art is often about constraint, and mastery of simple tools.

I identify with @antirez's sentiment. I know both C and C++ very well. I find C definitely more artistic. C++ is utilitarian.

Prolog is the other language I code in "artistically". It too is quite simple and constrained, though it is on the opposite end of the high/low-level spectrum as C.

Re:Relive: 50 years of C, the good, the bad and the ugly by bakuninsbart on Friday December 30, 2022 @11:44AM (#34186733)
What is your take on Perl and Ruby? They seem to be the two languages where the communities themselves talk the most about poetry and elegance.
Re:Relive: 50 years of C, the good, the bad and the ugly by sph on Friday December 30, 2022 @01:11PM (#34187906)
Perl and Ruby are very expressive. Python on the other hand feels like a scripting language designed by a 1990s corporate Java developer.

/unpopular-hot-take

Re:Relive: 50 years of C, the good, the bad and the ugly by MrLeap on Friday December 30, 2022 @01:37PM (#34188245)
I mostly agree with this. I'll tepidly come to pythons defense though. Python is a gorgeous language wearing an ugly hat. The hat has __multiple out of place brims__, all of which are about two underscores wide.
Re:Relive: 50 years of C, the good, the bad and the ugly by sph on Friday December 30, 2022 @02:31PM (#34188969)
It's not a hat, it's a snake that swallowed a Java engineer :)
Re:Relive: 50 years of C, the good, the bad and the ugly by tuatoru on Friday December 30, 2022 @02:46PM (#34189136)
The name came from the author's love of Monty Python's Flying Circus, so perhaps it's an experiment in low-key absurdist humor or surrealist art. Like chindōgu[1].

1. https://en.wikipedia.org/wiki/Chind%C5%8Dgu

Re:Relive: 50 years of C, the good, the bad and the ugly by colanderman on Friday December 30, 2022 @04:11PM (#34190165)
Perl (5) I find quite complex, the opposite of C and Prolog. I suppose the elegance some find comes from packing lots of behavior into very few characters of code. When I want to code as art though, I prefer simpler, less "magical" tools.

I've never used Ruby but from what I've seen I understand it to be similar to Perl in that regard.

Re:Relive: 50 years of C, the good, the bad and the ugly by mikem170 on Saturday December 31, 2022 @04:03PM (#34200715)
I agree that perl can be complex, its feature list is longer than C. Trying to be artistic in it, to me, means trying to make it so my code reads as much like pseudo-code as is reasonably possible. At its best the users are able to read the business logic portions and understand what is going on.

Of course good naming and abstractions are of key importance, and comments and inline documentation are important finishing touches, which so many programmers don't seem to have the time for. It doesn't hurt that Larry Wall, the designer of perl, was a linguist. Perl was meant to be flexible and expressive.

And everyone knows that there's nothing worse to read than obfuscated perl. Perhaps some think that is artistic in a different way, to make the shortest and most unreadable program possible. Not my thing, personally.

Re:Relive: 50 years of C, the good, the bad and the ugly by Koshkin on Friday December 30, 2022 @11:48AM (#34186775)
True; on the other hand, personally, I think that normally C and C++ shouldn't be even mentioned in the same context. (My C++ code bears virtually no resemblance to my C code.)
Re:Relive: 50 years of C, the good, the bad and the ugly by xigoi on Friday December 30, 2022 @10:29AM (#34185871)
Can you expand on that?
Re:Relive: 50 years of C, the good, the bad and the ugly by antoniuschan99 on Friday December 30, 2022 @02:43PM (#34189101)
What are your goto sources of knowledge for C? I’m learning it to write embedded stuff and so far it’s mainly the k&r book, one from no starch press, and a udemy course. Thanks!
Re:Relive: 50 years of C, the good, the bad and the ugly by colanderman on Friday December 30, 2022 @04:18PM (#34190220)
Not the GP, but cppreference.com [1] is the best reference I've found for C (and C++) in 20+ years, short of just reading the standards themselves.

[1] https://en.cppreference.com/w/c

Re:Relive: 50 years of C, the good, the bad and the ugly by antoniuschan99 on Saturday December 31, 2022 @12:51AM (#34193994)
Thank you!
Re:Relive: 50 years of C, the good, the bad and the ugly by Emigre_ on Friday December 30, 2022 @08:28PM (#34192365)
I think you’ll like Fluent C: Principles, Practices, and Patterns by Christopher Preschern (O’Reilly, 2022).

The books you have are excellent ways to learn the language, and this one complements them in that it lists common practices around, for example, error handling, and other common topics. It shows different approaches and mentions practices from real-world open-source C projects that follow them.

It seems like a good book to continue exploring C after learning the language.

Re:Relive: 50 years of C, the good, the bad and the ugly by antoniuschan99 on Saturday December 31, 2022 @12:51AM (#34193993)
Thank you!