Live data from Hacker News

I stopped everything and started writing C again

kmx.io

411–420 of 475 posts

Re: I stopped everything and started writing C again

#411
post #241
post #221

Earlier quoted context omitted.

This is objectively nonsense

Interesting use of the word 'objectively' there.

>> One catches far more issues than another

> akshually they have same amount of bugs

You literally segfault by dereferencing invalid pointer.

Re: I stopped everything and started writing C again

#412
post #176
post #127

I'm kinda in the opposite camp. After doing a bunch of VB in my tweens and teens, I learned Java, C, and C++ in college, settling on mostly C for personal and professional projects. I became a core developer of Xfce and worked on that for 5 years. Then I moved into backend development, where I was doing all Java, Scala, and Python. It was... dare I say... easy! Sure, these kinds of languages bring with them other pro…

The biggest problem with C is that doesn't even have enough features to help you build the features and abstractions you need and want. For example with C++ the language offers enough functionality that you can create abstractions at any level, from low level bit manipulation to high level features such as automatic memory management, high level data objects etc. With C you can never escape the low level details. Cur…

so confused by this one. C is the most free to build systems and abstractions. it doesnt lock you down into any paradigm so you can build your own....

you can abstract away perfectly fine low level details and use your own high level constructs to build what you want in a memory safe way...

high level daya objects?

sure it doesnt have garbage collection, so it motivates you not to leave garbage laying around for some slow background process to collect.

actually you can build this in C you just do not want to...

you can give all your objects reference counters and build abstractions to use that, you can implement 'smart pointers' if u want, and have threads do garbage collection if u want... why not? what exactly is stopping you?

maybe its less convenient to go that route. but impossible? nope.

connect GDB to your c++ program and see how it works... its not like c++ suddenly doesnt become machine code. and c translates perfectly fine to machine code...

Re: I stopped everything and started writing C again

#413
post #407

Earlier quoted context omitted.

> Do you have any examples of C outperforming Rust? I don't have a pony in that race. > uutils/sort outperforms coreutils/sort by 6x "He used the hyperfine command-line benchmarking tool to run a test ten times; sorting a text file containing all of Shakespeare's works to see which implementation was faster. The first time he performed the test, he used a debug build of the Rust version of sort. In that demo, Rust's…

Might not. The Rust standard library has a state of the art sort implementation. There’s nothing faster, in any language - https://github.com/rust-lang/rust/pull/124032 . And sure, it’s possible that someone could write a C program that compares in speed to all the Rust programs I’ve mentioned. C is a Turing complete language after all. I’m only pointing out that it hasn’t happened in practice. Also check the Android…

> And sure, it’s possible …

Because anecdote. We can only know when the thing is designed as an experiment.

(All credit to who-so-ever is working to write improved versions.)

Re: I stopped everything and started writing C again

#414
post #227

Earlier quoted context omitted.

Sure, that's a pretty common pattern in use in C to this day. It's a useful pattern, but it's still all manual. Forget to fill in a function pointer in a struct? Crash. At least with C++ it will fail to compile if you don't implement a method that you have to implement.

