Ironic that he begins by taking issue with the idea that you should avoid writing C if you can, then proceeds to provide the best evidence possible for why it's true. Why on Earth would you voluntarily code in a language where people can debate something as simple as which type to use for integers, unless you absolutely had to?
"Why on Earth would you voluntarily code in a language where people can debate something as simple as which type to use for integers, unless you absolutely had to?" Because we have no alternatives so far. I do C programming for a living, but I'd be more than happy if there were some type and memory safe language I could use to program any tiny, obscure MCU, that could stay at least in the same order of magnitude of s…
A critique of "How to C in 2016"
171–180 of 181 posts
Re: A critique of "How to C in 2016"
#172Earlier quoted context omitted.
> For example I never could understand why we need enums. > Why should I ever put const in the argument of a function? Reducing potential state and conveying programmer intent. Both lead to safer and more performant code (by way of compiler optimizations).
What you say is incompatible with the "Cross-platform assemble", simple language ideals. If that was the intent why not throw namespaces and other goodies in?
Defining sets (enums) and memory access constraints (consts). I wouldn't describe that as high level from a conceptual or practical perspective. Namespaces are simple conceptually but not in practice. The same can be said about the beautiful logical consistency of S-expressions.
Re: A critique of "How to C in 2016"
#173Earlier quoted context omitted.
> imagine some 20 year old college student - is "Am I ready to pick a denomination and religion and read hundreds to thousands of pages of gospel?" There is no such barrier with any other language. Haskell comes to mind. There's a denomination and a religion. I'm not sure that the gospel runs to hundreds of pages, but there are many prophets who tell you that you need to know category theory, so for that sect, yes, i…
> but there are many prophets who tell you that you need to know category theory I challenge you to show me one!
My impression is that Haskell "experts" here say some variant of "of course all this is obvious because category theory" (implying "you have to know category theory or you're an uneducated heathen") at least three times as often as they say "you don't really need to know category theory".
Re: A critique of "How to C in 2016"
#174Earlier quoted context omitted.
> ehmmmm standard C has floats and doubles. so they are valid C Sure, but the standard says hardly anything about their behaviour, making it practically impossible to write code that actually does anything with floats and doubles that will behave correctly on any standards-compliant C implementation. I suggest you refrain from personal attacks, especially based on your own misreadings of the comment you're replying t…
>but the standard says hardly anything about their behaviour, making it practically impossible to write code that actually does anything with floats and doubles that will behave correctly on any standards-compliant C implementation. No, not really. This reminds me the common "you can't write anything serious in C without undefined behaviour" bs. However, if you DO have a real need of IEEE-compatible floats for whatev…
Sure - but in that case why not do the same thing for insisting that char be 8 bits?
Re: A critique of "How to C in 2016"
#175Earlier quoted context omitted.
>but the standard says hardly anything about their behaviour, making it practically impossible to write code that actually does anything with floats and doubles that will behave correctly on any standards-compliant C implementation. No, not really. This reminds me the common "you can't write anything serious in C without undefined behaviour" bs. However, if you DO have a real need of IEEE-compatible floats for whatev…
> However, if you DO have a real need of IEEE-compatible floats for whatever reason, then there is nothing wrong with checking __STDC_IEC_559__ and reporting an error if it is not defined. Sure - but in that case why not do the same thing for insisting that char be 8 bits?
If it does limit you somehow and you really need char be 8 bits, then sure.
Re: A critique of "How to C in 2016"
#176The discussion usually boils down to a. We need a better C b. We need better programmers. Personally I believe C tries to hard to be high level instead of what it really is. Newer revisions should try to make it lower level. For example I never could understand why we need enums. Enums are very useful for Java or Golang which are high-level. C never needs enums. Why should I ever put const in the argument of a functi…
Re: A critique of "How to C in 2016"
#177Earlier quoted context omitted.
There is no reinventing going on here. In C you have to write relatively low level code. This includes manually calling allocs for objects, which includes the code for checking your arithmetic. At some point you will have to write that code. If you are smart you will wrap it into a function.
I don't see the point of the discussion, that piece of code (or relatively equivalent), is already being performed by a libC function (calloc, in this case), how is that less convenient than you writing it yourself? It has nothing to do with how smart you are or how low level C is, you are effectively reinventing that part of calloc by wrapping malloc.
That's why OpenBSD has reallocarray(3) (which serves as a fine malloc, though the kernel not having reallocation has mallocarray(9))
Re: A critique of "How to C in 2016"
#178Earlier quoted context omitted.
> but there are many prophets who tell you that you need to know category theory I challenge you to show me one!
If I knew of a decent search function for HN comments, I could show you several. As it is, I can only offer my memory of what I have read in the comments here. My impression is that Haskell "experts" here say some variant of "of course all this is obvious because category theory" (implying "you have to know category theory or you're an uneducated heathen") at least three times as often as they say "you don't really n…
Re: A critique of "How to C in 2016"
#179Re: A critique of "How to C in 2016"
#180Earlier quoted context omitted.
"Why on Earth would you voluntarily code in a language where people can debate something as simple as which type to use for integers, unless you absolutely had to?" Because we have no alternatives so far. I do C programming for a living, but I'd be more than happy if there were some type and memory safe language I could use to program any tiny, obscure MCU, that could stay at least in the same order of magnitude of s…
What do you think Rust needs to do to become viable in the embedded world?