Live data from Hacker News

"No way to prevent this" say users of only language where this regularly happens

xeiaso.net

261–270 of 342 posts

Re: "No way to prevent this" say users of only language where this regularly happens

#261

Earlier quoted context omitted.

C/C++ being non-opinionated is the main source of the security vulnerabilities. Let's face it, it felt good to be a lone cowboy carrying a lot of responsibility and knowing what you are doing. I was there myself and I'll admit the ego trip was awesome. These times are long past and naturally, people refuse to adapt. > Unfortunately you can't just have Rust's safety checks, without opting into restrictions that Rust d…

>Show me something that does better and I'll switch tomorrow. There's no limit to perfection, but if you merely don't write C of opportunistic kind, logical errors quickly start to outweigh other types of errors.

Are you willing to die on this hill? I remember an HN post a while ago where both Microsoft and Google said something like 65% of the bugs in C code were related to memory (un)safety.

Re: "No way to prevent this" say users of only language where this regularly happens

#262

Earlier quoted context omitted.

What things simplicity do you lose? I think there isn't much of a difference between these dialects. Most important one might be possibility to define variables on the spot instead of at top of block. Then, some people like C99 compound literals. I don't think any of these break simplicity, they are quality-of-life improvements with no interactions with the rest of the language semantics. Next one is what, the C11 me…

Here's my thinking. It's fair to say C99 isn't that much more complicated than C89, which formalizes various things that are a bad idea such as "volatile", as well as numerous good ideas like hey we should let you define a variable where you use the variable - however C99 adds more of the bad like "restrict". In both those cases the K&R C model was very simple. You could decide you love how simple this model is, and…

So you're focusing on the memory model. To which I'll say, it's not the language but it's the _machines_ that have SMP so effects will be visible out of order. The machines provide you with escape hooks to serialize read and write effects, and the language must give you access to these hooks because if the language opts to keep up the illusion of all sequential effects even in the face of SMP, it has to do so by serializing basically all memory accesses, which is going to be incredibly slow.

That code doesn't appear to be sequential from other threads is not the language's fault. It's just a fact of reality.

If you don't want to do SMP / lock-free programming, you don't have to pay for the complexity. You can still write "sequential programs" like it's K&R. Don't do multiple threads, and you don't have to care. You can also do multiple threads but use mutexes for synchronisation, everything will be fine.

Pretty much nobody uses restrict or volatile. There is some fringe stuff that is obsolete and maybe badly designed, but by and large you don't have to use it or interact with it. Compare this to other languages / ecosystems which have this amount of cruft times 100.

It's still this language where you can define a struct, then define a function that receives a pointer to the struct, and it does as you say, and you can actually read and understand the code a month later.

If you need to go fancy for a reason or another (most likely a bad reason), you can do that too, and of course you'll have to pay for it. But most likely, the complexity is not "cancerous" -- define a simple function interface with the most basic assumptions you require, and the complexity is pretty much isolated behind a simple pointer to an opaque structure.

> So C11 definitely isn't the simple language for a 1970s computer any more. C11 is a competitor with C++ or today Rust. And it doesn't fare so well by that comparison.

That's ridiculous and you know it.

Re: "No way to prevent this" say users of only language where this regularly happens

#263
post #133

Earlier quoted context omitted.

Comment above, mentioned borrowing while structs instead of borrowing memory. I believe this was once discussed under term 'partial borrows', but the "idiomatic" aproach is to 'just split your structs'. Which isn't really a good aproach to structuring codebase, it's just to appeal to borrow checker inflexibility. Lack of global scope. Lack of function overloading.

> Comment above, mentioned borrowing while structs instead of borrowing memory. I believe this was once discussed under term 'partial borrows', but the "idiomatic" aproach is to 'just split your structs'. You're mistaking "idomatic because it's the only way" with "idomatic because we say say so". There is currently no way in Rust to specify the granularity of a borrow, so we're stuck with splitting your structs to ge…

That's truism, ofcourse there is no way to do something that is not impemented.

The question is whether or not the fact of it not being implemented comes from problem difficulty, or designers explicit refusal to do so

Re: "No way to prevent this" say users of only language where this regularly happens

#264
post #206

Earlier quoted context omitted.

Most of the free democratic western world does not have a lax gun culture like the US has and yet there's no tyranny. Weird.

This isn't as clear cut of a case as you make it out to be. Britain's recently been on a path of overregulation bordering tyranny and limiting free speech. Canada is on a similar path. German green and red party politicians recently caught flack for trying to criminalize unpleasant critique. Press freedom and press independence are actively getting worse and Europe is setting course on a path of nationalism and conse…

I don't think you can call the British thing tyranny, speaking as a Brit.

Ok there have been some hate speech laws, but we have elections and can vote the pols out, no armed uprising required.

