5 ms·
C is a simple language and at least used to be a language almost everyone knew. I don’t know why they’re writing the parser using globals though instead of pas
by david2ndaccount 5y ago
C is a simple language and at least used to be a language almost everyone knew.
I don’t know why they’re writing the parser using globals though instead of passing a pointer to a parser state struct.
- arcticbull 5y agoC is an incredibly complex language, it just appears simple. It's simple to get started and incredibly hard to do correctly, like skiing.
- retrac 5y agoNo, those things are not a complexity of C. They're just complex to implement at a lower level. They're complicated in any language, often, if approached at the level C provides. You have to hand-hold the machine through it. A C-like implementation of linked lists in an array of memory using pointers, for example, looks just as bad if written in that way in unsafe {} Rust, or even some mutating thing in Haskell. You can do that if you want, but you don't have to. Those languages allow you to abstract that away very quickly (often already pre-abstracted for you with default approaches). That's what people mean when they say C is simple. Plain and simple. Minimal. You have to do much of the heavy lifting.
- arcticbull 5y agoRespectfully disagree. A language that fails to adequately provide safeguards to a user is a complex language because it forces all the complexity of dealing with the underlying machine onto the user. These are things a user needs to know to be effective in the language, which in turn makes using the language complex. It's a deceptively simple language. C is complex because of what it doesn't do, not what it does. That's IMO worse.
- retrac 5y agoIt's not so much that we're disagreeing as arguing different points about the language, I think. You are right that it is not a simple language to use, in many ways. Archaic, unnecessarily complicated to implement many standard approaches, and very repetitive. The header system is just the wrong approach. Etc. I wouldn't pick it for the main language for a new project, if at all avoidable personally. It's very easy to implement, though. A compiler fits in 32 kilobytes of RAM on some architectures. Only a handful of control structures. Limited types. That's the sense of simple that I meant, and which most people meant. It's not a compliment. It's a neutral observation. It's actually C's greatest weakness. It's too simple.
- arcticbull 5y agoI think we’re in violent agreement :)
- IdiocyInAction 5y agoC itself is not particularly complex, especially compared to other languages, like C++. It does have a ton of footguns and nasty UB things though. But writing good, safe code in C can be very complex. That doesn't make the language itself is complex.
- int_19h 5y agoParsers involve a lot of string processing, which is really inconvenient and easy to get wrong in C.
- gnubison 5y agoWell, only the lexer deals with strings, and even then… it’s not really creating strings, just extracting some information from them. Creating strings efficiently and safely is IMO the hard part of string management in C.
- userbinator 5y agoI don’t know why they’re writing the parser using globals though instead of passing a pointer to a parser state struct. Because there's only one. Why obfuscate that fact? Don't be tempted by the cargo-cult to make things more complex than they need to be just to appease some dogmatic "best" practices that actually aren't.
- throwaway17_17 5y agoI think this is a really good example to point to in discussions of ‘cargo-cult’-ing. GP is merely reciting the standard ‘best’ practice for development in C, and on a more complex project or in another use case, they may be correct to do so. However, as you pointed out, in this case the globals are true single instance ‘objects’ and the use is semantically sensible and justified. It dovetails nicely with some of the DoD vs ECS discussion from the front page earlier today. Do what makes the most sense for your use case for reasons that apply to your project, everything else is abstraction.