9 ms·
Then you are seeing what you want to see. People are straightforwardly arguing that C is semantically rich which is indeed laughable. I have addressed the point
by WastingMyTime89 4y ago
Then you are seeing what you want to see. People are straightforwardly arguing that C is semantically rich which is indeed laughable. I have addressed the point under but clearly a lot of you don’t understand what language semantics are.
Considering I was having interesting discussion about the subtleties of the Hindley-Milner type system on this same website a decade ago, yes, I do think HN is becoming a joke. The joke is on me however because apparently I keep commenting for reasons which are not always apparent to me I must confess.
- asveikau 4y agoThere are plenty of interesting C works out there, as well as data structures or algorithms that C can express elegantly. Small example, linked lists. I don't think non-C linked list code tends to be as straightforward as I've seen in C. Or the character-at-a-time style of string processing. It's kind of unique to C. You can say there is stuff about that you don't like. That's fine. Linked lists suck with modern CPU caches anyway. C strings have lots of misadventures in terms of buffer overflows. But it's unique and interesting. Lots of elegant things have been written this way. Your unfamiliarity with it doesn't make it "a joke" to point this out. I have my own gripes with HN. Try mentioning politics and it brings out all sorts of fascist-sympathizing crazies. But saying good to neutral things about C (while not even universally praising it) is not one of those issues.
- Koshkin 4y ago> as straightforward as I've seen in C To be fair, the most straightforward definition of the linked list is generic, and C completely lacks such facility. > fascist- Sounds familiar. https://news.ycombinator.com/item?id=33478321 https://news.ycombinator.com/item?id=33478321
- asveikau 4y ago> C completely lacks such facility. Generic linked lists can be done with pointer casts. See the way the Linux kernel does it. The list manipulation routine takes a pointer to a member, and the more specific type is opaque. The code that knows what the actual structure is can derive it from a node pointer. A structure can even have multiple node pointers in this scheme.
- kazinator 4y agoGeneric facilities can be opinionated. There are various ways to skin the cat, with different tradeoffs. Template mechanisms cause code bloat and encapsulation violations: having to reveal the entire implementation to the clients so they can instantiate it for whatever type they want. Some generic mechanisms have dumb restrictions, like you can make a "list of integer", whose elements, sadly, all have to be integers. In C you can envision what you want genericity to look like at the detailed bit-and-byte memory level, and how you'd like to be able to work with it at the language level, pick some compromises where the two are at odds, and make it happen. It is false to say that C completely lacks any generic facility because it has union types. Using a union we can put several types into a structure along with a type field which indicates which. We can overlay an integer, character, floating-point number, or pointer to something outside of the node.
- imran0 4y ago> Sounds familiar. I cannot decide whether it's an honor or an insult to be called a _fascist sympathizer_ for opposing the authoritarian suppression of speech.
- asveikau 4y agoI didn't want to address this because it's a tangent, but I understand that free speech protects expressing fascist thought. I can still disapprove of it and not want to be around a lot of it, consider high concentrations of it to be a sign of an unhealthy community, without saying it should be somehow illegal.
- WastingMyTime89 4y agoI am extremely familiar with C. I used to work on a static analyser for it. The issue is that there is very little to like in how C is designed from a PL point of view. You are confusing what the language can do and what is semantic is. C strings are just a contiguous allocation of byte and a bunch of functions which interprets it as ascii characters and stop on a specific value. That’s literally the worst representation of a string you can have.
- kazinator 4y agoI think it's a nice representation, allowing easy recursion. const char *my_strchr(const char *str, int ch) { if (*str == 0) return NULL; if (*str == ch) return str; return my_strchr(str + 1); } It's a good format for storage and communication. Name any other string data structure and I will cite you all the disadvantages compared to the C string. - If the format contains pointers, you have to marshal it to a flat representation to communicate or store it. The C string is already marshaled. - If the format contains size fields, their own size matters: are they 16, 32, 64. What byte order? Again, needs marshaling. You might think not if going between two processes on the same machine. But, oops, one is 32 bit the other 64 ... I shudder to think of what FFIs would look like, if C strings were something else. It's the one easy thing in foreign interfacing. C programs themselves sometimes come up with alternative string representations, for good reasons; but those representations don't interoperate with anything outside of those programs, or groups of closely related programs.
- WastingMyTime89 4y agoC null terminated strings are not magic. Protocols between the sender and receiver have to be defined. You face exactly the same problem regarding byte order, size consideration and marshalling with C strings. You are basically arguing that C strings are a good default because they are the default. If they were something else, well, we would have saner FFI in a lot of place. C strings are a terrible default. They are fundamentally unsafe. Mishandle the null char for any reason and you now face a serious security issue.