#๐ช -progaming
1 messages ยท Page 61 of 1
i can't work out where startsWith is implemented
inside v8
so u wont find it
that's an ECMAScript native
so its inside v8 itself

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
at least he hates java too ig
do it
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
Systemd is a core software suite across most Linux distros but there's a lot more in that suite than you typically use, so why not build a Linux distro that uses as much systemd tech as possible
==========Support The Channel==========
โบ Patreon: https://brodierobertson.xyz/patreon
โบ Paypal: https://brodierobertson.xyz/paypal
โบ Liberapay: ...
little does he know that any primitive value in generics becomes autoboxed
meaning Map<Integer, Integer> is all reference types

evil
@hoary sluice @placid cape uv mango in elle
and the code is beautiful
ok time to commit everything i did
@valid jetty is a mango
my bots
@valid jetty how do you handle binary operator precedence?
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
first we had init
next a bootloader
and now a distro
the systemd bloat keeps on going
real
yeah, but keep in how old buffer is, it was made before any standards etc
and now it's legacy code that keeps losing perf to maintain compatibility
the b in systemd stands for bloat
it's crazy though
i guess it probably compiles the regex too so makes sense
it'd be interesting to see spidermoney results compared to v8 results 
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

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?
i got B again from derivations ๐ญ
i genuinely dont know where do i make mistakes
in what subject
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
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
atleast i think i aced the literature test(wow flashcards carried my ass) and waiting for results on my economics test too
and in the first semester i had an A in eco and a B in another subject which i now fixed
literature test???
i thought u were slovak
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
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
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
u have matura too??
yes
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
oh i had jit off in chromium lol
that makes more sense
that explains why regex was faster somehow
with jit on in vivaldi they are both the fastest
cool
im in a 5 year technical high school (do u have those too?) and for our department theres an event organized where we present our projects and the 4th year can see them
last year someone made a rocket controller
theyre a lot cooler in a technical school
unfair
we have a few specialists who have barely anything
but some are pretty cool
someone vibe coded a dashboard
yea i mean, it depends how much is the person motivated... teaching xampp and old school php in 2025 ๐คฎ
he spent like 25โฌ on cursor doing vibe coding exactly as in the definition
we did that last year too
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
i should pickup some rust basics if i want to rewrite the vm...
i used cursor once trying to fix my code so it runs faster. it took almost 1 hour and the only optimization was that it runs 6x slower. idk how people can even use it
omg pinning in rust seems like a cool concept i could utilize in heap expansion
what vm
i did a decent part of my voice assistant with ai (mainly boilerplate) and the only part it actually helped with besides reducing typing time was refactoring my local recorder to be synchronous and not unsafe
what ur avg grade
3.4
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
pretty easy (coping) we do that here too
im not the kind of person that could just remember things
i guess that's good?
just go through some essaywork or something and read different things
nah it doesnt compile regex, it justs uses native code to operate on the string via a native regex engine
because its more stable
it scales better with memory usage
its GC is way smarter
it turned out i had jit turned off in chromium
spidermonkey starts eating shit the moment u start GC'ing anything
regex jit certainly does exist in some libs

