Live data from Hacker News

Matt Godbolt sold me on Rust by showing me C++

collabora.com

641–650 of 675 posts

Re: Matt Godbolt sold me on Rust by showing me C++

#641

Earlier quoted context omitted.

The result type is obviously insufficient for writing nontrivial programs, because nontrivial programs fail in nontrivial ways that need exceptional control flow. The result type does not work because you have to choose between immediate callers handling failures (they don't always have the context to do so because they're not aware of the context of callers higher up on the call stack) or between propagating all of…

> The result type is obviously insufficient for writing nontrivial programs Counterpoint: there are many non-trivial programs written in Rust, and they use Result for error handling.

Pointing to programs written with design flaws caused by the flaw in the programming language does invalidate the claim that the flaw exists and negatively affects those programs.

You can write any program in COBOL. Most people would say that it's an insufficient language for doing so.

"Insufficient" here obviously does not mean that it's impossible to write non-trivial programs, just that they'll have bad code.

Re: Matt Godbolt sold me on Rust by showing me C++

#642
post #42
post #8

The one thing that sold me on Rust (going from C++) was that there is a single way errors are propagated: the Result type. No need to bother with exceptions, functions returning bool, functions returning 0 on success, functions returning 0 on error, functions returning -1 on error, functions returning negative errno on error, functions taking optional pointer to bool to indicate error (optionally), functions taking r…

I wish Option and Result weren’t exclusive. Sometimes a method can return an error, no result or a valid result. Some crates return an error for “no result”, which feels wrong to me. My solution is to wrap Result , but it still feels clunky. I could of course create my own type for this, but then it won’t work with the ? operator.

Well, I think returning "not found" when action performed was an "update X" and X doesn't exist. Result is totally normal where it makes sense, tho.

Re: Matt Godbolt sold me on Rust by showing me C++

#643
post #637

Earlier quoted context omitted.

Why should I defend Rust? You haven't even defined "good code", which has eluded the best minds in the field for as long as the field has existed. You are not a serious person.

I don't need to define "good code" for my argument. You're not a person capable of using logic, apparently. As is characteristic of Rust zealots.

> When I say "it doesn't work" I mean that it doesn't allow you to write good code

But you skipped over how you are defining, "good code"? Without that part, "doesn't allow" cannot be evaluated in the context of Java or C++ or Python or Go or Rust.

Logic.

Re: Matt Godbolt sold me on Rust by showing me C++

#644
post #387
post #350

Earlier quoted context omitted.

> I just almost never have problems with this sort accidental conversion in practice. 95% of C++ programmers claim this, but C++ programs continue to be full of bugs, and they're usually exactly this kind of dumb bug. > will be noticed by literally just running the code once. Maybe. If what you're doing is "tricky mathematical algorithms", how would you even know if you were making these mistakes and not noticing the…

It’s the sociology of software development. The guild of software developers has no real standards, no certification, no proven practices outside and while continuing to depend on the whims of project managers, POs and so-caled technical leaders and others which can’t tell quality code from their own ass. There’s usually no money in writing high-quality software and almost everything in a software development project…

[deleted]

Re: Matt Godbolt sold me on Rust by showing me C++

#645
post #598
post #387

Earlier quoted context omitted.

It’s the sociology of software development. The guild of software developers has no real standards, no certification, no proven practices outside and while continuing to depend on the whims of project managers, POs and so-caled technical leaders and others which can’t tell quality code from their own ass. There’s usually no money in writing high-quality software and almost everything in a software development project…

Software developers no, but Software Engineering does, it is a professional title in many countries, where universities and engineers are only legally allowed to use such titles after being validated.

I really don't think this matters. It's the processes beyond physical engineering that make it better. I have seen the most highly accredited software devs write the worst code. I have seen self-taught devs deeply consider implication of the things they are writing and solve the problem simply. And it's not even the case that I can perceive a trend. Well except for PhDs, I have met only one PhD that I know can write actual good code.

Re: Matt Godbolt sold me on Rust by showing me C++

#646
post #626

Earlier quoted context omitted.

The std has diagnostics struct you can give to the json parser. Zig is manually memory managed language so it doesnt have payloads in errors for a good reason.

Manual memory management is not a reason Zig couldn't have supported sum types for error returns. You don't need an allocator involved at all to return a discriminated union like Rust uses. I actually find Zig quite a pleasant language other than my gripe with not handling more complex errors as cleanly.

You would have to give up on global error set with sum types, unless you want to see the global error set bloat with the largest sum type. Also if the error payload needs allocating what are you gonna do? Allocating is no no no here. I know rust will just panic in OOM but zig chooses not to do that. Even if you allocated, since zig has no borrow checker the error handling becomes nightmare as you now have to deal with freeing the potential allocations.

Using out parameters for context, or diagnostic pattern like std does is not bad at all imo.

The only nice thing error payloads give you is better error messages in case of uncaught errors.

Re: Matt Godbolt sold me on Rust by showing me C++

#647
post #624
post #577

Earlier quoted context omitted.

