Hacker News new | ask | show | jobs
by batty_alex 1229 days ago
> for (size_t i = 0; i < raw_level.size(); i++)

They say this is C++ code but, this is all C code. For instance, why aren't they using a range-based for loop?

for (auto& level : raw_level)

Boom! No more bugs.

> I certainly don’t feel as safe writing this code as I would in rust

Ah... there it is

2 comments

Unfortunately, it's also C++ code. Most of the weakest parts of C++ come from its close association with C.

When asking why some people like Rust over C++, I think not enough weight is given here: Rust got to not worry about decades of legacy C stuff seeping in. If Rust isn't your jam -- and I get why it wouldn't be -- there are some initiatives starting now from within the C++ community to shed the C legacy with a new language that feels a lot more like modern C++. Herb Sutter's cppfront[0] and Carbon[1] are examples.

But I don't think it makes sense to dismiss this criticism just because the author happens to like Rust. These C idioms continue to be valid and reasonably widely used in C++.

[0]: https://github.com/hsutter/cppfront [1]: https://github.com/carbon-language/carbon-lang

As this is HN, all trendy systems languages must be mentioned so here I go:

Jokes aside, I think these are the types of errors I assume Carbon would be well suited to prevent and justify why Carbon is a great idea.

Yes the code is C technically not C++, but the issue remains that it isn’t forced to be safer. The goal of languages like Carbon is to force these things in those large C++ repos.