News for hackers. Stuff that matters.
Re:Modern C [pdf] by buserror on Monday November 28, 2016 @08:16AM (#13055183)
Yeah, again and again. it's like blaming a hammer for the potential of breaking your finger when you use it, and proposing the use of a spoon, instead.
Re:Modern C [pdf] by marcosdumay on Monday November 28, 2016 @08:35AM (#13055264)
More like blaming a power-saw for the potential of destroying your table when you want to cut some bread.

If you are in for cutting a tree, go for it.

Re:Modern C [pdf] by adamnemecek on Monday November 28, 2016 @08:38AM (#13055283)
This C apologism is holding the industry back. Software development has changed many times over since C came out and it just isn't a good tool for tackling a lot of the issues that we have today. Just about every software project written in C has some serious bugs.

I personally judge a language by how well it lets you to define abstractions. In C's case, it doesn't let you do that very well.

Re:Modern C [pdf] by buserror on Monday November 28, 2016 @09:13AM (#13055488)
"Just about every software project written has some serious bugs"

There, fixed it for you. Seriously, vulnerabilities and bugs are found everywhere not just in C.

I've been programming for 35 years, in so many languages I lost count, and every time I've seen the 'let's not use C because it'll lead to bugs' it was to be replaced by another thing that was ALSO leading to bugs, and/or become so bloated it was in itself... a bug.

Re:Modern C [pdf] by pcwalton on Monday November 28, 2016 @10:53AM (#13056176)
> Seriously, vulnerabilities and bugs are found everywhere not just in C.

The black-and-white security fallacy again!

The simple fact (and this is a fact, not an opinion) is that the most severe security problems—remote code execution, in particular—are found way way way more in programs written in C and C++ than in other languages.

Re:Modern C [pdf] by paulmd on Monday November 28, 2016 @12:55PM (#13057105)
I strongly agree with your point in general, memory safety is a major problem with C/C++ to an extent that is not found in other languages. Even worse, these often become problems long after they are written when the compiler gets "smarter" and does a trick with your code. Call it "code rot" or whatever you want, but it happens a lot more and a lot faster on C/C++ than other languages.

However, the nature of where C/C++ code is used does lend itself to severe problems. When you have a JVM vulnerability, you shouldn't be able to get any farther than a regular user with only sandbox privileges. When you have a kernel vulnerability, by definition you have the keys to the kingdom.

Of course there are always holes that can be used to escalate, but that also comes back to the problems of having a primarily C/C++ ecosystem...

Re:Modern C [pdf] by sidlls on Monday November 28, 2016 @07:44PM (#13059768)
Per unit of code or as an absolute value? That's significant, but not even the whole picture. It's trivial to have a low (absolute and per-unit) number if the total number of units is low, for example. So by itself your fact is almost useless.
Re:Modern C [pdf] by benmmurphy on Monday November 28, 2016 @09:38AM (#13055619)
The big problem with C is the memory safety issues. It is extremely difficult to write C code and be safe from malicious input. If you use a memory safe language these difficult issues are erased.

I realise the compiler/runtime can't stop all bugs but fixing these simple errors goes a long way to producing robust secure software.

Re:Modern C [pdf] by ArkyBeagle on Monday November 28, 2016 @06:42PM (#13059396)
I am sorry, but there's nothing difficult about it. Tedious, yes. Difficult? No.
Re:Modern C [pdf] by adrianN on Monday November 28, 2016 @10:14AM (#13055881)
I hope you will agree that there are things where C is not the optimal choice (e.g. you wouldn't choose C for writing scripts). Many people argue that C is still suitable if you need maximal performance or do stuff that is very close to the hardware, like operating systems. Now, people who say that C shouldn't be used at all are just convinced that even in those applications there are now better choices than C. Safer languages like Rust exist that at least claim to fill the same niche as C.
Re:Modern C [pdf] by adamnemecek on Monday November 28, 2016 @09:21AM (#13055528)
A: "Let's not reuse syringe needles, it leads to spread of HIV".

B: "I've been using syringes for 35 years and clean needles won't get rid of HIV entirely".

Well no duh. But that isn't really a counter argument.

> become so bloated it was in itself

Whereas C is the pinnacle of expressiveness?

Re:Modern C [pdf] by targ2002 on Monday November 28, 2016 @09:10AM (#13055469)
I don't think it sensible to single out C for having serious bug. It should be most software projects have serious bugs.
Re:Modern C [pdf] by quickben on Monday November 28, 2016 @08:48AM (#13055341)
Your criticism lacks constructivity. What do you propose we replace C with?
Re:Modern C [pdf] by loup-vaillant on Monday November 28, 2016 @10:32AM (#13056006)
Whatever doesn't have extremely tight constraints (CPU, memory, embedded…) should probably use garbage collection. Now your language can throw a nice exception (or otherwise cleanly abort the process) before any memory corruption (and subsequent vulnerabilities) can occur.

Otherwise, I'd say try something like Rust. And if Rust doesn't make the cut, maybe go write your own C-like dialect, with less undefined behaviour.

Re:Modern C [pdf] by adamnemecek on Monday November 28, 2016 @08:49AM (#13055350)
Depends on what you are writing. C isn't 100 percent replaceable right now but the more people bitch about it and support the alternatives, the better for the future.
Re:Modern C [pdf] by SeanDav on Monday November 28, 2016 @09:01AM (#13055425)
Just curious, what are us C apologists supposed to be apologizing for:

- A lack of suitable replacement for C?

- C is too ubiquitous?

- C has been an integral part of most of the best software ever written?

Re:Modern C [pdf] by dbaupp on Monday November 28, 2016 @06:26PM (#13059320)
FYI, "apologist" is often not used to literally mean "one who apologises", but rather "one who defends"[1], with a negative connotation (at least in my experience).

I would guess the "C apologism" in the original comment is referring to defenses of C that pretend C is safe "in practice" (or "for people who know what they're doing") or minimise/ignore the strong correlation between the use of C and serious problems/vulnerabilities.

[1]: https://en.wiktionary.org/wiki/apologist

Re:Modern C [pdf] by naasking on Monday November 28, 2016 @10:41AM (#13056061)
Ada has been a suitable replacement for C since the early 90s when GNAT was released. Prior to that there were still plenty of suitable C replacements given a little work, like Pascal and Oberon.
Re:Modern C [pdf] by usefulcat on Monday November 28, 2016 @09:39AM (#13055622)
Agree with the first two but the last isn't saying much. C has been an integral part of most software ever written, best, worst, and everything in between.
Re:Modern C [pdf] by pcwalton on Monday November 28, 2016 @10:54AM (#13056181)
Rust?
Re:Modern C [pdf] by ArkyBeagle on Monday November 28, 2016 @06:40PM (#13059384)
C enables - in my opinion - better abstractions than languages which constrain you to the use of their suite of abstractions. I'd include C++ in that, and especially template-heavy C++.
Re:Modern C [pdf] by CmdrSprinkles on Monday November 28, 2016 @08:41AM (#13055305)
While I am all about C/C++ (even if I hate it), it makes sense

HN is probably something like 99% web and app developers (I would argue that all are the former, but my definition may be a bit old). In those cases, you actively don't want to ever use C and anyone who does is kind of an idiot. It is the logic by which "systems project" means "script to run on a server" for a lot of people around here.

And that is fine. But just like this place's obsession with Rust would lead to derisive mockery by "real" systems people, so too is C hated here.

It also doesn't help that universities, at least in the US, seem hellbent on teaching along these lines. A few years ago Eclipse was "the thing you use when you are poor or doing Java". These days? I am seeing disturbing numbers of graduates who refuse to use Visual Studio for a project on Windows and insist on boostrapping together something that is only half functional. And talking to my academia friends (and even doing a fair amount of guest lecturing for them), I know where the indoctrination is coming from.

Re:Modern C [pdf] by pjmlp on Monday November 28, 2016 @08:57AM (#13055395)
My university in the mid-90's already knew it was better to teach safe practices in C++ and Pascal dialects than keep teaching pure C.

We were supposed to be able to use C in the OS design classes from our C++ learnings.

Re:Modern C [pdf] by CmdrSprinkles on Monday November 28, 2016 @09:09AM (#13055459)
And I think that is the way to go. I am personally a fan of having more sciencey programs use matlab and more "pure" CS use python as the first languages. Save C/C++ for the lower level stuff (as in OSes and hardware interfaces and optimization). Although, I would argue that nothing beats C++ for teaching OOP and data structures

My problem is the almost dogmatic indoctrination that goes along with it. My cousin's Intro to CS class was taught by a professor who spent about a third of the time basically parroting Stallman (he actually would regularly bring up blog posts and articles on the screen and read them to the class...) and screaming about how everyone needs to use either Vim or Jetbrains tools. That isn't teaching. That is pushing an agenda. And it just makes for worse students and hell for those of us who still spend some time with the interns and new hires.

Always explore new and better tools. But understand why. Sous-vide is awesome and has the potential to make some of the best food you will ever eat. But it also understand that even a "worse" method can be much more efficient or effective.

Re:Modern C [pdf] by pg314 on Monday November 28, 2016 @10:14AM (#13055879)
I would argue Smalltalk is a far superior language to teach the essence of OOP. Students in Smalltalk will be writing programs in the first hour while their C++ counterparts will still be struggling to understand #includes.

To quote Alan Kay: Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind.

Re:Modern C [pdf] by CmdrSprinkles on Monday November 28, 2016 @10:47AM (#13056133)
I am definitely biased, but I think the includes are important and are almost part of the lesson. Teach someone how to write their own containers and classes, then show them that there is a library they can easily access that does a much better job than they ever will and just how easy it is to use.

And while there are better languages from an educational standpoint, having something that is usable/"real" is quite valuable.

But I definitely approach things from a more practical/industry oriented perspective. so grain of salt.

Re:Modern C [pdf] by dang on Monday November 28, 2016 @12:25PM (#13056874)
> HN is probably something like 99% web and app developers

Most generalizations about HN are merely projection based on sample bias, so please don't post such generalizations unless you have representative data.

We're thinking about adding that sentence to the site guidelines, because spurious general claims about HN are a cliché here.

Re:Modern C [pdf] by CmdrSprinkles on Monday November 28, 2016 @02:59PM (#13057905)
Except that this is a discussion on how news and topics are received at HN. So making a projection based on available data is actually quite reasonable and if there is a sample bias, it is a valid one. Because it doesn't matter if there are nine hundred billion hardcore VHDL folk around here. The most popular discussions tend to be tech related to web technologies and the associated tools. If the consistently popular and top discussions on HN aren't adequate to make a generalization of the general makeup of the active HN users, then I don't know what is.

And, I thought it was pretty clear with the "probably something like" and "99%" that it was a number being pulled out of my arse for the sake of discussion.

That being said, actual data on the skillsets and interests of the more active members would be a very interesting bit of data. But it is also really hard to measure as lurkers don't contribute to discussion but will gladly vote in a poll.

Re:Modern C [pdf] by dang on Monday November 28, 2016 @04:06PM (#13058417)
You're not making a projection based on data, you're generalizing from things you personally happened to notice, which is practically the definition of sample bias.

It's extremely common to do this (I'm not picking on you personally!), but such generalizations have no objective value and lead to repetitive, low-quality discussion, which is why I think we're going to add a guideline asking people not to do it.

Re:Modern C [pdf] by CmdrSprinkles on Tuesday November 29, 2016 @03:34AM (#13061706)
Again, the discussion was about why topics like C/C++ are dismissed/disliked around here and I presented an argument based upon observations in threads. That is actually a valid approach.

And if your issue is actually that I very clearly pulled a number out of my arse and went out of my way to make it clear that I had: Are you also going to make it mandatory for everyone to preface every non-cited statement with "in my opinion"?

Look, I get that this is your bread and butter and that it is important for HN to be presented as being THE place for tech and blah blah blah and being pigeonholed into "a site for web and app developers who like silicon valley" isn't necessarily what you want, but trying to pretend that a rule to not "generalize" as a way to not have people speculate and discuss why some topics just aren't particularly welcome here isn't the way to go. Just make it a rule, you aren't fooling anyone.

Also, if you REALLY wanted to improve discussions here: Make a rule against pseudo-technical naval gazing (is there a term for that? "Naval gazing" is more associated with philosophy and potheads) as far too many threads devolve into "We can't help but be introverted because our minds are designed that way and I need to be isolated to code because I need to optimize everything".

Re:Modern C [pdf] by otabdeveloper1 on Monday November 28, 2016 @09:22AM (#13055529)
> While I am all about C/C++ (even if I hate it), it makes sense

There's no such thing as "C/C++". They're two totally different languages. (C++ actually has more in common with something like Haskell than C.)

Re:Modern C [pdf] by JustSomeNobody on Monday November 28, 2016 @10:04AM (#13055809)
Come on.

That nomenclature has been around for decades. We ALL know they're different languages.

Re:Modern C [pdf] by grabcocque on Monday November 28, 2016 @08:19AM (#13055192)
If the handle of the hammer you're holding was a chainsaw that randomly turns on and off. And also sometimes explodes killing your entire family and pet dog. Don't blame the explodey-chainsaw-hammer, it's just a tool. Okay an idiotically dangerous too that nobody in their right mind should use, but still just a tool.
Re:Modern C [pdf] by quickben on Monday November 28, 2016 @08:33AM (#13055252)
Eh, no need to overreact that much. Look. Hardware is hardware, and this is where tire meets the road so people can lay the foundation for the upper levels.

It is what it is. It's not user friendly because hardware just isn't, low levels aren't, and it has to just perform.

> 'idiotically dangerous'

Well, I don't want to sound harsh, but nobody forces anybody to do systems programming if they perceive C as such. There is JavaScript, python and plethora of other safe and cozy languages, but: the low level has to be done.

Re:Modern C [pdf] by yxhuvud on Monday November 28, 2016 @08:44AM (#13055318)
Hardware is hardware, but C is not. People need to stop pretending that it is.
Re:Modern C [pdf] by nurettin on Monday November 28, 2016 @10:51AM (#13056156)
Look at all his comments in this thread. He is just fishing for an argument/attention.
Re:Modern C [pdf] by grabcocque on Monday November 28, 2016 @08:36AM (#13055272)
Oh, I see it's not that there's such a thing as a bad tool, or that C is unsafe.

Simply most of us don't have your towering intellect to appreciate it. Got it.

Re:Modern C [pdf] by quickben on Monday November 28, 2016 @08:40AM (#13055300)
Maybe I was too harsh, I apologize. But c is far less dangerous than a kitchen knife.

Tools are tools, some are used with a great amount of care: jackhammers, routers, compression hammers, chainsaws etc.

Heck: driving a vehicle is probably the single most dangerous activity we do on a daily basis.

Re:Modern C [pdf] by geezerjay on Monday November 28, 2016 @08:32AM (#13055248)
> If the handle of the hammer you're holding was a chainsaw

Except it isn't.

It's just a hammer, with a handle of a hammer.

> And also sometimes explodes killing

Except it doesn't.

At best, some people are reckless and end up causing problems due to their recklessness.

Enough with these silly hyperboles. Cushioned environments lead to less problems.

Re:Modern C [pdf] by chrisd1100 on Monday November 28, 2016 @08:57AM (#13055392)
C is utterly predictable. Maybe you're the exploding chainsaw in this metaphor.
Re:Modern C [pdf] by adamnemecek on Monday November 28, 2016 @09:24AM (#13055534)
How detailed is your knowledge of undefined behavior?
Re:Modern C [pdf] by module0000 on Monday November 28, 2016 @09:41AM (#13055639)
We know when undefined behavior will occur(the specs are written very clearly), but not what will happen when it occurs. Our job as competent C programmers is to avoid undefined behavior. C isn't hard(perhaps tedious to do correctly) - it does exactly what you tell it to.
Re:Modern C [pdf] by mathw on Monday November 28, 2016 @11:01AM (#13056226)
It does, but it's unnecessarily difficult to keep track of all the places undefined behaviour might occur and make sure you don't step into any of them under any conditions ever.

We shouldn't have to work like this anymore. C's been an amazing language, but it's getting time to gently, respectfully, move on. There's active and interesting development in alternatives which attempt to retain C's primary advantages while also allowing the compiler to keep you out of trouble as much as possible.

We have hugely powerful computers available to use as developers. We can contemplate designing and compiling languages with a complexity which would have completely defeated the systems available when C was developed. Why shouldn't we use some of that power to make our lives easier?

Re:Modern C [pdf] by adrianN on Monday November 28, 2016 @10:16AM (#13055907)
You'd be hard pressed to find a non-trivial C program that doesn't contain any undefined behavior.
Re:Modern C [pdf] by sidlls on Monday November 28, 2016 @01:32PM (#13057365)
Depends on what you mean by "non-trivial," I should think.
Re:Modern C [pdf] by pcwalton on Monday November 28, 2016 @10:55AM (#13056185)
> it does exactly what you tell it to.

This is a tautology.

What do you expect to happen on signed overflow?

Re:Modern C [pdf] by digler999 on Monday November 28, 2016 @03:09PM (#13057981)
> sometimes explodes

thought you were talking about java bloatware for a second. Oh your OS doesn't have 1.2gb for HelloWorld.class? Enjoy your OutOfMemoryException!