nvim
actually good suggestion
no
:(
I don't understand how Map.get is faster than Array.find even if the first item is matched
maybe i made a mistake
it shouldnt be
in fact array is faster than Map for small amount of elements
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
array.find probably has a lot of overhead
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

why not
well.... yeah
js arrays arent actually arrays
typedarrays are
arrays, maps and objects are O(1)
just the O is different costs
but surely v8 is smart enough to actually store arrays as
[ptr to first value][ptr to second value]
in memory

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
it seems for of is faster than c style loop in js
wait nvm
it depends
super weird
status: | "CURRENT"...?
C for loop used to be much faster than es6 loops
but they fixed performance and now they're pretty close
it only seems to have a large difference wqith 1m items
at that point use postgres

they are a LOT of slower
my beloved
loop {
println!("loop");
}
but the utility they offer is unmatched
nah that's outdated
trust, it aint XD
when iterating arrays its close to the same
when iterating ANYTHING else they are very slow
such as
that said, i use for of exclusively
well yeah I meant array
and iterator
you can't directly index raw iterators...
for of Object.entries(), Object.keys(), Object.values(), Map.values(), Set.values()
yeah no shit!
since iterators are streams
in fact for (let i = 0; i < arr.length; i++) is probably slower than for of because it gets array.length each iteration
not precalculated data
yeah lol
nah v8 optimises that
in that case the alternative is not a C style for loop pretty sure
it's for in
maybe it does
I wouldn't rely on it
for of is clearer intent than C for loop
i benchmarked the fuck out of this, because i made a 3d rendering library which did 100 mil iterations per frame
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
yes isn't the bottleneck just the fact is has to allocate pointless arrays
it doesnt rly matter
(albeit for a more pleasant programming experience)
what about map
even object[8001] = value eats shit
no problems there
which is why i made https://www.npmjs.com/package/object-like-map
i just try to avoid using objects if it's something with dynamic keys
just so i can use a map like an object
people love abusing objects
due to concerns with bugs
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)
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

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
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
not use an enum
enums in js dont work
my horrible js code only takes ~7.5s to parse a 250MB text file 
ass image
i feel like that could be faster
slow

my js takes <2s to parse a 1.8GB video file
:DDDDD
my js is literally just parsing commands but i wanted to microoptimise it because yes

yep, thats what the spec is called
Advanced Sub Station alpha
nop ASS is for subtitles
tbf most of the time is (probably) just spent doing ```js
const lines = text.split('\n');
horror
yes, this is indeed the topic of conversation
why the hell are you reading the entire string into memory instead of streaming
there's your problem
yea
laziness โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
i don't know how you'd read a line at a time in js
async iterators sir
aren't streams event based
async iterators for streaming data are bae
*in node
yes**
horrorcode 
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}`);
}
sublime text*
oh ofc
but yes, monocraft my beloved
yes but no
readline is really bad
it's funny how bad reading from stdin in node is
because it fucks chars
because it forces some weird char map
which isnt uft8
and it can break a LOT of shit
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)
}
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
for (let i = 0, len = arr.length; i < len; ++i) 
why yes
why use zed/nvm when you can use nano ๐ฅ
do i do this????
"An infinite loop was detected while parsing xyz.
This is an internal bug. Please report it at <issue url>"
what if someone needs an infinite while loop...
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
@deep mulch i wonder if it would be possible to rewrite sadanify native in c#
from c++
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 */,
},
}
Sure, that's what references are
i mean, realistically youre never gonna have the real estate to parse a file at the size of like u64::MAX
1800 petabytes goes hard
id go as far as to say u32::MAX
no way you have a file thats 4 gigs
i just check is_eof() lol
works too ig
hii @valid jetty your stdlib is missing a comma at std/collections/hashmap.le line 42
iโm writing a tree sitter grammar for it and just so happened to pick that file to parse
or well, rather, the parser
insnae
yeah i was like how does that even compile
because it parses until , instead of parsing an expr (which im moving towards)
https://github.com/acquitelol/elle/blob/rewrite/std/collections/hashmap.le#L50-L53
duplicate __internal_key_exists_check call since HashMap::get also calls it
hashmap.le: Lines 50-53
fn HashMap::__load__<T, U>(ElleMeta meta, HashMap<T, U> *self, T key) {
__internal_key_exists_check(self, key, meta);
return self.get(key);
}
just use crystal, the best language
File.each_line(file) do |line|
puts line
end
also would be nice if it like returned null or threw an exception (if thats a thing in elle) instead of straight up aborting
@valid jetty whats your opinion on heap defragmentation
there's safe_get
nop its not duplicate, if you do it from within .get the location of the error will be in __load__ instead of the caller's location, you dont have this problem when you call .get directly
although get being safe by default and having unsafe_get would probably be better
true
wdym, get already does it tho
yeah but uhhh
Also what is it even compiling here, cef is distributed in shared object form
Are the rust bindings really that big
millennias yeah
compiling function defs or something ig :^)
i want to port my spotify mod to rust
but for that, it needs to dynamically link to libcef with cef-rs
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
so im seeing if cef-rs supports that
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
time to clone rust's track_caller api!
lmao true