> still all manual That pretty much is the definition of C. It was designed to be a system language, that was "one step beyond" (my own Madness reference) the assembler. It's a dangerous tool, and should be wielded by experts. The same goes for all kinds of similar stuff. And "experts" is kind of a darwinian thing. There's not really that many folks that can successfully wield it in large quantities (a certain cranky…

haha every segfault puts me back down into the valley of despair xD. thats totally ok!

higher level languages often make it so you can focus on the language mostly. C and assembly, i think, you need a lot of context. what is running the code, and how.

Re: I stopped everything and started writing C again

#415

Earlier quoted context omitted.

The problem is that regardless of the amount of confrontation it does not have an answer for any infinite run time event-loop based program, other than "allocate all of memory into a buffer at startup and implement your own memory manager inside that". Which just punts the problem from a mature and tested runtime library to some code you just make up on the spot.

Heap was invented for a reason, and some tasks are naturally easier to model with it. The problem is that once it's there, people start using it as the proverbial hammer, and everything looks like a nail even if it isn't. Note though that ""allocate all of memory into a buffer at startup" is a lot more viable if you scope it not to the start of the app, but to the entrypoint of some code that needs to make a complica…

That works for something where the events being handled are like "serve a web page" or "compile a C function". It doesn't work for a spreadsheet or word processor or a web browser.

Re: I stopped everything and started writing C again

#416

Earlier quoted context omitted.

Try doing C with a garbage collector ... it's very liberating. Do `#include ` then just use `GC_malloc()` instead of `malloc()` and never free. And add `-lgc` to linking. It's already there on most systems these days, lots of things use it. You can add some efficiency by `GC_free()` in cases where you're really really sure, but it's entirely optional, and adds a lot of danger. Using `GC_malloc_atomic()` also adds eff…

>Try doing C with a garbage collector ... it's very liberating. Doing that means that I lose some speed and I will have to wait for GC collection. Then why shouldn't I use C# which is more productive and has libraries and frameworks that comes with batteries included that help me build functionality fast. I thought that one of the main points of using C is speed.

Every time I've tried it, adding GC to a C program makes it faster. It will increase the RAM usage by a bit, and exactly when pauses happen is less predictable (unless you explicitly trigger a GC in e.g. your main loop), and possibly individual pauses larger, but overall program execution time -- throughput -- increases.

Malloc() and free() aren't free, and in particular free() does a lot more bookkeeping and takes more time than people realise.

Re: I stopped everything and started writing C again

#417
post #413

Earlier quoted context omitted.

Might not. The Rust standard library has a state of the art sort implementation. There’s nothing faster, in any language - https://github.com/rust-lang/rust/pull/124032 . And sure, it’s possible that someone could write a C program that compares in speed to all the Rust programs I’ve mentioned. C is a Turing complete language after all. I’m only pointing out that it hasn’t happened in practice. Also check the Android…

> And sure, it’s possible … Because anecdote. We can only know when the thing is designed as an experiment. (All credit to who-so-ever is working to write improved versions.)

> Because anecdote

I don’t think anyone could have said something more rude or ignorant if they tried.

> designed as an experiment

Ha. As if you could design such an experiment. What, you’ll place two rats at a keyboard and ask them to implement grep? Bffr.

I’m pointing out the obvious - no one has actually written these mythical C programs that outperform Rust, to say nothing about security and reliability. You’ve deluded yourself into thinking that all it needs is “an experiment”. lol.

Re: I stopped everything and started writing C again

#418
post #11

I fully understand that sentiment. For several years now, I have also felt the strong urge to develop something in pure C. My main language is C++, but I have noticed over and over again that I really enjoy using the old C libraries - the interfaces are just so simple and basic, there is no fluff. When I develop methods in pure C, I always enjoy that I can concentrate 100% on algorithmic aspects instead of architectu…

[deleted]

Re: I stopped everything and started writing C again

#419

What's the best way to learn C? Any good modern book recommendations, or sites?

I highly recommend Zed Shaw's "Learn C the Hard Way": https://learncodethehardway.org/c/ I worked through this and felt well-prepared to actually use C in anger when I had to.

Terrible overall and entirely wrong in multiple places. If you learn C from this book, you should't be writing C.

The last bit is also true for K&R The C Programming Language (avoid at all costs).

You're better off with:

- Modern C (whatever edition is current)

- Seacord's Effective C: Introduction to professional C programming

- C Programming: Modern Approach 2nd edition (bible)

Re: I stopped everything and started writing C again

#420

What's the best way to learn C? Any good modern book recommendations, or sites?

There's a second edition of the legendary K&R book¹ to get you started. ¹ https://www.amazon.com/Programming-Language-2nd-Brian-Kernig...

See my previous comment, anyone learning C from K&R should not be writing C period.

That book is legendary only in the magnitude of financial damages it (directly and indirectly) enabled, caused by people who read it and thought that they could now write C.

Post reply on HN