Live data from Hacker News

Switching from C++ to Rust

laplab.me

141–150 of 289 posts

Re: Switching from C++ to Rust

#141

So the problem with rust you will find is the abuse of unwrap in ecosystem, so your code will need to be panic-safe. We wanted to get rid of C++ exceptions but traded it for panic hell.

"Panic" and "exception" is literally the same thing.

Sorry you were misled, but programming is, indeed, hard, and no, you can't go shopping instead.

Re: Switching from C++ to Rust

#142
post #97

Earlier quoted context omitted.

I hate it too, but every alternative can't handle some dark corner of my build that just works in cmake.

Have you tried just using bash? (not a joke) I do this for personal projects and honestly, considering the alternatives, I think it rules.

Bash cannot handle figuring out all my dependencies and how to run them in across howeverany CPUs I have. Nor can it handle all the different cross compile, static analysis, address sanitizer, and so on.builds I run.

Re: Switching from C++ to Rust

#143
post #61

Earlier quoted context omitted.

I can’t imagine not having the ability for a variable to be one of multiple potential types. I could probably work around it, sure, but why would you want to?

i can't imagine why you would want that. for example, why would i want something defined as an integer hold something other than an integer? this is how strongly-typed languages work.

You definitely want an integer to always be an integer, but you often want to represent "A or B". E.g. user has a contact method that's a phone number or an email address. Result of validation is a validated value or a failure message.

Re: Switching from C++ to Rust

#144

Earlier quoted context omitted.

> C++ enums can't have methods, even C++ 11 scoped enums ("enum classes") can't have methods, I have no idea why that restriction seemed like a good idea It is possible that Oracle holding the patent[1] to methods on enums is the blocker, rather than any technical restriction. [1]: https://patents.google.com/patent/US7263687

That sounds bizarre. So this means that parents are potentially holding back programming language innovation? I hope I don’t have to consult with a lawyer every time I invent a new variation on the for loop. (I anticipate that someone will then tell me that there already is a patent for that…)

Why would it be bizarre? It's not exactly a fringe belief that patents in all software are holding back innovation.

I don't think programmers often consult 20 year old "inventions", so it seems pretty obvious on its face that the supposed benefit of patents, that something is _only_ locked up for 20 years, is quite pointless in software.

Anyway, for loops are safe, unless the for loop is over the elements of a linked list. Then you need to wait until next year: https://patents.google.com/patent/US7028023B2

Re: Switching from C++ to Rust

#145

"First of all, generics without duck typing are greatly appreciated." Err..C++ has concepts. No duck typing required.

Err... C++20 added concepts but not definition checking, so templates are still duck typed. That is, it is still possible for a substitution failure to occur after performing a concept check. Definition checking would eliminate such failures.

In every language that I can think of that supports generic programming (including Go), there's support for definition checking.

Re: Switching from C++ to Rust

#146

So the problem with rust you will find is the abuse of unwrap in ecosystem, so your code will need to be panic-safe. We wanted to get rid of C++ exceptions but traded it for panic hell.

"Panic" and "exception" is literally the same thing. Sorry you were misled, but programming is, indeed, hard, and no, you can't go shopping instead.

Panics and exceptions are not the same thing. For one, it's not possible to recover from a panic. You can handle a panic from within a handler before the program terminates, but you cannot resume execution as you can with exceptions.

Re: Switching from C++ to Rust

#147
post #27

Earlier quoted context omitted.

[flagged]

Based on your other replies in this thread, as far as I can tell, you're not here to try and understand something. You're here to fuck around and play games with people over definitions. So, I'm not responding to you. I'm responding to the people following along who might get confused by the mess you're making here. More to the point, the Wikipedia article for "sum type" redirects to "tagged union," which just honest…

> But you can disable it for a particular sum type with the '#[non_exhaustive]' attribute.

I’m not sure this is the best description of what `#[non_exhaustive]` does in Rust. It doesn’t so much disable exhaustiveness checking as it marks the given list of variants as incomplete.

In Rust, some pattern matching contexts are required to be exhaustive (e.g. ‘let pattern = …;’, ‘match … {}’), and others are not (e.g. ‘if let … = … {}’). When an enum is tagged as ‘#[non_exhaustive]’, the former are required to include a wildcard matcher that will accept unknown variants, even if all known variants are explicitly matched.

Rust also allows structs to be `#[non_exhaustive]` to mark that the listed fields might not be sufficient. This disables the ability to (outside of a privacy boundary) directly construct an instance of the structure, or to destructure it with an exhaustive pattern.

Re: Switching from C++ to Rust

#148
post #97

Earlier quoted context omitted.

I hate it too, but every alternative can't handle some dark corner of my build that just works in cmake.

Have you tried just using bash? (not a joke) I do this for personal projects and honestly, considering the alternatives, I think it rules.

Bash doesn’t scale unless you build out an entire system to make up for all the things cmake does for you, and keep it up to date.

Need to handle creating projects for multiple ides? That’s a pain with bash unless you make an entire library of tools.

Need to handle finding libraries with all their transitive dependencies? Another set of tools.

At that point you’d just have reinvented cmake in a different language.

Out of curiosity, are you using bash for projects that are limited to just yourself?

Re: Switching from C++ to Rust

#149

Earlier quoted context omitted.

This is exactly what I think too. Sum types are so powerful, I feel a lot safer in Python + mypy with sum types (`from typing import Union`) than anything with C++ [1] even though C++ has a significantly more complex type system (it's type system is TC) and Python is as type-unsafe as a language can get. C++ made this odd choice as if any complex type system is better than a simple type system. When I was a younger s…

> even though C++ has a significantly more complex type system (it's type system is TC) For what it's worth, Python's type hints are also Turing complete ( https://arxiv.org/abs/2208.14755 , discussed on HN at https://news.ycombinator.com/item?id=32779296 )

Rust’s type system is also Turing complete: https://sdleffler.github.io/RustTypeSystemTuringComplete/

Re: Switching from C++ to Rust

#150

So the problem with rust you will find is the abuse of unwrap in ecosystem, so your code will need to be panic-safe. We wanted to get rid of C++ exceptions but traded it for panic hell.

What libraries have you found to use unwrap liberally?

_This_ is what I want to know.
Post reply on HN