HN user

josephg

21,267 karma

https://josephg.com/

Email me@josephg.com

[ my public key: https://keybase.io/josephg; my proof: https://keybase.io/josephg/sigs/F1nFs1IINV56Uq1naP2gxZ1lPnPFdZNvMA5ffdbXUAk ]

Posts6
Comments5,063
View on HN

The only part the compiler actually enforces is that you mark the specific spots where you make use of the operations that 'unsafe' allows.

Yes, I wish there was a way to mark code as unsafe without also allowing unsafe operations. Its quite common I have some "safe" code that generates values which are eventually used in an unsafe block. If the "safe" code is wrong, my unsafe code will fail in memory-unsafe ways. But there's currently no way to annotate this sort of "safe" code. Rust provides the unsafe keyword - but that keyword is generally reserved for code which needs to actually make unsafe operations (like derefing pointers or calling other unsafe functions).

In short, if you use an unsafe block, then potentially any part of your code is unsafe.

The way I think about it is that the unsafe keyword is a promise that you’re going to maintain the safety invariants yourself, manually. The program is memory correct if it correctly maintains a certain set of invariants. Unsafe punts responsibility over those invariants to the programmer. If you use unsafe and mess up, the program may be in an invalid state. Yes - it might crash, anywhere. But the bug is still almost always in an unsafe block.

It’s often possible to make fully safe wrappers around unsafe code which maintains all those invariants manually. (Either statically or dynamically.). A lot of the rust standard library does this. For example, Vec, Box and slice all use unsafe code internally to create safe APIs.

People are so funny about rust.

“Safe rust isn’t expressive enough!” -> then use unsafe rust.

“Unsafe rust lets you do anything! Even crazy things!” -> then use safe rust. Or just don’t write crazy code?

Does bun actually do anything insane like that in its unsafe blocks? Or are you just fear mongering?

I’ve never seen them for sale except the US one

Apple - at least used to - sell an international plug pack if you’re missing some. I can’t even remember where I got some of my plugs. They’ve been doing this for decades, and the international plugs are still compatible.

If you’ve got one of the older style Mac chargers, the part which plugs into the wall physically separates from the rest of the charger. You can connect different plugs for all the different countries. There is a plastic seam where the charger separates. It’s easy to miss.

I’ve slowly acquired all the global adaptors for Mac chargers. I just bring a usbc Mac charger when I travel with the destination country plug attached.

I wish Apple made gan chargers though. Those look great

If the readme is anything to go by, this doesn't look like it was written by hand. Codex if I were to guess. I wonder the coding agent "improved" the code.

The readme hints at the prompt:

It keeps the original system's semantics — what it does — while rethinking how it's expressed: stronger types, clearer module boundaries, idiomatic abstractions everywhere.

"idiomatic abstractions" would certainly bloat the line count.

Eh, that argument cuts both ways. Lots of the defaults in C++ are bad. Like, most people don’t know how compiling all your code in a single code unit will improve performance. Or how to do it. In rust it’s a single flag in cargo.toml which is widely talked about. Rust has a much better, faster standard library than C++. Any code which makes heavy use of - for example - sorting in C++ and rust will favour rust because it uses a better algorithm by default.

Rust had the opportunity to iterate on C++’s default choices and improve on them in many cases. I’m not convinced that naive C++ is particularly efficient.

(That said, lots of rust beginners make heavy use of Box and clone() and write inefficient programs that way. It’s hard to actually measure average, beginner code.)

If you have a hot loop where it matters, you can put an assert outside the loop which lets llvm remove the bounds checks. Or use unsafe { get_unchecked() } to remove the bounds check entirely.

I don’t know what you’re referring to. Unsafe seems pretty well defined for 99% of use cases. Unsafe blocks allow you to dereference raw pointers and call unsafe functions. Thats about it. Remarkably, even in codebases which need a lot of unsafe (eg the kernel), almost all code is safe code.

Yep. And array bounds checks have a miniscule performance impact at runtime because they're so friendly to branch prediction.

I can understand when you need the absolute best performance and you decide to drop to down to C++

Rust is just as fast as C++.

I disagree. Rich text editors on the web are already a massive hack, because there aren’t any built in input elements which support rich text. There’s just contentEditable and textarea (plain text). There’s no such thing as “doing it properly” when it comes to rich text. Editors have to hack around what the browser provides via a million event handlers. And - surprise! Mobile browsers don’t expose the same events as desktop browsers.

The right fix is for browsers to have a real rich text element of some sort. Then editors wouldn’t need all their hacks. And mobile browsers would be able to behave correctly when you tap on some editable rich text.

Should…

Whenever I travel, I bring a CO2 meter with me. It’s amazing how often the air is bad. Often in unexpected places. My meter hit 3100 in an uber once. I didn’t even notice until I got to my hotel room and looked at the data log. It was a fresh, hot day outside. The uber had windows closed and AC on. I bet he had no idea - but he was driving with significant cognitive impairment. Takeoff and landing in planes are always the worst. If you get sleepy as the plane is taking off, it’s not you. The plane’s ventilation doesn’t work properly when the plane is stationary. So before a plane is in the air, they often hit 2500.

Yeah I did a review of web based rich text editors a couple years ago. They all seemed fine on desktop, but on mobile every one I tried was junk. I couldn’t select. Autocorrect was broken. Tapping text didn’t move the cursor. Typing would stop working. The keyboard wouldn’t disappear when the element lost focus. And so on.

There have been several efforts over the last couple decades to add a proper rich text element to the web. I don’t know why they have all failed - I guess it’s a large, complex and thankless task. It’s a pity. Proper native rich text support is one of the web’s big blind spots. It’s a problem native platforms have solved decades ago.

I had an 11” 2011 air. An incredible machine, one of the best I’ve ever owned. I stupidly replaced it with the 2016 retina touchbar MacBook Pro - which is hands down the worst Mac I’ve ever owned bar none. My modern M1 is fine. But that little air was somehow more fun.

Where are the dozens of European tech winners? Seriously. They have the best education system in the world, strong social safety nets, cheap healthcare, and great lifestyles. Why have they not created innovative technologies that turn into worldbeating companies?

This is a great question. I'm Australian, and I ask myself the same question constantly here in Aus. The engineers I graduated with in Sydney are easily as good as the engineers I worked with in the Bay Area. But where are all the startups?

Having worked in Aus and SF, I think the two big elements are culture and finance. We don't have a culture in Aus of risktaking and entrepreneurship. People just seem less interested here in changing the world by starting a tech company. If you do start a business, you're kind of on your own. There isn't a community of people who've done it before who can guide you. And there isn't the same sort of venture capital here. Lenders only want to make sure bets. There's money for low risk, low yield lending. But there are barely any funds for high risk, high yield. The successful tech startups I know in australia bootstrapped themselves (Fastmail, Atlassian).

As far as I can tell, Europe has the same problems. Europe has capital, but I don't think that capital it looking to make angel investments.

But maybe cutting ties with the US tech scene would help change that? So long as Google Docs works well, nobody is clamouring to make or fund a competitor. But take google docs away, and suddenly there's a clear need and a chance to make a lot of money. That could spur innovation.

If the EU takes the DPA 'independence' seriously, they will end up marginalized in the tech space.

If NVIDIA can't sell GPUs to China, will that marginalise chinese technology? Or will it help supercharge a local industry? It might do both - hobbling chinese AI in the short term, but helping chinese competitors emerge in the medium to long term. US tariffs are the same. They might "marginalise" the US economy. But maybe they'll revitalise the US manufacturing industry too? We'll see!

The EU has a tremendous number of smart software engineers. They're more than capable of recreating the US technology stack locally. Especially with the benefit of hindsight, and with access to opensource software. In the long run, I wouldn't be surprised if Europe ended up richer by building their own tech stack "in house" instead of outsourcing to US hyperscalers.

Me too. It’s output was fabulous. And it acted like a senior engineer - actually coding up hypotheses, testing them, finding problems and presenting good, usable recommendations backed by solid evidence and wisdom. It can probably do most of my job, which gave me a bit of an existential crisis.

I’ve paused my Claude subscription until they bring it back. Opus makes mistakes constantly, on every level of abstraction. Every time I look closely at its work I find problems.

Yes, I agree. But not all technical writing is README files. For books and long form articles, markdown simply isn't powerful enough. And for stuff like this, nobody cares whether or not the source is readable as plain text.

But you can't abstract. I can't make a custom template for an image + caption, and use it throughout my markdown document.

You can do some pretty wild stuff with html. But if you do, you get an unreadable jumble of markdown and HTML. It loses the single advantage of markdown - which is that its human readable as a text file.