« first day (2002 days earlier)      last day (1486 days later) » 

1:27 AM
From a slack I'm in
 
2:08 AM
Also, I just "independently" "developed" arc-swap
By which I mean I finally understand why I've seen it in my cargo build output
 
 
3 hours later…
5:36 AM
@Shepmaster that's pretty :)
 
6:28 AM
I just made optional a feature and its dependency. And I don't use it. And my program is bigger. What did I mess ?
 
@PeterVaro Why "Oh my" ?
 
Weeeelll, I don't have an educated opinion on this as of yet (I have several half baked thoughts though) but this entire approach feels bad, that's why.
If there's one thing I'm thankful that Python exists is the Zen of Python:
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
 
ok. I get you then.
 
And the second guideline in there is one of my favourite: Explicit is better than implicit.
 
I've found anyhow to be quite enjoyable in application code (not libraries)
It's a kind of middleground I guess
 
7:03 AM
I still haven't came across a scenario, where I couldn't fight my personal laziness and wrap the errors to a higher level, unifined one myself.. And when I say a unified one, I still mean a structured one: different portions of the code have different unified errors and the top level one is just unifying these. (These higher level ones can be arbitrarily "deep")
but maybe I'm doing something wrong or missing something, 'cause this approach is just enough..
 
Do you handle your errors completely by hand ? use a lib / macro ?
 
Mostly by hand, yes
 
@PeterVaro I don't know. Handling errors by hand seems very OK to me and should probably be done more often
In application code, anyhow is convenient IMO
 
Maybe it is.. maybe if I would maintain a 20k+ code base I would think otherwise -- which I've done in several other languages but not with Rust as of yet..
 
If I count all the dependencies I wrote, broot is about 20k loc of rust...
 
7:12 AM
Dependencies doesn't count -- why would they?
 
Which seems a little mad for such a small program
@PeterVaro The dependencies I wrote specifically for broot. I could have chosen to put them directly in the same repo. I'm the main (or sole) user
 
Ah, right, then those do count ;)
That's exactly how I'm solving most of my problems -> refactoring it into a smaller project
 
most of the dependent are my own programs
I'm really puzzled as why removing a feature and a dependency makes my binary bigger
ok... found it... this specific crate was already added by a dependency... the dependency graphs grow too fast
 
7:47 AM
@DenysSéguret maybe your 1000 inlines increase the size of your program :p
@PeterVaro Oh my...
 
You both already knew Fehler, didn't you ?
 
Not really but this clearly look like exception :p
 
I think I read about it before but didn't look into details until the above article
 
And I meh exception
Also annotated every function gonna be painful
 
my problem is not about the similarity of exceptions -- this is still not that, though using similar keywords / naming
my problem is implicitness / hidden magic, and yet complex function signatures
 
 
4 hours later…
12:21 PM
I would like to alias function so much
// op-id = token
fn op_id = base::token;

fn op_id(input: Input) -> Output<base::Token> {
    base::token(input)
}
 
That's what you just did, I think
 
@PeterVaro you have seen SNAFU, yeah?
 
The error here feels like a limit of the compiler: play.rust-lang.org/…
 
@Shepmaster sure
 
On the other hand, it looks useless anyway (not snafu, static fn)
 
12:47 PM
@Stargateur did you mean to make that infinitely recursive?
You can do the alias as a local variable
 
 
1 hour later…
1:53 PM
My kingdom for a good migration from quick-error.
It amounts to the only reason why I had to increase the compiler's maximum number of recursive calls, and the resulting errors aren't that great.
 
@E_net4iscleaningup define good + PRs to SNAFU accepted :-)
Especially for a new section to the "migration from" guide for SNAFU ;-)
 
whelp
I'll get back to you on that
 
@E_net4iscleaningup <3
I understand time is a precious commodity
My Next Big Thing for SNAFU is supporting standalone structs
and then "roll-up enums"
e.g.
#[derive(Snafu)]
struct MyThing {
    user_id: i32,
    source: AnotherError,
    backtrace: Backtrace,
}

// and
#[derive(Snafu)]
enum Error {
    MyThing(MyThing),
}
 
2:19 PM
ho ho ho @mcarton
 
Alloc? i am tr i gger11!!
 
3:04 PM
Questions get weirder every day.
 
3:42 PM
@E_net4iscleaningup I don't even understand what's happening here stackoverflow.com/questions/61082710/…
 
Answering that one was a trap. My condolences. :(
AsPrimitive was a bit of a bummer, after all. It clutters impls when we want to be able to cast from multiple types.
:<
This is an open problem in the nifti crate.
 
@Shepmaster Invite received, thanks.
 
o/
@JohnKugelman noticed you liked cleaning up ;-)
 
