News for hackers. Stuff that matters.
Re:On the history and justification of the C programming lan... by nickpsecurity on Thursday August 18, 2016 @05:16PM (#12316384)
"... as if all development of C stopped with the first ANSI standard?"

The purpose of the text was to trace why the specific problems in C exist. Its proponents claimed all sorts of justifications and design tradeoffs. After digging through source papers, I found most of these were myths with two, real justifications: hardware constraints & personal preferences. What happened latter on in C didn't matter as core problems were due to the EDSAC, PDP-7, and PDP-11 hardware constraints plus personal tradeoffs of authors. The point is that (a) it wasn't actually designed that way for a good reason (just chopped due to constraints), (b) the possibly good justifications for chopping safety/maintenance no longer applied with better hardware, and (c) people should stop repeating misinformation that there was some grander reason they were there so we can adapt language to new constraints. We might get more improvements on C itself or alternatives as more C users understand there is no grand reason behind the root causes of problems: only due to constraints on hardware you can't buy any more.

"They still have the usual warts but the tooling is great and support is coming along for the newest features to most platforms."

C is bad at the foundation. Alternatives, esp variants on Wirth's stuff, was better within a decade or so. By then, people should be building on better foundations & improving C's. Some even did but little uptake over inertia & backward compatibility. Social & economic thing, not technical.

"As a high-level language, C is one of the few that gives the programmer some control over how memory is mapped to the target platform and allows them to build the appropriate abstractions on that hardware."

There's been safer alternatives that could do that at various points. I'll consider including them in a future version.

" humans make mistakes and inevitably those mistakes make it into our programs. When working in a language like C one must conduct ones self accordingly."

This is sort of a strawman that C proponents critically depend on. C makes many common operations unsafe by default where alternatives, esp like Modula-2, make it safer by default with ability to go UNSAFE if performance or low-level absolutely depend on it with that contained in a module. The reason these problems are in C language by default is nobody changed them. The reason they entered the language early on are the people who invented that philosophy & tech in BCPL had an EDSAC, next had a PDP-7, next had a PDP-11, and none of the three tried a safe subset of ALGOL like Hansen & Wirth did. Both of those built on PDP-11's. Hardware constraints, personal preferences, and not caring about safety/maintenance. That's it.

Once you know this, there's no reason on modern hardware to do a clean-slate project in C if usable alternatives exist. Then someone mentions libraries or compilers. Many safe languages do a strong FFI for C or can compile to equivalent C code. So you still don't need C's problems at level you work with. Then someone mentions talent availability for C. The funny thing about that is that there's very little talent that can write robust, C apps esp under pressure of management to ship fast and including poorly-documented, 3rd-party libs. Only good counter-argument I've seen for using C was, ironically, in safety-critical from a NASA guy pointing out their people with years of C coding using a C subset w/ C testing rigs and four, static analyzers were collectively better bet than clean-slate language w/ less tooling on a project where absolutely everything has to be right. That was true but not the typical situation. ;)

"It'd be nice to be able to define how memory should be handled for a particular application at the granularity of the target platform while still getting the safety guarantees."

Stuff like that already exists and non-experts rewrote ext2 filesystem in it successfully:

https://ts.data61.csiro.au/projects/TS/cogent.pml

Currently using C as the output language given (a) compiler advantage as above and (b) they have the tooling to formally check it via that organizations' work on seL4 project. The part that verifies C is actually a simpler, formally-speced language/framework called Simpl that they embed C into. Myreen et al can go from specs to machine code directly with verified translation, which seL4 used IIRC. So, COGENT could probably go right to machine code via those without C at all. Outputing C is just very practical given their constraints and goals.

I've always suggested modifying PreScheme to do what you said, though. It was a low-level, efficient Scheme meant as a C alternative which outputed C to leverage compilers & optimizations. It and Scheme48 were mathematically verified for correctness in VLISP project. One could add Oberon, SPARK or Rust style checks to PreScheme with ability to turn them off. Basic ones wouldn't be a lot of work at all given it's so small.

https://en.wikipedia.org/wiki/PreScheme

You might also find Habit interesting. It was designed by those behind the House operating system, a Haskell OS. They were designing a new language, Habit, that did things like bit control. They got poached onto a better project IIRC but published a bit on Habit:

http://hasp.cs.pdx.edu/habit-report-Nov2010.pdf

So, there's you three, different approaches to the problem with functional/safe bent.

Re:On the history and justification of the C programming lan... by hga on Thursday August 18, 2016 @05:59PM (#12316632)
Myreen et al can go from specs to machine code directly with verified translation, which seL4 used IIRC.

His special method is to meet in the middle, to analyze the binary code and "turn it into logic" and then check that against the higher level spec. Or something to that effect.

They tried CompCert but there was evidently too great an impedance mismatch. Good thing, too, since CompCert isn't free for most uses.

Re:On the history and justification of the C programming lan... by nickpsecurity on Thursday August 18, 2016 @08:02PM (#12317136)
Basically. The good news is CompCert might not be needed. Remember that seL4 bypassed need for CompCert by somehow translating it directly to ASM. I found out they used Myreen et al's method.

https://www.cl.cam.ac.uk/~mom22/stacks.html

Their work is mindblowing. There's almost no TCB left lol. I still want diverse verifiers in diverse logics and machine codes to verify the HOL checkers and such. I don't trust their verify it in itself sort of method. Not entirely. They do have a nice projects page for CakeML listing each improvement that would be useful and skill estimate. More should do that.

Look at NICTA's COGENT, too. It's open-source now with an ext2 implementation partly or mostly done.

https://ts.data61.csiro.au/projects/TS/cogent.pml

Here's the Simpl language I referenced that's I believe at the heart of AutoCorres tool. They embedded C in it but it's not C specific.

https://www.isa-afp.org/entries/Simpl.shtml

Re:On the history and justification of the C programming lan... by agentultra on Thursday August 18, 2016 @08:04PM (#12317149)
Thanks for this amazing reply. If only you, catnaroek, and I were able to sit down over coffee for an hour or two.

This has been a fascinating thread.

Re:On the history and justification of the C programming lan... by nickpsecurity on Thursday August 18, 2016 @08:39PM (#12317269)
That would be fun. The thread has been more interesting than I thought it would be. Probably thanks to Tomte changing the title haha. We'll all have to have that coffee sometime.