#๐Ÿช…-progaming

1 messages ยท Page 61 of 1

supple whale
#

and also

async function* foo() {
  yield 1;
  yield 2;
}

const stream = Readable.from(foo())
stream.pipe(process.std.out)

if you NEED a stream for some nodejs API

winged mantle
#

i can't work out where startsWith is implemented

supple whale
#

inside v8

#

so u wont find it

#

that's an ECMAScript native

#

so its inside v8 itself

winged mantle
#

i wonder whether there's a faster way to match any whitespace than to just use /\s+/

#

it probably doesn't matter that much but if i would rather not use regex if possible

median root
#

at least he hates java too ig

supple whale
#

regex is stupidly fast in js

#

especially if you dont have any lookaheads or lookbehinds

#

which means you have O(n) where N is string length

#

but the operation cost is x100 lower since its native

formal belfry
ornate quiver
valid jetty
#

and the code is beautiful

#

ok time to commit everything i did

deep mulch
#

@valid jetty is a mango

valid jetty
#

wtf elle went from 44 stars to 50 in like a day

#

insane

deep mulch
#

my bots

fleet cedar
#

@valid jetty how do you handle binary operator precedence?

royal nymph
#

dude buffer is so fucking slow

#

I was benchmarking js some while ago against C implementing some bruteforce password algorithm using byte[] and Buffer

#

js was so much slower

#

then i implemented the js one with raw U8Array over Buffer and it was like 60% of the C performance

#

obviously my implementations were probably not ideal but the fact that just switching from Buffer to U8Array made it get somewhat close to C was very eyeopening

dawn ledge
#

the systemd bloat keeps on going

ornate quiver
#

real

supple whale
#

and now it's legacy code that keeps losing perf to maintain compatibility

lavish frigate
winged mantle
#

i guess it probably compiles the regex too so makes sense

#

it'd be interesting to see spidermoney results compared to v8 results blobcatcozy

#

interesting how in firefox both are faster...?

#

but the loop is faster

#

why are we using v8 based node.js instead of spidermoney based idk... soda.js

hoary sluice
#

@valid jetty i aced the economics checkup

#

got perfect gpa now

winged mantle
#

maybe this is just a very unscientific test

#

on my desktop pc with loads of other programs open

#

but it's like night and day

#

in chromium i have to wait ages for the tests to complete and in firefox they're basically instant

#

so weird

#

maybe it's because i don't actually use the values

#

and spidermoney is smarter about ignoring unused code?

dense sand
#

i genuinely dont know where do i make mistakes

hoary sluice
dense sand
#

math

#

like the stuff was easy af, i was done like 2nd in the whole class, but i have 0 clue what i did wrong

hoary sluice
#

my eco teacher graded my test very unfairly (still a B) probably cause im never in class and she thinks i just go home but any time i skipped eco i was either sick or at an open day at a uni (4 times) and i told her that and she offered me to do a checkup

#

cause its on friday and open day is usually on friday

dense sand
#

atleast i think i aced the literature test(wow flashcards carried my ass) and waiting for results on my economics test too

hoary sluice
#

and in the first semester i had an A in eco and a B in another subject which i now fixed

dense sand
#

yes

#

czech literature

hoary sluice
#

i thought u were slovak

dense sand
#

czech

#

hyro is slovak

hoary sluice
#

oh i thought both of u were

#

alr

dense sand
#

im thinking of buying markers so i can practice math on our whiteboard in class before school startsd

#

i haven nothing to do on dorms anyways

#

and writing it on paper is lame

hoary sluice
#

i might buy a remarkable tablet soon

#

im going to uni in september and im probably gonna pay attention in class cause its actually the stuff im interested in and not german or hardware development

#

like its cool and all but i really dont care about how to improve electromagnetic compatibility on a printed circuit board

dense sand
#

quite excited for my 4th year in HS, besides having to study for czech part of maturita, the stuff seems pretty exciting

#

i still have to pick my final project

#

i will either take some nextjs app or rewrite of my jvm to rust

hoary sluice
#

u have matura too??

dense sand
#

yes

hoary sluice
#

im doing mine in may / june

#

graduating april 30th

dense sand
#

nicee, i want to go see the presentations of matura final projects

#

to see what people make

#

i know for a fact that my friend has a plain html/css website... ๐Ÿ’€

#

4 years in hs for this

winged mantle
#

that makes more sense

#

that explains why regex was faster somehow

#

with jit on in vivaldi they are both the fastest

#

cool

hoary sluice
#

last year someone made a rocket controller

hoary sluice
dense sand
#

our technical hs is 4 years long

#

im in 3rd year

hoary sluice
#

unfair

#

we have a few specialists who have barely anything

#

but some are pretty cool

#

someone vibe coded a dashboard

dense sand
hoary sluice
#

he spent like 25โ‚ฌ on cursor doing vibe coding exactly as in the definition

hoary sluice
#

at least i can start in 3rd semester of uni so it wasnt wasted time

#

im probably gonna do a master or even a phd cause its literally just working on a hobby project while getting sponsored and paid a lot and you get a phd for it

dense sand
#

i should pickup some rust basics if i want to rewrite the vm...

leaden crater
dense sand
#

omg pinning in rust seems like a cool concept i could utilize in heap expansion

dense sand
#

my jvm

#

OMG I GOT MARK 1(A) FROM CZECH LIT

#

LETS GO

hoary sluice
hoary sluice
dense sand
#

i hate czech

#

i skill issue so hard in this subject

#

like im sorry but how tf do i bang information about 20 authors and 30ish of their works into my head

leaden crater
#

pretty easy (coping) we do that here too

dense sand
#

im not the kind of person that could just remember things

dense sand
#

@hoary sluice what to use for rust dev

#

i guess i could stick to nvim

leaden crater
supple whale
supple whale
#

it scales better with memory usage

#

its GC is way smarter

winged mantle
#

it turned out i had jit turned off in chromium

supple whale
#

spidermonkey starts eating shit the moment u start GC'ing anything

winged mantle
hoary sluice
dawn ledge
#

actually good suggestion

lavish frigate
#

zed!!!

#

with a cute pink theme

#

:3

dense sand
#

no

lavish frigate
#