@valid jetty does elle have destructing
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();
i did the same thing that rust does
well borrow checker is indeed a pain in the ass to use and implement
lmao yep
isnt that just for the map["foo"] syntax, while map.get is Option<T>
Option<&V> apparently
oh, yeah i can set up that interface
get will become unsafe_get and safe_get will become get
cause it hates you ๐
enjoy 200% cpu usage
remind me why do you need cef
Wait, elle parses binops by finding and splitting on the lowest-precedence op in the input, and then parsing the halves ๐ญ?
it's what spotify is built on ๐ญ
Or am I misunderstanding the code
slap the syntax in tree-sitter and use it for parsing 

Insane
yes but on the tokens which makes it less insane
would be funnier if i did it on the source code
Only slightly
Still a majorly insane parsing method
is it possible to build a shared object with rust
the parser is dearly missing a rewrite
yeah a parse_expr would probably be sane
that just looks like a standard recursive descent
Yeah pretty much, other than preprocessing into token trees
But I think my precedence handling is pretty elegant
yeah definitely lmao
why is cargo trying to build both an executable and a shared library
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
guhhh i managed to fix it
Better solution is usually to use the standard layout
sadan is a conservative so he doesn't wanna name it lib
guhh is there no hooking lib for windows on rust
i cant find up to date bindings for detours either
insane
?crate retour
@valid jetty can you help a bit (very hard)
nop
Yes
wdym lol, it doesn't support arm while detours does
Yeah but nobody uses arm do who cares
please enlighten me on how i'm supposed to use it then
If you intentionally use an obscure arch, that's on you
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
lol this is just a rust issue
with c/c++ you can easily do this
and arm isnt obscure lol
uhhh do you have any more detail
it doesnt even support modern macos
It's not a language issue
there are a lot of ways i can interpret that lol
It's a "probably hundreds of contributors for many years" issue
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
lol nope i have no idea what youโre talking about
is there a way to do a constant array in rust without having to change the length every time i add something
Make it a &[&str]
@royal nymph https://youtu.be/z_itQLvQxtk
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...
i wanted to ping rosie how did it ping vee
???
@valid jetty
dont mind the upload date