Sure do. I spend about 5X more time fixing things up than I do answering.
 
Our home is your home! #stayAtHome
 
3:50 PM
@JohnKugelman fills me with a warm fuzzy feeling.
 
Gotta say, Rust is my new love. I just picked it up a few months ago.
The Rust questions are the most well-curated section of SO I've seen. The dupe hammering is real.
3
 
@JohnKugelman Rust is pretty great, but you're preaching to the choir here, I suppose. :-) What have you been using Rust for?
 
Even the newbies are on point. Everyone posts MREs with playground links and error messages. It's wild.
 
@JohnKugelman I've read more-or-less every Q&A for the last ~5 years, so finding dupes is straightforward (plus some custom searches help)
 
I've been convincing folks at work to let me rewrite our C++ code in Rust. We've got a suite of client/server networking programs that do cybersecurity stuff.
I'm the one who wrote all the C++ code. And I really dislike C++. Rust is everything I wanted C++ to be. It's sooo good.
 
3:55 PM
@JohnKugelman Ah, RIIR; so you are a member of the RESF :-)?
 
Is there hazing?
If I gotta pay my dues so be it...
 
I think any such hazing would be reading /r/rustjerk for "long enough"
 
@Shepmaster The limit does not exist.
Howdy, John. Glad to have you around.
 
@Shepmaster reading/writing :>
@JohnKugelman You'll fit right in. I still greatly appreciate the major principles of C++, but the language has many things in it to loathe as well.
 
C++ has a good philosophy, but Bjarne & co don't have good taste. The Rust community is chock full of good taste. It's hard to define but good taste just permeates the language and the community.
I'm glad I can now channel my energy into using and perhaps one day helping advance a language I enjoy rather than just casting stones at one I don't.
 
4:07 PM
And C++ has some features Rust craves (specialization, const generics)
I forget the C++ names for those, if they differ.
 
template wizardry
Which includes SFINAE
 
My only complaint about Rust... I cannot for the life of me ever remember how to convert an Option to a Result or vice versa. The method names will not stick in my head.
 
@JohnKugelman I want to make a joke along the lines of "Ok... or?"
 
Oh you...
 
4:13 PM
You can try but I won't get it.
 
Ok, or else!
 
or else is so ominous
 
@JohnKugelman I've made a lot of crates. I still must open the doc of Result and Option all the time
 
