News for hackers. Stuff that matters.
Re:Essential C (2003) [pdf] by freedomben on Sunday December 30, 2018 @04:00PM (#18791299)
Oh man, I feel exactly the same my friend. People who have never gotten into the C world find it frightening, but it's a beautifully simple language loaded with (at times dangerous) power. It's so much closer to the hardware that you can't use a declarative approach easily (which now that I've drunk the functional programming kool-aid, I do love), but in many ways it's actually much simpler to understand. You can also be pretty declarative if you are just smart about breaking things into functions.

I still glance longingly at my dusty paper copy of The Linux Programming Interface (https://nostarch.com/tlpi)

/nostalgia

Re:Essential C (2003) [pdf] by vardump on Sunday December 30, 2018 @09:02PM (#18792568)
> People who have never gotten into the C world find it frightening...

I got into C over 25 years ago. Didn't find it frightening back then, but I sure do now.

Still use it pretty often for firmware and kernel driver development, but I want to replace it with something safer. Then again, I also use assembler for same reasons... sometimes C just doesn't cut it for interrupt handlers when every cycle and/or code byte size counts.

Re:Essential C (2003) [pdf] by freedomben on Monday December 31, 2018 @12:29PM (#18795641)
> Didn't find it frightening back then, but I sure do now.

Why is that? Security related stuff?

Re:Essential C (2003) [pdf] by vardump on Monday December 31, 2018 @04:05PM (#18797024)
Yup. Things are increasingly connected to network. Including legacy codebases.

Also when you have larger teams and more people touching the code, C can really shoot at your feet and elsewhere. From new and surprising angles.

Re:Essential C (2003) [pdf] by freedomben on Monday December 31, 2018 @06:47PM (#18797888)
No doubt. It's amazing too how some code that was never expected to be exposed to untrusted/unsanitized data gets re-factored into a new spot or called from somewhere else, and fails to provide sanitation expecting that the callee will do it, or simply forgetting altogether (easy when under pressure to deliver). I coded a pretty bad security hole myself once by doing something like that, and I am a security specialist that knows what to look for lol!

I love C, but it really is a security nightmare full of footguns.

Re:Essential C (2003) [pdf] by vectorEQ on Monday December 31, 2018 @06:11AM (#18794050)
> Still use it pretty often for firmware and kernel driver development, but I want to replace it with something safer. Then again, I also use assembler for same reasons... sometimes C just doesn't cut it for interrupt handlers when every cycle and/or code byte size counts.

That's what you have ASM for :D j/k

Re:Essential C (2003) [pdf] by mpweiher on Sunday December 30, 2018 @04:05PM (#18791331)
> beautifully simple language

:-)

Of course there are those who claim it is actually frightfully complex, when it is those same people who are re-interpreting the standards to actually create that very complexity.

Re:Essential C (2003) [pdf] by cblum on Sunday December 30, 2018 @04:48PM (#18791544)
Not sure if this is what you meant, but a lot of the stuff they added to C in the latest standards really turn me off. C89 has a special place in my heart.
Re:Essential C (2003) [pdf] by vectorEQ on Monday December 31, 2018 @06:13AM (#18794055)
i still only code in C, didn't start in the stone ages, but i love it. C and asm give me the feeling i'm programming my computer, and really for low level stuff trying to find a good alternative which is as good and simple (yes simple :D c/asm is just pure logic!) is difficult for me.

I don't code professionally though, since i can't for the life of me find a job in C which doesn't have already tons of guys like you guys with a century of experience in the language lining up to take it :D

C/asm is awesome, can't bare anything else

Re:Essential C (2003) [pdf] by tombert on Sunday December 30, 2018 @04:36PM (#18791479)
Honestly, if you use one of the available GCs out there (like Boehm's), and give up on static typing, and heavily rely on function pointers, you can write C similar to how you'd write something like Haskell. Yes, it won't go as fast as it the most idiomatic C, and you can't really make an operating system if you have a GC, but really, how often do most of us actually write code that can't use a GC these days? Even with a GC, it'll still probably perform better than 90% of languages.
Re:Essential C (2003) [pdf] by cblum on Sunday December 30, 2018 @04:52PM (#18791564)
At that point it's practically not C anymore :)

I'm not a fan of adding GC to C. I've hard my fair share of stress caused by GC issues. It's great 99% of the time but when you run into performance issues caused by the GC it becomes a very very leaky abstraction.

Re:Essential C (2003) [pdf] by tombert on Sunday December 30, 2018 @05:04PM (#18791627)
I'm ok with it not being 70's-era C to be honest; I even with the extra stuff, I find the language to be fairly simple to pick up compared to C++.

I haven't had any problem with performance with the Boehm GC personally, though for what I've used C for is not-real-time video processing stuff. I found I typically got better throughput using Boehm than I did when I was manually managing my memory, but for what I was using it for, a small pause wasn't really a problem as long as the throughput wasn't really affected.

Re:Essential C (2003) [pdf] by kevin_thibedeau on Sunday December 30, 2018 @07:40PM (#18792230)
One may as well just use C# without classes.
Re:Essential C (2003) [pdf] by n4r9 on Monday December 31, 2018 @06:59AM (#18794156)
Pedantically speaking that's impossible. But loosely speaking that's the essence of how I write most of my C#.
Re:Essential C (2003) [pdf] by sfifs on Sunday December 30, 2018 @11:28PM (#18793014)
If you are doing that, you might as well use Go and get green threads and little or no undefined behaviour in a modern actively developed language for free. Go is practically C without the undefined behaviours.
Re:Essential C (2003) [pdf] by disishhsha on Sunday December 30, 2018 @06:59PM (#18792091)
If you have a GC and no static typing, is it better than other functional languages (many of which have benefits of both GC and static typing)? Not a rhetorical question, I have never used a GC with C.
Re:Essential C (2003) [pdf] by tombert on Sunday December 30, 2018 @07:27PM (#18792178)
For what I was doing, which was video processing stuff, I'm not sure that it was faster than if I had written it in Haskell. For this job, I was required to use C or C++, and so I never attempted to port it to Haskell or OCaml or something. I'm more of a wannabe-academic and certainly not a systems programmer, so I did what I could.

If I were to guess, the C version would have a bit better performance in a single-threaded context due to the fact that I would occasionally use tricks to avoid reallocations/frees, and the Boehm GC is opt-in, so when I was reasonably certain I could handle the memory correctly, I would do it myself, minimizing how much was actually being done by the GC.

I do feel that a static functional language like Haskell might perform well (maybe even better-on-the-average-case?) in a multi-threading context, since I personally find dealing with locks in C (and C++) to be very difficult to do correctly, so utilization of some of the cool tricks in Haskell to avoid manual locking might benefit. I was too much of a coward to use threads and locks much at that job, so I haven't had much of a chance to test it.

Re:Essential C (2003) [pdf] by bitwize on Monday December 31, 2018 @11:14AM (#18795173)
Static typing is the whole point behind Haskell.

C - static typing + closures and GC ≈ Scheme. If I wanted to write in that style, I'd just use Gambit and be done with it.