:(

winged mantle
#

I don't understand how Map.get is faster than Array.find even if the first item is matched

#

maybe i made a mistake

royal nymph
#

in fact array is faster than Map for small amount of elements

winged mantle
#

yes

#

i would've thought

#

and this is a very small data set

#

it makes zero sense

#

i guess it's just the overhead of needing to do includes on each item

lavish frigate
#

array.find probably has a lot of overhead

winged mantle
#

for loop had same issue

#

what if i do indexof instead of includes

#

how is Map.get literally faster than [0]

#

i thin kthat's enough premature optimisation for today

placid cape
jade stone
#

How

supple whale
#

js arrays arent actually arrays

#

typedarrays are

#

arrays, maps and objects are O(1)

#

just the O is different costs

winged mantle
#

but surely v8 is smart enough to actually store arrays as
[ptr to first value][ptr to second value]
in memory

supple whale
#

eeeeeeeeeh

#

not really

#

arrays in js are a piece of fucking wizardry

#

that noone understands

#

esp when it comes to spread iterables

#

and how weirdly fast they are

#

there's fuckery afloat, a lot of it

#

HMMMMMMMMM

#

ARE YOU SURE ABOUT THAT

winged mantle
#

it seems for of is faster than c style loop in js

#

wait nvm

#

it depends

#

super weird

lavish frigate
royal nymph
#

C for loop used to be much faster than es6 loops

#

but they fixed performance and now they're pretty close

winged mantle
#

it only seems to have a large difference wqith 1m items

#

at that point use postgres

supple whale
lavish frigate
#

my beloved

loop {
  println!("loop");
}
supple whale
#

but the utility they offer is unmatched

royal nymph
supple whale
#

when iterating arrays its close to the same

#

when iterating ANYTHING else they are very slow

winged mantle
#

such as

supple whale
#

that said, i use for of exclusively

royal nymph
#

well yeah I meant array

supple whale
winged mantle
#

you can't directly index raw iterators...

supple whale
#

for of Object.entries(), Object.keys(), Object.values(), Map.values(), Set.values()

supple whale
#

since iterators are streams

royal nymph
#

in fact for (let i = 0; i < arr.length; i++) is probably slower than for of because it gets array.length each iteration

supple whale
#

not precalculated data

winged mantle
#

yeah lol

winged mantle
#

it's for in

royal nymph
#

maybe it does AyameZoomDerpy I wouldn't rely on it

winged mantle
#

oh wait for map and set

#

what would you do there..

royal nymph
#

for of is clearer intent than C for loop

supple whale
#

i benchmarked the fuck out of this, because i made a 3d rendering library which did 100 mil iterations per frame

winged mantle
#

i avoid object.entries

#

i thought that created an array not an iterator though

supple whale
#

for (let i = 0; i < images.length; ++i) is the fastest loop u can get in js

#

i ended up moving the iteration code to WASM tho, faster

winged mantle
#

yes isn't the bottleneck just the fact is has to allocate pointless arrays

supple whale
#

it doesnt rly matter

winged mantle
#

(albeit for a more pleasant programming experience)

supple whale
#

unless u have >8k keys

#

objects eat shit at >8k keys

#

no matter what u do

winged mantle
#

what about map

supple whale
#

even object[8001] = value eats shit

supple whale
#
winged mantle
#

i just try to avoid using objects if it's something with dynamic keys

supple whale
#

just so i can use a map like an object

royal nymph
#

people love abusing objects

winged mantle
#

due to concerns with bugs

supple whale
#
import olm from 'object-like-map'

const myOLM = olm({ first: 1, second: 2 })

const third = myOLM.third = 3

const exists = 'first' in myOLM

delete myOLM.second

for (const [key, value] of myOLM) {
  console.log({ key, value })
}

myOLM.clear()

console.log(myOLM.size)
winged mantle
#

i see people do EnumName[key as keyof typeof EnumName] and this has a bug i found

#

i mean i'm sure other people found it but they weren't commenting about it on stackoverflow for some reason

royal nymph
#

just don't use non-const ts enums

#

they suck

winged mantle
#

people do that to "parse" an enum but obviously if you pass constructor or __proto__ it will give you something different

#

ah

#

i wish i'd known about that

supple whale
#
void decodeBitmap(double alpha, size_t *data, ASS_Image *img, int w, int h) {
  uint32_t color = ((img->color << 8) & 0xff0000) | ((img->color >> 8) & 0xff00) | ((img->color >> 24) & 0xff);
  uint8_t *pos = img->bitmap;
  uint32_t res = 0;
  for (uint32_t y = 0; y < h; ++y, pos += img->stride) {
    for (uint32_t z = 0; z < w; ++z, ++res) {
      uint8_t mask = pos[z];
      if (mask != 0)
        data[res] = ((uint32_t)(alpha * mask) << 24) | color;
    }
  }
}
#

ah yes

#

good old times

#

i love bitwise hacks

winged mantle
#

what's the best way to do an enum lookup table

#

i just did a switch case

supple whale
#

enums in js dont work

still jolt
#

my horrible js code only takes ~7.5s to parse a 250MB text file blobcatcozystars

winged mantle
winged mantle
supple whale
#

:DDDDD

winged mantle
#

my js is literally just parsing commands but i wanted to microoptimise it because yes

supple whale
#

Advanced Sub Station alpha

royal nymph
#

nop ASS is for subtitles

still jolt
winged mantle
#

horror

supple whale
winged mantle
#

what is javascript bufferedreader equiv

supple whale
#

you dont need to do that

#

js strings simply arent dumb like java

royal nymph
#

there's your problem

winged mantle
#

yea

still jolt
winged mantle
#

i don't know how you'd read a line at a time in js

winged mantle
#

aren't streams event based

supple whale
#

async iterators for streaming data are bae

winged mantle
#

*in node

supple whale
still jolt
#

horrorcode blobcatcozystars

winged mantle
#

using minecraft font in vscode

royal nymph
#
const fileStream = fs.createReadStream('input.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });

for await (const line of rl) {
    // Each line in input.txt will be successively available here as `line`.
    console.log(`Line from file: ${line}`);
  }

still jolt
still jolt
#

but yes, monocraft my beloved

supple whale
#

readline is really bad

winged mantle
#

it's funny how bad reading from stdin in node is

supple whale
#

because it fucks chars

winged mantle
#

i should've remembered this trick which is used

supple whale
#

because it forces some weird char map

#

which isnt uft8

#

and it can break a LOT of shit

winged mantle
#

"at least it's not as bad as php"

#

(me writing javascript project circa 2025)

supple whale
# royal nymph ```js const fileStream = fs.createReadStream('input.txt'); const rl = readlin...

i ended up having to do:

async function * findByteSequence (sourceIterator: AsyncIterable<Uint8Array>, targetSequence: Uint8Array) {
  // not great but good enough
  const buffer = []
  let targetLength = targetSequence.length
  let matchIndex = 0

  for await (const chunk of sourceIterator) {
    for (const byte of chunk) {
      buffer.push(byte)
      if (byte === targetSequence[matchIndex]) {
        matchIndex++
        if (matchIndex === targetLength) {
          // Sequence found, yield all data up to but not including the sequence
          if (buffer.length > 0) {
            targetSequence = yield new Uint8Array(buffer.slice(0, -targetLength)) || targetSequence
          }
          buffer.length = 0 // Clear the buffer
          matchIndex = 0
          targetLength = targetSequence.length
        }
      } else {
        matchIndex = (byte === targetSequence[0]) ? 1 : 0
      }
    }
  }

  if (buffer.length > 0) yield new Uint8Array(buffer)
}
winged mantle
#

what the

#

truck

supple whale
#

yeah its for spliting data streams by a specific byte

#

i needed it when implementing the NNTP protocol

#

cuz nntp is "hey here's some utf8 text data, WOOP NEVER MIND RAW BINARY NOW"

#

and using textdecoder with "stream: true" and appending a single byte at a time is too slow

#

when u want to truput gigabytes of data per second

valid jetty
dense sand
valid jetty
#

i actually have a cute pink zed theme

#

not fully pink but mostly pink

leaden crater
#

why use zed/nvm when you can use nano ๐Ÿ”ฅ

valid jetty
#

do i do this????

#

"An infinite loop was detected while parsing xyz.
This is an internal bug. Please report it at <issue url>"

lavish frigate
valid jetty
#

no no not that

#

hard cap on while loops in the compiler not on code written in elle

#

like here

loop {
    if self.parser.current_token().kind == TokenKind::LeftCurlyBrace {
        nesting += 1;
    }

    if self.parser.current_token().kind == TokenKind::RightCurlyBrace {
        if nesting > 0 {
            nesting -= 1;
        } else {
            break;
        }
    }

    self.parser.advance();
}
``` it could potentially never stop
jade stone
#

@deep mulch i wonder if it would be possible to rewrite sadanify native in c#

#

from c++

dense sand
#

would it be possible to have enum in rust with entries having structs which reference other structs?
something like in C:

struct ComplexStructure {
  uint8_t tag;
  union {    
    struct A {
      const char *data;
    }
    struct B {
      A *a;
    }
    struct C {
      A *a;
    }
  }
}

in rust something basically based on:

#[derive(Debug)]
pub enum ConstantPoolEntry {
    Utf8(str),
    Class {
        value: /* reference to Utf8 */,
    },
    String {
        value: /* reference to Utf8 */,
    },
}
fleet cedar
#

If you mean self referential types, then no

#

(Not safely)

dense sand
#

damn

#

and can i reference to the same string in memory from multiple places

#

?

fleet cedar
#

Sure, that's what references are

dawn ledge
#

1800 petabytes goes hard

dawn ledge
#

no way you have a file thats 4 gigs

valid jetty
#

i just check is_eof() lol

dawn ledge
#

works too ig

lucid trail
#

hii @valid jetty your stdlib is missing a comma at std/collections/hashmap.le line 42

valid jetty
#

lmao i would have NEVER caught that thank you

#

that should probably throw an error

dawn ledge
#

insane parser

#

how does the compiler even accept it as valid syntax

lucid trail
#

iโ€™m writing a tree sitter grammar for it and just so happened to pick that file to parse

dawn ledge
#

or well, rather, the parser

jade stone
#

insnae

lucid trail
#

yeah i was like how does that even compile

valid jetty
dawn ledge
pearl stagBOT
royal nymph
dawn ledge
#

also would be nice if it like returned null or threw an exception (if thats a thing in elle) instead of straight up aborting

dense sand
#

@valid jetty whats your opinion on heap defragmentation

jade stone
#

i love rust

#

things don't take years to build

#

ever

valid jetty
lucid trail
#

although get being safe by default and having unsafe_get would probably be better

valid jetty
#

true

valid jetty
#

yeah but uhhh

jade stone
# jade stone

Also what is it even compiling here, cef is distributed in shared object form

#

Are the rust bindings really that big

dawn ledge
dawn ledge
jade stone
#

i want to port my spotify mod to rust

#

but for that, it needs to dynamically link to libcef with cef-rs

valid jetty
# dawn ledge wdym, get already does it tho
foo[1];

calls foo.__load__(1)

if that calls .get directly and it fails, the error wont be at foo[1] itll be at foo.__load__'s definition because thats where the ElleMeta was generated for .get

jade stone
#

so im seeing if cef-rs supports that

valid jetty
#

if i do a second bounds check and it fails inside of foo.__load__, the error will be generated at foo[1] because the ElleMeta was generated there

dawn ledge
valid jetty
dawn ledge
jade stone
#

@valid jetty does elle have destructing

valid jetty
#

there is a GC, but if you use a different allocator you can also just create a Foo::free and ```rs
foo := Foo::new(1, 2, 3);
defer foo.free();

dawn ledge
#

drop

#

can't believe elle is gc based ๐Ÿ’”

valid jetty
dawn ledge
#

well borrow checker is indeed a pain in the ass to use and implement

valid jetty
#

lmao yep

dawn ledge
#

Option<&V> apparently

valid jetty
#

oh, yeah i can set up that interface

#

get will become unsafe_get and safe_get will become get

jade stone
#

why is it building again

#

it just built

dawn ledge
leaden crater
dawn ledge
#

remind me why do you need cef

fleet cedar
#

Wait, elle parses binops by finding and splitting on the lowest-precedence op in the input, and then parsing the halves ๐Ÿ˜ญ?

jade stone
fleet cedar
#

Or am I misunderstanding the code

dawn ledge
#

slap the syntax in tree-sitter and use it for parsing blobcatcozy

fleet cedar
#

Insane

valid jetty
#

yes but on the tokens which makes it less insane

#

would be funnier if i did it on the source code

fleet cedar
#

Still a majorly insane parsing method

jade stone
#

is it possible to build a shared object with rust

fleet cedar
#

Yep

#

Rust calls them cdylib

valid jetty
valid jetty
#

yeah a parse_expr would probably be sane

#

that just looks like a standard recursive descent

fleet cedar
#

Yeah pretty much, other than preprocessing into token trees

#

But I think my precedence handling is pretty elegant

valid jetty
#

yeah definitely lmao

jade stone
#

why is cargo trying to build both an executable and a shared library

fleet cedar
#

It builds a bin because you have a main.rs

royal nymph
fleet cedar
#

You are correct that cdylibs are more bin like than lib like, but don't think that can be changed at this point

#

Maybe with a new edition, so 2027 at earliest

jade stone
#

guhhh i managed to fix it

fleet cedar
#

Better solution is usually to use the standard layout

royal nymph
lavish frigate
#

i see 2 lines you can completely delete just by... you know... renaming your main.rs to lib.rs and basically nothing will change

royal nymph
#

sadan is a conservative so he doesn't wanna name it lib

jade stone
#

guhh is there no hooking lib for windows on rust

#

i cant find up to date bindings for detours either

#

insane

fleet cedar
#

?crate retour

leaden crater
#

@valid jetty can you help a bit (very hard)

jade stone
fleet cedar
#

Yes

jade stone
fleet cedar
#

Yeah but nobody uses arm do who cares

jade stone
fleet cedar
#

If you intentionally use an obscure arch, that's on you

valid jetty
leaden crater
# valid jetty depends with what lol

So i have some number suffixes and want to apply them to other number suffixes in an elegant manner. do you know how i could do that without writing everything down by hand

jade stone
#

and arm isnt obscure lol

valid jetty
jade stone
#

it doesnt even support modern macos

fleet cedar
#

It's not a language issue

valid jetty
#

there are a lot of ways i can interpret that lol

fleet cedar
#

It's a "probably hundreds of contributors for many years" issue

leaden crater
# valid jetty uhhh do you have any more detail

k m b t qd qn sx sp o n
de ud dd tdd qdd qnd sxd spd ocd nvd
vgn uvg dvg tvg qtv qnv sxv spg ovg nvg
tgn utg dtg tstg qttg qntg sxtg sptg octg nvtg
qddr uqdr dqdr tqdr qdqdr qnqdr sxqdr spqdr ocqdr nvqdr
qqgnt uqgnt dqgnt tqgnt qdqqnt qnqgnt sxqgnt spqgnt ocqgnt nvqgnt
sxgnt usxgnt dsxgnt tsxgnt qdsxgnt qnsxgnt sxsxgnt spsxgnt ocsxgnt nvsxgnt
spgnt uspgnt dspgnt tspgnt qdspgnt qnspgnt sxspgnt spspgnt ocspgnt nvspgnt
ocgnt uocgnt docgnt tocgnt qdocgnt qnocgnt sxocgnt spocgnt ococgnt nvocgnt
nvgnt unvgnt dnvgnt tnvgnt qdnvgnt qnnvgnt sxnvgnt spnvgnt ocnvgnt nvnvgnt
centillion (e303)
uncentillion (e306)
! let centillion = c
----> write them out to console with a comma until nvnvgntc
! Also let a centilliard = 1000 nvnvgntc = cd
----> write them out to console with a comma until nvnvgntccd
... i got no more ideas after this :p

#

maybe im not making sense

valid jetty
#

lol nope i have no idea what youโ€™re talking about

jade stone
#

is there a way to do a constant array in rust without having to change the length every time i add something

fleet cedar
#

Make it a &[&str]

hoary sluice
#

LEARN PYTHON3.14 WITH THE SHEAFIFICATION OF G
You will NOT need any other tutorial after you complete this 15 MINUTE COURSE!
Don't forget to like, comment, subscribe, and hit the bell!

Buy my FULL PYTHON 3.14 COURSE for $314.15.


Errata:
06:08 - The shebang actually tells the OS (not the shell) to invoke the python interpreter, thank...

โ–ถ Play video
#

i wanted to ping rosie how did it ping vee

#

???

#

@valid jetty

#

dont mind the upload date

shrewd canopy
#

Seems 3.14 didnt even release

hoary sluice
#

did you watch the video

valid jetty
#

just make it &str

#

and you also need & on the array on the rhs iirc

jade stone
#

is it possible to do something like this

dawn ledge
#

kinda

lavish frigate
#

๐Ÿ˜ญ

#

okay

dawn ledge
#

yeah if youre just adding things then go with concat

lavish frigate
#

my solution wasnt completely atrocious?

dawn ledge
#

although idk if concat accepts identifiers

lavish frigate
#

it doesnt

dawn ledge
#

yep then const_format is what you need

jade stone
dawn ledge
#

what do you not need a crate for

jade stone
spark tiger
#

why is format! not able to do so despair

spark tiger
dawn ledge
#

no

#

format does heap alloc

#

heap allocs arent possible in const context

spark tiger
#

the fact that you need a 3rd party crate for that sounds so dumb to me

jade stone
#

thats what im saying blobcatcozy

valid jetty
#

or is that only for literals

jade stone
#

how do you create a top-level variable if let is a syntax error and const / static require constant expressions

jade stone
valid jetty
#

whatโ€™s stopping you from just doing concat!(โ€œdisloโ€, TARGET) tho donโ€™t you get the same result

jade stone
#

i dont want to have to chain 3+ to get what i want

valid jetty
#

hm

valid jetty
valid jetty
#

lmao idk thereโ€™s probably a better way

#

thats one way that i know of tho

jade stone
#

love rust's learning cliff

valid jetty
#

itโ€™s probably just hard because top level variables are bad practice

dawn ledge
dawn ledge
#

i would only use LazyCell or mut static vars if the data is like dynamic or cant be constant at all

#

if its just simply a string that wont change i'd much rather cope with adding an extra dependency

#

what does 2 more do to an already insane amount of 300

valid jetty
#

@jade stone

dawn ledge
#

please jeez this is even worse

valid jetty
#

its beautiful

#

you can just write a macro to get the value out idk

#

once_cell is in std now you can probably just use that even

dawn ledge
#

X Y ahh solution

jade stone
dawn ledge
#

cargo target is basically js node_modules

#

no difference

hoary sluice
#

@valid jetty how do u handle linebreaks in codeblocks in typst

dawn ledge
#

both bloated

valid jetty
#
use std::cell::OnceCell;

let cell = OnceCell::new();
assert!(cell.get().is_none());

let value: &String = cell.get_or_init(|| {
    "Hello, World!".to_string()
});
assert_eq!(value, "Hello, World!");
assert!(cell.get().is_some());
hoary sluice
jade stone
#

how would you do something like this

valid jetty
#

&format

#

surely

hoary sluice
#

inside a codeblock

valid jetty
#

why is it not doing that automatically wth are you doing lol

dawn ledge
hoary sluice
valid jetty
#

oh because youre returning it from the closure

hoary sluice
winged mantle
valid jetty
#

i wonder if you do

#show raw.where(block: true): block.with(
  width: 100%,
)
#

that might not work actually

dawn ledge
hoary sluice
#
#raw(
  "username:\u{2060}$6$VH6ZrhwD0XmxmZYH$ftK/\u{2060}droDPnK6loNiY7GeUvXki0u39CjZk4qHb41Ubm5uH6Qfm8BGDjVyFhGuGuUpV.IoLdGGDbgHu7C0wuzK1:1006:1006::/home/username:/bin/sh",
)
valid jetty
#

