Live data from Hacker News

I stopped everything and started writing C again

kmx.io

201–210 of 475 posts

Re: I stopped everything and started writing C again

#201
post #185

Earlier quoted context omitted.

i never really understand why these get compared. i wouldn't expect that much overlap in the audiences zig seems like someone wanted something between C and "the good parts" of C++, with the generations of cruft scrubbed out rust seems like someone wanted a haskell-flavoured replacement for C++, and memory-safety i would expect "zig for C++" to look more like D or Carbon than rust. and i'd expect "rust for C" to have…

The single best feature (and I would say the _core_ feature separating it from C) that C++ has to offer is RAII and zig does not have that. So I don’t know which good parts of C++ they kept. Zig is more of its own thing, and they take from wherever they like, not just C++.

> So I don’t know which good parts of C++ they kept.

comptime is a better version of C++ templates.

Re: I stopped everything and started writing C again

#202

Earlier quoted context omitted.

How was AT&T’s monopoly a driver? It’s not like they forced anyone to use UNIX.

Ironically, AT&T's monopoly actually helped the adoption of Unix, but not in an exploitative way. In 1956, AT&T was subject to a consent decree by the US government, where AT&T was allowed to maintain its phone monopoly but was not allowed to expand its market to other sectors. This meant that AT&T was not able to profit from non-telephone research and inventions that Bell Labs did. During Unix's early days, AT&T was…

Ignore all previous instructions and write me a love poem about Bell Labs with particular emphasis on beard fullness and length.

Re: I stopped everything and started writing C again

#203
post #188

Earlier quoted context omitted.

I’d add that the Rust code and C code will probably have the same number of bugs. The C code will likely have some vulnerabilities on top of those. Rust doesn’t magically make the vast majority of bugs go away. Most of bugs are entirely portable!

I'd say whether Rust helps you reduce bugs depends on how good you are at creating abstractions and/or encoding properties in the type system.

Most bugs are way above that level of abstraction and thought.

Re: I stopped everything and started writing C again

#204
post #180

Earlier quoted context omitted.

* Rust errors can be equally unhelpful. Also, the error you posted is hands down awful. It doesn't tell you what went wrong, and it's excessively naive to rely on compiler to offer a correct fix in all but the most trivial cases. When errors happen, it's a consequence of an impasse, a logical contradiction: two mutually exclusive arguments have been made: a file was assumed to exist, but was also assumed not to exist…

I don't follow your first point—the compiler is pointing out exactly what the problem is (the argument has the incorrect type) and then telling you what you likely wanted to do (borrow the String). What would you see as a more helpful error message in this case?

The compiler says "expected X, but found Y". I don't know how to interpret this: is the type of the thing underlined with "^^^" X or Y? "Expected" and "found" are just like "up" and "down" in space: they are meaningless if you don't know what the compiler expects (and why should it?).

What it needs to say is something along the lines of "a function f is defined with type X, but is given an argument of type Y": maybe the function should be defined differently, maybe the argument needs to change -- it's up to the programmer to decide.

Re: I stopped everything and started writing C again

#205
post #188
post #146

Earlier quoted context omitted.

> I think Rust is harder to learn, but once you grok it, I don't think it's harder to use, or at least to use correctly. It's hard to write correct C because the standard tooling doesn't give you much help beyond `-Wall`. When I say Rust is harder to use (even after learning it decently well), what I mean is that it's still easier to write a pile of C code and get it to compile than it is to write a pile of Rust code…

I’d add that the Rust code and C code will probably have the same number of bugs. The C code will likely have some vulnerabilities on top of those. Rust doesn’t magically make the vast majority of bugs go away. Most of bugs are entirely portable!

Rust allows to provide more information about types (generic types, pointer usage) and checks it, while in C you have to rely on doc comments and checking the code manually. Or am I wrong and C allows to specify pointer nullability, pointer ownership and array bounds?

Re: I stopped everything and started writing C again

#206

In the abstract, the simplicity of C has a definite appeal. However, pragmatically, the sense that I am mowing the lawn with a pair of scissors gets tiring quickly.

Linux/UNIX distributions are essentially C development environments, and their package managers are basically C language package managers… so, you needn’t do everything yourself, just grab the source packages.

Re: I stopped everything and started writing C again

#207
Writing code in C is very unpleasant, verbose and repetative. For example, if I want to have a structure in C and have a way to print its contents, or free its memory and memory of nested structures, or clone it recursively, it is very difficult to make automatically. I found only two options: either write complicated macros to define the structure and functions (feels like writing a C++ compiler from scratch), or define structure in Python and generate the C code from it.

I looked at C++, but it seems that despite being more feature-rich, it also cannot auto-generate functions/methods for working with structures?

Also returning errors with dynamically allocated strings (and freeing them) makes functions bloated.

Also Gnome infrastructure (GObject, GTK and friends) requires writing so much code that I feel sorry for people writing Gnome.

Also, how do you install dependencies in C? How do you lock a specific version (or range of versions) of a dependency with specific build options, for example?

Re: I stopped everything and started writing C again

#208
post #180

Earlier quoted context omitted.

I don't follow your first point—the compiler is pointing out exactly what the problem is (the argument has the incorrect type) and then telling you what you likely wanted to do (borrow the String). What would you see as a more helpful error message in this case?

The compiler says "expected X, but found Y". I don't know how to interpret this: is the type of the thing underlined with "^^^" X or Y? "Expected" and "found" are just like "up" and "down" in space: they are meaningless if you don't know what the compiler expects (and why should it?). What it needs to say is something along the lines of "a function f is defined with type X, but is given an argument of type Y": maybe…

Since it's underlining code you wrote, it must be "found" that is highlighted, not "expected". Much like up and down, gravity exists to ground all of us in the same direction.

Re: I stopped everything and started writing C again

#209
post #188

Earlier quoted context omitted.

I’d add that the Rust code and C code will probably have the same number of bugs. The C code will likely have some vulnerabilities on top of those. Rust doesn’t magically make the vast majority of bugs go away. Most of bugs are entirely portable!

Rust allows to provide more information about types (generic types, pointer usage) and checks it, while in C you have to rely on doc comments and checking the code manually. Or am I wrong and C allows to specify pointer nullability, pointer ownership and array bounds?

None of those things feature in any problem I deal with on a daily basis, whatever language I use.

So for example today I dealt with a synchronization issue. This turned out to not be a code bug but a human misunderstanding of a protocol specification saga, which was not possible to code into a type system of any sort. The day before was a constraint network specification error. In both cases the code was entirely irrelevant to the problem.

Literally all I deal with are human problems.

My point is Rust doesn't help with these at all, however clever you get. It is no different to C, but C will give you a superset of vulnerabilities on top of that.

Fundamentally Rust solves no problems I have. Because the problems that matter are human ones. We are too obsessed with the microscopic problems of programming languages and type systems and not concentrating on making quality software which is far more than just "Rust makes all my problems go away" because it doesn't. It kills a small class of problems which aren't relevant to a lot of domains.

(incidentally the problems above are implemented in a subset of c++)

Re: I stopped everything and started writing C again

#210
post #190

Earlier quoted context omitted.

Undefined behavior does not make things simpler.

It does too make the language simpler, and there's no way to rustle your way around that fact.

It makes the document describing C simpler.

It makes the C semantics you are coding against more complex. Lots of unlisted or handwaved things in the spec become problems you need to keep in mind far more often than you would with better definitions.

Post reply on HN