robinm

joined 2 years ago
[–] [email protected] 1 points 4 months ago

That's why I did not said it was impossible, just order of magnitude harder to catch in C++ compared to Rust.

To have asan finding the bug, you need to have a valid unit test, that has a similar enough workload. Otherwise you may not see the bug with asan if the vector doesn't grow (and thus ref would still be valid, not triggering UB), leading to a production-only bug.

Asan is a wonderfull tool, but you can't deny it's much harder to use and much less reliable than just running your compiler.

[–] [email protected] 1 points 4 months ago (3 children)
void foo() {
    std::vector v = {0, 1, 2, 4};
    const auto& ref = v[1];
    add_missing_values(v);
    std::cout << ref << "\n";
}

void add_missing_values(std::vector<int>& v) {
    // ...
    v.push_back(3);
}

Neither foo(), nor add_missing_values() looks suspicious. Nonetheless, if v.push_back(3) requires v to grow, then ref becomes an invalid reference and std::cout << ref becomes UB (use after free). In Rust this would not compiles.

It is order of magnitudes easier to have lifetime errors in C++ than in Rust (use after free, double free, data races, use before initialisation, …)

[–] [email protected] 1 points 4 months ago (5 children)

Is it possible to do in Rust?

Yes

Is possible to do in Rust, by mistake, and not easily caught by a review?

Definitively not.

[–] [email protected] 1 points 5 months ago

DRY and YAGNI are awesome iif you also practice YNIRN (You Need It Right Now)! Otherwise you just get boilerplate of spaghetti

[–] [email protected] 27 points 5 months ago

You got me in the first 3 quarters, not gonna lie!

[–] [email protected] 1 points 6 months ago

There are cases where instead of origin/master..HEAD you may want to use @{upstream}..HEAD instead to compare with the upstream of your current branch. It's unfortunately quite unknown.

[–] [email protected] 3 points 6 months ago

The fact that rustc has bugs (which is what cve-rs exploit) doesn't invalidate that rust the language is memory safe.

[–] [email protected] 2 points 8 months ago (1 children)

git worktree could become your new friend then :)

[–] [email protected] 1 points 8 months ago

The quote (and the associated discussion) is such an important part of Rust and why I love this language so much. Anything that can be automated should at one point be automated reliably, and the sooner the better.

[–] [email protected] 1 points 10 months ago

It's a question of workflow. Git doesn't guide you (it's really workflow agnostic) and I find it easier to taillor CLI to fit my exact need, or use whatever was recently added (like worktrees a few years ago). I have yet to find a GUI/TUI that I'm not frustrated with at one point but everyone has its own preferences.

[–] [email protected] 1 points 10 months ago (2 children)

If you use the git command line (and I do) you should spam git log --graph (usualy with --oneline).

And for your filesystem example I sure do hope you use tree!

[–] [email protected] 2 points 11 months ago

I absolutely agree that method extraction can be abused. One should not forget that locality is important. Functionnal idioms do help to minimise the layer of intermediate functions. Lamda/closure helps too by having the function much closer to its use site. And local variables can sometime be a better choice than having a function that return just an expression.

view more: ‹ prev next ›