oh

#

theres no spaces in it lol

hoary sluice
#

thats my point

#

it should break the word

valid jetty
dawn ledge
#

isnt word joiner counter intuitive

hoary sluice
#

idc i want it to break the hash across lines

dawn ledge
#

you do it manually then

jade stone
#

how can you return a Path if it doesn't have a known size and a reference would be dropped

hoary sluice
#

might as well write it with a pen on paper and scan it

dawn ledge
#
|name| {
  let file = format!("{name}.cpp");
  Path::new(&file)
}
dawn ledge
#

horrible

#

(also the -> Path and return are useless)

#

rust as implicit returns

jade stone
#

i'm aware, but i'd rather fix the error first

valid jetty
#

wait yeah why are they manually adding the extension lmao

#

i just noticed that

#

@nimble bone

jade stone
# dawn ledge

that works, but it's fucking insane that you have to do it that way

dawn ledge
#

why is it insane

#

why not use the api provided

valid jetty
#

with_extension is saner actually

#

because you can pass into it /foo/bar/baz.xyz and with_extension will replace the xyz with something else for you

jade stone
#

its more that the docs suck

valid jetty
#

(iirc)

valid jetty
#

i use it in elle to maintain the same path but put the IR and executable in the same place with the same name but different extension its useful

dawn ledge
valid jetty
#

