« first day (1926 days earlier)      last day (1545 days later) » 

 
5 hours later…
1:13 PM
-15
A: The C++ tag (and previously the C tag) is being displayed with a Qt icon

JD-StackThanks for pointing this out! We’ve experienced a bug with our internal tool that we use for ad campaigns, this is now fixed. You should see a non-blurry logo appear next to the C++ tag.

Lulululul
 
1:30 PM
@hellow :stare:
 
@Stargateur I don't know it's current state but when i was developing mobile apps with QT, i remember it was 5.5 or previous , there was a lot of internal bugs, QML wasn't that bad though. I wonder how it works now.
 
Hey guys! Is there any hope integer division for negative numbers will get fixed? I really hate that it is truncating like C. This behavior is simply not useful! Why did they not adopt flooring like Python did?
 
@purefanatic Are you looking for this?
 
@purefanatic doubtful, and I'd argue about "fixed". Chances are good that it does what the hardware does.
 
Changing integer division would be a huge breaking change, I wouldn't except this to happen ever
 
1:39 PM
But yes, I expect that there's a function to do the right thing for your case
 
I don't remember the last time I had to divide negative numbers :thinking:
 
@purefanatic That's a good point that @mcarton makes — can you share why you are dividing negative numbers, just for our education?
Let's see if OP likes their answer.
 
literally any stuff that makes sense with modulo arithmetics like date and time <-> timestamp conversion, computing periodic functions (suppose you have cos(x) where x = 2* pi * N / period) etc.
 
But you don't use those formulas with integers
 
And given how tricky data and time handling is, I'd leave that to a library, and anyone playing with those shouldn't be afraid of a division anyway
 
1:51 PM
Well the same problem applies for floats in the case of cos(x) and why would I need any floats for date / time <-> timestamp conversion?
 
It is not really shadowing, but "replacement", guess_str is no longer used once guess_int is in place. And no need to introduce dummy scope to "end" a variable. — Jarod42 3 mins ago
That's a good point
 
@MarcoBonelli nothing special here, I just did a Google search for rust rfc shadowing and clicked on the sixth link, then copied-and-pasted the quote. :-) — Shepmaster 3 mins ago
 
@purefanatic to be sure we are talking about the same thing, you mean how in Python -1 // 2 produces -1 and in Rust -1 / 2 produces 0, right?
 
"I just did a Google search […] clicked on the sixth link" that guy…
 
@mcarton I didn't even use my Firefox "limit search to Rust Stack Overflow"!
 
1:53 PM
@mcarton Well my point is, it's literally only those people that deal with dividing negative integers and for those guys it's making everything harder!
@Shepmaster Yes exactly.
 
:48397857 I also tried to like this message before you could delete it
@purefanatic I don't think the same thing applies to floats. -1. / 2. is -0.5
 
@Shepmaster Yeah I copied the wrong link (ie your name rather than the grayed out date next to it)
 
@mcarton come on do not underestimate the 6th link, most of them gives up on first
 
@purefanatic This behavior can be easily implemented
 
@purefanatic It's a bit awkward, but it's how most hardware works. For example
Why ALUs implement remainder-like math rather than modulo-like math, I'm not 100% sure, but I could make some guesses
wait, darn, that was "unsigned" divide
 
1:57 PM
@Shepmaster ah I mean if you define a periodic function such that it trivially repeats some mapping like f(x) = sqrt(x) for x ∈ [0,1), f(x) = f(x-1) for x >= 1, f(x) = f(x+1) for x < 0. Then you have some continuous x ∈ ℝ so I would just like to do f(x % 1) to get the correct result - this won't work. I have to do f(x % 1) if x >= 0 else f(x % 1 + 1)
 
To be fair, as someone who has never dealt with that problem, I'd naively expect -1/2 to be 0
 
Why is it limited to negative integers? With this logic, 5 // 2 should be 3
 
Even though this turns out to be less useful
 
@FrenchBoiethios what you normally want, with modulo arithmetic, is for the remainder to be the same sign as the divisor
 
@trentcl Really?
 
1:58 PM
@FrenchBoiethios 5 / 2 = 3 remainder -1 is weird
 
@trentcl Yep, I didn't understood that it was about the remainder
 
@trentcl yes, and I think modulo arithmetic is the only arithmetic that programmers normally need when computing fractions with negative numbers.
there are simply no use cases for -3 / 2 = -1.
 
@purefanatic I'm not arguing, except to say that "normally" is a bit of a squishy word
(In my job I mostly deal with real numbers)
(btw, IDIV is the instruction I should have linked to earlier instead of DIV)
 
@purefanatic That's not a matter of usecase, but how the hardware works
Rust is a low-level language, unlike Python
 
