HNHacker News
TopNewBestAskShowJobs

oneshtein

680 karma · joined February 26, 2023

submissionscomments
oneshtein··on The borrowchecker is what I like the least about Rust
What stops you from writing such data container with interior mutability, like vec_cell[0], which then enforce borrowing rules at runtime?

[0]: https://github.com/alexanderved/vec_cell

oneshtein··on The borrowchecker is what I like the least about Rust
I can do business logic, like complex CRUD, in Rust much faster than in other languages. I assume, «lousy programmers» have problems with separation of concerns, which then cause problems with borrow checker, because developers need to perform different things in different ways on different parts of data structures (AKA «god object» anti-pattern).
oneshtein··on The borrowchecker is what I like the least about Rust
Rust borrow checker is designed to enforce "one owner" model (a tree). When you need to have more than one reference, you can use Rc + Weak[0]. Example DoubleLinkedList implementation:

  struct Node<T> {
    pub data: T,
    pub prev: Option<Weak<RefCell<Node<T>>>>,
    pub next: Option<Rc<RefCell<Node<T>>>>,
  }
Moreover, if you have cycles instead of trees, you can use a garbage collector with support for cycles, like rust-cc[1].

So yes, it's cannot be done statically, because Rust is not designed for that.

However, problem disappears when 'static lifetime is used (or arenas). Nodes can be marked as deleted, instead of dropping them, so pointers are always valid.

In same vein, when nodes are deleted rarely, they can be simply marked as deleted, without dropping them completely (until sibling nodes are updated, at least):

  struct Node<T> {
    pub data: Option<T>,
    pub prev: Option<Weak<RefCell<Node<T>>>>,
    pub next: Option<Rc<RefCell<Node<T>>>>,
  }
When node is deleted (its payload is dropped), linked list is still walkable.

[0]: https://doc.rust-lang.org/std/rc/struct.Weak.html

[1]: https://github.com/frengor/rust-cc

oneshtein··on The borrowchecker is what I like the least about Rust
Rust have few garbage collectors[1] to chose from. For example, rust-cc is simple to use, just put #[derive(Trace, Finalize)] on struct.

[1]: https://crates.io/keywords/garbage-collector

oneshtein··on The borrowchecker is what I like the least about Rust
You can use a garbage collector in Rust to circumvent borrow checker. You can use simple reference counting (Rc, Arc), or trace and sweep, arenas, or generation based garbage collectors. Even a simple .clone() can help a lot in many cases.

Borrow checker is my friend, it helps me write better code, but it doesn't stops me when I don't care about code quality and just want a task to be done.

oneshtein··on The borrowchecker is what I like the least about Rust
In my eyes, Rust code is as simple as Python code or even simpler in most cases, but it also allows to create and maintain complex pieces of abstraction, when necessary, then hide them in a library or a macro. :-/

Can you show example of "written by random cat" code you often see?

oneshtein··on Ukrainian hackers destroyed the IT infrastructure of Russian drone manufacturer
Name your number.
oneshtein··on Ukrainian hackers destroyed the IT infrastructure of Russian drone manufacturer
It's tough to say that Ukraine and US are allies right now. US refuses to hold security assurance, as promised, and forbids Ukraine to restore nuclear arsenal, as before the promise. Bullies behave is such way, not allies.
oneshtein··on Where's Firefox going next?
WebSerial and WebUsb can be implemented as separate plugins in the same way as support for H264 and DRM was added.
oneshtein··on Archaeologists unveil 3,500-year-old city in Peru
I was very surprised when I saw ancient cement kiln in Peru, very similar in size and technique to freshly built one (20 years ago) near to my parents town, but labeled as «a religious structure fit with stones».

As I see here[0], cement stucko on top of natural stone was pretty popular technique back then.

[0]: https://odysee.com/@hiddenincatours:3/megalithic-saqsaywaman...

oneshtein··on Vitamin C Boosts Epidermal Growth via DNA Demethylation
Which daily skincare you recommend to use?
oneshtein··on Quantum mechanics provide truly random numbers on demand
> "Mathematic model of quantum world" provide truly random numbers on demand
oneshtein··on Research suggests Big Bang may have taken place inside a black hole
Black holes may contain a second event horizon in the center, like a Poisson's spot. So it was the Big Rip, when this spot was born.
oneshtein··on Introducing stronger dependencies on systemd
Mate supports Wayland since Mate 1.28.