Re: "No way to prevent this" say users of only language where this regularly happens

#265

Earlier quoted context omitted.

Switzerland has very high rates of fun ownership, but their laws are far from lax. They are much stricter than the US. You need a permit to buy anything other than a hunting rifle. You can't buy a gun if you have been convicted of a crime, have an alcohol or drug addiction or express a dangerous attitude. You generally can't carry a gun except when going to and from hunting or a shooting range and you can't have the…

> You need a permit to buy anything other than a hunting rifle. You can't buy a gun if you have been convicted of a crime, have an alcohol or drug addiction or express a dangerous attitude. ...as opposed to the US? Do you think you can just buy a machine gun over the counter without any checks in the states?

Not an actual machine gun (a weapon specifically designed for automatic high rate of fire), no.

The US Supreme Court has repeatedly struck down reasonable restrictions for hand guns and rifles though, and seems likely to conclude that modifying a weapon to in effect become fully automatic is somehow OK. This creates a convenient gap which I don't think a reasonable person can believe is a mistake.

Re: "No way to prevent this" say users of only language where this regularly happens

#267
post #182

Earlier quoted context omitted.

The oversimplification is part of the joke.

[flagged]

It's not even really benefits of guns are outweighed by people doing murders. All countries pretty much have some gun availability. In the UK where I am you can get a shotgun without huge problems for example. Also all countries have restrictions - even in the US I don't think you are allowed to stock up on M777 howitzers and ammo (British gun by the way). It's about having sane regulation.

Re: "No way to prevent this" say users of only language where this regularly happens

#268

Earlier quoted context omitted.

I'm feeling my lack of academic training here, but I needed to make sure. When you say sum types, are you referring to enums, or is it a broader concept than that? The Wikipedia article was quite archaic but seemed to support my initial understanding that you're talking about enums. Are you talking about enums?

In Rust they are called "enum", elsewhere "tagged union", "discriminated union" or "variant" (under the hood, all of those are just a C-style union bundled with a tag field which identifies the active content of the union). The rest is language specific syntax sugar which makes their usage more or less convenient and typesafe (and sometimes more memory efficient, for instance a pointer|null type doesn't need the tag…

> (under the hood, all of those are just a C-style union bundled with a tag field which identifies the active content of the union)

Crucially that's not necessarily what's going on in Rust and (assuming it lands) won't be the actual implementation of C++ std::optional specialisation.

Instead the language can decide from the value which type it has. This is where Rust's Guaranteed Niche Optimisation kicks in. If we've promised the compiler that type T's values don't occupy the space needed fully, the GNO promises that sum types consisting of T plus one other value are the same size as T was. There is no "tag field".

In practice, the compiler can provide optimisations beyond the Guarantee. For example the compiler can see that OwnedFd (a file descriptor) has a niche so Option is the same size as OwnedFd (ie the same size as a C integer, typically 4 bytes), but it can also see that char has a huge niche. Many of the 32 bits aren't needed to store a 21-bit Unicode scalar value, so (although the guarantee doesn't apply) a sum type of a char and six hundred other named possibilities is the same size as just the char was.

Ah, I see you mention this at the end, I think it's worth highlighting much earlier, that the "tag" isn't actually a mechanically necessary part of such a type.

Re: "No way to prevent this" say users of only language where this regularly happens

#269
post #230

Earlier quoted context omitted.

This isn't as clear cut of a case as you make it out to be. Britain's recently been on a path of overregulation bordering tyranny and limiting free speech. Canada is on a similar path. German green and red party politicians recently caught flack for trying to criminalize unpleasant critique. Press freedom and press independence are actively getting worse and Europe is setting course on a path of nationalism and conse…

And the US police routinely rob travellers of their cash and goods at gunpoint. So again, what good are the lax gun laws providing the populatnon against tyranny?

As we've learned recently, American gun owners don't give a shit about tyranny so long as the tyrants don't come for their guns.

In fact, depending on whose head the boot comes down on, they'll even cheer it on.

Re: "No way to prevent this" say users of only language where this regularly happens

#270
post #206

Earlier quoted context omitted.

Most of the free democratic western world does not have a lax gun culture like the US has and yet there's no tyranny. Weird.

This isn't as clear cut of a case as you make it out to be. Britain's recently been on a path of overregulation bordering tyranny and limiting free speech. Canada is on a similar path. German green and red party politicians recently caught flack for trying to criminalize unpleasant critique. Press freedom and press independence are actively getting worse and Europe is setting course on a path of nationalism and conse…

American take:

- UK sociopolitical problems caused by lack of guns - Canada sociopolitical problems caused by lack of guns - German sociopolitical problems caused by lack of guns

I think I can complete the rest of the thinkpiece on my own, with the help of ChatGPT. My prompt starts with, "You are a gun"

Post reply on HN