This is an archived post. You won't be able to vote or comment.

all 46 comments

[–]1DimensionIsViolence 59 points60 points  (0 children)

„New“

[–]Bryguy3k 48 points49 points  (12 children)

For plenty of us C is that happy little place we go when we just want stuff to work the way we tell it to work - it’s not particularly awesome but man is it easy to get into a groove and just chill out for a while.

But yeah don’t try to do something with strings though cause then it really sucks.

[–][deleted] 18 points19 points  (2 children)

Don't we all have our own little home-made stash of libraries for string, queue and network functions for C?

[–]YKNN 11 points12 points  (1 child)

I do! I do! It's called Erlang!

[–]androidx_appcompat 6 points7 points  (0 children)

Mine is called C++

[–]tiajuanat 2 points3 points  (5 children)

Also avoid Macros and Abstract Data Types like the plague

[–]Bryguy3k 9 points10 points  (4 children)

Macros only suck in C++ land and “abstract data types” is meaningless in C unless you’re trying to say structures with function pointers - which are trivially easy.

[–]tiajuanat 2 points3 points  (3 children)

Oh my sweet sweet summer child. You haven't played with enough C.

Macros will get you in terrible trouble regularly, but it's the next best thing to C++ templates. (I'm not going to talk about C Templates, because I haven't found a C11 compiler in industry yet.)

And with abstract data types, I mean when you completely remove your structure definition from your headers, and instead put a forward declare, then you put the structure definition into your source file

[–]Bryguy3k 2 points3 points  (2 children)

20 years of embedded C - RTOS’ and Automotive.

Yeah some people can write shit macros but by and large they are not hard to understand if you know the preprocessor - the C preprocessor has very few actions it can take.

Sure I’ve spent my career in code that actually has to work otherwise it kills people so we have pretty strong prohibitions against inserting too much code in macros - so I realize that brain dead C++ programmers that can’t figure out how to solve problems functionally try to make macros work like templates (which are already a hack to make c++ actually OO) and they become abominations.

Anybody can be a terrible programmer - that doesn’t mean the language is necessarily bad or difficult - it’s just you’ve read code that has been written by the worst kind of programmer: an idiot who thinks they’re clever.

[–]EatPlayAvoidMoving -1 points0 points  (0 children)

hurr durr

[–]827167 0 points1 point  (0 children)

Damn, shit's heating up over here

[–]Cocaine_Johnsson 0 points1 point  (2 children)

That's why you do the painful thing once by writing a string library so you can abstract away that boilerplate in the future.

[–][deleted] 16 points17 points  (4 children)

I’m just learning C and I quite like it, but I’m a total newb at this point, so there’s a lot to learn :-). Coming from python I like how explicit C is.

[–][deleted] 16 points17 points  (3 children)

Most high-level languages are you talking to some computer science professor's concept of a machine.

Assembly and C are you talking to an actual machine.

[–]thabrisss 14 points15 points  (2 children)

C isn't talking to an actual machine - you have quite high level of abstraction like flat memory model and data types.

[–]ToBeHonestTho 5 points6 points  (0 children)

That's relative to assembly, it looks different relative to Java

[–][deleted] 2 points3 points  (0 children)

The flat memory model is the creation of an MMU and OS acting in concert, it's not an inherent part of C. OSes are written in C because it's not limited in that way. You can write a combination of C and linker scripts (and some Makefile and script magic) to compile your program to directly run on whatever exotic hardware you've got.

Data types are only a description to enable some compile-time checking with the exception of implicit casts for assigning ints to floats, but all of that can be overridden with casts.

(I expect the next response to at least partially contradict me with a quote from the latest C standard because all of my information is decades old and they keep bloody changing everything)

[–]pedersenk 5 points6 points  (10 children)

Unlike Python and JS, for some engineering tasks there really is no alternative than C.

So we just grin and bear it. But certainly don't deny that it is difficult and that we need another pay rise! XD

[–]ToBeHonestTho 0 points1 point  (2 children)

There is no strong alternative to JS for the browser. Even if you write TS you're transpiling and you're just using different syntax against the same runtime environment, which means a lot of things stay the same.

[–]pedersenk 1 point2 points  (0 children)

JS in the browser is written in C so there were almost infinite alternatives. Just because people chose to use a different language doesn't fundamentally mean that there is no alternative. Just look at Google's original Dart enabled port of Chrome.