@purefanatic As I said I don't remember the last time I ever had to use an integer division on signed numbers, but in my work (robotics) I'd expect (±n)/(±m) to all give the same absolute value or you'd have symmetricity issues (although anything involving that kind of division would probably be done on floats anyway)
@FrenchBoiethios And yet we check for overflow by default, surely division could have been fixed if it was a real problem
 
2:10 PM
@mcarton The way it is defined though, it's just asymmetric in a different way
Personally I always triple-check things when I'm dividing integers that might be negative
 
@FrenchBoiethios That does not make any sense. Today, with two's complement, flooring integer division would even be simpler to implement in hardware! The fact that Rust still chooses to work like IDIV in Intel will just reinforce this bad design decision in newer hardware.
 
although, I can't remember when the last time I did that was...
 
@purefanatic Do you want those results? play.rust-lang.org/…
@purefanatic I've honestly no strong opinion about either case; I was just trying to find an explanation
Well, I don't correctly handle the zeros in numerator, but you see the algorithm.
 
@purefanatic ARM's sdiv does the same thing, for the record
 
Even if it would be easier, I'd bet there's just so much inertia behind "the way it's done now"
 
2:15 PM
And I'm not sure I agree with flooring division being simpler to implement, although I haven't worked on an ALU in years
 
It wouldn't be worth it (literally!) to have that implementation in hardware
 
@Shepmaster Probably the real answer.
 
2:34 PM
@Shepmaster I think that's a better duplicate stackoverflow.com/questions/59861885/…
 
@FrenchBoiethios totally possible, but without an example, its hard to tell
 
My guess was right B-)
 
3:03 PM
@trentcl I read that somewhere but am not certain either. I would guess that unsigned division is simpler and that you can more trivially translate between unsigned division and signed division when using modular arithmetic because two's complement is also modular, but maybe this is insignificant.
 
3:24 PM
@FrenchBoiethios I would like to have the remainder (or rather modulo) like python's %. abs(a%b) does not really make any sense to me. Also, div_euclid and rem_euclid that you linked earlier behave differently to python for negative divisors. But while I stumble over negative dividends from time to time, negative divisors are rare so I could mostly use those functions from i32 and would be happy.
 
3:35 PM
Comments are not for extended discussion; this conversation has been moved to chat. — deceze ♦ 1 hour ago
We don't get many of those
 
deceze is still a mod ?
 
@Shepmaster moderator ?
yes there are a species in crisis
 
@Stargateur that slash "moved to chat"
 
@Shepmaster yeah yeah you are not fun :p
oh I read the comment while I was on deplacement
question have been reopen so
BTW, 200,175 !!!
200kkkkk
 
3:54 PM
:-)
 
congrats
 
🎉
 
On 250k, the old SO used to send stuff, like mugs and tshirts
You'll tell us if the new management kept this tradition
 
@Shepmaster regarding this one -- you still have no idea how to actually solve this with unsafe?
 
@DenysSéguret They did that for 100k, actually. And I did get a mug and shirt and stickers :-)
 
3:59 PM
@Shepmaster more easy you live in US
 
@Stargateur probably very true
 
I got some stuff for the 250k but it was strangely unpersonnal, as if they had forgotten to unplug an old process, and some people after me told me that the 250k stuff had stopped
 
4:24 PM
@mcarton Does this mean I need to create a user to run psql without sudo, then make the connection? — ComplicatedPhenomenon 7 mins ago
I really dying to see people use thing that don't at all understand
 
TBH the auth/user part is the most confusing part of psql. This is a failure ux-wise in my opinion
(still better than oracle even on this topic, though)
 
@DenysSéguret 'true'
but this is not the problem
as shep said
It seems likely that one path is using a Unix socket and the other is using a TCP socket, but you haven't configured your Postgres server to allow TCP connections from that user. — Shepmaster 11 mins ago
damm can't be afk, shep always answer before you
 
sorry, was just answering the comment. I don't go to main anymore
 
5:08 PM
you look so.... not happy ^^
 
There is cause for that
 
5:32 PM
0
Q: Cast Result<Box<Struct>> to Result<<Box<dyn Trait>>>

NikBondI have some struct MyStruct that implements trait MyTrait. How I can map Result<Box<MyStruct>> to get Result<Box<dyn MyTrait>> without passing to map() explicit lambda with the return type? The code let res: Result<MyStruct> = Ok(MyStruct{}); let res: Result<Box<dyn MyTrait>> = res.map(B...

I already saw a very very similar question
as always impossible to find anyfind
 
@Stargateur looks like you found it :-)
 
@Shepmaster lucky
 
5:50 PM
I added more dupes to the new one
 
6:03 PM
I think stackoverflow.com/q/59860476/7076153 deserve on other answer
 
