Live data from Hacker News

A critique of "How to C in 2016"

github.com

121–130 of 181 posts

Re: A critique of "How to C in 2016"

#121
post #98

Earlier quoted context omitted.

Because it's simple and low-overhead and compilers for it exist on every lump of hardware I've ever had to work with, from a clunky x64 to a PIC to a TigerSHARC to a bizarre DSP thingy from a tiny fab lab somewhere. A great many of the problems that people experience with C code can actually be nullified (zing!) by finding a competent C programmer who does the job properly. A tool being easy to misuse doesn't mean we…

The key phrase here is " if you can avoid it". When your target platform is an 8-bit microcontroller or an embedded system with hard real-time requirements, your options are very limited. But there are plenty of situations where there are alternatives, and often these allow you to solve your problem in less time, with much lower risk of bugs than in C. As always in life, one has to evaluate one's options, consider th…

> When your target platform is an 8-bit microcontroller

Funnily enough, you could use OCaml on PIC18 (which are as far as I know 8-bit microcontrollers) using OcaPIC[1]. I was thinking of getting one of those and implementing a keyboard firmware on it.

[1] http://www.algo-prog.info/ocaml_for_pic/web/index.php?id=oca...

Re: A critique of "How to C in 2016"

#122

This, ladies and gentlemen, is why C gives me the willies. And why this happens: http://www.cvedetails.com/vulnerability-list/year-2016/month...

Those are due to programmer error. The fact that C doesn't lie to you means that it takes a bit more experience to program properly; as with all things, with great power comes great responsibility. You don't blame the gun for killing people, you blame the person for shooting it.

Not even the very best C programmers will write memory safe code. When you write C you will write exploitable code, no matter who you are. Don't blame the programmer for stepping onto a mine in the minefield, blame the minefield.

Re: A critique of "How to C in 2016"

#123

Earlier quoted context omitted.

By the same argument we shouldn't assume that bits have only two values - what, you mean I can't write C for my ternary logic computer? You need to make a decision about which simplifying assumptions you make - C has decided not to assume there are 8 bits to the byte. I think it's arguable that in 2016 this is not the best decision, and they could get rid of some cognitive overhead by making the simplifying assumptio…

Unfortunately, there are real world systems with C compilers that do not have 8 bit bytes. It's easy to forget the embedded world. C is one of the very, very few languages that you can reasonably expect to run on your weird embedded microprocessor, microcontroller, DSP, or whatever. Bit, however, means "binary digit". That's the literal definition of the word. Historical usage of the word "byte" has varied.

As a male human of questionable maturity, I'd just like to say that I am really looking forward to working with ternary digits!

Re: A critique of "How to C in 2016"

#124
post #79

Earlier quoted context omitted.

Sure, but in a way C is the JavaScript of systems programming languages, in a deep need of a "The Good Parts" book as well.