4:35 PM
@Shepmaster link? :(
 
 
1 hour later…
6:11 PM
@JohnKugelman I'll remember to remind you that "everyone posts MREs and playground links" :-)
 
@Shepmaster Any problems with this answer? I'm scared to post an answer...
e.g. I thought a slice has a length attached, but your "you absolutely can compare a Vec with a slice" comment indicates that [2] is a slice.
 
@JohnKugelman I should clarify that.
 
I thought an unsized array is different.
 
@JohnKugelman There's arrays (length known at compile time) [T; N]
And Vec, owning, length known at run time Vec<T>
And slice, reference, length known at run time &[T]
So ["a", "b"] is an array ([&str; 2])
and vec!["a", "b"] is a Vec<&str>
 
Are there unsized arrays [T]? Or are they always [T; N]?
 
6:25 PM
unsized types exist, but are a pain to use (and are only tangentially related to C's stack-allocated things)
you are right that a slice has the size attached — it's a fat pointer
data + length
7
Q: Why can fixed-size arrays be on the stack, but str cannot?

wigyAnswers to What are the differences between Rust's `String` and `str`? describe how &str and String relate to each other. What is surprising is that a str is more limited than a fixed-sized array, because it cannot be declared as a local variable. Compiling let arr_owned = [0u8; 32]; let arr_sl...

so in stable Rust you always need to have the unsized type behind a pointer
So you can have a &[T] or a Box<[T]> or a Rc<[T]>...
 
Rc<[T]>, Arc<[T]>, NonNull<[T]>, *mut [T]
 
OK so [T] does exist, but not on its own?
Not a bare [T]?
 
Purrty much.
 
Quick question, is `as_slice()` idiomatic and stable? I wrote this:

```
let hash: Vec<u8> = cursor.get_bytes(20)?;
let hash: [u8; 20] = hash.as_slice().try_into().unwrap();
```

Would `(&hash[..]).try_into().unwrap()` be better? Or some other alternative even?
 
@JohnKugelman &hash[..] and hash.as_ref() work too
 
6:30 PM
[T] is a type on it's own, just can't be on the stack on it's own (yet) because it's not sized.
 
Code blocks how do they even work
 
The former uses slice indexing, the latter uses AsRef.
@JohnKugelman They only work on a dedicated message here in chat.
 
separate message for code; then control-k to format it
<<<chat>>>
 
the arguments around &foo[..] and .as_slice() and as_ref() don't have a great answer. All are good.
I use &[..] b/c I know what it does and it's shorter
I answer questions with .as_slice when I think about it b/c its more obvious
 
6:33 PM
I hit an "as_slice is unstable" error on some other piece of code so I thought maybe I was poking at places I shouldn't.
 
@JohnKugelman I do think that the answer could be extended to explain why their original code didn't work (due to the types)
 
"Note that the traits AsRef and AsMut provide similar methods for types that may not be fixed-size arrays. Implementors should prefer those traits instead."
Oh, well then. Docs recommend not using as_slice().
 
Trait methods have the benefit of enabling generic programming. See e.g. the signature for std::fs::File::open. Instead of some specific path value type, it takes something that implements AsRef<Path>.
 
Meaning, don't call it directly? It's just there for generic programming?
 
Oh, you can! But using trait constraints, you can take advantage of that behavior in functions without stating a specific type.
 
6:42 PM
@Shepmaster Updated... "The original code fails to compile because the inner arrays have different lengths, and therefore different types: [&str; 3], [&str; 2], and [&str; 1] are three distinct types and the outer array can't contain heterogeneous types. The inner types, including lengths, would have to match."
@E_net4iscleaningup Gotcha, gotcha.
I'm still trying to get a grasp on "idiomatic" Rust. Sometimes there are six different ways to do something due to the abundance of traits.
 
I find that challenging too - often it stems from something as simple as a slice being viewable as a collection of objects in several useful ways, so, to enable abstractions over each of those views, there are many names for ways to do the same or similar things
 
Which IMO is a good thing compared to having one poor abstraction
filled with a lot of unimplemented!
but annoying when you want this trait + that trait
trait aliases will be nice when they stabilize
and what would be super cool (and dangerous) is some middle ground of Go
where everything implements any interface magically
imagine if you could do
 
Absolutely. I love that traits are bolted on to concrete types, rather than the other way around like most every other language. It's so much easier to add new abstractions after the fact, or push unstable ones into external crates.
 
fn foo<T>(t: T) {
    t.len();
    t.get(54).unwrap();
}
And the compiler is like "yo, those methods could come from A + B, do you want to make an alias for those traits and require it for T?
 
Yeah - I find it challenging almost entirely because of the plethora of names to do similar things - and in the same vein, sometimes you have the same trait implemented for several types. So it can be easy to stumble into a surprising transformation - or difficult to find the transformation you want.
And yeah, go sounded nice to read about, ut I.. I don't know how I'd manage to be effective in it.
 
6:56 PM
There are also a few abstractions we can't do so well with traits. Namely those requiring GATs.
 
fwiw, I haven't written in something without real generic support since VB 6. And I.. don't want to ever really do that.
 
@Shepmaster Mmmmmm
 
I guess that's half a lie. MATLAB is... something else
 
Does that include dynamically typed languages e.g. Python? Surely you've used some of those.
 
I haven't. I write C# at $WORK part time (it's not a software engineering job), and I write in rust and C# at home.
MATLAB was for undergraduate research. I still write it a bit to help maintain it.
Oh, my university was (is?) a strong believer in Java. I.. I have something fo a hatred for it now. But it does have generics.
Some of that dislike is language design decisions, some of it is probably how very bored I was in the intro Csci class (I was a physics major) - I'd already been writing code for probably 10 years at that point, so the basics of control flow and OOP were not new to me.
 
7:11 PM
I will say, seeing what life's like without generics could be valuable. I don't know if I'd really get monomorphization if I hadn't experienced having to write separate linked list implementations for every node type back in my C days.
Linked list with ints? Linked list with floats? Better get copying and pasting!
Separate structs, separate functions, separate everything.
 
C has monomorphization just fine: #define
;-)
 
I do worry sometimes that we might choose monomorphization too readily, and code size suffers for it.
Like we're not making a deliberate choice. Strategic boxing could keep executable size down and keep us from blowing out the code cache too readily.
But I feel so dirty writing Box<dyn _>...
 
I concur; it's an interesting reflection on how the defaults of a language matter
dynamic dispatch is so "scary" and then I remember that many other languages do dynamic dispatch All The Time
 
ALL. THE. TIME.
The phrase "zero-cost abstraction" nags at me for the same reason.
 
need to have a genetic algorithm / machine learning / AI / whatever that can run the perf tests and then flip static/dynamic dispatch and test again, finding the minimum
 
