TGViewer
Блог* Блог* @dereference_pointer_there · 1.97K subscribers
Post #10424 963

Forwarded from Panic! At the 0xC0D3 (Lev)

Зачем вам типы если вы их игнорируете
Я устал поэтому просто побугурчу
Сколько ворнингов/ошибок должна выдать такой код?
constexpr std::array<int64_t, 3> a{1, 2};
std::cout << a[3];

Тут будет 0 ошибок и ворнингов с -Wall -Wextra -Wpedantic
А если так?
constexpr int64_t a[3] = {1, 2};
std::cout << a[3];

Тут компилятор догадается, что a[3] это какая-то лажа, но вот что ты массив из 3х элементов двумя инициализируешь ему норм
ууу сссука У вас вся информация в системе типов есть, почему нельзя быть как раст:
(у раста при этом эти переменные не constexpr даже!)
let a: [u32; 3] = [1, 2];
dbg!(a[3]);


error[E0308]: mismatched types
--> <source>:2:23
|
2 | let a: [u32; 3] = [1, 2];
| -------- ^^^^^^ expected an array with a size of 3, found one with a size of 2
| | |
| | help: consider specifying the actual array length: 2
| expected due to this
error: this operation will panic at runtime
--> <source>:3:10
|
3 | dbg!(a[3]);
| ^^^^ index out of bounds: the length is 3 but the index is 3
|
= note: #[deny(unconditional_panic)] on by default


Ну даже если причины это легаси, почему ворнинг то показать нельзя аааа

Че бугуртить то

Для меня главный юзкейс типов это то, что код легко рефакторить. Ты чето поменял, у тебя компиляция упала везде где сломалось
А тут мы видим, что если у тебя был код вида
constexpr std::array<int64_t, SOME_CONST> a{1, 2};

И ты поменял константу на +1, то плюсы сожрут и ничего не скажут.
  • 👍 20
  • 😁 2
  • 🌚 2
More from @dereference_pointer_there
  1. Oct 16, 2026Тем временем разработчики на Go *tailscale
  2. Oct 16, 2026А всем остальным нам?!
  3. Oct 16, 2026#meme про сон
  4. Oct 15, 2026#prog #rust #suckassstory rustc uses the Path hash code to identify files, and the Path ha…
  5. Oct 15, 2026#python #meme
  6. Oct 14, 2026r/rust (потому что написано вроде на Tauri)
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →