Skip to content

Instantly share code, notes, and snippets.

View Verdagon's full-sized avatar

Evan Ovadia Verdagon

View GitHub Profile
valerian@ubuntu:~/core/build$ cmake -DOPTION_BUILD_LOADERS_C=ON -DOPTION_BUILD_LOADERS_RS=ON ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++

Prototyping and Iterating

The borrow checker can be [slower](https://news.ycombinator.com/item?id=31063493 .anecdote) to prototype [with](https://news.ycombinator.com/item?id=26419670 .anecdote) when we just want to [solve](https://news.ycombinator.com/item?id=28804477 .anecdote) [the problem](https://news.ycombinator.com/item?id=23744577 .anecdote) rather than being [distracted by the language](https://blogs.dust3d.org/2019/03/13/why-i-rewrote-the-mesh-generator-of-dust3d-from-rust-to-cplusplus/ .anecdote), even for [more](https://lobste.rs/s/veinkw/comparison_rust_zig#c_nmf8jz .anecdote) [experienced](https://news.ycombinator.com/item?id=31568497 .anecdote) [rustaceans](https://www.reddit.com/r/rust/comments/iwij5i/blog_post_why_not_rust/g627nwx/ .anecdote).

[One user says,](https://www.reddit.com/r/rust/comments/iwij5i/comment/g62ytxa/?utm_source=share&utm_medium=web2x&context=3 .anecdote) "Rust’s complexity regularly slows things down when you’re work

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <setjmp.h>
_Thread_local void* current_coroutine_args = NULL;
size_t rotate_left(size_t x, int bits) {
return (x << bits) | (x >> ((sizeof(size_t) * 8) - bits));
}
// Make some accounts.
let accounts = [];
accounts.push({ name: "Bob", money: 100, labelView: null });
accounts.push({ name: "Cindy", money: 100, labelView: null });
accounts.push({ name: "Reginald", money: 100, labelView: null });
accounts.push({ name: "Jim Argalax", money: 100, labelView: null });
accounts.push({ name: "Valerian Vast", money: 100, labelView: null });
accounts.push({ name: "Archonicus Auriarch", money: 100, labelView: null });
// Add each account to the document. It will look like:
let accounts = [];
accounts.push({ name: "Bob", money: 100, labelView: null });
accounts.push({ name: "Cindy", money: 100, labelView: null });
accounts.push({ name: "Reginald", money: 100, labelView: null });
accounts.push({ name: "Jim Argalax", money: 100, labelView: null });
accounts.push({ name: "Valerian Vast", money: 100, labelView: null });
accounts.push({ name: "Archonicus Auriarch", money: 100, labelView: null });
accounts.forEach(account => {
let row = document.body.appendChild(document.createElement("div"));
struct Account {
name: String,
money: i64,
labelView: i32
}
struct Button {
onclick: Box<dyn FnMut()>
}
@Verdagon
Verdagon / python_data_race.py
Created January 12, 2022 20:55
Example of a data race in Python
# Does Python have data races?
#
# As we've seen, Java can have data races, according to
# https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html
# It says an example of a data race is when:
# - there is a write in one thread,
# - a read of the same variable by another thread,
# - and the write and read are not ordered by synchronization.
#
# This program attempts to cause a data race in Python.
struct Spaceship {
subsystem: Subsystem
}
enum Subsystem {
Engine { fuel: i64 },
Navigation { antenna: Box<Antenna> },
}
struct Antenna {
frequency: i64
}
"If a language only allowed owning references, memory management would betrivial, but ownership rules would severely limit the programmer."
Now that I think of it, this would just be a lot of copies. In fact, someone has tried something like this: https://degaz.io/blog/632020/post.html
"1.2.2 Borrow References". The term "borrow references" is fine, but might want to make it clear up front that they don't work like Rust's borrow references. Or sometimes, I call them non-owning references, to avoid confusion.
"while C++ uses the unique_ptr and shared_ptr classes mentioned in 1.1.1 to accomplish the same goal." -> "while C++ uses unique_ptr and raw pointers respectively mentioned in 1.1.1 to accomplish the same goal.
(shared_ptr is for RC in c++, and shared_ptr and unique_ptr dont mix)