Thank you! I can try to answer your questions if they are important to you, but it will require some significant effort, so I'd like to be sure they aren't rhetorical first.

Honestly, I'm wondering what kind of pathology do you see that isn't just a community stereotype, and that won't change with the influx of new programmers? And how does it differ from the average Open-Source Project?

The particular kind of pathology I see here is a strong centralization of the Rust community under the control of an unaccountable leadership caste. The point of free-software licensing is to minimize the control "owners" of software have over their users, protecting those users from abuses by leaders. Somehow Rust users seem to have, to a significant extent, abdicated the rights guaranteed to them by the software license.

For example, in your example of "inserting two mandatory ads to be watched during each Java compiler run", the OpenJDK license guarantees your right to remove those ads from your copy of javac, and to redistribute that copy of javac as the official Debian or Ubuntu version of javac. F-Droid does this routinely to such "antifeatures" in open-source Android applications, and of course Android itself exists because the open-source licenses of projects like Harmony, IDEA, and Eclipse protect Google from such malfeasance.

I'm not sure what the "average open-source project" is. Maybe something like https://github.com/justinasr/FantilatorOS/, the firmware for a redundant array of 64 inexpensive muffin fans that someone set up at CERN? https://web.archive.org/web/20231010215437/https://onlyfans.... Or https://github.com/antimatter15/splat, a Gaussian splat renderer in WebGL? I think those are both "non-average" in that they have a very above-average number of forks and stars. But, like the overwhelming majority of open-source projects, neither of them has a community in any meaningful sense, so I think the question doesn't make sense, given that it's a question about community dynamics.

Re: Matt Godbolt sold me on Rust by showing me C++

#648

Earlier quoted context omitted.

Er... why would you need a different API for this? Why not just convert to unitless at the point where the number flows into the UI? Or better yet, parametrize the UI library so that it can display any unit automatically. It could even pull the metadata (like the string for the unit) from the template, so that e.g. binding a kg value to a label would automatically show as "42 kg" etc.

At the point where you convert to unitless you lose all the benefit of strong types. Which is a trade off maybe you can accept. One part of that trade off that you are adding the ability to convert to unitless and thus making it easy to use unitless where you shouldn't. there are many different ways to implement unit systems. I know of 3 other attempts someone made on just our project to make units work before we set…

I understand that there may be other requirements that dictate the design. It's just that the specific one that you gave originally - that of displaying the values - strikes me as something that shouldn't be difficult even when you have units reflected statically in the type system.

> At the point where you convert to unitless you lose all the benefit of strong types.

Right, but if you do that right before it actually gets displayed, then it shouldn't be a problem since all actual computations have been performed already? I mean, you also need to convert numbers to text to render them, so all the same arguments apply.

So e.g. in the "ideal" desktop app using MVVM, that would happen on the boundary between the model and the view-model.

> One part of that trade off that you are adding the ability to convert to unitless and thus making it easy to use unitless where you shouldn't.

But any typed unit-of-measure system inherently has such an ability if it tracks units properly for arithmetic operations - you just divide by 1 of the same unit to get a unitless value. E.g. in F#:

   let v = 10      // in m/s
   let n = v / 1   // unitless

Re: Matt Godbolt sold me on Rust by showing me C++

#649
post #619

Earlier quoted context omitted.

Even then you're probably better off using something safer that transpiles to C.

”Transpiles to c” - how do you generally optimize single line performance hotspots in that case?

I don't see why that would make any difference? The generated C code is just a build artifact in this case, similar to IRs often used by compilers internally. You don't think about e.g. gcc IR when you optimize hotspots in code written in C, though - you just look at the C source and the generated asm code. If you have, say, Zig transpiling to C (which it can do with `-ofmt=c`), you'd similarly look at the Zig source and the generated asm code.

Re: Matt Godbolt sold me on Rust by showing me C++

#650
post #632

Earlier quoted context omitted.

Honestly I'm not even sure that Java checked exceptions are so bad in general compared to Result . The amount of verbiage is roughly the same. Where Java failed is the inability to write generic code that uses checked exceptions - e.g. a higher-order function should be able to say, "I take argument f, and I might throw anything that f() throws, plus E1". But that, as you rightly point out, is a Java problem, not a ch…

I liked checked exceptions. I just think they were overused. Had a CS prof that summed up the optimal case like this: Programmer's fault: runtime exception Not programmer's fault: checked exception Reading from a file but the disk fails? Not programmer's fault. IOException (checked). Missed a null somewhere? Programmer's fault. NullPointerException (unchecked).

Lack of parametrization meant that any interface that could be implemented in a way that could e.g. throw IOException had to declare it on its methods, even if only a single implementation out of several actually used it. And API clients then had to handle those exceptions even if they knew that they never use the interface implementation that could throw.

Or, alternatively, the interface wouldn't declare it as thrown, and then you couldn't implement it in terms of disk I/O without rewrapping everything into unchecked exceptions. A good example of that is java.util.Map, if you try to implement it on top of a file-based value store.

Post reply on HN