News for hackers. Stuff that matters.
Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @05:49AM (#10908443)
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 shouldn't use it; it just means we should demand high standards of the programmers and not employ some chancer who learned how to program from the back of a cereal packet. I give young children plastic safety scissors. I give competent adults chainsaws and scalpels.

Re:A critique of "How to C in 2016" by krylon on Friday January 15, 2016 @07:52AM (#10908966)
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 their respective advantages and weaknesses and then make a choice.

If I had to write a document like that, I would use a different phrasing from "if you can avoid it". But the sentiment - to avoid using C where superior alternatives exist[1] - is something I agree with.

> 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.

That is kind of like saying the solution to traffic accidents is only letting people drive that don't cause accidents or demand of people that they drive sufficiently carefully. Sure, that is something worth wishing for - but it is not very realistic to expect this to actually happen.

Not that I disagree that C is a very demanding language. Even the best programmers make mistakes. But this is the reason the author of the original document the linked article refers to advised people to avoid C where possible. Most programmers will be better off for most of their projects with a language like Go, or Python or whatever.

[1] Of course, if by "alternatives" I mean languages like Perl, Python or Ruby, it is worth keeping in mind that their main implementations are written in C.

Re:A critique of "How to C in 2016" by pjmlp on Friday January 15, 2016 @09:22AM (#10909436)
> 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" by krylon on Friday January 15, 2016 @10:06AM (#10909681)
I get your point. However, I did not say there were no alternatives, just that they were "very limited" (when compared to, say, Debian running on amd64).
Re:A critique of "How to C in 2016" by LeonidasXIV on Friday January 15, 2016 @09:08AM (#10909337)
> 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" by whyever on Friday January 15, 2016 @09:01AM (#10909305)
> to avoid using C where superior alternatives exist is something I agree with.

Who wouldn't?

Re:A critique of "How to C in 2016" by lucian1900 on Friday January 15, 2016 @06:05AM (#10908491)
As a society, we still avoid tools that are easy to misuse whenever we can. Modern chainsaws have several safety features that were missing from earlier ones and that doesn't make them less useful.

Just because the most popular systems language is dangerously unsafe doesn't mean a safe alternative couldn't replace it (like, say, Rust).

Re:A critique of "How to C in 2016" by pjmlp on Friday January 15, 2016 @05:57AM (#10908463)
See, that is the problem right there.

Even if one does find such competent programmers, I doubt they the way C culture works it would help.

Most C devs I have met, if given a memory safe systems programming language like Modula-2 or Rust, would just use SYSTEM or unsafe {} everywhere without any proof of a profiler if it really matters to the customer.

As for being available everywhere, that is an historical accident of C's adoption. I remember when C was only available in UNIX and we had things like RatC.

Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @06:51AM (#10908675)
Slightly off-topic, I'd say that the majority of programmers, C devs included, are barely competent. They know enough to bash through to something clunky and dangerous that kind of does what's needed at a demo. Whilst it's true that taking away all the dangerous tools would make it harder for this great sea of perpetual amateurs to do so much damage, I think it's not right to blame the tools.

By simply being here and reading this, you're almost by definition in the top 20% of programmers. Hyperbole, yes, and counter-examples exist, but anyone who routinely comes here will improve; the majority of programmers never do.

Re:A critique of "How to C in 2016" by omgtehlion on Friday January 15, 2016 @06:37AM (#10908614)
heck, even in c# I use unsafe{} here and there ((
Re:A critique of "How to C in 2016" by NoGravitas on Friday January 15, 2016 @02:49PM (#10911630)
))
Re:A critique of "How to C in 2016" by mchahn on Sunday January 17, 2016 @02:56AM (#10918742)
;
Re:A critique of "How to C in 2016" by stupidcar on Friday January 15, 2016 @06:02AM (#10908485)
Again, if people can't agree what type to use for integers, then it's not "simple".

And yes, a tool being easy to misuse absolutely means we shouldn't use it unless we have to. A competent adult would never use a chainsaw or a scalpel except for tasks where nothing else would work.

Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @06:28AM (#10908565)
Pick the integer type that is best suited for your use, given your circumstances.

I can't make it any simpler. There is no one true magical perfect solution for all circumstances in all places at all times. This is why I employ competent programmers; to make these choices.

A competent adult would never use a chainsaw or a scalpel except for tasks where nothing else would work.

Of course they would. I do, frequently; not chainsaws and scalpels, but there are dangerous tools that I am really good with that I can produce really good work with, quickly and efficiently, and there are safe tools that would mean I take longer and can't do exactly what I want to do and produce a less satisfactory result. I don't pick the safe tool; I pick the right tool for the job, given the circumstances and the requirements.

Are there people who deliberately pick the tool that will give a worse outcome? If one of the tools available is something that the person using it isn't competent to use, that doesn't mean the problem is with the tool.

I freely accept that a good C programmer needs knowledge and experience beyond that of many programmers. This is not somehow a bad thing.

Re:A critique of "How to C in 2016" by anon1385 on Friday January 15, 2016 @06:36AM (#10908605)
>Pick the integer type that is best suited for your use, given your circumstances.

>Pick the fission reactor type that is best suited for your use, given your circumstances.

Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @06:42AM (#10908630)
I cannot tell if you are in favour of, or against, the principle that one should pick the right tool for the job.
Re:A critique of "How to C in 2016" by anon1385 on Friday January 15, 2016 @07:09AM (#10908756)
Saying "just pick the right tool" is a worthless statement when the question is the difficulty of doing that. Would you enter a discussion about curing cancer or depression and announce "just pick the right cure for the disease" and then get upset when people don't agree with you?
Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @07:19AM (#10908812)
Now I can understand your argument. I upvoted you because I like to encourage clarity. This sounds patronising but that's the limitations of a text interface for you.

I think you're arguing that sometimes it's difficult to work out what the right tool is for the job. That's true, and not what I'm talking about. I'm saying that the principle of selecting the right tool for the job is sound, and that sometimes C is the right tool for the job and should be selected.

Re:A critique of "How to C in 2016" by anon1385 on Friday January 15, 2016 @08:22AM (#10909104)
The chain of discussion:

>Because [C] is simple

>Again, if people can't agree what type to use for integers, then it's not "simple".

>Pick the integer type that is best suited for your use, given your circumstances.

It had nothing to do with deciding to pick C. It was about the difficulty of picking integer types in C being a demonstration of how C isn't simple. That doesn't mean C isn't sometimes the right tool for the job. It does mean that C isn't simple.

Re:A critique of "How to C in 2016" by stupidcar on Friday January 15, 2016 @07:00AM (#10908713)
Look, nobody cares how clever and talented a programmer you are, or think you are. Please just drop the unsubtle boasting and passive aggressive insults, they only make you sound like an insecure egotist. Concentrate on the actual issue.

In 99.9% of languages, there is one true magical perfect solution to a question as basic as "what type should I use for integers?", and it's "use the integer type". The fact that C not only has options in this case, but that experienced developers seemingly cannot even agree on best practices, is a very good reason to avoid using the language unless you have to.

Re:A critique of "How to C in 2016" by jevgeni on Friday January 15, 2016 @08:26AM (#10909125)
The reason why C has several integer types, is because there are different ways to represent integers for computers. Everything else is convention.

I mean, if that bothers you, then meta-programming in Ruby and Python, as well as different lisps should really bum you out.

Re:A critique of "How to C in 2016" by ketzu on Friday January 15, 2016 @07:04AM (#10908730)
I think what the discussion about this statement misses is the "unless you need to" part. There are cases where you should use C! It is not "never ever use C".

If the use-case is being able to run on everything from TigerSHARC to x64, you probably should use C. If you want a GUI based Windows App or a webapplication, that might not be a "you need to use C" case.

Re:A critique of "How to C in 2016" by Avshalom on Friday January 15, 2016 @06:15AM (#10908525)
Those compilers exist because of path dependency from unix not from any unique qualities of C
Re:A critique of "How to C in 2016" by EliRivers on Friday January 15, 2016 @06:34AM (#10908592)
This makes no sense and I believe you are incorrect. When Analog Devices churned out the TigerSHARC processor, they did not decide to write a C compiler for it because of unix path dependencies.
Re:A critique of "How to C in 2016" by Avshalom on Friday January 15, 2016 @08:02AM (#10909018)
When Analog Devices churned out the TigerSHARC processor they wrote a c compiler because "C is what you use for low level code" not Forth, Pascal, Modula, Ada, Fortran, Algol, a lisp or any of the other hundreds of programming languages that have been used to write programs directly on metal on computers that the TigerSHARC outclasses by magnitudes.

and "c is what you use for low level code" because decades of Unix. Decades of C being the lowest (non-assembly) level of programmers' systems, decades of being the only language that doesn't make you install an additional runtime, decades of accumulated wisdom...

But those are a side effects of Unix winning, not C qua C.

Re:A critique of "How to C in 2016" by pjmlp on Friday January 15, 2016 @07:33AM (#10908883)
C become widespread because of UNIX, just like JavaScript got widespread because of the browsers ubiquity.

Eventually developers wanted to take home to their 8 bit computers what they were coding at the university and work.

So RatC, Small-C and many other C dialects were born.

Just like node.js nowadays, with UNIX adoption becoming the basis of the 80's graphical workstations, the pressure to have easy access to C compilers increased.

Also back in the day, one paid for compilers, so the majority went to whatever what the OS official system programming language.

So this is how we ended up in this situation.