5 ms·
When I first used python like 20 years ago I was blown away by how much functionality was blown in, and it can be annoying using languages where even the most b
by resoluteteeth 7y ago
When I first used python like 20 years ago I was blown away by how much functionality was blown in, and it can be annoying using languages where even the most basic functionality involves downloading 50 packages from the internet, but on the other hand the standard library does seem to be a mess now.
- new4thaccount 7y agoYea. I'm using Rust at the moment for fun and the amount of things not in the standard library is crazy to me. What? There is no built-in dictionary? What do I use instead and where is it? Edit: based off of all the replies below, everyone understands the validity of what I'm trying to say, but also have fortunately pointed out my admittedly grevious error of not knowing you can just import hashmap from stdlib. The extra step is pretty minimal and not a problem. I'm hoping this is covered in the Rust book.
- resoluteteeth 7y agoYeah Rust is pretty extreme. I was just trying to generate a random number in it and was pretty surprised to find out that at some point it did have this functionality in the standard library but they actually removed it and now it's a separate crate.
- nicoburns 7y agoThat is actually being considered for inclusion at some point. It was mainly excluded due it not being ready and them not wanting to commit to the existing API. That said, I like the Rust way. Including a library is pretty easy, and it mains you get the best API as the main one (rather than a stdlib function that is "good enough", and another library to use if you really care about that functionality).
- jzoch 7y agoYou mean a map? It's in the standard library.
- new4thaccount 7y agoYep. Map/Hash/Dictionary. I didn't know it was included in stdlib (I really thought it wasn't) and feel idiotic now. It is still odd (having a primarily scripting background and not coming from the systems side) that I have to include what seems to be essentially an import statement at the top. I guess it is a lot more efficient that way though. Thanks for pointing out my error!
- jgibson 7y agoEr, doesn't hashmap do pretty much the same thing? https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.HashMap.htm...
- nicoburns 7y agoDictionary in the python sense? There are two! https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.HashMap.htm... https://doc.rust-lang.org/std/collections/struct.BTreeMap.html https://doc.rust-lang.org/std/collections/struct.BTreeMap.ht...
- new4thaccount 7y agoAt least the first one seems pretty straightforward and thanks for replying. I only just started and have a lot to learn.
- StavrosK 7y agoOof, I wasted a good hour+ trying to convert from one to the other. Maybe there's an easy way to do this, but not many people on IRC knew (or were available at the time).
- edflsafoiewq 7y agouse std::iter::FromIterator; BTreeMap::from_iter(hash_map.into_iter())
- steveklabnik 7y agoOr .into_iter().collect(), I believe. No import needed.
- a1369209993 7y agoAssuming the keys are Hash + Ord, wouldn't that just be: for (k,v) in &src { dst.insert(k,v); } ?
- StavrosK 7y agoYes, that's what I ended up doing, but the error confused me and I ended up looking for a less hacky way for more than an hour until I said "fuck it" and just did that.
- CDSlice 7y agoIf you are using dictionary in the Python sense, Rust has that built in too, you just have to import it from the standard library collections module. https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.HashMap.htm...
- jonesetc 7y agoI know it's not the whole point, but there is a hash map and sorted (btree) map in the std collections. That being said the point still stands, I remember specifically feeling it at the lack of included regex. I overall prefer the slim std lib of rust over the massive python though. Especially with the community being pretty good about nominating de facto standard packages like for regex.
- rightbyte 7y agoWhen I first touched Python I had only used C. Is your story similair? Had I been using Java or Visual Basic or even C++ proirly maybe I wouldn't be so impressed as I were. I think the mistake Python is doing is messing with it's simplicity with decorations, halfass lambdas and stuff. As a newbie you could understand Python code, while eg. C++ templates were magic. You need to know more Python to understand Python code nowadays.
- icegreentea2 7y agoDecorators added were in in 2004, I think lambdas were an original language feature (like... before 2004). There are other new stuff that might be confusing to beginners (like our mighty walrus operator), but those two examples have been there for effectively forever.
- rightbyte 7y agoOk it's maybe just my random perception of the language evolving in unsync with my (moderate) skills in it. I just had the feeling there's more "stuff" that you need to know.
- geofft 7y agoI found that attractive when I first learned Python, but when I (much more recently) started picking up Rust, I was blown away by how easy and normal it is to use external packages: the build tool and package manager are the same thing and shipped with the language, the hello-world-equivalent docs assume you're using it, and even the Rust compiler and standard library themselves can (carefully) depend on external packages. Having run up against limits of the Python standard library several times in years of writing production software in it and not just learning it, I find the batteries-not-includes-but-easy-to-install approach better on the whole. (Rust is not the only language that does this - my impression is Node/NPM and Swift, at least, are similar - but it's the one I happen to be familiar with.) In Python's defense, this was not obvious at the time; my understanding is Rust came to this approach by looking at the experience of Python and other languages. When Python's standard library was first being written, there were no easy package managers for any language, and the normal thing to do for installing dependencies in e.g. C was to grab random tarballs and figure out how to build and deploy them yourself. So avoiding that process made perfect sense.
- civility 7y ago> Having run up against limits of the Python standard library several times in years of writing production software in it and not just learning it, I find the batteries-not-includes-but-easy-to-install approach better on the whole. Obviously it doesn't apply to everyone, and it certainly doesn't apply to most startups or open source developers, but I spent most of the last 20 years working in environments where you have to get permission for every third party library you bring on to the network. Many networks were essentially "airgapped", so it's not like you could just ignore the rules. The bureaucratic process alone meant that we preferred large bundles like Anaconda or Qt. Trying to use Cargo as it is typically used and documented would be a complete non-starter.
- geofft 7y agoYes, my own employer is similar (you don't need permission, but production systems have no internet access and so you need to pre-download all your tarballs etc.), and cargo doesn't work right. But I think there is work on pointing cargo at an internal mirror. We do have an internal PyPI mirror (with devpi) and we point `pip` at that, and it works pretty well.