Live data from Hacker News

Switching to C over 'Modern' Programming Languages

devtails.xyz

161–170 of 170 posts

Re: Switching to C over 'Modern' Programming Languages

#161
post #133

Earlier quoted context omitted.

Okay, so you write your own string library. Now you'd like to do the same thing for resizable arrays, so you write a resizable array li… oops, you can't, because C doesn't have parametric types.

Preprocessor macros are an entirely valid tool in the C language toolbox, even if demonized by C++ coders.

it is black magic, absolutely respect C developers.

Re: Switching to C over 'Modern' Programming Languages

#162
post #111
post #89

Earlier quoted context omitted.

What exactly is a problem with C++’s strings, or especially Rust’s? Everything you mentioned can be controlled as explicitly as you want. The only problem is C is simply not expressive enough to have proper abstractions like that.

Last time I checked "Formatting is Unreasonably Expensive for Embedded Rust" (1) And/or you need a crate like alloc, heapless, etc. For the sake of a sprintf "abstraction"... (1) https://jamesmunns.com/blog/fmt-unreasonably-expensive/

It’s not really a sprintf abstraction.

Re: Switching to C over 'Modern' Programming Languages

#163
post #133
post #73

Earlier quoted context omitted.

> The very common thing I want to use in C is some sort of variable size string object. But no, I have to dynamically allocate a buffer that I know will be at least the right size for any text I ever put into it, or do I create a buffer that's the correct size for that string but re-alloc if I ever change it to a longer string. But then how do I store the buffer size? As a C programmer shouldn't you have a library ab…

Okay, so you write your own string library. Now you'd like to do the same thing for resizable arrays, so you write a resizable array li… oops, you can't, because C doesn't have parametric types.

He didn't say "write your own library". He said "use" one (your own if you prefer). Or are you going to suggest there are no good string handling libraries for C?

Re: Switching to C over 'Modern' Programming Languages

#164
post #16

Is this becoming a thing now (or maybe it was always a thing), where a language, like Rust, has become popular enough that instead of everyone talking about learning it, they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist? Rust exists for a reason, and it solves specific problems. That’s the “magic”, just like any abstraction in any…

If there's a "hipster" notion here it's not that of choosing C as rebellion against Rust, but that choosing C constitutes a rebellion against Rust and only Rust, as if it's the only systems programming language worth it's salt.

E.g., explain to me like I'm 10 why you think Rust is better than, say, D.

Re: Switching to C over 'Modern' Programming Languages

#165
post #16

Is this becoming a thing now (or maybe it was always a thing), where a language, like Rust, has become popular enough that instead of everyone talking about learning it, they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist? Rust exists for a reason, and it solves specific problems. That’s the “magic”, just like any abstraction in any…

If there's a "hipster" notion here it's not that of choosing C as rebellion against Rust, but that choosing C constitutes a rebellion against Rust and only Rust, as if it's the only systems programming language worth it's salt. E.g., explain to me like I'm 10 why you think Rust is better than, say, D.

It seems to me like D is like if you took the most complicated language in the world, C++, and did even more stuff to it, like adding in an optional garbage collector. One reason it's so complicated is that "low level" programming plus OOP seem to be a terrible mix. D is trying to improve a messy room by re-organizing some things and introducing a Roomba.

Rust blazes a whole new path, with the slightly different objective of safety. It's simple and lean, almost like C. It bakes in lessons learned over the years like inheritance being overly complicated, OOP generally being overly complicated, and how dangerous systems programming can be by having modules instead of classes, composition instead of inheritance, and memory safety as a default. It also broke the false dichotomy of "fast but dangerously leaky" or "slow but safely garbage collected" by introducing borrow checking and move semantics, allowing speed and safety with no garbage collection.

D feels like a continuation down an evolutionary dead end, like teleputer cartridges in Infinite Jest.

Rust feels like an innovative fresh start, like transferring digital DRM-free files.

(If you think that makes D sound charming, I agree. But realistically I would stick with Rust. :p)

Re: Switching to C over 'Modern' Programming Languages

#166
You ever get the feeling that C should be grouped with all the XML and (semantic) web technologies the W3C no longer has active working groups for?

Maybe combine them to make a Spring-like framework, but for C?

Long standing non-changing specs and standards should be married, and with children.

Re: Switching to C over 'Modern' Programming Languages

#167
post #36
post #16

Is this becoming a thing now (or maybe it was always a thing), where a language, like Rust, has become popular enough that instead of everyone talking about learning it, they now want to talk about how “simple” and “beautiful” C is for no other reason than signaling how different you are from the zeitgeist? Rust exists for a reason, and it solves specific problems. That’s the “magic”, just like any abstraction in any…

I'm a C programmer by day and I disagree with them, C is only simple if you're trying to do simple tasks with it. The very common thing I want to use in C is some sort of variable size string object. But no, I have to dynamically allocate a buffer that I know will be at least the right size for any text I ever put into it, or do I create a buffer that's the correct size for that string but re-alloc if I ever change i…

> But then I can't use sizeof() if I pass that buffer into a function via a pointer.

Obviously, this isn't necessarily an improvement, but in theory you could do this:

  size_t getlength( int m, char (*p) [m] ) { return sizeof *p; }
where you'd be calling it like this:

  char mystring[] = "Hello";
  getlength( sizeof mystring, &mystring )
But then you're back in "having to pass the length as a separate parameter" territory, I guess. (but at least it's the length of the array here, not just the zero-terminated component, which is what you wanted).

Re: Switching to C over 'Modern' Programming Languages

#168

Earlier quoted context omitted.

If there's a "hipster" notion here it's not that of choosing C as rebellion against Rust, but that choosing C constitutes a rebellion against Rust and only Rust, as if it's the only systems programming language worth it's salt. E.g., explain to me like I'm 10 why you think Rust is better than, say, D.

It seems to me like D is like if you took the most complicated language in the world, C++, and did even more stuff to it, like adding in an optional garbage collector. One reason it's so complicated is that "low level" programming plus OOP seem to be a terrible mix. D is trying to improve a messy room by re-organizing some things and introducing a Roomba. Rust blazes a whole new path, with the slightly different obje…

I won't lie, I lol'ed at the Roomba bit :D

Re: Switching to C over 'Modern' Programming Languages

#169
post #133

Earlier quoted context omitted.

Okay, so you write your own string library. Now you'd like to do the same thing for resizable arrays, so you write a resizable array li… oops, you can't, because C doesn't have parametric types.

He didn't say "write your own library". He said "use" one (your own if you prefer). Or are you going to suggest there are no good string handling libraries for C?

It doesn't matter. My point is that it's not possible, not for you and not for anyone else, to implement a type-safe generic resizable array library in C.

Re: Switching to C over 'Modern' Programming Languages

#170

Earlier quoted context omitted.

Preprocessor macros are an entirely valid tool in the C language toolbox, even if demonized by C++ coders.

it is black magic, absolutely respect C developers.

But the preprocessor is just simple text replacement, nothing magic about it.
Post reply on HN