that sentence did not english

#

yeah

jade stone
#

when i run into an error and can't find anything on google, i don't want to have to look at every method to see if there's something that might come in handy

esp. in rust where viewing the LSP is the worst ive ever used for listing methods on an object

valid jetty
#

only annoying thing is turning a path back into a string kinda sucks

#

path.to_str().unwrap().to_string() โค๏ธ

jade stone
#

(more about the LSP being ass when it comes to viewing methods on something unless theres a way to do it that i don't know)

dawn ledge
#

its not really that hard, just open up the docs for path and ctrl+f extension

#

well ig if im running into an error saying size cannot be known and my solution is to use a random method on path its not really that intuitiv

valid jetty
#

seems to work for me

#

you even get examples

dawn ledge
#

but then again it links up once you understand why its throwing the error
str ref -> (formatted) String -> converted back to a ref and returned but also being dropped -> dont allocate a String that drops -> look for extension api

valid jetty
#

a beginner-ish rust developer is NOT gonna think like that lmao

jade stone
valid jetty
#

read the rust book

jade stone
#

i tried, it sucks

valid jetty
#

(i say that while having not read it)

jade stone
#

*not that it's bad, but it didn't help me

dawn ledge
#

honestly i havent read the rust book

valid jetty
#

idk the best way to learn is to just get into the depths of a big project in rust and come across times when you need that kind of knowledge

dawn ledge
#

my entire process of learning a language is fuck around and find about

jade stone
#

what would be nice is common patterns in other languages and how they're best done in rust

valid jetty
#

then once you learn it it becomes engraved in your head because you think you might need the info later on

jade stone
#

and just basic thing side by side

valid jetty
#

thats what i do

dawn ledge
#

i always learn "good practices" and "conventions" last when learning a language

#

that shit just stalls you

valid jetty
#

thats why i know like 5 languages to varying degrees lmao

dawn ledge
#

lol

valid jetty
#

all modern languages are basically the same except for syntax

#

its just small differences in semantics and conventions (although rust is quite different)

jade stone
valid jetty
#

things like swift, js, C, py, objc, ruby, go, php

#

even though there are differences

#

you can do the same thing more or less a similar way in all of them

valid jetty
#

ive heard people go to prototype in other languages like python then move to rust to build the production thing

#

because rust has a lot of boilerplate you cant really let your developer freedom run when prototyping in rust because youll constantly get yelled at

dawn ledge
#

i am not a productive person
even much less in rust
idek why i like rust so much atp

dawn ledge
#

prototype in js/py

valid jetty
#

i like rust because it feels very polished compared to other languages

jade stone
valid jetty
#

everything just clicks into place

valid jetty
#

you run into those issues when writing the "production" version of the code and thats when you learn

dawn ledge
valid jetty
#

you dont need to use another language its just a common thing for people to do

fallen nebula
#

fun fact : pressing the ' key on French Azerty Keyboards create this error in the log of discord

react_devtools_backend.js:4026 [KeyboardLayoutMapUtils] KeyboardMapper - Key code mismatch for key ': 222 !== 52
valid jetty
#

you can just always write in rust, learn and understand its pitfalls, and eventually be able to prototype in it

#

there is a reason everyone says rust has a very high learning curve

jade stone
dawn ledge
#

you run into an error
you look it up
if you dont find a solution you ask around, just like you did here
and then you find the solution
and it goes to your mental library
and slowly you start picking up patterns

valid jetty
#

^^^^

#

it gets easier as you write more code

fallen nebula
fallen nebula
valid jetty
#

that can be said for any langauge but especially in rust

jade stone
dawn ledge
#

its gonna get easier over time

valid jetty
#

and anyway, once rust becomes engraved in your head, youll see that the errors from the compiler are actually very helpful lmao

dawn ledge
#

the rust learning curve is
/\____
until you get to async
then you get euler spirals

valid jetty
#

async rust is NOTHING like normal rust

#

fuck async rust whoever came up with Pin<Box<dyn Future: Send> is insane

jade stone
#

i know what pin is

idfk what box is

fallen nebula
# jade stone yes, that's what i do with all languages but it's hard when rust takes **at lea...

i think that's an issue with some people
personally i'm learning rust rn
like reading the book and trying things out
but i don't think i'll get a lot this way, i'll just start to get a basic feeling
the way i'll truly learn is when i'll truly decide to code some project in it
also the time spent learning doesn't matter, because you should be constantly learning
i'm currently an intern at some place because it's needed to finish my bachelor and i actually did make my internship master learn things, because i had knowledge that i did just bring in
on the other hand, i'm learning a hella lot because i'm doing OOP typed python stuff that i had never done

valid jetty
#

lmao

jade stone
#

is dyn Future: Send a triat that extends send

valid jetty
#

Send is a trait

formal belfry
valid jetty
#

Future is a struct iirc, dyn allows for dynamic dispatch

#

you can have a Result<(), dyn Error> to allow for ANY error resolved at runtime

#

uhhhh probably not a good idea to worry about that now

#

the rabbit hole extends far

jade stone
dawn ledge
#

you cant dyn a struct

valid jetty
#

oh wait yeah

dawn ledge
#

since its meant for traits

valid jetty
#

so like in js you can have a

function add(x, y) {
    return x + y;
}

assert(add("a", "b") === "ab");
assert(add(1, 2) === 3);
#

its similar to that

#

its kinda in the name, "dispatch the right thing dynamically based on the type (at runtime)"

dawn ledge
#

yeah

#

hate when i hate to do dyn and the trait isnt object safe

valid jetty
#

WAIT i got myself confused ๐Ÿ˜ญ

#

its dyn Future + Send right

dawn ledge
#

probably

valid jetty
#

allows for any type that implements the Future and Send traits

dawn ledge
#

to maintain my sanity i have never looked at async types

valid jetty
jade stone
valid jetty
#

nop i typed the colon by mistake

#

it should be +

jade stone
valid jetty
#

you can specify that something is bound by multiple traits via +

jade stone
#

Yea, ik that

#

I wish rust had extension functions like kotlin

valid jetty
#

it does lol

jade stone
dawn ledge
#

X: Y is basically X implements Y

valid jetty
#

just make a trait and impl that trait for your struct

#

although some built in structs dont allow for trait extensions

jade stone
valid jetty
#

oh you wanna override existing methods?

jade stone
dawn ledge
#

a generic T defined as where T: Clone would mean whatever T is, it implements clone

valid jetty
#

^

jade stone
#

I'll send a kotlin example when I get home

valid jetty
#

okk

dawn ledge
valid jetty
#

you can do this in elle because fuck orphan rules

jade stone
valid jetty
#

oh my god they blocked the cat word with 2 ws

#
fn u32::cat_word(u32 self) {
    for i in 0..self {
        $println("cat_word");
    }
}

fn main() {
    39.cat_word();
}
#

you can do that]

