5 ms·
It's such a shame that C gets some things like strings so wrong. Writing in C shouldn't have to be so painful, but I guess they were the pioneers in a lot of t
by raverbashing 7y ago
It's such a shame that C gets some things like strings so wrong.
Writing in C shouldn't have to be so painful, but I guess they were the pioneers in a lot of things and the "high level assembly" idea stuck. (Premature optimization?)
Also having objects and method calls, even if it's syntactic sugar deep down, is the best kind of syntactic sugar
- saagarjha 7y agoI think you're looking for C++, or maybe Rust.
- compiler-guy 7y agoThere was nothing "premature" about C's "high-level assembly" idea. It is somewhat archaic now, but C took off because it was so, so much better than normal assembly. If handling strings in plain C is hard, handling them in assembly is 10x as hard.
- saagarjha 7y agorepne scasb disagrees with you :)
- compiler-guy 7y agoAs would many other assembly instructions on many other architectures.... and thereby proving my point. :-)
- MadWombat 7y agoThis is kind of the point of C. It maps directly to the hardware. There are very few decisions the compiler has to make about the code. And it is for that reason that C does not allow for higher level abstractions. On one hand, it is a pain to write. On the other hand, you know exactly what is going on under the hood and nothing is ever going to stop you from shooting yourself in a body part of your choice :)
- kllrnohj 7y ago> This is kind of the point of C. It maps directly to the hardware. No it doesn't. It didn't in the past, it was a high-level abstraction. And it doesn't today, because CPUs don't behave at all like C's defined virtual machine.
- justinmeiners 7y ago> CPUs don't behave at all like C's defined virtual machine What "virtual machine" are you referring to?
- saagarjha 7y agoThe one defined in the standard.
- anticensor 7y agoOne that ISO 9899 refers to as its abstract machine.
- ncmncm 7y agoC gives the illusion of mapping to the hardware. Hardware manufacturers have moved heaven and earth to help maintain the illusion. It finally got too hard and they had to admit atomics and cores ro the model. The next watershed will be along soon enough, but the ability to present as a C machine has long been the gateway to success or failure of a new hardware architecture. Myriads of arguably superior machine designs have foundered on "but can I code for it in C?"
- tinus_hn 7y agoHow can it map directly to the hardware and be portable at the same time?
- wahern 7y agoC's model is great for implementing complex, efficient data structures. Pointers are an amazing abstraction. But in many respects strings are the antithesis of a data structure, and unsurprisingly C falters hard. The problem is that most programmers don't build data structures; they build Rube Goldberg machines for munging strings, even when they're using low-level languages. Data structures to most programmers are things you import into your Rube Goldberg machine. They don't understand that good programs are made of layers of meticulously crafted, bespoke data structures where the final product is effectively one giant data structure tailored for a particular task, with interfaces to match. It follows that good C programs don't do very much strings munging even if all they do is process text. The text is systematically atomized from the very beginning. The same is true for good programs in any other language.
- klingonopera 7y ago"It's such a shame that human beings get some concepts like strings so wrong." - C language Strings are "unnatural" to the binary system, it's a human concept.