Guild icon
DDraceNetwork
Development / developer
Development discussion. Logged to https://ddnet.tw/irclogs/ Connected with DDNet's IRC channel, Matrix room and GitHub repositories — IRC: #ddnet on Quakenet | Matrix: #ddnet-developer:matrix.org GitHub: https://github.com/ddnet
Between 2021-06-07 00:00:00Z and 2021-06-08 00:00:00Z
Avatar
Avatar
Learath2
oh, is there an "idiomatic" way to do global application state in rust?
The idiomatic way is to avoid it, unless u are doing microcontroller stuff
06:01
I personally rly like thiserror
06:01
I dont write many binaries so i havent used anyhow much
06:04
API documentation for the Rust dashmap crate.
Avatar
^ "Blazingly fast concurrent map in Rust."
Avatar
403803d Give mouse settings a maximum - Jupeyy cd68b46 Make calculation which sets mouse pos safer - Jupeyy 8bd552d Merge #3884 - bors[bot]
Avatar
@Deleted User @Chairn i answered on github but i just proposed to create teams faster
08:56
idk if we must create a new issue for what u asked or if we can put it in the same one
Avatar
if it's related to the same issue comment on it
Avatar
i did i did bluekitty
Avatar
4788511 Remove Tom & sirius from CHN mods - def-
Avatar
Avatar
Ryozuki
The idiomatic way is to avoid it, unless u are doing microcontroller stuff
I'm an old man. I like my global state no matter why you kids call it unsafe :P
Avatar
Avatar
Learath2
I'm an old man. I like my global state no matter why you kids call it unsafe :P
well in rust ur forced to handle the unsafeness
10:24
as u have seen
10:25
monkalaugh
10:25
thats why its a chore
10:25
to use global state
Avatar
(I also ise it an an extremely specific way that where I ensure the safety)
Avatar
hmm i dont understand what u saying here
10:25
u worded it a bit weirdly
10:25
xd
Avatar
Heinrichs wrapping of it is quite nice but I ended up passing the state along to functions at the end
10:26
Much cleaner, very expensive but much cleanrr :P
Avatar
have u checked the concurrent hashmap i sent
10:26
maybe its useful
Avatar
Avatar
Ryozuki
hmm i dont understand what u saying here
I use global state in a way that specifically avoids the issues that cause people to call global state unsafe
Avatar
I ended up not using a hashmap either. I'll deal with dynamic configuration when I get to it. Just using a struct for now
Avatar
im using reactjs again, seems like the idiomatic way is to use functional components for everything now
10:28
feels weird but its way less boilerplate code
10:28
so i can see why it is like this
Avatar
Very expensive to pass a struct full of strings but whatever. It looks pretty
Avatar
@Learath2 what are you trying to do?
Avatar
Well I have some configuration that must be shared amongst threads
Avatar
look at this monkalaugh
Avatar
The configuration becomes immutable way before the threads are launched, and the threads only ever read the configuration
10:31
So in theory it should be very safe and very cheap. Heinrichs wrapping of a cell looks like it would compile down to what I expect
Avatar
@Learath2 for my config i usually use https://docs.rs/config/0.11.0/config/ and it maps everything to a struct
Config organizes hierarchical or layered configurations for Rust applications.
10:32
which is usually safer and faster than a hashmap after
Avatar
Do you have one instance of the config and how does it handle concurrency?
10:33
I currently have a struct that I just clone to each thread but if performance starts being an issue I was thinking of putting it in an Arc<RwLock<>>
Avatar
hmm im using actix-web which provides a rly nice way
10:34
i think it wraps it in a arc
10:34
i load it
10:34
wrap it
10:34
and pass it here
10:34
and with some magick, i get it on my endpoint
10:34
xd
Avatar
I'm also doing another smaller project in rust where the config is so small and threads so infrequent that I actually don't care about the clone overhead
Avatar
since i dont need to modify my data i dont need a lock iirc
Avatar
Avatar
Ryozuki
and pass it here
Yeah I'd guess it's an Arc if that clone is cheap and safe.
Avatar
my settings*
10:36
actually idk
10:36
i should look into this
10:37
i dont think it clones the data
10:37
since my struct is not Clone
Avatar
Avatar
Ryozuki
since i dont need to modify my data i dont need a lock iirc
You don't multiple readers is safe
10:37
if i wanted to modify it i would need to do this
10:37
but i dont so
Avatar
But you can only have immutable borrows of your struct iirc. Otherwise rust will complain
10:39
btw calling a clone on an Arc<T> is not cloning the internal data
10:39
so its always cheap iirc
Avatar
Yeah. Just an atomic increment
10:39
Fairly expensive but much cheaper than memcpying an entire struct full of string data
Avatar
yeah, it only clones it initially when starting the threads
10:40
i think
Avatar
Avatar
Ryozuki
yeah, it only clones it initially when starting the threads
I don't think so, doubt things live in thread local storage by default
10:41
An Arc should probably never cause a clone
Avatar
i mean the arc clone
10:42
idk
10:42
what actix-web does is spun up x threads for each cpu core initially, thats why u clone the settings_data there
10:43
this runs 12 times for me
10:43
monkaS
Avatar
I'm using tokio for the small discord bot I'm making
10:44
I'll probably only ever need to run it single threaded but still need to keep it thread safe
Avatar
@Learath2 can u show me how u added tokio to ur toml
10:45
if u added full it uses a multi threaded runtime btw
Avatar
@Deleted User (or anyone else who might know this): do you happen to know the scale of the ingame emoticons?
Avatar
so u are on a multithreaded enviroment already
Avatar
Hm, the docs said the full version still uses the single threaded scheduler, you sure?
Avatar
where do u see this?
10:47
i used tokio full with warp and it definitly shwoed me 12 threads
10:47
i have 12 virtual cores
10:48
Avatar
ah, I misread, yeah I guess it does use the mt scheduler
10:49
Oh btw, if any of you want to make a discord bot in rust I've already went through all the available libraries and I like twilight the best
Avatar
i wanted to do one but i was always lazy
Avatar
serenity is waay too idiomatic with it's frameworks
Avatar
you mean it forces you to use the frameworks for commands e.g?
10:51
twilight logo looks better poggers
Avatar
The way the framwork is set up with an abundance of macros is just unwieldy imo
10:52
You can indeed use it without a framework, but eeeh. I liked twilight better
Avatar
yeah i definitly see why twilight looks better
10:53
starred
10:53
HN is so funny, i always see a wikipedia link there
10:54
This particular drive model was reported to have unusually high failure rates, approximately 5.7 times higher fail rates in comparison to other 3 TB drives.
10:54
ah
Avatar
You can only skip a docker update on mac if you pay for the PRO version, LOL
13:13
I'm so glad we all embraced this obviously corporate company into our ecosystem
13:13
s/(obviously|company)//g
13:14
sudden brain damage leading to loss of english skills
Avatar
Avatar
Patiga
@Deleted User (or anyone else who might know this): do you happen to know the scale of the ingame emoticons?
should be same as the body
Avatar
Avatar
Learath2
You can only skip a docker update on mac if you pay for the PRO version, LOL
lel
Avatar
any electrician here?
Avatar
Heh, I asked this a couple weeks ago, so nope
14:28
But I can try to answer simple things
Avatar
you can make entities invisible if you try to recolor game layers using multi selection
Avatar
I need to fix alot about multi selection :/
Avatar
but at least if you do this then everything in entities is invisible
Avatar
ah thx for the reminder,tsfreddie also found out you can do this(not in editor), guess we'll just not allow it before it gets abused on some mods xd
14:33
except this is wanted
14:33
bcs even front layer etc. respect these values, kinda strange
Avatar
Avatar
Learath2
But I can try to answer simple things
It's about connecting my router to the upper room via an old telephone cable
14:35
It works in the one room, even gigabit connection (we have 150mbit by ISP, so our full strength gets up there), but not in the room next to it...
14:35
cables are both the same
14:36
patched it all together the same way, in the second room it caps at 93 mbit, router interface says that connection is a 100MBit/s connection and the one thats working is a 1 Gbit/s connection
14:37
And no, I will not use dlan, i am trying to get away from it D:
Avatar
gbit over phone cable? I'm guessing you mean ethernet
Avatar
yes, but over a telephone cable
14:42
its an old cable in the walls of the house
Avatar
then you're lucky it's even getting 100 mbit/s
Avatar
you need some isolation, use cat5 or higher rated cables
Avatar
Avatar
deen
then you're lucky it's even getting 100 mbit/s
well, the other room gets 150, which is our ISP limit and i dont know why it wouldnt work in the other room
14:43
its the same cable
14:44
i know about the isolation
Avatar
Avatar
Ravie
but at least if you do this then everything in entities is invisible
14:45
then how will i play your maps
Avatar
Uhm, can you show me the cable or atleast the jack? I don't think it's possible to run gbit over the 2 pairs inside a telephone cable
Avatar
Avatar
louis
oh yeah I wasn't able to single out front layer tho
Avatar
its 8 veins
14:47
its also correctly applied to the "Netzwerkdose"?
14:47
xD
Avatar
maybe cause it was the same map file that was already messed up
Avatar
There are larger telephone cables with multiple pairs inside, we have the same in the multi-apartment building I'm living in
14:47
such a thing
Avatar
so 4 pairs, rj14 I guess
Avatar
it has no pairs
14:48
4 white veins and 4 colored ones, i am pretty sure the white veins arent set correctly, but i have tested that already... so idk
14:49
weird enough: fast ethernet (100 mbit) needs 4 veins (1,2,3 and 6)
14:49
for me, it just worked with 3 veins
14:49
and thats super weird
14:49
I really have no idea, i think i will need an eletrician for that
14:49
and gbit ethernet only works in the other room
Avatar
oh the bugs continue xD
Avatar
as i said, router interface shows connection between pc1 and router as 1 gbit/s and the otherroom as 100mbit/s, so that means it detects the cable strength or whatever, but its weird because the cable is identical
Avatar
Anyway, @fokkonaut as far as I'm aware the devices will do autonegotiation to determine the speed to run at. iirc part of autonegotiation is also checking the line. If they don't like the SNR they might be falling back to fast ethernet
Avatar
found something about that too, but the laptop i tested with couldnt select 1gbit full duplex
14:51
it wasnt listed, so i left it on auto negotiation
14:52
in the other room i got 150 also with the laptop, and it is a gigabit network adapter built in, so thats not the proiblem
Avatar
Avatar
fokkonaut
for me, it just worked with 3 veins
SUPER WEIRD!!
14:53
fast ethernet requires 4 veins usually
Avatar
i get 250mbits with 1 vein
Avatar
thats not one vein xD
Avatar
1 vein download one upload
Avatar
250 mbits over a single twisted pair?
Avatar
yes
Avatar
what is this sorcery?
Avatar
didnt i post my router results once
Avatar
what standard even supports it?
Avatar
its this new super vectoring
Avatar
Ah, VDSL with super vectoring
14:55
We are talking about ethernet here though
Avatar
yeah but in the end its same physics xd
14:55
u just need the components to build that
Avatar
Well very different modes of operation, very different characteristics
Avatar
DSL and ethernet work quite differently 😄
Avatar
you could indeed have a DSLAM in your house 😛
Avatar
they work differently but you just need to translate it for the computers using it
14:57
in the end they can send the same data
Avatar
every method of communication can send the same data "in the end" 😄
Avatar
so he needs a programmer that implements his hack xd
14:58
and ofc the hardware
Avatar
Avatar
Ravie
oh the bugs continue xD
did you try to give it a color animation?
Avatar
@fokkonaut I couldn't really think of how to get 100baseT working over just 3 wires, maybe you have an odd device that supports 100BASE-T1 and can do 100mbit over a single pair
Avatar
no just different stuff happens either on a new file or different layer combos, not sure (edited)
Avatar
ahh too bad
15:02
but i think its even possible to animate the game layers xD
15:02
u just need to hack an envelope id into it
Avatar
Avatar
Learath2
@fokkonaut I couldn't really think of how to get 100baseT working over just 3 wires, maybe you have an odd device that supports 100BASE-T1 and can do 100mbit over a single pair
i dont think so, i connected it as the standards say
Avatar
well if you connected it as the standards say you need 2 pairs to do 100base-tx so that's 4 physical cables
15:05
which one did you omit to test with 3 cables?
Avatar
Fast Ethernet (100BASE-TX) runs over 4 wires, terminated on pins 1, 2, 3, 6. If you ran it over 3 wires instead you need to have omited one
Avatar
fast ethernet uses one RX pair and one TX pair = 4 wires, but both wires in one pair carry the same signal (one is inverted and the second one is not), so technically it can "work" with 3 wires only 😄
15:12
by the way, fast ethernet works just fine over telephone cable if it's not too long and there's nothing else around
Avatar
it could, but I'm not sure many receivers would compensate for that well
15:13
but gigabit ethernet over telephone cable.... you know, those wires are twisted for some reason 😄 (edited)
Avatar
(fwiw I had a similar thing back in my parents house, I ended up pulling a cat6 cable through by tying it to the phone cable, very very risky but it worked out with a bit of soap to lubricate 😄
👍 1
Avatar
@Deleted User I guess if you had some tool to mess with map files you could make really funky stuff that editor doesn't allow?
Avatar
yes, Patigas map tool reports, if you hit "undefined" behavior in a map, and some of these things can be abused
Avatar
telephone cables must be removed from this world because they create problemsworkarounds like xDSL
Avatar
bcs the client doesnt check for correctness of the map
Avatar
@Comrade well they give us better range than ethernet, so if they are going away we need fibre optics everywhere to replace it
Avatar
myy router's telephone cable litterally goes outside so it has the shortest path from underground to router xd
15:19
for short distances inside the house it could probs still handle quite alot of bandwith
Avatar
Avatar
Learath2
@Comrade well they give us better range than ethernet, so if they are going away we need fibre optics everywhere to replace it
yes, xDSL should be considered as something wrong and disgusting, otherwise people get used to it and there will be no reason to put fibers everywhere 😄
15:22
cable television is quite common in some countries, so there must be a way to do one more upgrade to fiber
Avatar
in our country it was prevented bcs the CEO from Sat.1 was good friend with a politican of that time, and Sat.1 is a television company xd
15:26
"Die sozialliberale Koalition unter Helmut Schmidt hatte bereits 1981 Pläne für einen bundesweiten Glasfaserausbau beschlossen. Ein Jahr später kam Helmut Kohl an die Macht, legte die Pläne aufs Eis und förderte lieber das Kabelfernsehen." Means, we had a plan in 1981 from the SPD leader but then corrupt CDU politican joined the chat xd
15:27
welcome to 2021 the future
Avatar
@Ryozuki are you familiar with macros in rust?
Avatar
quite a bit
15:47
A rust derive macro to generate HTML forms from structs. - edg-l/formy
15:47
here is something i made
15:47
dont ask me why
15:47
xd
Avatar
Can you think of a way to have non-local effects? I need to generate code elsewhere for an annotated function
Avatar
elsewhere?
15:49
derive macro?
15:49
sry im in the middle of a doto ranked
15:49
you probs can do it
15:49
macros can even connect to a database to check schemas
Avatar
Like I annotate a function with #[command] I need to generate a line inside another function fn register_commands to register it
Avatar
uhm idk rn
15:51
u can make command create code that automatically registers tyhis function
15:51
somehow
15:51
u know like python decorations
Avatar
I probably can, but something needs to call all these registerers we generated
15:52
and that something needs to know what to call, so a list of all the functions I've annotated
Avatar
when i made a discord api in python i had a array of event subscribers and a decorator to easily add a function there
15:53
you can make the decorator like this
15:53
impl_event!({ pub fn your_function() {} });
15:53
brb 5 min
Avatar
@Learath2 you probs need a derive macro, derive macros must be in their own crate and can only export derive macros, you probs can achieve this looking at how https://github.com/dtolnay/no-panic is implemented
Attribute macro to require that the compiler prove a function can't ever panic - dtolnay/no-panic
Avatar
this exact guy has a crate that does what I'm looking for using a rather nasty hack, it abuses ctor as the list of things to run
Avatar
its a rly simple crate that shows how to modify a function
16:08
ah
16:09
this guy is a rust mastermind btw
16:09
Avatar
yeah he has very interesting repos
Avatar
he literally made the most famous crates
Avatar
I don't think what I'm looking for is possible :/
Avatar
@Learath2 why do u need to generate code inside a function rather than call a function to register that command?
16:10
hmmm
Avatar
Well I'm looking to do something like we do in teeworlds, where just defining a macro and including a file registers all the commands
Avatar
@Learath2 do u know u can declare functions inside functions right
Avatar
I have a handful of commands now, so registering them one by one is no big trouble, but I just wanted to see if it was possible
16:12
yeah, I saw nested functions
Avatar
idk rn
16:13
monkaS
Avatar
me neither and I'm not crafty enough with the macros yet to achieve it
Avatar
im sure thinking of a different way to architecture this is better
16:14
16:14
monkalaugh
Avatar
Well there is no avoiding a list of all the functions I want to register if there is no way to do non-local code generation, or compile time storage
16:17
ahahaha, someone worked around the fact that there is no compile time storage by using a file in /tmp
16:19
I&#39;m tinkering a bit with procedural macros and encountered a problem that can be solved by keeping state in between proc macro invocations. Example from my real application: assume my proc-...
16:25
and serenity makes you use another macro to list all the annotated commands, if there was a way around it I guess they'd have implemented it
16:27
Oh I know a solution, running rust code through the C preprocessor 😛
Avatar
compile rust code into memes. Contribute to mattsse/cargo-memex development by creating an account on GitHub.
Avatar
hm, I thought rust would be much more flexible at compile time but it's still fairly rigid
Avatar
@Learath2 why u learn rust btw(i mean motivation wise) or do you just want to test its limits 😄
Avatar
nim and zig are probably as good as it gets compile time wise
Avatar
Avatar
Deleted User
@Learath2 why u learn rust btw(i mean motivation wise) or do you just want to test its limits 😄
Well I had a small project I wanted to implement and rust is all the hip right now
16:40
I wanted to see why so many people like it so much
Avatar
i'd like to start too, but i'd prefer a non object orientated project as start, but dunno never really find anything interesting i want todo xd
Avatar
so far I'm still on the fence, I like that it's safe and all but I find myself wasting far too much time thinking about edge error cases and borrow semantics
Avatar
cuz u need to get more used to it
16:42
at the end u end up doing things directly in a way you know you wont have problems with the borrow
Avatar
traits are not really a good implementation of OOP imo, so it's a good idea to start with some project that doesn't do OOP
16:42
Generics are among the best I've seen in a language though, by far
Avatar
well i dont think rust claims to be oop
16:43
its data oriented
16:43
A trait tells the Rust compiler about functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We can use trait bounds to specify that a generic can be any type that has certain behavior.
16:43
you dont have inheritance
Avatar
i'd love to see a language beeing more aggressive on range checks(like defining what range a variable can have, to e.g. prevent more logic bugs
16:44
so it forces you to handle all cases urself 😄
Avatar
The inability to specify fields inside traits is annoying, it pretty much forces the compiler to emit a virtual call
Avatar
rust forces u to handle all enum cases
Avatar
but u can still do out of bounds, it just panics instead of going undefined behavior
Avatar
and e.g u can declare a let x and initialize it inside a if else
16:45
and it forces u to have it initialized on both
Avatar
and i feel like most bugs i do are logic errors
Avatar
thats not what statistics tell
16:45
monkalaugh
Avatar
@Deleted User I saw an interesting RFC for rust a couple days ago for implementing ranged integer types like Ada
Avatar
thats why i need personal programming language 😄
Avatar
Avatar
Deleted User
and i feel like most bugs i do are logic errors
isnt this solved by those super logical languages
16:46
e.g prolog?
Avatar
if they dont come in trade of usebility
16:46
i often feel like they have bad syntax or arent as powerful as like c++
Avatar
whats not as powerfull?
Avatar
i mean like, the things u can do in a matter of the language itself, e.g. templates
16:47
you can abuse so much stuff in c++, and i kinda like it many times
Avatar
prolog is very declarative, not much you can do in it
Avatar
main reason im interested in rust is, bcs it still tries todo zero cost stuff, even if some aren't like array index checking
16:48
but its still around as fast as c, thats nice
Avatar
it's like C++ but safer
Avatar
Avatar
Deleted User
main reason im interested in rust is, bcs it still tries todo zero cost stuff, even if some aren't like array index checking
u can disable the index chewcking btw
16:49
checking*
16:50
iirc
Avatar
in unsafe you can call non checking functions, cant u?
Avatar
like get_unchecked or smth
16:50
sure but if i'd use rust i'd prefer to minimize use of unsafe
16:50
else i could also use c++ xD
16:50
i prefer it having bounds checking anyway
16:51
idk how much perfomance overhead ith as
Avatar
for me its not about that
Avatar
but its prob worth for 99.99% of software out there
Avatar
its that the logic bug isnt prevented
16:51
if you have out of bounds, u still have a bug
16:51
doesnt matter if crash or not
16:52
i mean the "dream" would be ofc to have a closed perfect system only input/output has to be checked
16:53
everything inside the system just works ™️
Avatar
i think this is too hard to achieve
16:53
given how complex stuff can get
Avatar
yeah, i dunno, hard to say
Avatar
but hey if they ever find a way to do it i welcome it
16:53
poggers
Avatar
maybe programming gets too unusable at some point 😄
16:54
imagine the optimization potential if the compiler has a garantuee of the flow of the program
16:55
would defs be interesting, even at the cost of slower programming
Avatar
@Deleted User with rust thanks to the explicit mutability you can enable optimizations, and they try, but llvm has bugs (mutable noalias) cuz nobody ever used it (hehe c++)
16:57
so rust is making llvm improve
16:57
poggers
16:58
The ring test suite started failing when I tried to upgrade to untrusted 0.8.0. The regression first shipped in nightly-2021-03-23: We were further able to narrow down the regression by bisecting d...
Avatar
well bugs are ok, aslong as the idea behind it isnt wrong
17:00
some day they fixed and then we've smth better
17:00
still considered "unsafe", ok kernel also does alot of weird hacks probably
17:00
but many projects already use O3 default, e.g. SDL2 (edited)
Avatar
>
I personally think -O3 in general is unsafe.
17:01
xd
17:01
yeah i think they are rly paranoid about this
17:01
but i guess rightly so
Avatar
i even use ofast for my graphic driver xD
17:01
never really had a bug, and in ddnet it even helped finding undefined behavior 😄
17:01
but yeah
17:02
i understand for kernel somehow, if it crashes it's more horrible than e.g. a user space programm
Avatar
well its what he says, if no one uses, bugs wont be found
17:02
so we should all use it monkalaugh
Avatar
yeah, well i assume the compiler teams also test it xD
Avatar
TETRIS is a popular video game in which you try to fill rows in a rectangular well using a sequence of tetrominoes chosen by the machine. Each time you succeed in filling a row, it is deleted from the well. Your game ends when you have stacked pieces up to the top of the well. I build a model of TETRIS and analyze the worst-case scenario, in whi...
17:49
proof that u cant win tetris
17:49
monkalaugh
Avatar
Sounds like the tetris player is at a slight disadvantage
17:54
lmao
Avatar
@Deleted User there are some languages where you can write provably safe code. but I don't know if you want to use them
18:41
check e.g. idris
18:41
Idris is a purely-functional programming language with dependent types, optional lazy evaluation, and features such as a totality checker. Idris may be used as a proof assistant, but it is designed to be a general-purpose programming language similar to Haskell. The Idris type system is similar to Agda's, and proofs are similar to Coq's, includi...
Avatar
but defs sounds interesting already
Avatar
I was down that road too, once ^^
18:50
you can also try coq 🙂
18:50
I ended up proving some pre-first semester math in coq instead of writing useful code 😄
Avatar
such languages would require alot of hype, so we'll see how good they actually can be 😄
Avatar
you can try languages without hype, too 😉
Avatar
yeah i mean like, that languages with these concepts are invented, until they reach a point of usefullness just like rust
Avatar
it's not entirely clear that they could reach that level
18:53
e.g. I'd say that something along the lines of brainfuck can't
Avatar
hype
Avatar
poggers
19:14
i love urbandict
Exported 366 message(s)