7:18 PM
Now you're talking!
What if the compiler were to decide, nah, it's better if I don't monomorphize right here... and transparently adds boxing...
It can ignore inline right?
 
@JohnKugelman it can, yes.
@JohnKugelman similar questions have been raised about enum variants
as having 15 variants with 1 byte and one with 500 bytes can be bad
so boxing that variant can get better perf
 
Oh interesting. I haven't been paying attention to how enums work. They're discriminated unions, eh?
They're so easy to use and awesome that I don't even want to think about that. Damn you.
 
7:41 PM
Hehehe. I have thought several times about writing specialized versions of.. collections, whatever. Ick.
In that CSCI1301, they didn't want to introduce generics.. so they gave us ArrayList
But yeah, it's funny to me how much I avoid dynamic dispatch in Rust. Reflection, type-metadata-inspection, and dynamic dispatch are so normal in C#, just.. everyday. In working on druid I have to be frequently reminded that those costs are nearly trivial on application scale. You've got to be doing a lot of processing to care about the extra instruction or ten.
 
8:02 PM
Hm. It's really cause of the ugliness of Box<dyn Trait>. If there were a one-character sigil for boxing and dyn weren't required we wouldn't be so gunshy to use it. Box<dyn Trait>^Trait or some such.
 
@JohnKugelman lulz.
There was a syntax for heap allocated dynamic thingamajigs before 1.0.
So you could write ~str instead of String.
 
and dyn is comparatively recent addition (and still technically optional)
So back in the day you could say ~Trait, presumably.
And you can say &Trait today
 
Not sure if my edit on the latest Q is a bit too much..
 
8:18 PM
I'm confused by that question. Isn't the whole point of Tokio to allow non-blocking I/O?
 
Perhaps they stumbled upon a quirk in a tls crate and thought they need to either drop async or drop tokio because of that.
 
@E_net4iscleaningup the edit seemed fine to me (but I'm also known to be heavy-handed). OP edited after you did and didn't undo everything.
 
@SvenMarnach I assume you were the one who upvoted my comment, but if not, I completely agree.
like... why are they using Tokio if they didn't think it's for non-blocking.
Or maybe they have some completely different meaning of "non-blocking"
I just got a message notification and it faded away as I went to click on it
first time that's ever happened
 
Got that too.
 
8:31 PM
@DenysSéguret fn op_id = base::token; doesn't compile xd
@Shepmaster no
 
Today I am reminded that macro identifiers are kept in a separate look-up table from other identifiers.
 
mod base {
    pub fn token(_: u8) -> u8 {
        42
    }
}

fn usage(input: u8) -> u8 {
    let op_id = base::token;

    op_id(input)
}
@Stargateur ^
it's not the same, I know
 
I know I can do that but that doesn't help me
 
type Parser = fn(u8) -> u8;

mod base {
    pub fn token(_: u8) -> u8 {
        42
    }
}

#[allow(non_upper_case_globals)]
static op_id: Parser = base::token;

fn usage(input: u8) -> u8 {
    op_id(input)
}
 
I have sevaral rule that just alias base rule
that still doesn't help ^^
 
8:38 PM
I guess const works as well
why doesn't the second one help?
 
it doesn't remove the need to define the function usage
 
@Stargateur it's not clear what you want usage to be
it seemed like you wanted it to be a usage of the alias op_id
 
@Shepmaster I want to alias function
like type
type Foo = Bar;
fn foo = bar;
 
8:56 PM
@Stargateur yes, and I showed how to alias a function. It's not that exact syntax.
static op_id: Parser = base::token;
 
Oh wait
I didn't realize
can't wait we don't need to type static and const - -
It doesn't work because I have a lifetime parameter
 
aww :-(
 
@mcarton what is the point if I need to write so much ?
error[E0404]: expected trait, found type alias `Parser`
   --> sip\src\headers\via.rs:111:23
    |
111 | static op_id: for<'a> Parser::<OpId<'a>> = base::token;
    |                       ------^^^^^^^^^^^^
    |                       |
    |                       type aliases cannot be used as traits
    |                       help: a trait with a similar name exists: `ParseTo`
I have errors I never seen before ^^
just to give you a picture:
pub use nom_locate::LocatedSpan;
pub use nom_tracable::TracableInfo;

pub type Input<'a> = LocatedSpan<&'a str, TracableInfo>;
pub type Error<'a> = nom::error::VerboseError<Input<'a>>;
pub type Output<'a, T> = nom::IResult<Input<'a>, T, Error<'a>>;

pub type Parser<T> = fn(Input) -> Output<T>;
 

« first day (2002 days earlier)      last day (1486 days later) »