#

just in your main entrypoint

valid jetty
#

idk why theres 2 ways to write it but there is

lavish frigate
valid jetty
#
fn foo<T>(x: T) where T: Clone {}

OR

fn foo<T: Clone>(x: T) {}
dawn ledge
# jade stone Iirc that doesn't work with name collisions

rust doesnt give a fuck about same identifiers

struct Foo {
  bar: u32
}

impl Foo {
  fn bar(&self) -> u32 {
    self.bar + 123
  }
}

trait Bar {
  fn bar(&self) -> u64;
}

impl Bar for Foo {
  fn bar(&self) -> u64 {
    u64::MAX
  }
}

fn main() {
  let foo = Foo { bar: 123 };
  println!("{}", foo.bar);
  println!("{}", foo.bar());
  println!("{}", <Foo as Bar>::bar(&foo));
}
valid jetty
#

the magic of rust i guess

dawn ledge
valid jetty
#

wtf is the <Foo as Bar>

#

i get that its converting but why is it in <>

dawn ledge
#

since Foo has a bar function i have to hint the compiler that im invoking the bar function from the Bar trait implementation of Foo instead of Foo's own implementation

valid jetty
#

nono i get that

#

but what is the <>

dawn ledge
#

it works too

valid jetty
#

thats a thing in elle too iirc but not the 3rd one :3

