←back to thread

271 points mithcs | 3 comments | | HN request time: 0.607s | source
Show context
miroljub ◴[] No.45953073[source]
Nice toy. It works until it stops working. An experienced C developer would quickly find a bunch of corner cases where this just doesn't work.

Given how simple examples in this blog post are, I ask myself, why don't we already have something like that as a part of the standard instead of a bunch of one-off personal, bug-ridden implementations?

replies(2): >>45953149 #>>45953168 #
Borg3 ◴[] No.45953149[source]
Yeah, kids like to waste time to make C more safe or bring C++ features. If you need them, use C++ or different language. Those examples make code look ugly and you are right, the corner cases.

If you need to cleanup stuff on early return paths, use goto.. Its nothing wrong with it, jump to end when you do all the cleanup and return. Temporary buffers? if they arent big, dont be afraid to use static char buf[64]; No need to waste time for malloc() and free. They are big? preallocate early and reallocate or work on chunk sizes. Simple and effective.

replies(4): >>45953181 #>>45953199 #>>45953578 #>>45953726 #
kstrauser ◴[] No.45953199[source]
God forbid we should make it easier to maintain the existing enormous C code base we’re saddled with, or give devs new optional ways to avoid specific footguns.
replies(1): >>45953269 #
mightyham ◴[] No.45953269[source]
Goofy platform specific cleanup and smart pointer macros published in a brand new library would almost certainly not fly in almost any "existing enormous C code base". Also the industry has had a "new optional ways to avoid specific footguns" for decades, it's called using a memory safe language with a C ffi.
replies(1): >>45953365 #
kstrauser ◴[] No.45953365[source]
I meant the collective bulk of legacy C code running the world that we can’t just rewrite in Rust in a finite and reasonable amount of time (however much I’d be all on board with that if we could).

There are a million internal C apps that have to be tended and maintained, and I’m glad to see people giving those devs options. Yeah, I wish we (collectively) could just switch to something else. Until then, yay for easier upgrade alternatives!

replies(1): >>45953539 #
mightyham ◴[] No.45953539[source]
I was also, in fact, referring to the bulk of legacy code bases that can't just be fully rewritten. Almost all good engineering is done incrementally, including the adoption of something like safe_c.h (I can hardly fathom the insanity of trying to migrate a million LOC+ of C to that library in a single go). I'm arguing that engineering effort would be better spent refactoring and rewriting the application in a fully safe language one small piece at a time.
replies(1): >>45953585 #
kstrauser ◴[] No.45953585[source]
I’m not sure I agree with that, especially if there were easy wins that could make the world less fragile with a much smaller intermediate effort, eg with something like FilC.

I wholeheartedly agree that a future of not-C is a much better long term goal than one of improved-C.

replies(1): >>45956345 #
uecker ◴[] No.45956345[source]
I don't really agree, at least if the future looks like Rust. I much prefer C and I think an improved C can be memory safe even without GC.
replies(1): >>45956442 #
whytevuhuni ◴[] No.45956442[source]
> I think an improved C can be memory safe even without GC

That's a very interesting belief. Do you see a way to achieve temporal memory safety without a GC, and I assume also without lifetimes?

replies(2): >>45956844 #>>45959873 #
1. uecker ◴[] No.45956844[source]
A simple pointer ownership model can achieve temporal memory safety, but I think to be convenient to use we may need lifetimes. I see no reason this could not be added to C.
replies(1): >>45957669 #
2. whytevuhuni ◴[] No.45957669[source]
A C with lifetimes would be nice, I agree.

Would be awesome if someone did a study to see if it's actually achievable... Cyclone's approach was certainly not enough, and I think some sort of generics or a Hindley-Milner type system might be required to get it to work, otherwise lifetimes would become completely unusable.

replies(1): >>45958268 #
3. uecker ◴[] No.45958268[source]
Yes, one needs polymorphism. Let's see. I have some ideas.