Live data from Hacker News

Let's Destroy C

gist.github.com

151–160 of 192 posts

Re: Let's Destroy C

#151

Reminds me of Arthur Whitney's k.h[1] Example: // remove more clutter #define O printf #define R return #define Z static #define P(x,y) {if(x)R(y);} #define U(x) P(!(x),0) #define SW switch #define CS(n,x) case n:x;break; #define CD default 1 - https://github.com/KxSystems/kdb/blob/master/c/c/k.h

Reminded more strongly of the Bourne shell macros which turned C into some awful Algol dialect:

https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd...

Re: Let's Destroy C

#152

I've been a C programmer for several years now (out of necessity - C is still the best language for firmware and embedded development) There's been a lot of noise on the internet about Rust and C++20 and "modern" languages. I recently had an opportunity to try some of these first hand. Honestly the new language features are all terrible with few exceptions. In general, anything that was added to a language to support…

Great post.

In particular: "remove some of the undefined behaviors" I think the confusion caused by this is not nearly worth the optimization gained.

Compiler folks will say "but look, this loop is 58% faster!" but ignore the fact that slow code can be optimized through other means, including profiling, restructuring, etc.

Re: Let's Destroy C

#153

Earlier quoted context omitted.

puts and printf aren't keywords, they're regular functions.

Well, sort of. Specifically, printf is an oddball function because it uses the varargs mechanism, and the whole format strings mechanism is inherently risky because it effectively bypasses the type system and says "trust me." Back when I was learning C, on a Mac with THINK C, misusing printf was a sure-fire way to crash the computer very quickly, especially since misaligned accesses of 16-bit or 32-bit words caused c…

Sure, but that's varargs being the special cased but, not printf (I've written printf implementations for some ebedded systems, it's always just regular C code).

Re: Let's Destroy C

#154
post #44

I guess this article is to be taken lightly as kind of a "joke" ? The first proposed macro displayln is the archetype of malpractice. What if I want to do: if(some_condition) displayln("enjoy debugging that"); etc etc... almost all proposed changes seem to be awful ?

You've done a fine job of elucidating one of the many reasons why responsible codebases require braces for single-statement if clauses.

Re: Let's Destroy C

#155

I've been a C programmer for several years now (out of necessity - C is still the best language for firmware and embedded development) There's been a lot of noise on the internet about Rust and C++20 and "modern" languages. I recently had an opportunity to try some of these first hand. Honestly the new language features are all terrible with few exceptions. In general, anything that was added to a language to support…

Great post. In particular: "remove some of the undefined behaviors" I think the confusion caused by this is not nearly worth the optimization gained. Compiler folks will say "but look, this loop is 58% faster!" but ignore the fact that slow code can be optimized through other means, including profiling, restructuring, etc.

Or avoid them when your compiler hasn't documented if they support it. Such as gcc supporting union type punning in c++. Many compilers allow for reinterpret_cast'ing too, e.g. gcc and -fno-strict-aliasing

This is more of knowing your language and tools. UB isn't some magic beast either, it's where it isn't really feasible for a language that runs on many platforms to dictate what happens. What should the std's say when you shift a signed int too far? Often the HW will have a way of doing it and others will not, so either don't do that or know your implementation

Re: Let's Destroy C

#156

Those defines remind me of how Bourne shell was originally written using such a system to make the source look more like Algol 68. It might even still be maintained that way in BSD to this day [0]. [0] https://books.google.ca/books?id=9f9uAQAAQBAJ&pg=PA9&lpg=PA9...

Yes! Has anybody written a head-to-head article pitting CNoEvil against BOURNEGOL yet? ISAGN

Re: Let's Destroy C

#157
post #13
post #8

Earlier quoted context omitted.

#define TYPE typedef #define STRUCT TYPE struct #define UNION TYPE union Well, that's extremely opinionated. Which I guess is the point. It does seem to add a BASIC-ness to the code. However, when I see landmines like these: #define TRUE (-1) #define FALSE 0 I might just hide instead of touching it.

Uh... This is serious landmine... I suggest author to change this.

Don't bash it til you understand it.

Re: Let's Destroy C

#158
post #26
post #24

This is amazing. Are there any larger examples that uses more of the functionality of the library that I could read?

Whilst it uses an older version of CNoEvil, and I haven't updated it yet, the largest application is probably evilshell [0]. There's also all the examples [1]. [0] https://git.sr.ht/~shakna/evilshell [1] https://git.sr.ht/~shakna/cnoevil3/tree/master/examples

I've already said this a couple other places but I really wanted to say: "This is amazing and it would be hilarious if you wrote a CNoEvil vs. BOURNEGOL head to head article".

<3

Re: Let's Destroy C

#159
post #18

Earlier quoted context omitted.

Can you explain why?

To emphasise: This is about Bournegol. Nothing to do with this post. > Can you explain why? Because it isn't how most C libraries expect true/false to be defined. stdbool in C99 standardized things a bit, but before then what was generally accepted was: > true is 1 > false is !true (Often 0 in practice). Which means that any trivial: if(true) { ... } Won't work under Bournegol. Instead you _need_ to compare when doin…

this is utter nonsense. in C, since before C89, all non-zero values are considered true in conditional contexts (if, for, while, ?:). http://port70.net/~nsz/c/c89/c89-draft.html#3.6.4.1. false must therefore be exactly zero. !1 is also always 0, as it must be. http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.3.
Post reply on HN