News for hackers. Stuff that matters.
Re:Let’s Stop Bashing C by kstrauser on Friday December 02, 2016 @11:06AM (#13089707)
My complaint against C is that some of the smartest people on the planet use it to write infrastructure that regularly fails catastrophically. If the experts who love it aren't capable of writing correct code, I have no chance whatsoever. Humans just aren't good at the fiddly bits (remembering to free(); not to free() twice; not to use after free(); accidentally adding a second clause to a non-bracketed if expression; how many times to we see these in vulnerability reports?).

C is obviously very powerful. There's no denying that. But it does approximately zero of the things to help programmers that a modern language does. It's not even strongly typed in the usual sense (is there the equivalent of casting void pointers anywhere else?).

Finally, C is slow. Yeah, you read that right. Its main problem is that it has no non-wizardry high level semantics for parallelism. For example, modern languages have map() to say "do this operation on all of these items". In C, you have to write that as "for each item in this collection, do this thing, then the next, then the next, ...". If the compiler is exceptionally smart, it might infer what's going on and help out. But with map(), you're explicitly telling the language "I want all of these things to be done" and it doesn't have to infer anything.

I respect C. It's given us a lot of great stuff. But there's no way I'd willingly start a new project in C today given the alternatives. I am dumb, and given the choice between languages which help me and languages which are basically a small step up from assembler, I'm going with one that gives me a reasonable shot at writing safe, fast, and understandable code.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @11:42AM (#13090070)
My concern is this seems like it's own fallacy now. You are assuming the same experts could have written these systems in another language.

Could they? Maybe. But there is no solid evidence that they could.

Is the argument appealing? Yes. But it is lacking the evidence of these systems that could be better in other languages.

My 2 cents for why, is that c is basically the only game in town that can easily use new and special assembly. Of which there is a lot. Consider, what is the fastest way to calculate a square root? And how old is that instruction? (I'm assuming it is actually used by higher level languages by now.)

Re:Let’s Stop Bashing C by jerf on Friday December 02, 2016 @12:13PM (#13090362)
As someone who is already fairly hostile to C and actually getting even more hostile over time (the recent shenanigans where the compilers are cracking down on "undefined" behavior with "optimizations", in a language where it's virtually impossible to avoid "undefined" behavior at scale, is insane), part of my hostility is precisely that there there have historically been no other engineering-valid alternatives. (There have been alternatives, just not ones you would have been wise to bet your career on.) It is an example of one of the worst local optimas we can find in computer programming, where something comes out that is pretty good for its time, and then entrenches itself so thoroughly that nothing can ever extract it ever again even though it isn't actually a great foundation to build on for decades at a time.

Other examples include SQL, Javascript (though WebAssembly may free us from that before we're stuck with it in 2040), and Unix.

When I say this sort of thing, people tend to flip out and start defending those techs against the claim that I don't think they're good at all. That's not the problem. They are good. The problem is that they're not good enough to build on for the future, but they are good enough to entrench themselves.

The consequence is that it takes a lot of riling up the community with knowledge of the shortcomings to fertilize the ground for alternatives to arise and be supported enough to make progress.

So, please stop defending C. It is what it is. It had a good run. Nothing will ever make it stop being the most important language of the last four decades. But if you don't want it to be the most important language of the next four decades... and you really shouldn't... please stop defending it. Give the alternatives space to breathe.

$OBLIGATORY_RUST_CALLOUT.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @12:21PM (#13090436)
I'm not defending C. If anything, I'm attacking all of the so called "better" replacements. Specifically your call out that they should have existed by now. I treat that argument as a fallacy nowdays. I'll call it the "wishful thinking fallacy."

I do this because if there is anything that calls into question the "science" part of computer science, it is the dogma of folks that refuse the empirical side of the field. It isn't like folks haven't tried to make better languages and toolchains throughout the years. You even acknowledge this. They just haven't delivered on their promises.

And, some of that is because you are ignoring all of the advances that have happened in C. If you are not using modern tools like valgrind/coverity/whatever, you are not comparing C fairly to contemporary languages.

Re:Let’s Stop Bashing C by kstrauser on Friday December 02, 2016 @12:35PM (#13090580)
FWIW, I worked at Coverity. I didn't write the analyzers, but I sat next to the team that did. It is an amazing piece of software and that team would regularly present new features to us that I would have sworn were provably impossible, like "you've just solved the halting problem" kind of things. I'm sure any of those engineers could glance at an IOCCC entry and say "oh, there's a missing semicolon in that part that looks like a cat's head". Seriously, it's black magic written by wizards and is the most impressive codebase I've ever seen.

But.

Holy crap, the idea that you have to use something like Coverity just to make C code not suck is a bitter pill. I mean, I'm glad it exists but it's terrifying that it has to and that it's still being developed. After decades of development, the Coverity team is still finding enough examples of new ways to write bad code that they can still improve it.

I don't write C because I'm on a first-name basis with the only people on the planet I trust to get it right, and I am not among them.

Re:Let’s Stop Bashing C by jerf on Friday December 02, 2016 @12:34PM (#13090572)
"If you are not using modern tools like valgrind/coverity/whatever, you are not comparing C fairly to contemporary languages."

I personally consider C + strong static analysis tools to be an entirely different language. I fully acknowledge this is my personal opinion.

Consequently, I consider it equivocation in this sort of context to be talking about C when convenient, then talk about C + strong static analysis tools when convenient. You're only programming in one or the other. My utter contempt is for C the language by itself. This is relevant because as near as I can tell, C has at least a 10:1 advantage in the field over C + strong analysis tools, and I'm probably off by at least a factor of magnitude. It is not realistic to pretend that C programmers are using these tools at scale. (Now, you can point at a ton of high profile C programs that do use these tools, because high profile C programs are exactly where they get used. But as near as I can tell they are firmly the exceptions, not the rule. And you can point at a ton of high-profile projects that don't use them, too.)

If everybody started using all these tools, including the ones that you actually have to buy because there's no open source equivalent of, it is true that most of my issues with C would be resolved. It would also be true that programmers would be a lot less gung-ho about C, though, because as anyone who has deeply integrated these strong tools into their workflow can attest, C + strong analysis tools is a much more complicated language. Now, in my opinion, that complication is being revealed by the analysis tools, not created, and all C code is actually that complicated and the programmers are merely kept in the dark by C's extensive structural deficiencies that make it so it's only safe to write in with these rather sophisticated tools, but the end result is still you're working in a much more complicated, demanding language with a much more baroque compilation process. Claims about C's productivity, compiler speed, probably execution speed, ease of programming, probably quite a few other things, all go flying out the window if this is the solution, and C looks eminently more replaceable.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @01:25PM (#13090958)
We have not escaped the "wishful thinking" yet. Do I want there to be a replacement? Yes. I do my coding in other languages.

Have I grown weary of the attacks on C? Also yes.

Are not enough people using advanced toolchains? Yeah. I agree with that. But, this is effectively the same complaint that not enough people are using higher level languages. With the exception that fitting some of the extra tools on there is easier than switching languages.

Re:Let’s Stop Bashing C by pjmlp on Friday December 02, 2016 @04:11PM (#13092333)
Lint was created for C in 1979.

In Dennis own words:

"Although the first edition of K&R described most of the rules that brought C's type structure to its present form, many programs written in the older, more relaxed style persisted, and so did compilers that tolerated it. To encourage people to pay more attention to the official language rules, to detect legal but suspicious constructions, and to help find interface mismatches undetectable with simple mechanisms for separate compilation, Steve Johnson adapted his pcc compiler to produce lint [Johnson 79b], which scanned a set of files and remarked on dubious constructions."

Taken from https://www.bell-labs.com/usr/dmr/www/chist.html

We are in 2016, and static analysis is still ignored by the majority of C programmers that "just get work done".

Re:Let’s Stop Bashing C by kazinator on Friday December 02, 2016 @09:36PM (#13093956)
Lint has a history of being proprietary.

The Free Unixes of the true UNIX DNA lineage have a lint that is a rewrite by Jochen Pohl (done for NetBSD sometime in the early 90's?) Somehow BSD didn't inherit lint. If you use lint on BSD, you're not literally using that program that dates back to 1979.

Other Lints like FlexeLint are proprietary.

C spread like wildfire in the 80's, but an implementation of lint did not follow. Most non-Unix systems that could be programmed in C did not have a lint accompanying that C compiler.

Definitely, it seems there was a lack of promotion of lint from the birthplace of C.

If I were to give a definition of lint, it would be: "that mythical C checking program everyone knows but hasn't used".

It must be suffering from a curse which affects all technology named using a four-letter word starting with L. (Or at least LI.)

Re:Let’s Stop Bashing C by pjmlp on Saturday December 03, 2016 @04:11AM (#13095053)
> C spread like wildfire in the 80's,

Maybe on US, I only got my first contact with C in 1992, via Turbo C 2.0.

Before that already had used multiple languages and was using Turbo Pascal 6.0 by the time I learned C.

Then again, I hardly knew anyone with access to UNIX, my first contact being Xenix in 1994.

This type of experience was quite common in Portugal, who had money to buy expensive UNIX workstations....

Also the fact of being proprietary, well I usually paid for my tools, before FOSS started to be a thing.

And on the same place where they had Turbo C 2.0, they also just got Turbo C++ 1.0.

So there was a tool that had the type system that allowed me to bend C to be more like Turbo Pascal, provided I cared to use the said type system improvements.

Which lead to me never using C++ as an improved C compiler, rather taking advantage of C++ type system to ensure my arrays and strings were properly bound checked, and IO was done safely.

Oh and taking part on C++'s side on the whole C vs C++ USENET debates, since 1994. Or type safety in systems programming vs C.

So these HN and Reddit discussions regarding the C's unsuitability to write safe software, are hardly anything new to me.

Re:Let’s Stop Bashing C by kwhitefoot on Saturday December 03, 2016 @05:19PM (#13097775)
Not just C programmers. I write mostly VB.Net, C#, Java, and I can never compile any of the programs that I work with (created by teams of smart people) with all warnings treated as errors, never mind any more sophisticated analysis.

And the justification is always the same, just as you said: "just get work done".

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @05:39PM (#13092956)
Apologies if this is rude, but I'm not sure what this is getting at. I know that static analysis is old. I also know that I have been guilty of ignoring it sometimes. Especially as I was learning.

I think it is still in the wishful thinking world to think "better tools" should have won by now.

Re:Let’s Stop Bashing C by pjmlp on Friday December 02, 2016 @05:58PM (#13093064)
The thing is that the C working programming class doesn't value quality and secure code, performance FTW everything else gets done later, if there is time that is.

Even the language authors were honest and:

1 - created a tool in 1979 that most C developers ignore even in 2016, 37 years later;

2 - realized that C was due its date and took part in Limbo and Go design

Yet lots of C coders continue to improve this NIST list, every single day:

https://nvd.nist.gov/visualizations/cwe-over-time

For me wishful thinking, is the mentality that there are C developers out there that manage to write memory corruption free without using such tools.

Never met any since my first contact with C in 1992.

Re:Let’s Stop Bashing C by ArkyBeagle on Friday December 02, 2016 @07:08PM (#13093377)
Okay, so I have written ... multiple projects that ran as long as they had power with no evidence of memory corruption over a span of 30 years.

I've used Lint. Early on. It was great training. After a while, you don't need it so much.

I think you are Vastly overestimating the skill level needed to write normatively-correct C code by quite a margin.

Re:Let’s Stop Bashing C by pjmlp on Saturday December 03, 2016 @02:25AM (#13094793)
> with no evidence of memory corruption over a span of 30 years.

How many people did you had on those teams and how was the development process?

Me too I have written such software, when working in teams of no more than two people where we taken a Pascal like approach to programming in C.

Basically:

- Use translation units as modules

- structs are always exposed as Abstract Data Types, with accessors either via macros (when speed matters) or functions

- assert everywhere any assumption that can lead to memory corruption

- on debug code, make use of assert with pointer validation library from debugger, e.g. IsBadReadPtr()

- arrays are never accessed with pointer syntax

- use of compiler extensions for bound checking during debug builds

- all warnings enabled and considered as errors

And quite a few others.

I can count up to 5, the amount of friends and co-worker that managed to write good quality C code, since I learned C in 1992.

C++ unfortunately also enjoys the flaws of C due to its C copy-paste capability, but at least I can make use of the type system via structs, classes and operator overloading to enforce code that in C cannot be more than plain patterns.

> I think you are Vastly overestimating the skill level needed to write normatively-correct C code by quite a margin.

Anyway I don't need to proof anything when we have so nice CVE databases full of examples.

Or companies like Apple, which are supposed to have such ideal C programmers, do an OS release with 36 bugs, 31 of these (86%) related to C memory corruption bugs.

https://support.apple.com/en-us/HT206903

Re:Let’s Stop Bashing C by ArkyBeagle on Saturday December 03, 2016 @08:00PM (#13098260)
I'm not trying to say you're wrong. Especially because "...so (many) nice CVE databases full of examples".

As I recall, you had six(?) defects identified on a rather significant subsystem. While that's hardly ideal, it doesn't sound like those six defects should cost that much to fix.

And I'm not trying to say I can achieve some abstract perfection - I will have the odd memory overwrite early in unit test. But SFAIK, I've caught the overwhelming majority of them. But I will also be able to spend several hours building scaffolding to flush 'em out... this is especially true of networked code. I tend to use Tcl to torture them.

I will say - all the old guys I knew who were good C coders just got out of coding pretty much altogether. When I see discussions from younger coders, based on the problems they have, I feel that there's been some loss of information.

Also - for a major release of something as big as El Capitan, 36 seems a not-unreasonable number of severe defects. Obviously, we'd prefer it was a smaller number, and we don't know how many will be found eventually.

Re:Let’s Stop Bashing C by blacksmythe on Saturday December 03, 2016 @11:27PM (#13098788)

  >> 36 seems a not-unreasonable number of severe defects.
The point is that it should have been 5 defects (36 total - 31 memory defects).
Re:Let’s Stop Bashing C by ArkyBeagle on Saturday December 03, 2016 @08:03PM (#13098267)
Also: "Me too I have written such software, when working in teams of no more than two people where we taken a Pascal like approach to programming in C."

There you go. That's how I have done it as well. The degree of "Pascal-like"-ness is always .. something to be humble about. I really, really wish it had been Ada all along but that seems not to be likely.

Re:Let’s Stop Bashing C by kazinator on Friday December 02, 2016 @09:43PM (#13093972)
Static analysis isn't the only game in town anyway. An approach that seems to be gaining popularity is fuzzing. I'm using the AFL program (American FuzzyLop) in an ongoing way to find problems in code. Stress tests under Valgrind, and fuzzing are quite powerful.
Re:Let’s Stop Bashing C by pjmlp on Saturday December 03, 2016 @02:28AM (#13094807)
Assuming one is using a C toolchain that allows for it, which usually isn't the case for most embedded projects and their commercial tools.
Re:Let’s Stop Bashing C by kazinator on Friday December 02, 2016 @09:40PM (#13093967)
Also the skill level needed to write code that will evade lint type tools, while being incorrect. :)
Re:Let’s Stop Bashing C by ArkyBeagle on Friday December 02, 2016 @10:18PM (#13094076)
Yeah, there's that :)
Re:Let’s Stop Bashing C by mannykannot on Saturday December 03, 2016 @09:06AM (#13095699)
It is not helpful to characterize a discussion of C's problems as C-bashing. H2C03 titled his article "Let's Stop Bashing C" , but the article he was responding to was not a rant against C. It was actually a suggestion that some of the more dubious features of C should not be carried forward into future languages. You may disagree with specific issues (I am with H2CO3 on braces), but I think you agree with the principle.
Re:Let’s Stop Bashing C by kazinator on Friday December 02, 2016 @09:25PM (#13093930)
Indeed. When we look at Valgrind for instance, that only runs on Linux (and not all architectures). So you can only use it to debug C code that you can port to Linux (which requires it to be portable, which is different from "correct"), and you can only debug those issues in that code which you can reproduce in that Linux port.
Re:Let’s Stop Bashing C by aseipp on Friday December 02, 2016 @01:08PM (#13090833)
> It isn't like folks haven't tried to make better languages and toolchains throughout the years. You even acknowledge this. They just haven't delivered on their promises.

The question also has to consider, why did they fail? And what is the criteria for failure? That may be entirely the point: the languages may be better by some metrics, worse in others, but they cannot easily beat the inertia factor, as a result of being so entrenched for 4+ decades. Everyone is very aware of the inertia factor; it seems to permeate all levels of technical decisions in all kinds of fields, for good and bad reasons. If the failure criterion is "not used as widely as C", then, like, everything has failed, so it's a pretty bad criterion, I think.

Ada has been around for a while now, and has seen a fair amount of high-assurance industrial use. It's really unclear if you can actually characterize Ada as a total failure for example, it lives on, although it's certainly less popular. But it was designed with the field in mind from day 1. I think a lot of this has to do with things like institutional knowledge and inertia, and vast amounts of time and money sunk into tooling for systems like C.

That's not bad, the money and stuff obviously helped; but it makes the narrative that all these other things are strictly worse/never attempted a little bit muddier. Does the "empirical" lack of better replacements imply that better replacements cannot exist, or never existed? I think Ada alone specifically negates the core of that argument, they've certainly been tried and seen some level of success. Or perhaps we didn't actually try enough due to resources, maybe? Or maybe it suggests that other contributing factors, externalities, gave rise to such a "monopoly" of computing intellect?

Also, it's easy to forget, but today, it seems general programming languages have enough demanding requirements in general (from things like expectations of package managers, to libraries, to editors), that actually supporting and promoting a general purpose language, to the point of wide usage, is ridiculously time and money consuming. Programming languages are a commodity, for the most part. Existing languages almost all either struggle to exist, have their primary developers financed by some corporations, or have existed for long enough to not simply drift into the void and become effectively immortal.

Yet, there's almost no money in it as a field. It's insanely hard to make a business out of things like compiler tech or programming languages these days, outside of specialized fields and clients. Unless you have deep pockets and a willingness to throw money into the void for a while, bootstrapping a "competetive" programming language is going to be insanely hard, on any kind of reasonable timeframe. Rust is a good example: Mozilla financed a vast amount of the development for a long time, and sustained it even in the beginning stages when it was much riskier as an investment. That's likely one of the major reasons it's even remotely as popular as it is today, because they ate the cost, to catch up with modern expectations.

All of these compounding factors are not going away. I agree there are few viable alternatives; but I don't agree it's so easy to explain it all away "empirically" with such a simple analysis as yours, that it was all either never tried or just "failed" (without defining what that even means).

> And, some of that is because you are ignoring all of the advances that have happened in C. If you are not using modern tools like valgrind/coverity/whatever, you are not comparing C fairly to contemporary languages.

The fact you suggest a 15+ year old, insanely complicated static analysis tool that's proprietary to ensure your code should basically be allowed to exist on the modern internet (because otherwise it will just be a nightmare hellhole security problem for someone down the road), yet continues to fail to find true high profile vulnerabilities that keep occurring, and still requires constant evolution -- all so that C can be "fairly" judged with modern languages... it's a bit alarming when you think about it.

Well, I'm being slightly tongue-in-cheek. I mean, every time I write C, I heavily indulge in these tools as my insurance to ensure I'm doing things correctly. I even tend to use CompCert to find undefined behavior! Coverity is really good, no doubt.

But when I do this, it definitely gives me pause at the investment I have to make. I don't sit around thinking "Yes, this is basically a great solution to the problem". It would almost be, like, I dunno... calling the story of the Titanic a success? Lifeboats hardly seem like the ultimate risk insurance when you're the one crashing into ice, especially when it seems we never have enough of them.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @01:31PM (#13091020)
I'm not sure where this conversation is going. :) I think I resonate/agree with your entire upper part. At least, I find myself nodding my head a lot.

For the criticism of age of static analysis tool. This criticism doesn't make sense. I could make the same criticism for a 26ish+ year old and insanely complicated language toolchain (Haskel). And that is if I just pick the popular one. I could go with your example, Ada, for a 36+ year old option.

If the criticism is simply due to the proprietary nature. That cuts against much of your upper argument. The lack of money in the field is a large part of the problem.

Re:Let’s Stop Bashing C by geofft on Friday December 02, 2016 @05:52PM (#13093030)
> The problem is that they're not good enough to build on for the future, but they are good enough to entrench themselves.

Richard Gabriel made the same observation in his 1989 "The Rise of Worse is Better": https://www.dreamsongs.com/RiseOfWorseIsBetter.html

The worse-is-better philosophy means that implementation simplicity has highest priority, which means Unix and C are easy to port on such machines. Therefore, one expects that if the 50% functionality Unix and C support is satisfactory, they will start to appear everywhere. And they have, haven’t they?

Unix and C are the ultimate computer viruses.

[...]

It is important to remember that the initial virus has to be basically good. If so, the viral spread is assured as long as it is portable. Once the virus has spread, there will be pressure to improve it, possibly by increasing its functionality closer to 90%, but users have already been conditioned to accept worse than the right thing. [...]

The good news is that in 1995 we will have a good operating system and programming language; the bad news is that they will be Unix and C++.

Re:Let’s Stop Bashing C by sinisterstuf on Saturday December 03, 2016 @06:19AM (#13095297)
I came here to share the same link. This is the reason why C is still relevant today; it continues to be good enough! I think the same goes for Unix.
Re:Let’s Stop Bashing C by agentgt on Friday December 02, 2016 @12:33PM (#13090565)
I mostly agree with you the exception of SQL.

I actually think SQL is a fairly good language for what it does and the alternatives have been fairly crappy (at the minimum it should not be lumped in with Javascript). If there is a Rust of SQL let me know.

Re:Let’s Stop Bashing C by jerf on Friday December 02, 2016 @12:39PM (#13090614)
SQL's problems can be seen by comparing the true relational database theory with what SQL can do.

In particular, relational database theory does not require tables to have homogeneous table rows that consist entirely of scalar values. That was an efficiency optimization introduced back in the 70s, for perfectly sensible reasons at the time. But writing that into the language at such a fundamental level bends the whole language around it in a really unpleasant way compared to what it could be. For a similar example, consider the difference between a language that has no first-class function references, vs. one that has them added in. The first language may do everything you need, but you'll be bending a lot of code around that problem.

Of course, a variety of extensions have been bodged on to the sides of SQL over the years to deal with the resulting problems, and generally in a good engine like Postgres or something you can do almost anything you want. I'd also say that if you can understand what I mean when I say "Postgres is actually a much better database than understanding SQL would lead you to believe", you're on the track of what I mean.

Again, I'm not saying SQL is bad, I'm saying its success is holding back the things that could be better.

Re:Let’s Stop Bashing C by blzzfiddy on Saturday December 03, 2016 @02:53AM (#13094872)
> In particular, relational database theory does not require tables to have homogeneous table rows that consist entirely of scalar values.

Are you sure about that? https://en.wikipedia.org/wiki/First_normal_form

Homogenous values are not required, but having atomic/scalars as a fundamental unit of a relation is a pretty core concept in database normalization theory.

Or are you saying database normalization is a performance optimization and we should judge RDBMS' by their support for relational algebra/calculus and not normalization theory?

Re:Let’s Stop Bashing C by agentgt on Friday December 02, 2016 @12:59PM (#13090764)
I agree SQL is not perfect but I don't know of many examples of alternative languages (that are not completely proprietary).

It honestly would be helpful to see some alternatives that you think are actually good (as the ones I have seen in the past are fairly awful). The homogeneous rows point is valid but I'm not entirely sure even SQL requires that (as you can have non scalar data types as columns in many databases... although I suppose that is to your point about postgres).

And yeah I mainly only use Postgres so I'm biased :)

Re:Let’s Stop Bashing C by jerf on Friday December 02, 2016 @02:27PM (#13091493)
"I agree SQL is not perfect but I don't know of many examples of alternative languages (that are not completely proprietary)."

That's the point.

Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @11:58AM (#13090235)
As another example could you write a device driver in a language like Python?

I was frankly a little disappointed in both the referenced article and the one it references. C basically is assembler. If you have a problem that needs hardware-level access you'll need things like pointers. The really hard parts of C (like handling null pointers or lack of concurrency primitives) seem to be the flip side of this access. Whether you use things like braces just seems to be a matter of taste.

Re:Let’s Stop Bashing C by a3n on Friday December 02, 2016 @12:05PM (#13090286)
> As another example could you write a device driver in a language like Python?

Sure, with Cython or a Python C extension. :)

Re:Let’s Stop Bashing C by RUG3Y on Friday December 02, 2016 @12:10PM (#13090339)
My thought exactly =)
Re:Let’s Stop Bashing C by luhn on Friday December 02, 2016 @12:32PM (#13090560)
Of course Python isn't up to the task of device drivers, but C isn't the only language that can do that. You could write a driver in Rust, which is a significantly safer language than C.
Re:Let’s Stop Bashing C by hellbanner on Friday December 02, 2016 @01:45PM (#13091144)
Why are C & Rust available to write drivers but Python cannot? Is this because Python is too abstracted, where C & Rust have access to the physical hardware without the need for an API?
Re:Let’s Stop Bashing C by gdwatson on Friday December 02, 2016 @06:33PM (#13093226)
Python has a much more complicated runtime system which assumes a lot of things that wouldn't be true for a driver. It could probably be adapted to work, but it's a square-peg/round-hole situation.

By comparison, C's runtime is very simple and assumes very little, so it's good for writing code in a kernel or integrated system where many OS services won't be available to you. It's also much faster, of course, and it gives more direct access to memory.

Re:Let’s Stop Bashing C by hellbanner on Monday December 05, 2016 @12:43PM (#13107372)
Thank you! So essentially because C gives you direct access to memory -- I remember you have to allocate array sizes which are literally contiguous blocks on your hardware -- you can control things directly. THanks
Re:Let’s Stop Bashing C by xorxornop on Friday December 02, 2016 @02:33PM (#13091539)
C and Rust compile to native code. Python doesn't. It's either interpreted, or run in an abstract machine (VM). Python was never really intended to interact with the actual hardware directly.

I mean, you could, there's no real technical blocker, but it'd be horribly slow. Plus many failure modes of touching hardware are very likely to break the VM process and make debugging very challenging

Re:Let’s Stop Bashing C by khedoros1 on Friday December 02, 2016 @05:46PM (#13092998)
I think that the real blocker is raw pointers. You need to be able to read+write data to specific memory addresses for most hardware, and I don't think Python's capable of that.
Re:Let’s Stop Bashing C by dbaupp on Friday December 02, 2016 @06:32PM (#13093224)
Python is capable, via the ctypes module.

The problems include:

- performance: implementations being interpreted, and relying on dynamic typing mean that Python is almost always slower than compiled languages.

- the run-time: Python assumes that things like allocations are always OK, and generally requires more operating system support than is available in low level environments.

Re:Let’s Stop Bashing C by khedoros1 on Saturday December 03, 2016 @04:44PM (#13097660)
Thanks for the reminder. I had it at the back of my mind that CPython is just about built as an abstraction on top of C, and so should be capable of anything C is, depending on where you wanted to draw the line between the languages.
Re:Let’s Stop Bashing C by zeveb on Friday December 02, 2016 @12:38PM (#13090606)
> As another example could you write a device driver in a language like Python?

You could write one in Lisp, which is in many ways a language like Python, but which does support bit twiddling & pointers if desired.

Re:Let’s Stop Bashing C by geofft on Friday December 02, 2016 @06:05PM (#13093094)
> Consider, what is the fastest way to calculate a square root? And how old is that instruction? (I'm assuming it is actually used by higher level languages by now.)

Isn't the right way to handle this for your code generator, e.g., LLVM, to know about this instruction, and your language implementation, e.g., clang or rustc, to just say "hey, give me a square root"?

I do buy your argument for very processor-specific things like writing a bootloader or a hypervisor.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @09:16PM (#13093883)
That is certainly the high level language way. Because the magic involved in the code generator is quite high.

C, however, gives you hold onto the generator to say "use this assembly". So, for new or one off instructions, it is a quick way to get an edge.

Re:Let’s Stop Bashing C by geofft on Saturday December 03, 2016 @02:28PM (#13097105)
My question is, does it actually get you an edge?

When you use inline assembly, the compiler (more or less) has to execute that inline assembly, right where you say it is. It can't speculatively execute it, it can't refactor the call into a different function if you're calling it twice, it can't optimize it out in certain circumstances, etc. It can't move the instruction around or choose a different form depending on register pressure. If you specify the right flags about what registers it clobbers, what memory barriers it requires, etc., the compiler can do some of it, but it's not going to be nearly as good as the compiler actually understanding what's happening, I think.

Telling the code generator (and C is a high-level language in this respect, if you want any performance out of C) what you're doing is likely to get you more of an edge, no?

I can certainly imagine cases where letting the compiler reorder a slow square root around a memory access will be faster in practice than a fast square root that can't be reordered.

Re:Let’s Stop Bashing C by kazinator on Friday December 02, 2016 @09:22PM (#13093910)
Support for inline assembly language in C is a compiler extension.

It is not exclusive to C compilers.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @11:09PM (#13094259)
Indeed it isn't. It does seem to be most common there, though. (See sibling post for comments of early lisps supporting this. Well aware of it, but many higher level languages do not commonly support it.)
Re:Let’s Stop Bashing C by nickpsecurity on Saturday December 03, 2016 @06:08PM (#13097938)
Burroughs ALGOL, Modula-2, and industrial Pascals could all do that. Amomg others. They were safer by default and fast. C looks weaker at this point.
Re:Let’s Stop Bashing C by zeveb on Friday December 02, 2016 @12:37PM (#13090596)
> My 2 cents for why, is that c is basically the only game in town that can easily use new and special assembly.

In Steel Bank Common Lisp, one can just write a new VOP to emit a new instruction.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @12:51PM (#13090706)
Yeah, I was aware of that. Naughty Dog did a similar thing with their toolchain.

Lisp seems to have been damaged by the functional programming dogma more than anything else, the more I learn about it. Which is a shame, because the functional parts are good. But so were all of the toolchains around interop with other systems.

Re:Let’s Stop Bashing C by kstrauser on Friday December 02, 2016 @11:53AM (#13090185)
I don't think that's true. Let's pick the Node.js ecosystem for an example (chosen because I use it very little, so I'm not hyping up my own pet language). Lots of non-expert programmers are writing Node packages, both for their own in-house use and to share with others. I'm going to assert that the average Node user has fewer years programming than the average C user. And yet, they seem to have fewer critical vulnerabilities per amount of code written. They still make mistakes all the time, sure! But they're a higher class of mistakes, more "this sets the wrong HTTP status code" and less "this exposes kernel memory to remote users". JavaScript handles the low-level abstractions so that its users can concentrate on breaking the higher-level stuff, hopefully in ways that are easier to test and notice.

Also, almost every language has a way to use C code directly (For example, see Go: https://golang.org/cmd/cgo/). C may be the best way to write low-level driver code. If it is, use it for that! I'm not convinced that there's a single best language for Ethernet card drivers and HTTP stacks, though.

Re:Let’s Stop Bashing C by dmitrygr on Friday December 02, 2016 @03:04PM (#13091829)
> fewer critical vulnerabilities per amount of code written

Because nobody uses node.js in serious infrastructure. Show me a serious ISP whose DHCP server is written in node. Know any whose DNS server is written in node?

Your statement is equivalent to: we should build bridges out of legos and not out of concrete because fewer people have been killed by collapsing lego bridges

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @12:04PM (#13090279)
What systems are we talking about, then? Few people are writing stuff in C/C++ nowdays. And the fields that do this on a regular basis are pretty much unchallenged by any of the higher level languages.

And, agreed, on truly expert systems, things do go polyglot. This has been true since pretty much the beginning of computers. I'm not sure what sort of evidence this provides, though.

So, to bring it directly to point. Where is the evidence that the systems people typically write in C could be written well in another language? About the best I have seen is some system utilities written in rust. Which is awesome, no doubt. And the beginnings of the evidence I'm asking for.

(To be fair, we often speak of mysterious wizards that wrote the symbolic lisp systems as though they succeeded at this. I want that to count as evidence, but it feels more like hearsay.)

Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @12:19PM (#13090420)
(Now arguing the other side...) There is a case for looking at safety issues in C. Reducing the possibilities for mayhem from null pointers would be helpful.

What I don't fully understand is critiques of C that lump safety issues in with use of braces or semi-colons.

Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @12:23PM (#13090466)
A lot of the safety issues in C have been decently solved, though. You just have to use a larger tool chain than just the compiler. (Valgrind, coverity, etc.)
Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @12:50PM (#13090702)
Fair point, I think what's missing from some of the discussion here is that very few languages are productive without an effective toolchain.
Re:Let’s Stop Bashing C by taeric on Friday December 02, 2016 @01:32PM (#13091030)
Yeah. I have tried times in the past to make sure folks don't just think in terms of language, but full toolchains. I confess I am not good at that thinking, either. :(
Re:Let’s Stop Bashing C by ksk on Friday December 02, 2016 @12:16PM (#13090386)
IMHO, people constantly introduce vulnerabilities when using high level code. Most websites are defaced this way. They're not exploiting flaws in Apache or IIS anymore. Its the Python or PHP or Node.js application or wordpress blog or similar that doesn't sanitize user input or has a buggy web api.
Re:Let’s Stop Bashing C by jerf on Friday December 02, 2016 @12:19PM (#13090414)
A C program talking to the web will have memory vulnerabilities, encoding vulnerabilities, and business logic vulnerabilities.

A modern program talking to the web will have encoding vulnerabilities and business logic vulnerabilities.

It's still progress.

There are cutting edge stacks which will effectively eliminate the encoding vulnerabilities, too, leaving more-or-less just the bugs you put in.

(Obviously I'm simplifying the types of vulnerabilities that exist to make a point.)

Re:Let’s Stop Bashing C by ksk on Friday December 02, 2016 @12:32PM (#13090558)
Well, you could make another argument too. Given X amount of time in a day, a C programmer can't really pump out _that much_ business logic code because they're also dealing with the other lower level stuff.

A high level language OTOH allows you to be more productive in terms of the business logic stuff, and therefore, I'm using a rough metric here, more lines of code, which also means more bugs in the business logic.

Like you said, these are all simplifications, but I think the primary problem is that people undertake projects that are way above their competency level.

Edit: If we could get some multiplayer-game like matching system where you are matched with the project depending on your skill level that would be awesome.

Re:Let’s Stop Bashing C by Retra on Friday December 02, 2016 @08:23PM (#13093681)
If you're working on a project that is not above your competency level, then you're wasting your time.
Re:Let’s Stop Bashing C by EpicEng on Friday December 02, 2016 @09:19PM (#13093898)
Yes, because the ultimate purpose of delivering software is to challenge the company's developers.

/s

Re:Let’s Stop Bashing C by petra on Saturday December 03, 2016 @05:26PM (#13097800)
What stacks eliminate encoding vulnerabilities ? And are there any stacks that even protect you from writing bad business logic , if that's even possible ?
Re:Let’s Stop Bashing C by jerf on Sunday December 04, 2016 @05:00PM (#13102010)
Using something like Shakespeare for Haskell makes it very difficult to write HTML that is incorrectly encoded without doing it on purpose: https://hackage.haskell.org/package/shakespeare

More conventionally, even something like Go's html/template [1], though I believe it uses a technique that can ultimately be fooled, is much harder to write accidental encoding vulnerabilities into. If you do the natural thing in the templates, the templates do the right thing.

Business logic errors I don't expect to be prevented by, well, anything. Oh, you can do some work to prevent certain sorts of errors with type systems, but a lot of business logic errors often start in the requirements, or the translation of the requirements into the code. Nothing will ever stop us from taking fuzzy requirements and translating them into wrong code, even if we can at least ensure the wrong code doesn't crash, corrupt memory, expose encoding errors, or violate simple invariants.

Re:Let’s Stop Bashing C by nickpsecurity on Saturday December 03, 2016 @06:06PM (#13097932)
You can use secure parser generators like HAMMER or Nail for encodings. If it's about integration, you can use something like ZeroMQ.

Far as eliminaging logic errors, you can make a lot of progress on that using formal specifications combined with modular code that matches them well. That's how med-high assurance was done. Some companies also specify domain rules in formal logic then implement them in Prolog or Mercury. You will have a hard time straying from intended logic when executing the logic itself. ;) Toolkits like Allegro CL and sklogic's DSL scheme let you mix and match things like LISP for power, ML for safety, and Prolog for logic execution.

Really niche stuff in industry, though.

Re:Let’s Stop Bashing C by kstrauser on Friday December 02, 2016 @12:21PM (#13090442)
That's all true, but consider how many vulnerabilities we'd be seen if the programmers who wrote those applications also had to deal with pointers and memory management. You'd get the current problems plus all of the stuff that regularly snags systems programmers.
Re:Let’s Stop Bashing C by ksk on Friday December 02, 2016 @12:28PM (#13090516)
I agree and we can take it further. If we had to hand encode the instructions it would cause even more bugs. The more decisions you have to make as a programmer, the more chances there are of making errors. High level languages make some decisions for you, but people still end up making mistakes. Maybe the goal should be to increase the bar at which a programmer is considered competent.
Re:Let’s Stop Bashing C by zzzcpan on Friday December 02, 2016 @12:48PM (#13090678)
I think you look at it a bit incorrectly. Those high level languages were designed not to avoid mistakes, but to push software complexity to a whole new level. You simply won't be able to get to that complexity with a lower level language, because people have limited ability to think about things and tend to fallback to solutions they can fit in their mind. Which is why you shouldn't expect high level languages to eliminate vulnerabilities, people still use their minds to the limits and make mistakes. Other approaches must be taken.
Re:Let’s Stop Bashing C by ksk on Friday December 02, 2016 @12:56PM (#13090752)
I think we agree. Its hard to encapsulate everything, so I just chose a smaller context for my argument. I was primarily thinking about resource allocation and such.

A HLL does indeed allow you to compose solutions to problems in terms of higher level abstractions, which I gather is your point.

Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @12:06PM (#13090303)
But it seems the OP's implicit point was that C is not the right language for higher-level operations. For low-level access it's not very obvious what else you would use.

Personally I rarely use C because I currently write network services with REST APIs. C is close to worthless for that purpose for many reasons, not just errors. It's analogous to writing an accounting app in assembler. Most people stopped doing that in the 1960s.

Re:Let’s Stop Bashing C by pjmlp on Friday December 02, 2016 @04:18PM (#13092375)
> For low-level access it's not very obvious what else you would use.

Extended Algol, created in 1961. Almost 10 years before C.

There are tons of other examples.

C got widespread thanks to UNIX, just like a few decades later, JavaScript got widespread thanks to Web 2.0 and the browser.

> It's analogous to writing an accounting app in assembler. Most people stopped doing that in the 1960s.

Lotus 1-2-3 was initially written in Assembler, Ι will let you track down when it was created.

My last 100% Assembly program was for MS-DOS in 1996.

Re:Let’s Stop Bashing C by hodgesrm on Friday December 02, 2016 @07:03PM (#13093357)
> Lotus 1-2-3 was initially written in Assembler, Ι will let you track down when it was created.

Interesting! I did not know that. I would still stand by the point that application programming by the end of the 60s was leaving the Assembler era and moving on to languages like COBOL and FORTRAN. (And weird cul-de-sacs like RPG which was my second programming language after BASIC.)

Re:Let’s Stop Bashing C by pjmlp on Saturday December 03, 2016 @02:18AM (#13094774)
This was true on mainframes and workstations.

At 8 bit and 16 bit computers target for consumers it was a different story.

Forth, Basic, Pascal, C, Amos, Modula-2, Clipper were the "managed languages".

Anything that required performance was written in Assembly, or high level in such "managed language" (Turbo Pascal on my case) with lots of inline Assembly.

Re:Let’s Stop Bashing C by StillBored on Friday December 02, 2016 @05:06PM (#13092755)

  Finally, C is slow. Yeah, you read that right. Its main problem is that it has no non-wizardry high level semantics for parallelism. 
Do you know about openMP? Which works in most mainstream c compilers (clang, gcc, icc, msvs, etc). Ok, its not part of the standard, but IMHO thats probably a good thing. C doesn't dictate a paradigm which allows it to support a wide range of competing standards. Pick the one best for your project, or embed something like openCL or lua right into your C project. Of course the opposite can be said as well, write your code in python/whatever and then write a C plugin for the critical portions. Because, outside of fortran or C++ pretty much nothing comes close to the capability of C to solve a problem quickly.

Which if no one noticed is even more important these days than it was two decades ago, when companies used crappy languages and shipped products that wasted 99% of the cycles of the users computer. Today doubling the performance of your product can literally 1/2 the computing costs at your friendly cloud provider/datacenter.

Re:Let’s Stop Bashing C by nickpsecurity on Saturday December 03, 2016 @06:10PM (#13097941)
Exactly. I studied HPC over a decade ago. All C and Fortran dialects with amazing performance. Today, they advertise updated versions of same languages.
Re:Let’s Stop Bashing C by bluecalm on Friday December 02, 2016 @11:54AM (#13090192)
>>remembering to free(); not to free() twice;

You can set the pointer to NULL, then freeing again won't hurt

>>not to use after free()

Set the pointer to NULL so it will crash.

>> Its main problem is that it has no non-wizardry high level semantics for parallelism.

Fair, the language doesn't have it. For everyday programming though you can use something like OpenMP where making things execute in parallel often requires adding one line above your for loop.

>>But there's no way I'd willingly start a new project in C today given the alternatives

There is no alternative for performance critical code (well, at least among popular languages of today). For other things - sure.

>>I'm going with one that gives me a reasonable shot at writing safe, fast, and understandable code.

If safety is your priority then likely C is not for you. As to performance it depends what you consider fast. If making stuff 50% faster no matter how fast it already is saves a lot of money you have no choice but C/C++/Fortran or just hand code in assembly.

Re:Let’s Stop Bashing C by rrauenza on Friday December 02, 2016 @12:08PM (#13090330)

  >>> remembering to free(); not to free() twice;
  > You can set the pointer to NULL, then freeing again won't hurt
  >>> not to use after free()
  > Set the pointer to NULL so it will crash.
I like C and think it is bashed too much, but double frees and invalid pointers are most often the result of multiple copies of the pointer... some other structure hanging onto the original reference.
Re:Let’s Stop Bashing C by chelahmy on Friday December 02, 2016 @12:54PM (#13090734)
> some other structure hanging onto the original reference.

Let's unleash the superpower of C. You should've been using pointers to a pointer so that it is always a single reference to a memory block.

You can't really be programming in C if you're not thinking in pointers.

One more thing; The article should have mentioned "pointer increment" which has nothing to do with "+= 1".

Re:Let’s Stop Bashing C by kbp on Friday December 02, 2016 @02:24PM (#13091473)
> One more thing; The article should have mentioned "pointer increment" which has nothing to do with "+= 1".

What do you mean? ++ptr is perfectly equivalent to ptr += 1, for any pointer type.

Re:Let’s Stop Bashing C by chelahmy on Friday December 02, 2016 @03:47PM (#13092150)
I read it as integer arithmetic. It is semantically different from pointer arithmetic.
Re:Let’s Stop Bashing C by rrauenza on Friday December 02, 2016 @03:30PM (#13092018)
So it's turt^H^H^H^Hpointers all the way down?
Re:Let’s Stop Bashing C by chelahmy on Friday December 02, 2016 @04:06PM (#13092298)
Will the following help with the depth, or any depth?

  int *a, **b, **c, **d;

  d = c = b = &a;
Re:Let’s Stop Bashing C by steveklabnik on Friday December 02, 2016 @12:29PM (#13090532)
> Set the pointer to NULL so it will crash.

Dereferencing NULL is not guaranteed to crash. It's undefined behavior, generally. SO that can lead to tons of other problems....

> There is no alternative for performance critical code

On many platforms, Rust exists today. C is still the king of that, though, especially for obscure embedded stuff.

Re:Let’s Stop Bashing C by bluecalm on Saturday December 03, 2016 @07:54AM (#13095479)
Right. Still, in practice, if you are setting pointers to NULL after freeing them (to say "there is nothing there" if some other part of the program wants to check) you will get a crash (as the compiler won't be able to prove the pointer is NULL if setting it to NULL depends on what happens at runtime).

I agree it's not perfect solution, just something to help you catching errors in your logic (not checking for NULL when something could be NULL is a bug in program logic).

Re:Let’s Stop Bashing C by steveklabnik on Saturday December 03, 2016 @04:55PM (#13097706)
If the zero address is valid, then one aspect of "undefined behavior" is that the result is "this will actually continue to 'work' until something random goes wrong". Someone just the other day on Reddit was talking about how this is a common issue in their workplace, as they work on a system that maps valid memory to 0.
Re:Let’s Stop Bashing C by module0000 on Friday December 02, 2016 @12:13PM (#13090358)
Just to add, that if you commonly make those mistakes in C/C++, it's time to learn to use lint. While humans commonly make these mistakes and fail to notice them, lint will scream quite loudly at you until they are fixed.

If you are writing code that is too complex to be linted, then you are also are at a level of expertise where those mistakes are absent or very uncommon.

Re:Let’s Stop Bashing C by bbatha on Friday December 02, 2016 @12:15PM (#13090374)
> Set the pointer to NULL so it will crash.

This doesn't work on all architectures which is why its undefined behavior.

Re:Let’s Stop Bashing C by EpicEng on Friday December 02, 2016 @09:22PM (#13093915)
Yet it will on the vast majority.
Re:Let’s Stop Bashing C by ArkyBeagle on Friday December 02, 2016 @07:13PM (#13093403)
I really have to disagree - I've seen and written a lot of perfectly safe C code. There are a lot of good reasons not to use C but that one's a rapdily expanding fallacy.

There is something missing from these discussions.

Re:Let’s Stop Bashing C by nickpsecurity on Saturday December 03, 2016 @06:17PM (#13097962)
"There is something missing from these discussions."

The reasons for the gap between the condition of most C code and what you describe. Plus how to close that gap with lower effort than just getting them to use Ada, Component Pascal, Go, Rust, etc.

I am keeping some notes on these discussions. Remembering you and TickleSteve in mind for the eventual roundtable discussion on Doing C Right With Ease (TM). pjmpl's list of safety tricks in the reply to you looks interesting, too. Once a basic strategy forms, then tooling can be designed to analyze conformance to it with helpful error messages and justifications. Built into IDE running in background as developer programs.

Re:Let’s Stop Bashing C by ArkyBeagle on Saturday December 03, 2016 @07:48PM (#13098234)
Well, it's not that I haven't thought about how to write a paper on the subject.

But frankly, the timbre of these discussions leads me to believe I'd simply be defending that for hours on end and I just don't wanna fool with it. The sheer rush to judgement is enough to make me think I'm sort of out of my depth in the ability to actually debate this properly. Part of my desire to say anything is trying to get the color and shape of that.

Plus, I'd rather not break anonymity, and I (amusingly) don't own any code of consequence that could demonstrate the principles - it's all owned by my employers.

Something like that - if I can't visualize the end-game, I probably have no business starting in it. Plus, I feel somewhat strongly that the languages designed to replace C should probably be given a chance. Throw in that the compiler people, in chasing absolutely performant executables, have left old code to rot... I'm also a bit feeling out of my depth.

I can more do it than talk about it.

Re:Let’s Stop Bashing C by dzdt on Friday December 02, 2016 @11:22AM (#13089864)
Are there any real world examples (with actual measurement) of languages where map uses hardware parallelisation to be faster than a c loop? Serious question! My impression is, no, outside of something like hadoop.
Re:Let’s Stop Bashing C by kstrauser on Friday December 02, 2016 @11:33AM (#13089971)
I don't have any off the top of my head, but I used a forking map in Python where the inner call was an image processing operation, and it was approximately #cores faster. I think it'd be enormously dependent on workload: if the inner operation is adding two ints, the gains might be lost in the parallelization overheard.

Map is just one example of a high-level construct that permits faster code, though. A lot of us here have done async IO in C because that was the option we had available to us for doing it, but I'd vastly rather do such stuff in Python (3), Go, or Node where the language itself gives you constructs for describing what you're trying to accomplish.

My impression is, no, outside of something like hadoop.

That's a pretty big exclusion, though! We use Hadoop-like stuff on, ahem, sizable quantities of data. That's not exactly an edge case.

Re:Let’s Stop Bashing C by lallysingh on Friday December 02, 2016 @11:29AM (#13089930)
https://donsbot.wordpress.com/2007/11/29/use-those-extra-cor...

This was a simple fib(), not a map(), but I think the point still stands pretty well.

Re:Let’s Stop Bashing C by kutkloon7 on Friday December 02, 2016 @11:30AM (#13089944)
FPGA implementations usually are made to do this, although there is usually a human writing dedicates VHDL. Also google course-grained reconfigurable architectures (which can sometimes be mapped automattically from code).
Re:Let’s Stop Bashing C by pjmlp on Friday December 02, 2016 @04:21PM (#13092391)
Check the now dead Connection Machine and *Lisp.
Re:Let’s Stop Bashing C by Ono-Sendai on Friday December 02, 2016 @11:41AM (#13090063)
Here's an example (something of a proof-of-concept/toy example though)

Auto-vectorisation and parallelisation in Winter: http://www.forwardscattering.org/post/22

Re:Let’s Stop Bashing C by simondedalus on Friday December 02, 2016 @11:48AM (#13090139)
To be fair, the value of the features you cite are very dependent on the size of the team and the type of work being done. If you're throwing tons of engineers, tests, and money at something--think aircraft or whatever--you're not relying on the language to be smarter than the programmer.

And as for operating systems being written in C and failing, writing a general purpose, hardware agnostic operating system isn't exactly easy. This is not to say that C should be the systems language of choice, or even that C is easier or more stable to write operating systems; just that stuff will be buggy regardless.

And I think your main complaint is stuff like OpenSSL and its vulnerabilities... I don't think I would blame the language there. I would blame age / inherited bugs / lack of testing (amazingly that's the case, but we don't live in a world that's too concerned with the common good).

I agree with you for many, many use cases for a programmer these days... but only if you just contextualize all these assertions.

Re:Let’s Stop Bashing C by nickpsecurity on Saturday December 03, 2016 @06:23PM (#13097981)
"And as for operating systems being written in C and failing, writing a general purpose, hardware agnostic operating system isn't exactly easy."

Wirth and Jurg did it in a year or two on custom hardware using Modula-2. They and thdir students repeatedly did it with Oberon variants. They were all safer and more reliable than earliest UNIX distro. Partly due go strong typing, interface checks, and GC's in later versions.

Similarly OS's written with Modula-3 (Spin), Haskell (House), Java (JX), and Rust (Redox) moved fast since the languages reduced number of problems they had. Spin could even dynamically link M3 code into running kernel with type system preventing many crashes or vulnerabilities. Made for great acceleration of networking apps, etc.

Re:Let’s Stop Bashing C by simondedalus on Sunday December 04, 2016 @11:25PM (#13103351)
I know that the response I'm about to give makes a statement that is not falsifiable and very much has the form of "I can cart this out and think I'm right no matter WHAT you respond," but I still feel compelled to say...

...the point I'm making is absolutely not that building an OS is equally hard in all languages, and equally likely to be buggy. My point is that creating a general purpose OS that only gets its rigorous testing from getting put into production before the majority of its target hardware has even yet been developed... that's going to be buggy in all languages.

Designing and running an OS on a known system with a few applications in mind can't really refute what I'm saying. I mean, I could of course be wrong. But I can't imagine a convincing counter-example that doesn't have for its evidence "largescale adoption on disparate systems."

(there could be an in-principle reason that I'm wrong that I just don't understand, but this is the risk we take in having opinions)

Re:Let’s Stop Bashing C by ArkyBeagle on Friday December 02, 2016 @07:01PM (#13093343)
"...some of the smartest people on the planet use it to write infrastructure that regularly fails catastrophically."

Not one thing said in that sentence fragment can be shown categorically to be true. Yo, software has defects. Some get past everybody. To wit:

1) It's 2016. There's a lot of old code out there. Old code tends to be C.

2) UB and implementation-defined behavior are just a fact in the language. This being said, they're not THAT hard to avoid.

I think the thing is whether or not people are habituated to thinking in constraints. People who aren't will be more dangerous with a C compiler than those who are.

FWIW, I've heard the phrase "knuckledragger C programmer" more than once. As a C programmer, it might even be apt. :)As in "monads? We don't need no steenking monads!" :) ( this being said, I use something akin to a monad pattern quite frequently and in C )

Re:Let’s Stop Bashing C by smitherfield on Saturday December 03, 2016 @04:43PM (#13097657)
If you tilt your head and look at it funny,

  p == NULL
  p
  *p
is a monad. :)
Re:Let’s Stop Bashing C by Kenji on Friday December 02, 2016 @12:11PM (#13090345)
not to use after free(); accidentally adding a second clause to a non-bracketed if expression;

Two methods I religiously use in my code: Set to NULL after freeing. free(NULL) is a no op, so freeing twice is never an issue anymore. And since you probably won't use the variable after that anyway, setting it to NULL eventually gets optimized out anyway, probably. And no if without brackets in my codebase.