dawn ledge
#

but inverse

#

like how you'd write Foo::foo(&foo) but you need to cast it to Bar but you cant use () instead you have to use <>

leaden crater
dawn ledge
valid jetty
#

woooo slay

dawn ledge
valid jetty
#

traits feel a lot like partial classes in c#

dawn ledge
#

you can also choose to write Trait::function instead of <Type as Trait>::function
but i like the latter since its more concise

valid jetty
#

where you define a piece of a class

dawn ledge
#

i usually see traits as interfaces in ts

valid jetty
#

i see traits as abstract classes but is there really a difference between that and interfaces

dawn ledge
#

brainrot terminology has ruined typescript abbreviation for me

dawn ledge
valid jetty
#

i guess

#

i mean i guess it is really similar to interfaces

#

because you can do like class Foo implements Bar

#

in TS

#

and it shouts at you like it does in rust when you dont implement some method

#

yeah i was right

dawn ledge
#

now that i think about it traiots are closer to abstract clases than interfaces

#

since traits can also have default implementations

valid jetty
valid jetty
dawn ledge
#

trait Bar {
fn bar() -> i32 {
-1
}
}

valid jetty
#

oh you can

#

fun so yeah they are closer to abstract classes than i thought

royal nymph
valid jetty
#

not in TS

dawn ledge
#

i dont speak of languages that are supposed to be turned into fossil fuel

valid jetty
#

TO BE FAIR js has abstract classes too

royal nymph
#

ts*

valid jetty
#

oh thats a ts thing???

#

interesting

royal nymph
#

the entire point of abstract classes is to force you to implement methods on a type level

#

so yeah js doesnt have that xd

valid jetty
#

good point

dawn ledge
#

classes arent real in js

#

:^)

royal nymph
#

they are in es6

dawn ledge
#

there are insane people who write the function form of classes

valid jetty
#
function Foo(x) {
    this.x = x;
    return this;
}