I'm sorry, but is this comment a joke? Have you ever read "The C Programming Language", and seen how simple C is? These arguments that the two OPs are having are important, but only when faced with obscure architectures that nearly nothing but C will run on. Conversely, JavaScript's failures are not because of the wide variety of architectures that it supports (a tiny fraction of C's), but instead on the monolithic a…

It is not a joke, rather the conclusion of someone that was already dismayed with C back in the mid-90's.

> If you read "The C Programming Language", you'll realize that in the ~240 pages of text, you know basically every feature of the language.

Except for those little compiler specific little issues, it seems:

http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

http://blog.regehr.org/archives/213

http://blog.regehr.org/archives/226

http://blog.regehr.org/archives/232

> It's small, and it's elegant, and it's portable

Have you had the pleasure to port C code across multiple C compilers and OS in the mid-90's?

Re: A critique of "How to C in 2016"

#125
post #79

Earlier quoted context omitted.

Sure, but in a way C is the JavaScript of systems programming languages, in a deep need of a "The Good Parts" book as well.

I'm sorry, but is this comment a joke? Have you ever read "The C Programming Language", and seen how simple C is? These arguments that the two OPs are having are important, but only when faced with obscure architectures that nearly nothing but C will run on. Conversely, JavaScript's failures are not because of the wide variety of architectures that it supports (a tiny fraction of C's), but instead on the monolithic a…

When you're done with The C Programming Language, read Expert C Programming, C Traps and Pitfalls, and The C Puzzle Book. Then tell me how simple C is.

Re: A critique of "How to C in 2016"

#126
post #79

Earlier quoted context omitted.

Sure, but in a way C is the JavaScript of systems programming languages, in a deep need of a "The Good Parts" book as well.

I'm sorry, but is this comment a joke? Have you ever read "The C Programming Language", and seen how simple C is? These arguments that the two OPs are having are important, but only when faced with obscure architectures that nearly nothing but C will run on. Conversely, JavaScript's failures are not because of the wide variety of architectures that it supports (a tiny fraction of C's), but instead on the monolithic a…

C is not simple.

Re: A critique of "How to C in 2016"

#127
post #79

Earlier quoted context omitted.

Sure, but in a way C is the JavaScript of systems programming languages, in a deep need of a "The Good Parts" book as well.

I'm sorry, but is this comment a joke? Have you ever read "The C Programming Language", and seen how simple C is? These arguments that the two OPs are having are important, but only when faced with obscure architectures that nearly nothing but C will run on. Conversely, JavaScript's failures are not because of the wide variety of architectures that it supports (a tiny fraction of C's), but instead on the monolithic a…

Have you read "Expert C Programming: Deep C Secrets"? That book will show you that a simple language does not mean that programming in it is simple.

On a related note, I believe "The C Programming Language" is not a good book for the realities of 2016.

Re: A critique of "How to C in 2016"

#128

This, ladies and gentlemen, is why C gives me the willies. And why this happens: http://www.cvedetails.com/vulnerability-list/year-2016/month...

Those are due to programmer error. The fact that C doesn't lie to you means that it takes a bit more experience to program properly; as with all things, with great power comes great responsibility. You don't blame the gun for killing people, you blame the person for shooting it.

> Those are due to programmer error.

How does that help? Almost all security vulnerabilities are due to programmer error.

> You don't blame the gun for killing people, you blame the person for shooting it.

It's more like choosing between a gun that makes it really easy to shoot yourself in the foot by accident and one that is safer.

Re: A critique of "How to C in 2016"

#129
post #98

Earlier quoted context omitted.

Because it's simple and low-overhead and compilers for it exist on every lump of hardware I've ever had to work with, from a clunky x64 to a PIC to a TigerSHARC to a bizarre DSP thingy from a tiny fab lab somewhere. A great many of the problems that people experience with C code can actually be nullified (zing!) by finding a competent C programmer who does the job properly. A tool being easy to misuse doesn't mean we…

The key phrase here is " if you can avoid it". When your target platform is an 8-bit microcontroller or an embedded system with hard real-time requirements, your options are very limited. But there are plenty of situations where there are alternatives, and often these allow you to solve your problem in less time, with much lower risk of bugs than in C. As always in life, one has to evaluate one's options, consider th…

> When your target platform is an 8-bit microcontroller or an embedded system with hard real-time requirements, your options are very limited.

You mean like the CPUs supported by MikroElektronika's Pascal and Basic compilers?

http://www.mikroe.com/8051/

http://www.mikroe.com/pic/

http://www.mikroe.com/avr/

Re: A critique of "How to C in 2016"

#130
post #5

> Zeroing memory often means that buggy code will have consistent behavior; by definition it will not have correct behavior. And consistently incorrect behavior can be more difficult to track down. I agree that using calloc should not be an excuse for writing sloppy initialization code. But in my experience, inconsistently incorrect behaviour (e.g. heisenbugs that tend to appear and disappear depending on the content…

I mean, reading zeroed out memory is not really incorrect behaviour anyway. If you know that it was zeroed out, then you're really just reading memory that was initialised with a specific default value. That being said, zeroing out everything you allocate will make it difficult for the kernel's paging system to defer allocating you a physical page until you actually need it, so you will need to be a lot more careful…

Unless the zeroing is defined by the language, assuming it t is incorrect and shouldn't be done.
Post reply on HN