8,671 karma · joined Dec 19, 2010 (15y ago) · 2,475 submissions
comment 18h ago · link · parent
To me the whole point of an "uninitialized variable" is to declare it in one place and then assign it in exactly one code path, which is exactly what rust supports without any unsafe code:
let i: i32;
if is_tuesday {
i = 0;
else {
i = 1;
}
foo(i);
is already perfectly valid, safe rust code, because the compiler knows that all code paths result in assignment before use. And the answer to "what happens on that first line?" is "nothing", because it's just a declaration. In the equivalent C++ you'd be running an arbitrary constructor on the first line, and hoping the compiler optimizes it away. Or if the default constructor doesn't exist or is deleted, you simply can't code that way.comment 18h ago · link · parent
Heck, Smalltalk is the original OOP language and has implementation-based inheritance, and construction is done through ordinary methods on class objects.
comment 19h ago · link · parent
This is definitely the closest thing to an answer in this thread. This is something that languages without constructors do struggle with, yes, and as other commenters pointed out, Rust sees this as a performance issue and is working on it.
Thanks for the informative reply.
comment 19h ago · link · parent
comment 19h ago · link · parent
Right, see the "I guess the argument might be" part above... I find this to be a very questionable design choice, leaving you to have to go and read a header somewhere to determine whether `Foo f;` is safe or not. But it's not really a choice, is it? C++ had to do it this way to be compatible with how C programs were written back in the 1970s.
> By the way, already in the 16 bit days you could configure to have warnings as errors for variables being used without initialisation.
Ah yes, the "but C can be configured to be not-insane" argument, one of my favorite pjmlp-isms, right up there with "but $LANG's compiler is written in C++" and "but you already get memory safety with a GC". Keep on doing you!
comment 20h ago · link · parent
#[derive(Debug)]
struct Foo {
_i: i32,
}
fn main() {
let x: i32 = unsafe { std::mem::zeroed() };
println!("x={x}");
let f: Foo = unsafe { std::mem::zeroed() };
println!("f={f:?}");
}
prints: x=0
f=Foo { _i: 0 }
It's unsafe because if Foo contained a String, it would be string with a null pointer inside it and you'd crash trying to read it. If you want "Default" values instead of zeroed (ie. you don't want to run unsafe code), that's what the Default trait is for, and this becomes: #[derive(Debug, Default)]
struct Foo {
_i: i32,
}
fn main() {
let x: i32 = Default::default();
println!("x={x}");
let f: Foo = Default::default();
println!("f={f:?}");
}
and prints the same thing.comment 20h ago · link · parent
comment 21h ago · link · parent
let x: i32;
foo(x); // compiler error
or if you really wanted to use uninitialized memory, let x: i32 = unsafe { std::mem::uninitialized() }; // compiler warning
foo(x);
which, in rust, can be done with any other type too (substitute i32 for any T and the above examples are identical.) I don't see anything different about built-in types here vs standard ones, other than the compiler has literals for the built-ins, which is more a consequence of rust not allowing literals for library types. But that's a very different discussion.I guess the argument might be that for C++, they want the author of the type to determine whether the value should be left uninitialized on declaration/construction, instead of the caller. Which is... not exactly the semantics I would have chosen.
comment 21h ago · link · parent
comment 21h ago · link · parent
Then you have languages like Rust, Go, Zig, etc which don't have them at all, constructors are just static functions in the namespace of the type, which return an instance of that type.
For the life of me I've never understood why you'd want the former. I'm sure there's a reason, but I never miss it when using languages in the latter category.
The explanation you typically hear is about OO and inheritance, but I don't buy it: If Animal had a ::new() that initialized private state, Cow could have a ::new() too that could call Animal::new() if it wanted, then do further initialization, etc... I don't think there's anything about inheritance that says constructors are a must. (Edit: In fact, ObjC does exactly this. I should have remembered that given that I did ObjC for a living for a while.)
comment 22h ago · link · parent
I would change that to "might not have any practical consequences". It could very well be that the proof that factoring is in P is made by discovering a polynomial-time algorithm for factoring. In fact that would be my default assumption if you told me "someone proved factoring is in P": they must have found an algorithm that does it. (I'm aware there's other ways to prove it, but to my dumb brain, proving the existence of X is easiest done by finding X.)
There's been lots of times in history where we thought a problem was in NP, then someone found a P solution for it. In fact that's one of the very reasons we don't know if P=NP or not.
comment 1d ago · link · parent
Your claim was that NeXT would have written a completely independent operating system core with no relationship to UNIX whatsoever, and the only reason they didn't was something hand-wavey about universities. Care to back that claim up and not respond with red herrings about user interface?
comment 2d ago · link · parent
The contrapositive would be that NeXT would have written a separate OS foundation that had nothing to do with UNIX, and your claim is that the only reason they didn't do this was to get universities to buy it. But your links only emphasize how much they wanted to hide the underpinnings (which is a good idea in general, since they were going for, y'know, a GUI.)
A much simpler explanation is that they needed UNIX's design as a well-understood and proven technical foundation, but were determined to hide that fact as much as possible, because they didn't believe in the CLI as the future of the user interface. But for markets where users actually wanted UNIX, they were happy to advertise that it was there.
comment 5d ago · link · parent
Will we be able to get an actual simulation of a system, which follows the Navier-Stokes equations, that will actually show the blow-up happen in real time, so we can potentially gain an intuitive understanding of where the equations don’t match reality?
The OpenAI release a couple months ago had a rendering of some arrows ascending in a tornado shape, but I don’t know if that’s just an “artist’s rendition” kind of thing or not… it would be interesting to see if a software simulation that simply followed the NS equations could be given some start conditions and then blow up to infinity, in a way I could see for myself. But I don’t know if the proof actually works that way.
comment 5d ago · link · parent
Was I happier when I believed in Santa Claus? Maybe. I'm sure lots of Christians who believe in heaven are happier about the prospect of death than I am. But you can't unlearn these kinds of things, you can only delude yourself.
comment 6d ago · link · parent
But then you have projects that just decide every other month that the abstractions they just introduced are now out of style and decide to rework everything. Changing names of functions, taking formerly-public types and making them private, utterly (and intentionally) breaking every single person that uses the library. I think we can agree that these types of changes are distinct from what you'd put under hyrum's law.
> The alternative to semver is not "projects don't make breaking changes", it's the old bad "projects make breaking changes randomly from release to release, and without carefully reading the changelog you will never know". But back then dependencies were rare, releases were a big thing, and people were OK with reading changelogs. At our current scale this is impossible.
I don't disagree with this, but you can't separate the good from the bad with semver. It makes bad engineering practices easier to spot, yes. But it also normalized them. Intentionally breaking compatibility in a software library is bad engineering practice. SemVer lets people pretend that's not true because they can increment a version number and skirt all blame for it.
(Edit: I'd be happy if the semver quasi-rfc at least paid lip service to the effect of "Backward incompatible changes SHOULD NOT be introduced a public API" or something, but it doesn't even say anything of the effect, just "Major version X MUST be incremented". The FAQ even says "Deprecating existing functionality is a normal part of software development and is often required to make forward progress", which just reinforces the attitude. It shouldn't be "normal" at all... a better wording might be "Deprecating existing functionality is regrettable but sometimes required to make forward progress.")
Again I want to stress that the actual thing I'm against, is the cavalier attitude towards backward compatibility. Like this thread starting from someone saying "I wanted to go into $crate and change everything and was met with resistance!" as if we should be sympathetic to them. No, I'm sympathetic to the maintainers of $crate who understand that if you don't like its API's you should start a new crate, not simply change an existing one to suit your tastes. We need more of this resistance.
comment 1w ago · link · parent
The correct answer is to just let your garage door opener be dumb, and buy a RatGDO, which works with any dumb opener including chamberlains: https://ratcloud.llc/
I like to think chamberlain sells their openers at a slightly lower price than they otherwise would, hoping to recover it on subscriptions. So by buying their opener plus a RatGDO, I’m hurting their bottom line just a tiny amount. It makes me feel good at least.
comment 1w ago · link · parent
The problem with SemVer is it encourages you to "move fast and break things", constantly bumping major versions as a standard practice, rather than thinking very deeply about what abstractions you make public in your library (often minimizing the surface area as much as possible) to avoid painting yourself into a corner, and being extremely deliberate about any time you need to break the API in order to make a change. Ideally forking things with the changes and releasing the new library "all at once" once enough accumulated changes have built up, rather than bumping the major once every time.
The real issue I'm complaining about is the cavalier attitude towards breaking changes that library maintainers tend to have, and how much I believe SemVer caused it. If this attitude was not prevalent I'd have no problems with SemVer.
comment 1w ago · link · parent
(Putting my flame suit on here, but...) I think that's a good thing, and I wish this were the norm with more libraries in the open source world. Once you hit a stable version, breaking changes should happen approximately never. Improvements that need breaking changes should happen under a new name, with a new project, so that the old project can still exist and receive updates.
I still say SemVer has done more harm than good for the industry... it normalized the idea that "it's ok to break compatibility, just bump the major version" and then you have libraries on version 26 that break everything every time the author decides to feng shuei the code some more. Every major version bump should be thought of as a sort of "grave marker" indicating a place in history where the author messed up and had to admit the old design was literally broken, and every downstream dependent had to go through some amount of pain as a result. It shouldn't be normalized.
You can say "nobody's forcing you to upgrade" but, with the amount of vulnerabilities out there, yes, you often are forced to upgrade certain dependencies.
You can say "just maintain the older versions too", and that would be absolutely great, if anyone really did this. In practice anything but the most recent major is neglected.
You can say "I agree and that's why I never release 1.0", and I'd say that's a reasonable approach, but that just changes the problem to "too many packages are pre-1.0" and we'd have the same issue.
You can say "that degree of compatibility is too difficult to expect out of open source maintainers", and my response is that there ought to be fewer open source maintainers. (For real. I'd rather have 1/100th the number of crates in Cargo, if the ones that were there were all maintained by people who were serious about backwards compatibility.)
You say "the API sucked and I hoped I could make it better", but the API is the library to anyone using it, and changing it means you're literally changing what the library is, which means all existing code using the library has to change to meet your new opinion on what the better API is (an opinion many wouldn't share, including and especially the original authors.) Why not just start a new project instead?
comment 1w ago · link · parent
The closest analog we have for "person goes into a school while it's in session to kill people at random" is the FBI's list of "active shooter" incidents, and only some of those are counted as "Mass killings", and the data there says we've has as little as 3 (in 2024) and as many as 15 (in 2023) per year in the past 5 years: https://usafacts.org/articles/what-is-considered-a-mass-shoo...
And that 3-15 number is all mass killings, not just in schools (I don't know how many of those were in schools, but we could stipulate maybe 1 in 3?)
So, the 250-350 number is a couple of orders of magnitude higher than the type of school shootings parents are actually worried about when it comes to needing to text them during the day.
comment 1w ago · link · parent
The point of cooldowns is for when a crate author’s account is compromised and used to publish malicious code. Saying “security advisories bypass cooldowns” wouldn’t really help anything there.
comment 1w ago · link · parent
It’s only weird if you come from languages like Java where “primitives” are distinct from “objects”, which is a self-imposed limitation the language imposes.
comment 2w ago · link · parent
This is exactly the same for me. The guitar fretboard is essentially synesthesia for me when I hear music. I hear a melody and part of my brain feels the shape of the fingerings as I go. It’s been like this for maybe 30 years or so (I started guitar at a really young age.)
I have no idea if this is common for guitar players though (I assume so? If you’re the sort of player that can play solos, you probably already “audiate” sounds via fingering) but it means I can basically always immediately play a song after hearing it once, even if it’s just the basic melody. I also have what I’d call “weak” perfect pitch (I can easily conjure an E in my head and then figure out from there what note I’m hearing via well-trained relative pitch) so often I can get the exact notes right the first time.