Python support for regular expressions
Python support for regular expressions
Posted Feb 23, 2022 10:24 UTC (Wed) by MrWim (subscriber, #47432)In reply to: Python support for regular expressions by NYKevin
Parent article: Python support for regular expressions
I realise this is a bit of a tangent, the subject is Python and not rust, but here goes anyway:
> On the one hand, import statements use a relatively straightforward, easy to understand set of semantics (i.e. "just stick a bunch of py files in a directory structure, and you're done!").
This is where rust isn't so good. It can be confusing how `mod` and `use` and `Cargo.toml` interrelate.
>This is good for scripting purposes, because you don't have to faff about with something like CMake just to build an entirely self-contained app.
Cargo helps here as it's the single blessed build system, and comes bundled with rust.
> On the other, those semantics are perhaps *too* simple, because there is no way to specify "I need version X or greater" within the import statement itself,
With Cargo these versions are specified in `Cargo.toml` - so still external.
> nor where the module actually comes from.
Cargo does restrict where the module comes from. You'll get the version you specified in your Cargo.toml, and you can't `use` things that you haven't specified there - even if they're included in a transitive dependency.
> To add insult to injury, you can't have two different versions of the same module in the same process
Cargo and rust fix this with clever symbol mangling. It could still be an issue with C dependencies, but they are relatively rare in rust land vs. Python
> And, of course, you have the common beginner mistake of accidentally naming a Python script after a stdlib module
This isn't a problem with rust - you can use from your local crate with `use crate::mymod`. And anyway - if you get it wrong you'll get a compile error, it's not going to silently give you the wrong behaviour at runtime.
Thanks for your comment, it encouraged me to finally publish that blog post. It had been sitting almost finished for about a year now.