See https://wiki.mate-desktop.org/developers-corner/wayland-meso...

Quote:

> One of the most notable improvements is the enhanced support for Wayland, bringing us closer to a fully native MATE-Wayland experience. Several components have been updated to work seamlessly with Wayland, ensuring a more integrated and responsive desktop environment.

oneshtein··on The Illusion of Thinking: Strengths and limitations of reasoning models [pdf]
It will be cost effective in just 25 years.
oneshtein··on How Ukraine’s killer drones are beating Russian jamming
Leaders of Hamas has no bank accounts, AFAIK. Did you mean cryptocurrencies? If so, it's unlikely that these funds are personal savings.

Usually, locals doesn't steal from locals in conflict zones, because their throats, or throats of their families, will be cut by other armed locals in no time.

Invaders and mercenaries often rob or kill locals in many, many cases.

oneshtein··on How Ukraine’s killer drones are beating Russian jamming
It's not a problem when Russia, Israel, USA, or other nations attacks civilians, because of a military reason. Why it will be a problem in this case?
oneshtein··on Ukraine's autonomous killer drones defeat electronic warfare
While not a land border, the Bering Strait does include two small islands, Big Diomede (Russian) and Little Diomede (US), which are only 3.8 kilometers apart.
oneshtein··on Don't watermark your legal PDFs with purple dragons in suits
Maybe, Foo Bar is a real person too. :-/
oneshtein··on Universal basic income: German experiment bring surprising results
In ancient Rome, slave labor was used.
oneshtein··on Fedora change aims for 99% package reproducibility
Exact same binary can be hacked in exact same way on all platforms.
oneshtein··on Man pages are great, man readers are the problem
Try HTML version:

  man --html=firefox man
oneshtein··on After 'coding error' triggers firings, top NIH scientists called back to work
Yep. Just look at countries with unbounded capitalism, like Russian Federation after fall of Soviet Union. It was a mess.

Developed countries installs thousands of regulations (100k - 2M regulatory acts per developed country) on top of wild capitalism to tame it.

However, even heavily regulated liberal capitalism is better than other systems.

oneshtein··on After 'coding error' triggers firings, top NIH scientists called back to work
"We" - humanity.

"We" actually experienced all social systems "we" invented so far, which are allowed by "our" productivity.

oneshtein··on Undergraduate Disproves 40-Year-Old Conjecture, Invents New Kind of Hash Table
Physics is inherently simple. Accurate mathematical modeling of physics is hard.

A layman can understand (real) physics easily, but cannot accurately predict anything except some simple things. Each additional digit of accuracy requires additional complexity in models, which laymen nor need nor understand.

Unfortunately, real physical physics, with inaccurate physical models, completely replaced by much more accurate mathematical models by «shut up and calculate» guys, which explicitly ignore real physical processes behind the scenes to perform calculations faster and with more accuracy.

It's similar to how we use AI: we ask questions, AI system performs abstract calculations, then we have an answer.

To advance in physics, we need to create inaccurate physical models of physical world. For example, hydrodynamic quantum analogs[1] are highly inaccurate, but they allow to develop intuition about quantum world.

[1]: https://en.wikipedia.org/wiki/Hydrodynamic_quantum_analogs

oneshtein··on Undergraduate Disproves 40-Year-Old Conjecture, Invents New Kind of Hash Table
There is Manga and anime about this: https://en.wikipedia.org/wiki/Orb:_On_the_Movements_of_the_E...
oneshtein··on Zlib-rs is faster than C
In reality, speed of light is slightly lower than speed of gravitation, because gravitation slows down speed of light.
oneshtein··on Zlib-rs is faster than C
An error value is valid output in both cases.
oneshtein··on Zlib-rs is faster than C
Gravitation is slightly faster than c in vacuum.
oneshtein··on Zlib-rs is faster than C
AI rewrote to avoid undefined behavior:

  int average(int x, int y) {
    long sum = (long)x + y;
    if(sum > INT_MAX || sum < INT_MIN)
        return -1; // or any value that indicates an error/overflow
  
    return (int)(sum / 2);
  }
← PreviousPage 7 of 32Next →