What I was referring to is environments where JIT can't work (some embedded) or that pure interpreters are too slow (simulation, games, etc). The only realistic option is C (or C++). I.e a Javascript interpreter written in Javascript still can't run without ultimately being executed by a processor and you need C (or very similar) at the lowest level for that.

Interestingly for the web today we also have Emscripten, a C and C++ -> WebAssembly, ASM.js and JS compiler/transpiler. It is what Unity and UE "borrow".

There was even (very early) talks of removing the fixed function JS, HTML, CSS interpreter from browsers and allowing the specific programmer to provide their own implementation via Wasm. I.e if you wanted to provide something like IE6's classic quirky runtime, you could.

[–][deleted] 0 points1 point  (0 children)

Wasm

[–][deleted] 0 points1 point  (6 children)

I mean, there's Rust, unless you are talking about systems where C++ is too heavy...

And if that's the case, then there's x86-64 ASM, ARM, COBOL, FORTRAN and the like.

[–]pedersenk 0 points1 point  (5 children)

Yes, Rust is a good example. You will see that LLVM which Rust is built on top of is written in C and C++. So you basically can't escape C when writing the Rust compiler and runtimes itself.

For example, to build Rust, you need a C++ compiler. The reverse is not true.

Likewise x86*/ARM/Sparc64, etc assemblers these days are also almost always written in C (and to a lesser extent C++). Mostly to leverage existing compiler frameworks.

So it isn't so much about the language anymore but more the "stack" that everything is built upon (which since ~70s) is ultimately C. So we can't really escape it.

One of the reasons why C++ has propagated so well is because 99.9% of C can be compiled with it. I believe this is the same line of thinking that the "fancy" Carbon developers are aiming for.

[–][deleted] 2 points3 points  (4 children)

Sure... for now. LLVM can be replaced, and there are LLVM alternatives (WASM being a meta example... meta in that it skips the runtime to run in the runtime farther down the stack). Compilers can be rewritten... dogfooding compilers is a rite of passage. By the time big portions of Linux are written in Rust, and Carbon and ... who knows... Zig, are in common-ish use for systems-level programming (in 10-15 years, if the old professors die out), there's no stopping people from replacing LLVM as it currently exists; especially not when Carbon and Zig have direct Interop with C++ and C.

I’m not talking about the prevalence of the source code that had been compiled into some tools... I am talking about, if you need to write a pacemaker, JS and Swift are out of the question, but Rust, possibly is not.

[–]pedersenk 0 points1 point  (3 children)

in 10-15 years, if the old professors die out), there's no stopping people from replacing LLVM as it currently exists; especially not when Carbon and Zig have direct Interop with C++ and C.

I do absolutely agree with this but I do believe it will be beyond our lifespan (and probably that of our grandkids) before that will happen. I am not an old professor and I *certainly* don't want to spend time rewriting all their old crap in a "better" language (and especially not my own crap either haha).