Seems 3.14 didnt even release
did you watch the video
pub static RESERVED_KEYWORDS: &[&'static str] = &[
"as", "mut", "enum", "match", "static", "super", "do", "macro", "step", "of", "class", "var",
"impl", "type"
];
just make it &str
and you also need & on the array on the rhs iirc
is it possible to do something like this
yeah if youre just adding things then go with concat
my solution wasnt completely atrocious?
although idk if concat accepts identifiers
it doesnt
yep then const_format is what you need
why the fuck do you need a crate for this 
what do you not need a crate for
string formatting
why is format! not able to do so 
can't you do like .to_string() or something
the fact that you need a 3rd party crate for that sounds so dumb to me
thats what im saying 
concat! no?
or is that only for literals
how do you create a top-level variable if let is a syntax error and const / static require constant expressions
concat isn't formatting
whatโs stopping you from just doing concat!(โdisloโ, TARGET) tho donโt you get the same result
i dont want to have to chain 3+ to get what i want
hm
you create a static mut and do unsafe assignment to it from within the main function probably
are you joking
love rust's learning cliff
itโs probably just hard because top level variables are bad practice
literals yeah
just use const_format atp
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
@jade stone
please jeez this is even worse
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
X Y ahh solution
Now you're thinking in javascript!
@valid jetty how do u handle linebreaks in codeblocks in typst
both bloated
like normal?
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());
what
ah ok thanks ill do it like normal
how would you do something like this
why is it not doing that automatically wth are you doing lol
what am i supposed to do
oh because youre returning it from the closure
i dont want hyphens
i wonder if you do
#show raw.where(block: true): block.with(
width: 100%,
)
that might not work actually
.as_str()
#raw(
"username:\u{2060}$6$VH6ZrhwD0XmxmZYH$ftK/\u{2060}droDPnK6loNiY7GeUvXki0u39CjZk4qHb41Ubm5uH6Qfm8BGDjVyFhGuGuUpV.IoLdGGDbgHu7C0wuzK1:1006:1006::/home/username:/bin/sh",
)
wouldnt that raise the same issue
isnt word joiner counter intuitive
idc i want it to break the hash across lines
you do it manually then
how can you return a Path if it doesn't have a known size and a reference would be dropped
im using typst specifically not to do that
might as well write it with a pen on paper and scan it
you make a variable
|name| {
let file = format!("{name}.cpp");
Path::new(&file)
}
same error
i'm aware, but i'd rather fix the error first
wait yeah why are they manually adding the extension lmao
i just noticed that
@nimble bone
that works, but it's fucking insane that you have to do it that way
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
its more that the docs suck
(iirc)
yop
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
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
only annoying thing is turning a path back into a string kinda sucks
path.to_str().unwrap().to_string() โค๏ธ
(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)
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
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
a beginner-ish rust developer is NOT gonna think like that lmao
||tbh i didnt even think something like with_extension was a thing as i've never used it in any other lang i've used||
how am i supposed to think like that when i'm starting out.
how am i supposed to learn and gain experience to be able to thing like that when i need to think like that to do basic things
read the rust book
i tried, it sucks
(i say that while having not read it)
*not that it's bad, but it didn't help me
honestly i havent read the rust book
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
my entire process of learning a language is fuck around and find about
what would be nice is common patterns in other languages and how they're best done in rust
then once you learn it it becomes engraved in your head because you think you might need the info later on
and just basic thing side by side
EXACTLY
thats what i do
i always learn "good practices" and "conventions" last when learning a language
that shit just stalls you
thats why i know like 5 languages to varying degrees lmao
lol
all modern languages are basically the same except for syntax
its just small differences in semantics and conventions (although rust is quite different)
yea, same. but how am i supposed to do that when i run into things like this often when learning rust that take an ungodly amount of time compared to other languages.
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
rust is a very "production" language
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
i am not a productive person
even much less in rust
idek why i like rust so much atp
yeah i do this
prototype in js/py
i like rust because it feels very polished compared to other languages
that's not what i'm really talking about and you still have the same issue
everything just clicks into place
thats what i meant tho
you run into those issues when writing the "production" version of the code and thats when you learn
you are an llm
you are being put through regression training
suffer
you dont need to use another language its just a common thing for people to do
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
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
that looks like a logged error, not something thrown
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
yeah just some log, it doesn't seem to do anything
basically how you learn to code indeed
that can be said for any langauge but especially in rust
yes, that's what i do with all languages
but it's hard when rust takes at least 2x as long, if not more
because when it takes that much longer, it's a lot easier to lose motivation and give up
its gonna get easier over time
but then you cant say "written in rust btw"
and anyway, once rust becomes engraved in your head, youll see that the errors from the compiler are actually very helpful lmao
the rust learning curve is
/\____
until you get to async
then you get euler spirals
async rust is NOTHING like normal rust
fuck async rust whoever came up with Pin<Box<dyn Future: Send> is insane
WHAT IS THAT
i know what pin is
idfk what box is
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
box is just a safe heap allocated pointer
lmao
is dyn Future: Send a triat that extends send
Send is a trait
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
whats dynamic dispatch 
i might know what it is, but ive never heard that name
nah its a trait
you cant dyn a struct
oh wait yeah
since its meant for traits
uhhhh basically the type is resolved at runtime
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)"
probably
allows for any type that implements the Future and Send traits
to maintain my sanity i have never looked at async types

