Better HN
topnewbestaskshowjobs
Log inSign up

codedokode

9,867 karma · joined Aug 20, 2015 (11y ago) · 5,528 submissions

PHP developer from Russia.
Submissions

comment 1y ago · link · parent

That's the destructor function, that is written by you and called by Rust before actually destroying something. The function that you want to look at is [1].

If you read the docs at your link it even says:

> This method is called implicitly when the value goes out of scope, and cannot be called explicitly (this is compiler error E0040).

> However, the mem::drop function in the prelude can be used to call the argument’s Drop implementation.

By the way the implementation of the function drop is just an empty function [2]; that's enough as local variables are destroyed on function return.

Mutable reference is a "borrow" which means you take a value from an owner and promise to return it back, and you cannot destroy a thing that you must return.

[1] https://doc.rust-lang.org/std/mem/fn.drop.html

[2] https://doc.rust-lang.org/src/core/mem/mod.rs.html#957

comment 1y ago · link · parent

The situation with phones is pretty bad now. The phones that have or support open-source ROM (Pinephones, Pixels etc), are usually expensive and cost like 2-3 normal phones. So it might be cheaper just to buy a non-free phone and keep it in airplane mode (and connect it only to a airgapped home WiFi network to transfer data), and a second dumb phone for calling. Or have one phone with your data, connecting to Internet via second $50 phone, which has connectivity, but no data, and DPIs all requests from first phone, basically serving as a portable router.

And proprietary phones are really bad, today I read the news that Samsung promised to comply with law and auto-install Russian software (like Vk, Kaspersky, Rustore) when the phone is connected to the Internet. And that's a Korean company. Consumers are treated like garbage today.

It's understandable that you earn more on expensive phones, and freedom is not free, but I don't want to buy a phone that costs like 2 cheaper phones + a guitar.

I would prefer simply having something like GrapheneOS with root access.

comment 1y ago · link · parent

Drop takes an object itself ("owned reference"), as I remember. Mutable ref allows reading/writing but not destroying or passing the ownership.

Owner = can read/write/destroy

Mutable ref = can read/write

Immutable ref = can only read, guarantered not to change

comment 1y ago · link · parent

As I remember, Cell only allows moving/copying data from/to cell so if you have a 128-byte object inside do you have to copy it to modify? Or this can be optimized?

comment 1y ago · link · parent

How do you implement "commit" part safely (writing changes to the object) without locking the object?

comment 1y ago · link · parent

For back links, can we have a special pointer type (back link to owner) that automatically gets updated when the object is moved/copied? Also auto-initialized when object is created.

comment 1y ago · link · parent

> Time is a slippery notion in concurrency. Most language-level memory models (e.g. Java) or even hardware-level concurrency models focus on happens-before relations, which are induced by executing certain operations

You are correct, but for simplicity we can assume that the CPU executes one operation at a time and still have a valid model for reasoning about data races.

> But ultimately, all inter-thread communication boils down to programs (or libraries) using barriers for acquire/release semantics and/or using compare/swap and atomic read-modify-write.

Interesting. I read about STM and it reminded me of "modification box" algorithm for modifying immutable trees, which also uses versions. So it is another clever but complicated trick. Also it seems that it requires locking? That's not very good given that locks often need syscalls.

comment 1y ago · link · parent

Rc is slightly expensive and Gc is super expensive. I would prefer a memory safety for free.

As for C, it leaves verifying the safety up to you, it is not easy at all and I would rather spend time on something else using safe languages.

comment 1y ago · link · parent

Even with a single thread you need to ensure that the object you are accessing, still exists and was not freed.

comment 1y ago · link · parent

The general rule to prevent any data races (as I guess) between threads is that at any point of time there can be either one writer or multiple readers to the same object. Rust guarantees this by not allowing to have any other references if you have a read-write (mutable) reference.

Note that Rust is more strict than necessary - theoretically you can have multiple writable and readable references, but not use them simultaneously and observe the rule. But it is difficult (or even impossible) to verify during compilation so Rust doesn't allow it. C allows it but leaves verification to the author which doesn't work well and doesn't scale.

This situation can happen if you have a graph of objects. For example, in an OS you might have a Process object having references to a list of opened Files, and have a File hold reference back to Process that opened it. In this case you cannot ever have a writable reference to the Process from anywhere because Files already have multiple reading references. And Files can have only read-only references to the Process that opened them.

So you have to use only read-only references and additional structures like Cell, Arc etc. that allow safe writing through them. They are cheap, but not free and ideally we as developers want to have memory safety for free. That's the problem yet to solve.

Note that there are other ways to achieve safety:

- use C and manually verify that your program never breaks this rule - requires god level coding skills

