« first day (2975 days earlier)      last day (499 days later) » 

5:40 PM
&str having for default "" is kind of WTF...
 
 
1 hour later…
7:10 PM
@DenysSéguret better no default ?
I don't like much default too
 
@Stargateur Yes of course. It's kind of a null. I'm fixing a bug because there's a struct with a id: &str field and a derive(Default). This shouldn't be possible
 
You think it should be:

impl Default for &str {
fn default() -> Self {
panic!("")
}
}

?
 
(more precisely I'm replacing all the id: &str with typed identifiers in a big project and I find hidden bugs like this one)
 
no he thinks no impl should exist in the first place
 
Yes, you shouldn't be able to derive Default on a field of type &str
 
7:12 PM
@DenysSéguret nice
 
This default "" looks directly taken from Go
 
That would be a crippling limitation for deriving Default on structs and enums
 
honestly derive default is 99% a bad idea
 
@PeterHall Never saw any such case before. If there's a &str, it's not default, it should be an Option<&str> which isn't even more expensive
 
@Stargateur I would argue that it is closer to 70% a bad idea.
 
7:14 PM
@PeterHall yeah maybe 70%
 
I found it pretty useful for structs like this:

#[derive(Default)]
struct DatabaseSettings {
host: String,
user: String,
password: String,
max_connections: usize,
}


Works absolutely as intended.
 
Use options as they're meant to be used
You don't have an empty password: you have no password.
 
I agree
I think onyl struct that should derive Default are very basic like:
struct Vector {
  x: i32,
  y: i32,
}
any non trivial struct should not
 
This one is nice because it gives crate-specific errors at the time you try to connect instead of up front when you parse the env vars.
 
But parsing as options always works too
 
7:20 PM
e.g.: Error: expected protocol in URL
or having a maximum number of connections be 0, so just nothing happens
this is all fun stuff
 

« first day (2975 days earlier)      last day (499 days later) »