5 ms·
Write a multithreaded program guaranteed to have no data races in C and tell me that C is simple. C _looks_ simple, deceivingly so. As soon as you need to deal
by mlindner 4y ago
Write a multithreaded program guaranteed to have no data races in C and tell me that C is simple.
C _looks_ simple, deceivingly so. As soon as you need to deal with a large project in a corporate environment on a code base aged in double digit years you don't think it's simple anymore. C is incredibly complex, unmanageably so.
- waiseristy 4y agoI would be interested to see someone write a program in any language (other than ones specifically designed to combat this, rust…) using threading and guarantee it to be data/race safe. But, I’m not arguing with you. I honestly think that any corporate codebase after double digit years (and seven figure LoC) turns into a completely unmanageable mess. If it isn’t, it’s because of the team culture and pure rigor. Not the language
- mlindner 4y ago> I would be interested to see someone write a program in any language (other than ones specifically designed to combat this, rust…) using threading and guarantee it to be data/race safe. I don't limit my statement to just C. The topic was C however so I mentioned C.
- waiseristy 4y agoI am limiting it to just C though, because I’m responding to an article about the sticking power of C. I’ve worked in a lot of massive and unmaintainable codebases, and I’ve always had the most fun untangling C ones. I don’t know exactly why, but I suspect it’s because at their core they are always plain ol’ simple C.
- simplotek 4y ago> I don't limit my statement to just C. The topic was C however so I mentioned C. Your comment reads like a red herring though. You're not actually trying to argue that C makes thing easier or hard. Your red herring only means that hard problems affecting all languages aren't magically turned into non-issues in C. You can still write a C program that uses threading and is as safe as any other language and end up being a far simpler project, but that means nothing because the subject is still hard. And what would that actually say about C, let alone refute?
- mpweiher 4y agoC is simple. Writing C is simple. Writing multithreaded programs is difficult and C doesn't help you with it.
- sacnoradhq 4y agoFlame bait. Haha. Let's not argue about religions online. The mullahs will arrest us for improper use of void.
- im3w1l 4y agoYou are confusing two different things, the simplicity of C itself, and the simplicity of using C for a certain problem.
- ihatepython 4y agoIt's never really necessary to write a multithreaded program. It's probably better to come up with a better architecture and communication method. In a corporate environment, just use Java or C# or whatever. It's a corporate environment, probably not that interesting. C is not necessary.
- pjmlp 4y agoIt isn't because most of us reach out to C++, when needed to step out of Java and C# among others. Even modern drivers for Apple, Google and Microsoft platforms are written in C++.
- mlindner 4y agoAll that network hardware in use all over the internet was designed in corporate environments. I'd bet they almost all use C.
- tomcam 4y ago> It's never really necessary to write a multithreaded program. It's probably better to come up with a better architecture and communication method. Mind expanding on that?
- snickerbockers 4y ago>As soon as you need to deal with a large project in a corporate environment on a code base aged in double digit years you don't think it's simple anymore. I've done this before, never felt like C wasn't simple.
- mlindner 4y agoHow big was the project and how many people were maintaining it? And were the people maintaining it the same people who started it? Perhaps I should have included a statement about coming in to work on a project that was already double digits old when you started working on it.
- snickerbockers 4y agoNot sure how many people worked on it but it was forked from FreeBSD 16 years before i joined and none of the original devs were there.
- rootw0rm 4y agoi have a C threaded producer that lives in a target process and exports data to a C# consumer in another process. (locks are shared between processes according to data in a predetermined memory segment. also, add a custom high bandwidth IPC protocol to that spec) ...it works beautifully. i did port the C to a mix of unsafe C# + atomic Windows intrinsics, but it's surprisingly robust. I think your main argument here is that large C code bases can easily become unwieldy, and I agree with you on that. However, simple multithreading in C is simple. It's not a terribly difficult problem to solve.
- jstimpfle 4y agoClassic confusion of simple vs easy.
- smitty1e 4y agoEverything us easy when you know how to do it. But that learning curve...
- jstimpfle 4y agoNobody said it's easy. Programming is hard. The statement is that the language is _simple_.
- Ygg2 4y agoNobody 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 sharpened rock. Possible but, why would you. Java is a complex language. Lots of complexity. Classes, annotations, async, System.out and so on. But multi-threaded and memory safe (memory leaks allowed ofc) programs is as simple as just not using Java's array of unsafe tooling.
- jstimpfle 4y agoSure, 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".
- sacnoradhq 4y agolibuv enters the chat.
- josefx 4y ago> Write a multithreaded program guaranteed to have no data races in C and tell me that C is simple. I could port most of the multiprocessing based python scripts I have lying around to C without a problem. Multithreading can be easy when you have a few rules in place what threads can read/modify data at a specific point in time.
- jen20 4y agoIt’s even easier when a compiler enforces those rules.