Foo.prototype.bar = function() {
    return this.x + 123;
}
``` classes โค๏ธ
jade stone
dawn ledge
dawn ledge
#

well
you CAN do it

#

but its a hack

jade stone
dawn ledge
#

yeah

valid jetty
jade stone
#

insane

dawn ledge
#

rust doesnt have function overloading

valid jetty
#

yeah

#

i dont think you even really need overloading

dawn ledge
#

you can "emulate" it by using generics
or you can implement Fn traits directly

valid jetty
#

you can achieve it pretty easily with smart usage of macros, generics, and traits

dawn ledge
#

generally if you need overloading in rust what you really need is generics or an enum

valid jetty
#

yea

jade stone
royal nymph
#

because ts overloading isnt real

jade stone
#

(very low bar)

jade stone
valid jetty
#

ts overloading is NOT overloading

#

i love if (typeof(x) === "string" && typeof(y) === "string")

winged mantle
jade stone
#

also why are you using parens

shrewd canopy
winged mantle
#

(love)

valid jetty
#

how does py overload

jade stone
valid jetty
#

oh

shrewd canopy
valid jetty
#

isnt py dynamic tho

jade stone
#

same as ts then im guessing

valid jetty
#

how does it know what to dispatch

shrewd canopy
valid jetty
#

oh ok

jade stone
#

@valid jetty insane overloaded function i wrote

winged mantle
#

i am worried if i try to refactor my ts project to use camelCase there will be something typed as any which breaks

jade stone
winged mantle
winged mantle
#

also renaming everything will take forever

royal nymph
#

you could make a BetterOverload library along the lines of

const myFunc = overloads(
  {
    params: [String, Object],
    call(stringArg /*: string */, objectArg) {}
  },
  {
    params: [Number, Object],
    call(numberArg /*: number */, objectArg) {}
  }
); /* type is (arg1: string | number, arg2: object)
#

cursed tho

nimble bone
valid jetty
winged mantle
valid jetty
#

even when its not here i can feel its presence...

winged mantle
#

i guess there would be errors

#

what if something was somehow typed as any and that avoided errors i can't think of an example but it seems possible

nimble bone
#

one day everyone will find out that you sleep scrobble and we will do #RosieIsOverParty

winged mantle
#

eh the effort is worth it

nimble bone
#

and i will finally be #1 in scrobble lb

winged mantle
#

inconsistent case feels like it would scare of contributors

jade stone
winged mantle
#

i try to

#

but i might have made mistakes

winged mantle
#

best to do it sooner rather than later

jade stone
#

^

winged mantle
#

i was just trying to use a very unlikely example to prove my point

#

๐Ÿ˜ฆ

#

mistakes like that are likely to go unnoticed

#

well... actually that's pretty likely

#

this is more likely

#

you might not notice you forgot to type the return

royal nymph
#

cool, interface rename even supports merging

#

(note how all 3 are highlighted)

winged mantle
#

like yes you shouldn't do this

#

that doesn't mean it would never happen

#

๐Ÿ˜ญ

#

idk what your point is

valid jetty
royal nymph
#

thats snake case girl

jade stone
valid jetty
#

thats

royal nymph
#

๐Ÿ

winged mantle
valid jetty
#

its hard to express tone via text

royal nymph
winged mantle
#

but also this doesn't rename

#

and there is no any

valid jetty
#

i meant like "it should be camel case.."

royal nymph
#

it infers return type

jade stone
valid jetty
#

as const for extra fancy inference

royal nymph
winged mantle
#

true but it also wouldn't rename automatically

jade stone
#

the handy noImplicitReturns

winged mantle
#

so still some wasted time

royal nymph
#

i hate explicit return typing

winged mantle
#

would help me catch these mistakes i guess

valid jetty
jade stone
valid jetty
#

(my behated)

winged mantle
#

noImplicitAny would be fine with me if you could just make it do unknown instead of any

#

and not emit a compilation error

valid jetty
#

like wdym i have to manually type every non-void function (tbf it probably makes the compiler more elegant, i have a similar issue in elle)

winged mantle
#

you gotta trick the compiler by doing as keyof typeof var

jade stone
supple whale
supple whale
#

or did u type that out manually?

royal nymph
jade stone
winged mantle
#

yes

supple whale
valid jetty
#

how did this chat move from rust to TS so elegantly

royal nymph
#

fair warning: it has the potential to make your lines very long lmao

supple whale
#

peak

#

thank you

winged mantle
# jade stone what <:wires:1262562427422244874>

this code does not compile with noImplicitAny despite it being perfectly safe

function doThingWithObject(obj: object) {
    const valueInObject = obj["someKey"]; // emits error

    // even though i'm actually being sensible and checking the value type
    if (typeof valueInObject !== "string")
        return;

    console.log("someKey = " + valueInObj);
}
supple whale
winged mantle
#

you would need to do "someKey" as never

#

(since that is keyof object)

supple whale
#
if (canvas.width && canvas.height && subtitles.renderer?._canvas) context.drawImage(subtitles.renderer._canvas, 0, 0, canvas.width, canvas.height)
#

i love ultrawide

royal nymph
winged mantle
#

i hate camelcase

#

so hard to read

royal nymph
#

clearer highlight

winged mantle
#

this does not work

#

you can fix it but now it thinks the type is never for some reason

#

kind of feels stupid

jade stone
#

@winged mantle

supple whale
#

obj: object

#

brotha man

#

you just defined an empty object that cant have keys

#

then said "yep this is a key of this object without keys"

winged mantle
#

an object with keys will fit into it though

valid jetty
# valid jetty like wdym i have to manually type every non-void function (tbf it probably makes...

so actually continuing from this @fleet cedar hi slightly random question

ok so currently my compiler is single pass, which means that you have to do the behated forward declaring of functions to make them be mutally recursive

i want to move away from that, and compile the headers of functions first before their bodies

the problem is that most functions dont have their return type set on the function header; its inferred from the body of the function

so now theres a paradox: to prevent forward declaring, you have to parse the header of functions first, but usually the return type of a function is in the body of a function so you have to also parse the body, but what if the function returns a call to another function which also is non-void, its just kinda an infinite problem and im not sure how to solve it while keeping the elegance of inferred return types

right now it seems like either:

  • keep forward declaring and allow implicit returns
  • force explicit return types on every function

but im wondering if you know of any other way to do it which prevents both of those

jade stone
winged mantle
#

the object type allows any keys

royal nymph
#

use any or something like Record<PropertyKey, unknown>

valid jetty
#

Record<PropertyKey, any> my beloved

winged mantle
#

fair but ugh

#

it still feels odd to me for some raeson

winged mantle
#

because normally it will let you index it

#

the type will just be any

hoary sluice
#

mainly for readability

valid jetty
winged mantle
#

which just feels weird... why can't it just be unknown if you have noImplicitAny turned on

supple whale
#

hmmm idk how i like this

jade stone
hoary sluice
royal nymph
valid jetty
#
fn foo<T>(T x, T y) -> T {
    return x + y;
}
``` the `-> T` just doesnt need to be there
#

