9,664 karma · joined Jun 14, 2010 (16y ago) · 1,504 submissions
comment 4y ago · link · parent
What we get in return for all that pain is slightly faster execution — in theory. A recent post on HN actually showed that at least in some cases, modern LLVM compiles to code that actually runs 1-2% slower than an ancient LLVM version.
Shouldn’t we conclude from all this that what we need is a movement to go back to simple, deterministic and fast compilers?
comment 4y ago · link · parent
comment 4y ago · link · parent
comment 4y ago · link · parent
You put your dynamic components into references and smart pointers of the form Box<dyn Component>, where Component is a so-called “object-safe trait” (which is exactly what you’d call an interface in the OO world). These traits can inherit from each other, and you can upcast a Box<ConcreteType> into a Box<dyn Interface> into a Box<dyn ParentInterface>.
comment 4y ago · link · parent
C++ seems perfect for these people because there are so many little traps and arbitrary rules to remember. “Ha ha, you wrote for (const auto x: y) instead of for (const auto& x: y)? Stupid fool!”
(Or is it auto&& now? decltype(auto)? I honestly don’t remember and don’t really care.)
I’m not remotely suggesting all or even most C++ experts are like this, but anecdotally, their share is higher than among, say, Python programmers.
It’s not like Rust is particularly easy to learn. On a conceptual level, it’s probably harder than C++ (traits, generics, lifetimes). It’s just so much less arcane.
comment 4y ago · link · parent
Nowadays, UIs are designed with the expectation that users don’t learn them. This limits what software can do, but (I don’t mean this cynically) was probably necessary to bring those apps to the majority.
comment 4y ago · link · parent
As someone who was in their mid to late teens at the time, I find nostalgia for Windows XP in particular a bit funny because back then, people couldn’t disable the new UI and activate the “classic look” (Windows NT/9x style) fast enough.
comment 4y ago · link · parent
I’ve seen software break due to a race condition when an upgrade made something faster. Hyrum’s Law tells us the performance was a hidden part of the interface. Is the solution to never optimize anything? Instead, I claim the client code was broken all along.
comment 4y ago · link · parent
comment 4y ago · link · parent
> struct foo{ int const x; };
> void some_func(foo*);
> int bar() {
> foo f { 123 };
> some_func(&f);
> return f.x;
> }
> bar will always return 123. The compiler may generate code that actually accesses the object. But the object model does not require this. f.x is a const object (not a reference/pointer to const), and therefore it cannot be changed.I like to think I know quite a bit about C++, but I don’t get this at all. Why is f.x a const object even when accessed through a non-const variable? f isn’t const; there’s no const_cast here. At first glance, this looks like a bug in the spec, roughly like confusing
int const *p
(pointer to const) with int const *const p
(const pointer to const). Only the latter will always point to the same thing.What am I missing?
(Edit: Since it’s a bit hidden in the SO question, the idea is that some_func does something like this:
void some_func(foo *f) {
new(f) foo { 42 };
}
Note that there’s no const_cast here, and f’s storage isn’t const, so this isn’t UB to the best of my knowledge.BTW, in case it’s not obvious, it’s not all that helpful to reply to the question why the spec is a certain way by tautologically repeating the spec.)
(Edit 2: Unfortunately also very typical for C++ discussions, I just love how people think that C++ confusing me must mean that I’m dumb, and then condescendingly post a wrong answer. Rule of thumb: If you’re confident in your ability to understand C++, you don’t understand it very well.)
comment 4y ago · link · parent
comment 4y ago · link · parent
TBH, I don’t find those arguments convincing, but then, WebGPU is largely a political compromise, not a technical one. In a politics-free zone, they’d have standardized a “WebVulkan”, not made an entirely new thing. That would have been on the table, but Apple vetoed it. The same for a “Web-SPIR-V”.
However, I also don’t think it’s that big of a deal in the grand scheme of things. I’m glad we have a viable standard at all.
comment 4y ago · link · parent
OpenGL/WebGL aren’t well enough aligned with modern hardware to serve as a cross-platform graphics layer.
That’s where the newer APIs come in. Vulkan, Metal and DirectX 12 all follow similar principles that would work from a technical standpoint, but we live in an age where platform vendors would rather cripple their platform than make it easy to port software. Apple is the worst offender here, because while Microsoft isn’t happy about it and disables it in “metro” apps, at least they don’t prevent GPU vendors from shipping Vulkan support for normal “desktop” apps.
But I’m optimistic about WebGPU: It’s designed to be efficiently implemented on top of the vendor APIs, so platform vendors can’t block it. And it’s low-level enough that it should allow implementing modern games on top of it.
(To clarify: I’m optimistic about WebGPU as an API for desktop applications. For browser apps, it seems like all vendors are on board already.)
comment 4y ago · link · parent
You can’t rotate all the way to lightspeed, that would be rotation by an infinite angle. For any finite angle (i.e. speed below c), you can always add the angle of the bullet to get a new (finite) angle.
comment 4y ago · link · parent
I think the hard problem in practice is that headers and templates make for a very fuzzy boundary between library code and client code. Calling C++ from Rust already works fine for traditional OO code, but it’s hard to imagine that anything could ever use modern templated C++ code that isn’t a full superset of C++.
comment 4y ago · link · parent
For object-safe traits where this would be possible, you can at least do this at the cost of an allocation, as you probably know:
fn some_func() -> Box<dyn SomeTrait> {
if some_condition {
Box::new(a)
} else {
Box::new(b)
}
}comment 4y ago · link · parent
The discussion is about large standard libraries vs. package managers. C and C++ are even older languages that had neither. Back then, the idea of having a large abstraction layer between the language and the OS wasn't even thinkable -- that idea didn't really appear before the 90s.
If you don't know the size of Java's standard library in the 90s, it's maybe risky to imply that it must have been small. :) Kidding a bit. But to give a hint, it included two different incompatible GUI frameworks by 1998.
JavaScript is from the 90s, but wasn't a standalone programming language until Node.js, which was released in 2009.
C# is the newest non-Go language you mention with a large standard library. It was released in 2000 (so in the 20th century if we're being pedantic), and even it has moved a lot of stuff into Nuget packages that used to be built in. For example, the entirety of ASP.net.
comment 4y ago · link · parent
Go just dodges that trend and does the 20th century thing, as it does for many other design decisions. Just as it has common data structures as hardcoded language features, instead of the ability to build them as abstractions.
To be clear: One can take the position that the trends go in the wrong direction and Go is right to reverse them -- that's a matter of opinion. I just don't think it's fair to argue Go is the language that does the more modern thing.
comment 4y ago · link · parent
But I agree that we’re past that point at least for simple async worker threads and simple IO. I don’t follow the progress that closely, but I think work is happening towards standardization there.