4 ms·
It's funny because in other typed languages a string can be null because of string being a reference type as opposed to a value type. I think Python type hints
by giancarlostoro 1y ago
It's funny because in other typed languages a string can be null because of string being a reference type as opposed to a value type. I think Python type hints make more sense than C# does in this respect, which gives me a chuckle (two of my favorite languages and the untyped one makes more sense with types). That said, not sure if you already have but I would add a github issue / ticket reporting your issue to raise awareness to the devs.
- _flux 1y agoIn some other typed languages, that is. E.g. in C++, OCaml, Haskell, F#, Kotlin, and Rust (a non-exhaustive list) you can have non-nullable strings, and other objects.
- asplake 1y agoIt’s worth noting that even though the runtime allows nulls (i.e. None) anywhere, Python type checkers do distinguish between optional and mandatory types.
- scuff3d 1y agoIn Zig you have to mark variables as nullable when they are declared. If you try to assign null to any variable that doesn't have it marked as such the program won't compile. Any nullable type has to be unwrapped before accessing the value, or again, won't compile.
- Scarblac 1y agoAll Python types are reference types. The reference to None isn't included in the str type. There's no way to get an actual null reference, afaik. Variables always have some value, possibly None. (not sure what happens if you set a reference to null from C - a crash, probably?)
- kstrauser 1y agoA quibble: Python is strongly typed. It’s not un-typed in any reasonable sense of the word. It’s dynamically typed, though: type information is on objects, not on the names referring to them.
- seabrookmx 1y agoIf you use the nullable types compiler option in C# (which defaults to enabled for new projects) then you need to declare you string as string? for it to be nullable :)
- pjmlp 1y agoYes, but you also need to turn the warning into an error for it to be actually usable, because .NET team didn't want to break the ecosystem, plenty of Assemblies out there didn't cared to update themselves. I still have to disable nullable types in some delivery projects.
- mixmastamyk 1y agoThe billion dollar mistake.