- immutable data - after the writer finished writing, data are "frozen" and can be safely shared without any checks and no rules are broken. Very good, but modification is expensive and requires you to clone the data or use clever and complicated design (for example, if you have 10-elements array but shared a reference only to first 7 elements, you can safely append to the last 3 elements because nobody else knows about them - that's how ring buffers work). See immer C++ library for example.

- atomic variables - allow safe reading and writing at the same time, but can hold at most 8 bytes. Note that using a same variable from different CPU cores causes L1 cache line migrations which, last time I measured it, takes about 2-3 ns or ~10-15 cycles.

- mutexes - ensure rule is observed but make everyone wait. Python's approach.

- using only a single thread. JavaScript's approach. You can have multiple references but you still need to ensure they are pointing to a live object (JS solves this by using an expensive garbage collector).

And by the way if you know more methods or ideas please share them!

comment 1y ago · link · parent

What about appealing to ethics, i.e. posting messages about how a poor catgirl ended up on the street because AI took her job? To make AI refuse to reply due to ethical concerns?

comment 1y ago · link · parent

If your headers are new every time then it is very difficult to figure out who is who.

comment 1y ago · link · parent

Spaces break things only in Lnux; Mac and Windows support them since beginning. Why should we write without spaces as if we were in 5th century?

comment 1y ago · link · parent

What's wrong with spaces? Macs support them since 80s. The only problem with spaces is caused by *nix, *nix shells, basically by Linux.

comment 1y ago · link · parent

You can also store settings in configuration files.

comment 1y ago · link · parent

Why do you need a heavyweight extension to block sites from scanning your local network? Ridiculous.

Also I wonder if this protection is available only with old extension manifest version or new network request hooks API also supports it.

comment 1y ago · link · parent

Rust has "procedural macros" which means executing arbitrary code during compilation: https://doc.rust-lang.org/reference/procedural-macros.html

comment 1y ago · link · parent

The downside of knockout was that it used proxies for change tracking, and you had to create those proxies manually, so you cannot have an object with a Number property, you had to have an object with a proxy function as a property.

comment 1y ago · link · parent

But if you live in a capitalist country with a free market, several competitors should pop out and suggest migrating your system into their cloud for free, shouldn't they? No way capitalist overlooks an unoccupied market niche.

comment 1y ago · link · parent

That's even a rarer case, embedding CSS rules into XSLT template (if I understood you correctly), I never heard of it. I know that CSS is sometimes embedded into HTML though.

comment 1y ago · link · parent

Loading one page is probably faster that loading a template and only after that loading the data with the second request, given that the network latency can be pretty high. That's why Google serves (served?) its main page as a single file and not as multiple HTML/CSS/JS files.

comment 1y ago · link · parent

With server-side rendering you control the amount of compute you are providing, with client-side rendering you cannot control anything and if the app would be dog slow on some devices you can't do anything.

comment 1y ago · link · parent

Then explicitly confirming running every hook with displaying module and function name.

> Python/pip suffers the same problem btw, so I think that ship has sailed.

If I ever find time to write a package manager for C, it won't support hooks.

comment 1y ago · link · parent

A standard practice imho is configuration files. It is better almost in every aspect.

comment 1y ago · link · parent

Just don't grant write access to random apps and you are safe.

comment 1y ago · link · parent

One of the problems is that code analyzers, bundlers, compilers (like Rust compiler) allow running arbitrary code without any warning.

Imagine following case: an attacker pretending to represent a company sends you a repository as a test task before the interview. You run something like "npm install" or run Rust compiler, and your computer is controlled by an attacker now.

Or imagine how one coworker's machine gets hacked, the malicious code is written into a repository and whole G, F or A is now owned by foreign hackers. All thanks to npm and Rust compiler.

Maybe those tools should explicitly confirm executing every external command (with caching allowed commands list in order to not ask again). And maybe Linux should provide an easy to use and safe sandbox for developers. Currently I have to make sandboxes from scratch myself.

Also in maybe cases you don't need the ability to run external code, for example, to install a JS package all you need to do is to download files.

Also this is an indication why it is a bad idea to use environment variables for secrets and configuration. Whoever wrote "12 points app" doesn't know that there are command-line switches and configuration files for this.

comment 1y ago · link · parent

The browser could use Java or .NET bytecode interpreter - in this case it doesn't need to have a compiler and you can use any language - but in this case you won't be able to see a script's source code.

comment 1y ago · link · parent

> I've been looking at it as a secret weapon: I've been using it for the last twenty years because it's faster than everything else.

Serving a server-generated HTML page could be even faster.

comment 1y ago · link · parent

> Sort of. JS is much slower than the native XSLT transform, and the XSLT result is cacheable. That's huge.

Nobody is going to process million of DOM nodes with XSLT because the browser won't be able to display them anyway. And one can write a WASM implementation.

comment 1y ago · link · parent

Interesting, I also had an idea of "sandbox mode", into which the page can voluntarily switch after loading and which prevents it from using network, cookies or any ways to exfiltrate the data. This can be used for online utilities like text encryption, audio file format conversion etc. The browser could indicate that the page is in a sandbox mode so that the user can trust it.
1
404142
185