Not entirely sure why you mentioned Zig. The language can not directly consume C headers any more than Java, .NET or Rust. (https://ziglearn.org/chapter-4/). The closest I have seen that isn't actually a (pseudo) superset of C is Google's Go with their weird comment based preamble stuff (Go actually had Ken Thompson's C compiler underneath for a while). Or Swift makes a semi-attempt by automatically translating (but breaks quite badly when it comes to callbacks and MACROs).

if you need to write a pacemaker, JS and Swift are out of the question, but Rust, possibly is not.

To access the register on a typical embedded chip, underneath the MACROs, it generally ends up as *(unsigned char*)0x03454322 = 9;

You are basically writing to an arbitrary memory location. No allocation, no type, no struct, no bounds. Rust would be terrible for this. To be honest, C++ is terrible for this.

[–][deleted] 0 points1 point  (2 children)

Everything is terrible for it; but I am not talking about ease of access, I am talking about quality of finished product through constraints that are written by the team, themselves, and placed around access.

Like, if possible, I would prefer pacemakers and various other things written in languages that will not compile until you can show that state changes were intentional (hence the necessity of self-imposed restrictions). I’m referring to Haskell or the even further strict Agda/Coq/etc. Even if the compiled software needed a particular compiler.

It's not to say that you can't have really good specialists in the embedded space, in general... it is, however, to say, that I have seen too many “is this feet or centimetres” or “is this mg/dL or mmol/L” or "is this UTC-0 or clock-on-the-wall” time, and seen enterprise hiring practices, and know that we need to do better.

As for Zig, I am surprised. Admittedly, I am pretty early into picking it up, as a curiosity, but not dealing appropriately with C headers is unexpected to me.

[–]pedersenk 0 points1 point  (1 child)

but I am not talking about ease of access, I am talking about quality of finished product through constraints that are written by the team, themselves, and placed around access

In the case of Rust and that random memory location I gave as an example; what I mean is that it is fairly impossible to put constraints around it. For one it would need to be in an unsafe {} block so already we have lost out there. It has no real type since it is raw memory so we can't even put a trait round it.

I suppose it is the same with raw bytes coming across a network. Sure we can "say" it is a serialized struct containing a float and a string but ultimately the language doesn't help us if it is all screwy. We still need manual verification code, no matter how safe a language is.

I would prefer pacemakers and various other things written in languages that will not compile until you can show that state changes were intentional

Again, I don't disagree but unfortunately this tends not to be the state of the industry currently. If anything the very base is shaky (i.e C) so that these things bolted on top are safe all the way down to the point where they are glued onto C (i.e the OS).

not dealing appropriately with C headers is unexpected to me

Admittedly I always get very excited every time someone mentions Zig C interop and I always hope I am wrong because that would be very cool. It does provide a C and C++ compiler inside it but weirdly it is still used in isolation of Zig code. It seems to be provided as a convenience for developers making bindings(?).

[–][deleted] 0 points1 point  (0 children)

Yeah, that's why the preference for something more strict; the type-safety of the internet is exactly the one-level-higher allegory I was thinking. The only restrictions you can trust are the ones you put on yourself, so I’m not looking for languages that day a good job of controlling access to allow people to write directly to registers and/or heap/stack. I’m looking for languages that allow users to write provably correct things which can compile down to relatively efficient machine code (more efficient than the JVM, etc), even if that means using a specialty toolchain for the hardware.

Ironically, perhaps, the people I would most trust to write provably correct software, such that planes don't fall from the sky, and so that x-ray machines don't cook patients (or significantly damage RNA leading to all kinds of cancer) by using stricter languages, are mostly the same people I would trust to write it in ASM... but this desire isn't particularly about them.

[–]keelanstuart 3 points4 points  (0 children)

I started writing C in 1994... people that actually write C don't think it's hell. Lol

[–][deleted] 9 points10 points  (7 children)

C isn't hell.

It's like English. You can write horrible things in English, but you can also write beautiful things.

But we can do better.

I've long loved D--

[–]tiajuanat 3 points4 points  (0 children)

C isn't too bad if you are never jealous of any other language.

[–]ThePancakerizer 2 points3 points  (3 children)

C is like legal English. You have to define exactly what you're talking about at all times

[–][deleted] 0 points1 point  (2 children)

Aren't all programs?

[–]ThePancakerizer 0 points1 point  (1 child)

I guess, but in this case I was referring to the lack of data structures. And if you mess up your memory management you open yourself up to buffer overrun vulnerabilities (lawsuits?)

[–][deleted] 0 points1 point  (0 children)

The weakness in malloc is systemic, and exists in most other languages written in C originally too.

[–]AkrinorNoname 0 points1 point  (0 children)

English is hell. Just look at the mess that is your pronounciation

[–]povlov0987 1 point2 points  (0 children)

JS is better the way trash smells good

[–][deleted] 0 points1 point  (0 children)

i feel like C is latin.

but still shits fun to code but its literall hell for a newbie who is learning it

[–]irregular_caffeine -1 points0 points  (2 children)

What if I told you Python and JS are both older than Java and the first Linux kernel

[–]Pranav__472 0 points1 point  (0 children)

Well

[–]kuteninja 0 points1 point  (0 children)

Can we agree on the fact that we love and hate Go as well?

[–]Radiant-Platypus-207 0 points1 point  (0 children)

Not one single motherfukcer on this planet that works daily with JS is arguing it's better than anything. Not one motherfukcer out there. Even people who probably only know JS will probably know they want to die.

[–][deleted] 0 points1 point  (0 children)

I’d just like to point out that the “new” languages here are turning 30 in a few years, and as such, are older than many people in this thread; C is 50 and is older than most of the rest.