Is there a colon operator for types then

you can specify that something is bound by multiple traits via +
it does lol
How
X: Y is basically X implements Y
just make a trait and impl that trait for your struct
although some built in structs dont allow for trait extensions
Iirc that doesn't work with name collisions
oh you wanna override existing methods?
No
a generic T defined as where T: Clone would mean whatever T is, it implements clone
^
I'll send a kotlin example when I get home
okk
rust orphan rules yeah
you can do this in elle because fuck orphan rules
Yea, I've seen where clauses and managed to piece together what it means
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
tbf it doesnt NEED to be where
idk why theres 2 ways to write it but there is
ill do this with vee
fn foo<T>(x: T) where T: Clone {}
OR
fn foo<T: Clone>(x: T) {}
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));
}
the magic of rust i guess
i personally prefer having where clauses instead of elongating my function signature
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
it works too
thats a thing in elle too iirc but not the 3rd one :3
its like turbofish
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 <>
is this rust playground
yes
woooo slay
horror
traits feel a lot like partial classes in c#
you can also choose to write Trait::function instead of <Type as Trait>::function
but i like the latter since its more concise
where you define a piece of a class
i usually see traits as interfaces in ts
i see traits as abstract classes but is there really a difference between that and interfaces
brainrot terminology has ruined typescript abbreviation for me
cant write function bodies in interfaces :^)
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
HOW
yeah i was right
now that i think about it traiots are closer to abstract clases than interfaces
since traits can also have default implementations
oh they can??
trait Bar {
fn bar() -> i32 {
-1
}
}
so can interfaces (in java)
not in TS
i dont speak of languages that are supposed to be turned into fossil fuel
TO BE FAIR js has abstract classes too
ts*
the entire point of abstract classes is to force you to implement methods on a type level
so yeah js doesnt have that xd
good point
they are in es6
there are insane people who write the function form of classes
function Foo(x) {
this.x = x;
return this;
}
Foo.prototype.bar = function() {
return this.x + 123;
}
``` classes โค๏ธ
what i'm trying to do is overload, not overwrite methods on standard types
forgor the if (this instance of Foo) crap
rust overloading is non existent
well
you CAN do it
but its a hack
really?
yeah
rust just kinda doesnt have overloading in general
insane
rust doesnt have function overloading
you can "emulate" it by using generics
or you can implement Fn traits directly
you can achieve it pretty easily with smart usage of macros, generics, and traits
generally if you need overloading in rust what you really need is generics or an enum
yea
at least it's better than typescript overloading
because ts overloading isnt real
(very low bar)
yop
ts overloading is NOT overloading
i love if (typeof(x) === "string" && typeof(y) === "string")
all overloads calls the same function
also why are you using parens
Python overloading
(love)
how does py overload
it doesnt?
oh
You decorate function with typing.overload
isnt py dynamic tho
same as ts then im guessing
how does it know what to dispatch
Yeah
oh ok
@valid jetty insane overloaded function i wrote
i am worried if i try to refactor my ts project to use camelCase there will be something typed as any which breaks

ts rename is cross-file
just run tsc --noEmit after to type check it
won't check for things which aren't typed as the right interface
also renaming everything will take forever
send example 
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

NO
just because this will fit into interface it doesn't mean it will get refactored i imagine
perish
even when its not here i can feel its presence...
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
one day everyone will find out that you sleep scrobble and we will do #RosieIsOverParty
eh the effort is worth it
and i will finally be #1 in scrobble lb
inconsistent case feels like it would scare of contributors
me when i dont type my shit
:Error or satisfies Error or as Error would work
if there are no compile time errors bugs will be found eventually
best to do it sooner rather than later
this is just wrong code
^
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
like yes you shouldn't do this
that doesn't mean it would never happen
๐ญ
idk what your point is
no camel case in ts...
thats snake case girl
the handy noImplicitAny
thats
๐
its hard to express tone via text
it wouldnt do shit here
i meant like "it should be camel case.."
it infers return type
wait, yeah im stupid
as const for extra fancy inference
true but it also wouldn't rename automatically
the handy noImplicitReturns
so still some wasted time
would help me catch these mistakes i guess
the handy rustReturnMode

(my behated)
noImplicitAny would be fine with me if you could just make it do unknown instead of any
and not emit a compilation error
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)
hop on esbuild (or anything that just strips types at compile time)
yo what infers that for u?
i use node
or did u type that out manually?
typescript
if u mean the inline hint that's just a vscode setting
--experimental-strip-types
yes
remember what its called?
how did this chat move from rust to TS so elegantly
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);
}
ultrawide gaming, i'm good
if (canvas.width && canvas.height && subtitles.renderer?._canvas) context.drawImage(subtitles.renderer._canvas, 0, 0, canvas.width, canvas.height)
i love ultrawide
funny
clearer highlight
this does not work
you can fix it but now it thinks the type is never for some reason
kind of feels stupid
@winged mantle
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"
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
nevermind, you're right
the object type allows any keys
object just isnt the right type here
use any or something like Record<PropertyKey, unknown>
Record<PropertyKey, any> my beloved
force explicit returns
mainly for readability
for small functions its so bad
which just feels weird... why can't it just be unknown if you have noImplicitAny turned on
hmmm idk how i like this
hop on keyof never instead of PropertyKey
why
because your code makes no sense
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
yes it does
your cast to keyof obj does nothing because obj has no keys
less confusion that way
i mean.. it does make the compiler be quiet
i wonder if thats how rust can prevent forward declaring
if you let people write ugly unreadable code they will do it, just look at js and ts
because the flag is called noImplicitAny, not implicitUnknown
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
}
}
implicitUnknown would be avoiding implicit any in a sense

idk about js but in ts you can hover over the function name to see the return type with a good lsp
just by making it something safer
i mean you can just recursively check implicit returns but explicit returns are more readable
implicit return type isnt confusing
or just put it in the code
can you send the type of StoredMedia and the type VariablesOf
but what about mutually recursive functions
cant, char limit XD
also just upload as file
or it literally shows inline as a hint xD
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<>
function get big, you have multiple places where it returns, its returns abstract factory builder, yes it gets confusing
fn foo() {
return bar();
}
fn bar() {
return foo();
}
``` how do you determine the return type of this
so its small
you dont
you dont
the second isn't generic
uuuuuh?
also it's just a syntax error lol
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
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
I guess you could do something where the types are computed lazily (and error if loop), but dunno if that'd be any good
@supple whale just upload the relevant code to tsplayground or smth
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];
}
fn foo(i32 x) {
if x == 1 { return 1; }
else { return foo(x - 1); }
}
``` it knows that foo's return is `i32` here
it feels weird to me that you need to do a cast
how is a type 3GB big
omg so much typescript slop i cant read the actual conversation
also it uses a ts server plugin, to convert gql strings to TS types
hmm yeah but idk how you would approach that
insane
its a type schema of an entire GQL DB
so i can write any gql query and get types out of that query
automagically
how is that all in one type
hi! so theres this thing called.......... an โจ object โจ
horror
this is probably how fp does it and @valid jetty should take a day to implement that and lazy function evaluation too
elaborate
partial application in elle ๐ฅบ
enums in typescript are just fucked lol
i feel like this is a lot slower than just parsing the return type explicitly, and its a lot more readable here
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, ...
kotlin does it perfectly, you have to specify the return type unless its an expression function that fits on 1 line
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
this works
just extracted the types for the one function i picked xd
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
why would you do | undefined in the type
it will always return string if you have to pass in a key
notably he type defs cant be modified, they are inferred
from the DB schema
i just copied it from what you sent
oh wait
what if i do getColorName("FOOBAR")
i get a type error but it still returns undefined
why... are you defining types there?
they are inferred just fine?
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
โค๏ธ
its trully a love/hate relationship
maybe