Live data from Hacker News

Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

humprog.org

111–118 of 118 posts

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#111
post #108

Earlier quoted context omitted.

GNU libc is an example of a relatively well known isxdigit() which uses a LUT even today. Its excuse is that this simplifies locale handling, you know for if your locale has hexadecimal digits in a different place from everybody else, presumably because you're from some alternate universe where Z is a hex digit.

But isn't that just a bad implementation in libc, rather than a problem with C itself? It should be trivial to rewrite isxdigit() copying rust's algorithm in C.

Or, you know, MIKBUG's implementation.

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#112
post #107

Earlier quoted context omitted.

Nobody said it's easy. Programming is hard. The statement is that the language is _simple_.

Nobody mentioned programming. And hard/easy is a relative term. My easy != your easy. Sharpened rock is a simple tool. Versatile too, but try using it to make a sculpture and it's going to be hard, very hard. Especially if you never used it extensively. C is a simple language. No doubt about it. But doing multi-threading and memory safety in C is like trying to build a 100m tall structure using nothing but a sharpene…

Sure, there is no real disagreement, it's only a confusion about terminology.

> But multi-threaded and memory safe (memory leaks allowed ofc) programs is as simple as just not using Java's array of unsafe tooling.

as _easy_ as just not...

"Complex" is the opposite of "simple". "Easy" is the opposite of "hard".

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#113

Earlier quoted context omitted.

> The modern hardware isn't actually a fast PDP-11 it's just capable of emulating one more efficiently than you would if people didn't insist on writing C. I'm not disagreeing with that. It's a valid remark. What I'm arguing is that it's a useless remark in practice. > So it may be that your "clever" C algorithm which in your head translates into just six CPU operations, unfortunately on a real modern CPU is six heft…

The C programmers do distort what makes sense, but they can't overcome practical realities. For example have you noticed your CPU is multi-core? The PDP-11 wasn't multi-core, and C doesn't really do well for writing concurrent software. Practically though, despite Amdahl's law it makes sense to provide a multi-core CPU. Most C software won't be able to take advantage, but some of your software is written by people wh…

The one example I like is shared memory multi-processing (what you mean when you say "multi-core", because multi-core systems are older than C), because I do see it as a hack done to preserve compatibility with a more traditional programming style (or dare I say, with a more traditional "programmer"). As I said, I agree with this, but the argument is still value-less. If you don't do multiprocessing this way you'll find yourself handicapped because _all_ current machines are heavily optimized for it. There's very little point to a language that doesn't do it this way, because it would not be able to run as well on current machines!

The other two examples are highly questionable. 0-terminated strings are not an artifact of the computer architecture, but a conscious trade-off, and in fact other languages already used Pascal strings (even on the PDP-11). Same as if you want your lists with a constant time size function or not. Sure your size() is now "much faster", but something else now becomes slower. In fact, you could argue x86 bends to supports _both_ string implementations, since the rep prefix does support (and update) a count.

And the final example, "isdigit" is arguably not even a language issue, and definitely not a legacy of the PDP-11 nor x86 architecture. I'm rather sure no one in his right mind would even consider wasting 0.25KiB just for such function, not until well into the 90s at least. These types of code-bloat optimizations are more of the 2000s and even 2010s "performance" craze. You yourself even say on the other thread that glibc is doing this to facilitate locales, and not for performance reasons.

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#114

Earlier quoted context omitted.

> It'd be interesting to see what interface we'd choose today with multiple decades of hardware and software development A worse one? Not a couple days ago there were a couple stories about Itanium here on HN (a designed-from-scratch ISA that turned out to be practically worse than the much more ad-hoc x86_64). Even e.g. RISC-V (which is not entirely free of legacy) is practically 1:1 with ancient ISAs like ARM.

ARM is an evolving ISA. AArch64 is quite different from ARMv7, and has nicer security features than the other leading brand, who can barely manage to ship SGX.

It's not like x86 or RISC-V are not "evolving ISAs" either. And personally I would classify SGX and other "security" features as misfeatures, but that's for another day...

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#115

Earlier quoted context omitted.

Not quite. The modern hardware isn't actually a fast PDP-11 it's just capable of emulating one more efficiently than you would if people didn't insist on writing C. So it may be that your "clever" C algorithm which in your head translates into just six CPU operations, unfortunately on a real modern CPU is six hefty macro-ops that will take dozens of cycles to execute and repeatedly go to sleep waiting for main memory…

It might be but it isn't. The promise of clever modern language beating C in performance is almost as old as C and we are yet to see one.

You didn't need to wait, Fortran has better performance than C from the outset.

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#116

Earlier quoted context omitted.

The C programmers do distort what makes sense, but they can't overcome practical realities. For example have you noticed your CPU is multi-core? The PDP-11 wasn't multi-core, and C doesn't really do well for writing concurrent software. Practically though, despite Amdahl's law it makes sense to provide a multi-core CPU. Most C software won't be able to take advantage, but some of your software is written by people wh…

The one example I like is shared memory multi-processing (what you mean when you say "multi-core", because multi-core systems are older than C), because I do see it as a hack done to preserve compatibility with a more traditional programming style (or dare I say, with a more traditional "programmer"). As I said, I agree with this, but the argument is still value-less. If you don't do multiprocessing this way you'll f…

What are you imagining alternatives would look like that are prohibited because of what you're calling a traditional "programmer" ?

There are a bunch of other things computers could do that would in principle go real fast but humans can't successfully reason about them. It seems like a stretch to blame C. I reckon that even the most precocious humans have experience with causality a long time before they write any C and it's this experience which makes it hard to handle a world which cannot be understood in terms of cause and effect for example.

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#117

Earlier quoted context omitted.

I would argue it's very easy to think one understands it. However I would wager most people who say they understand C don't really know many of the undefined behaviour cases and their implications.

Undefined behaviour being weird and having bizarre implications is not a feature of C. It is a feature introduced by compiler writers who prize esoteric optimisations more than simplicity. And it is not forbidden by the standard, though discouraged.

> Undefined behaviour being weird and having bizarre implications is not a feature of C.

How so? It is behavior left undefined in the C standard.

> It is a feature introduced by compiler writers who prize esoteric optimisations more than simplicity.

It's not the compiler writers who left the behaviour undefined, but the standard writers. If it was so clear what should be done (so all compiler writers should do it in one way) then why did they not define it?

> And it is not forbidden by the standard, though discouraged.

What do you mean it's not forbidden in the standard, it's undefined in the standard hence the name. Because of this you really should not rely on it, because the behavior could change.

Re: Some Were Meant for C – The Endurance of an Unmanageable Language (2017) [pdf]

#118

Earlier quoted context omitted.

First off, new/delete are only used for objects that are allocated on the heap. Even then, modern C++ has RAII wrappers such as std::unique-ptr. You should only need new/delete in rare cases.

By default, unique_ptr calls delete. It therefore still calls the destructor. So this has literally no bearing on the problem. It doesn't help at all.

Of course it calls the destructor. What else should it do? The point is that you don't get any double frees, because you never have to call delete manually. Or maybe I misunderstood your complaint?
Post reply on HN