if it can be inferred why shouldnt it

hoary sluice
#

yes it does

royal nymph
#

your cast to keyof obj does nothing because obj has no keys

hoary sluice
winged mantle
valid jetty
#

i wonder if thats how rust can prevent forward declaring

hoary sluice
#

if you let people write ugly unreadable code they will do it, just look at js and ts

jade stone
supple whale
#

speaking of keys, i couldnt get this working:

_fillOutKeys (entry: StoredMedia, variables: VariablesOf<typeof Entry>) {
  const keys = ['status', 'score', 'repeat', 'progress'] as const

  for (const key of keys) {
    // @ts-expect-error idk how to fix this tbf
    entry.mediaListEntry[key] = variables[key] ?? null
  }
}
winged mantle
valid jetty
winged mantle
#

just by making it something safer

hoary sluice
royal nymph
jade stone
valid jetty
supple whale
jade stone
#

also just upload as file

royal nymph
supple whale
#
type StoredMedia = {
    id: number;
    isFavourite: boolean;
    mediaListEntry: {
        id: number;
        status: "CURRENT" | "PLANNING" | "COMPLETED" | "DROPPED" | "PAUSED" | "REPEATING" | null;
        progress: number | null;
        repeat: number | null;
        score: number | null;
        customLists: unknown;
    } | null;
}

variables: {
    score?: number | null | undefined;
    repeat?: number | null | undefined;
    progress?: number | null | undefined;
    status?: "CURRENT" | "PLANNING" | "COMPLETED" | "DROPPED" | "PAUSED" | "REPEATING" | null | undefined;
    id: number;
    lists?: (string | null)[] | null | undefined;
}
#

actually i forgot i used Pick<>

hoary sluice
valid jetty
#
fn foo() {
    return bar();
}

fn bar() {
    return foo();
}
``` how do you determine the return type of this
supple whale
#

so its small

jade stone
royal nymph
#

in typescript that will return any

#

you have to manually type one of them

supple whale
jade stone
#

also it's just a syntax error lol

supple whale
#
Type 'number | "CURRENT" | "PLANNING" | "COMPLETED" | "DROPPED" | "PAUSED" | "REPEATING" | null' is not assignable to type 'null'.
  Type 'number' is not assignable to type 'null'.t
#

idk

valid jetty
#

tbf it does that in elle too, if you have a recursive function the return type is either:

  • if the first return type is non-recursive, that thing's type
  • void
fleet cedar
jade stone
#

@supple whale just upload the relevant code to tsplayground or smth

supple whale
#

its legit not possible bro

#

this shit is like 3GB of depenendencies deep

winged mantle
# royal nymph your cast to keyof obj does nothing because obj has no keys

how about this don't you think this feels weird

enum Colors {
  RED,
  GREEN,
  VIOLET,
}

const colorNames = {
  [Colors.RED]: "red",
  [Colors.GREEN]: "green",
  [Colors.VIOLET]: "violet"
};

function getColorName(color: Colors): string | undefined {
  if (!Object.hasOwn(colorNames, color))
      return undefined;

  return colorNames[color as keyof typeof colorNames];
 }
valid jetty
#
fn foo(i32 x) {
    if x == 1 { return 1; }
    else { return foo(x - 1); }
}
``` it knows that foo's return is `i32` here
winged mantle
#

it feels weird to me that you need to do a cast

jade stone
hoary sluice
#

omg so much typescript slop i cant read the actual conversation

supple whale
#

also it uses a ts server plugin, to convert gql strings to TS types

valid jetty
supple whale
#

so i can write any gql query and get types out of that query

#

automagically

jade stone
supple whale
#

it needs to be pre-computed

#

otherwise TS lang server blows up

valid jetty
jade stone
#

horror

supple whale
#

and its 3GB of deps

#

not 3GB of types

hoary sluice
hoary sluice
#

partial application in elle ๐Ÿฅบ

winged mantle
#

is there a better way of doing this

supple whale
#
  • schema which is 172kb
jade stone
hoary sluice
valid jetty
# winged mantle elaborate
const colorNames = {
  RED: "red",
  GREEN: "green",
  VIOLET: "violet"
};

type Colors = keyof typeof colorNames;

function getColorName(color: Colors): string | undefined {
  if (!Object.hasOwn(colorNames, color))
      return undefined;

  return colorNames[color];
 }

and you just get lsp autocomplete for RED, GREEN, VIOLET instead of doing Colors.RED, ...

hoary sluice
#

kotlin does it perfectly, you have to specify the return type unless its an expression function that fits on 1 line

winged mantle
#

you still gotta do keyof typeof

#

a

valid jetty
#

heck you can even just do this

const colorNames = {
  RED: "red",
  GREEN: "green",
  VIOLET: "violet"
};

type Colors = keyof typeof colorNames;

function getColorName(color: Colors): string | undefined {
  return colorNames[color];
}
#

itll return undefined anyway if its not in the object

#

no need to manually check

winged mantle
#

why would you do | undefined in the type

#

it will always return string if you have to pass in a key

supple whale
#

from the DB schema

valid jetty
winged mantle
#

oh wait

valid jetty
winged mantle
#

in myt thing you might not necessarily have needed to do as keyof

#

uh

valid jetty
#

i get a type error but it still returns undefined

winged mantle
#

don't do that

#

__proto__ will return unexpected type

supple whale
#

they are inferred just fine?

winged mantle
#

i think the issue was with name -> enum mappings i was trying to do

#

i think i made a mistake i think you would not need as keyof typeof there

#

as keyof typeof is just my enemy

#

i love typescript

#

โค๏ธ

supple whale
#

its trully a love/hate relationship

winged mantle
#

maybe