6:14 PM
I am suffering from Arc<Mutex<_>>, because results of futures change the state of the program and tired of moving Arc Mutexes into the closures, before moving you need to clone them, if you have more than one reference like this it makes code unreadable, you need to give nonsense names to the owners
and also i am always trying to avoid Boxing things but tokio-executor just boxes the whole future before spawn
 
@ÖmerErden I feel like you shouldn't be using Arc<Mutex<_>> heavily in futures code
Not that you should never use it, of course
 
@Shepmaster I feel the same but according the libraries or apis i need to manage many things after and_then or or_else
 
@ÖmerErden you got any smallish examples?
 
6:38 PM
I have limited futures as spawned, they all do the same work with different inputs, and at the end of each execution they need to create future from other inputs in the queue then spawn. in the end they may fail or get succeed.
system has a strategy according to fail, may retry that input or cancel the whole process
This is a bit abstract and not small example i guess
Also according system's state, whole process may get succeed or continue selecting new inputs from the queue
And this does multipart upload/download with balancing concurrent transfers, since rusoto_s3 fails and exhaust on sloppy networks a lot.
 
7:03 PM
hah, this is new:
> note: the compiler unexpectedly panicked. this is a bug.
 
@PeterVaro happen sometime
 
'tis a first for me..
 
they try to keep it rare :p
 
LOL
 
7:24 PM
@PeterVaro are you using nightly features?
 
@Shepmaster damn, I didn't notice I was on nightly..
but I didn't use any of the nightly features..
 
@PeterVaro potentially more worrisome then
that would indicate that something is broken that was stable
If it's reproducible, it's likely a good idea to create a minimal case and look for / create an issue
you can search the issue tracker first, before minimizing, of course
 
could mean that, though my nightly is 2 weeks old..
 
well, if it's repro as it is now, try updating, then see if it still is :-)
 
@Shepmaster I tried to, I couldn't as of yet
(once I cleaned the target)
my suspicion is that it has to do with incremental changes/compilation
(if that's a thing for rustc, I have no idea.. ;))
 
7:33 PM
It is a thing, yeah
 
8:31 PM
How's it going everybody?
I have a "simple" issue that I can't resolve.
 
8:46 PM
@Unbreachable sharing a playground with the issue is the fastest way (as well as the usual "don't ask to ask, just ask" advice)
 
ask for ask is stupid
 
alright alright let me see
https://play.rust-lang.org/ So ALL i am trying to do is pass arguments from one fn to another. I only wanted to pass the arguments from the fn edit() to fn profile() but realized that i was calling fn profile() everywhere because I am using it as a navigation. My issue is trying to resolve this but when I actully just decide to pass the argumnet to all fns, then i got an error of fn main(first_name: String) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
 
@Unbreachable try again...
 
huh?
 
@Shepmaster we need a tutorial for share playground link
@Unbreachable your link is useless, click on share button
 
8:54 PM
which link?
i have
 
play.rust-lang.org is the url of playground, this doesn't share your code
you need to click on the share button
and copy paste the link given
 
@Stargateur I've debated (and there might be an issue for) changing the URL bar when you click share.
 
@Shepmaster that would clearly be good I think
 
@Unbreachable yes, the main function does not take arguments
 
9:02 PM
@Unbreachable what is your reasoning about main taking an argument ?
main(first_name); even if you can call main in Rust I will not recommand it
 
I have a navigation bar, and in that navigation, I am using fn profile() which takes an argument......I need to supply that argument everywhere I use fn profile()
 
just do another function don't use main for that
you are basically doing a state machine
Your way to do it could lead to a... stackoverflow
 
Funny thing, I actually tried that by creating an fn dashboard() in replace of the fn main() but then I need to call it in main.......still needing the argument, sighhh
how funny
How to get around this?
 
14
A: A pattern for finite (game) state machine in Rust with changing behavior?

ShepmasterA finite state machine (FSM) can be directly modeled using two enums, one representing all the states and another representing all the transitions: #[derive(Debug)] enum Event { Coin, Push, } #[derive(Debug)] enum Turnstyle { Locked, Unlocked, } impl Turnstyle { fn next(sel...

 
That's a good looking avatar ^
 
that's it
welp
 
I wonder how much space is taking all snipped in gist.github.com/rust-play
mmm actually let's say 1000 ko for every snipped and that a big assumption
that not taking much space :p
I wonder if github put a limit
@Shepmaster github.com/integer32llc/rust-playground/issues/542 guess you should look at this
 
9:27 PM
Yeah, I plan on switching to private gists.
 
secret
secret gist
it's not private
because as you I don't mind this change
but people need to not account this as "my code is private and safe"
 
Sure.
 
and actually I think an option would be nice
either share public or secret
 
well, options get into "I want to share it using my github account"
 
ah that would be good too
 
9:29 PM
which is also a good thing but even more annoying
 
yeah this one require a lot
 

« first day (1926 days earlier)      last day (1545 days later) »