thephd,
@thephd@pony.social avatar

Something that bothers me a lot in Python is not really Python's fault but when I use it and make a bug and my brain immediately goes

"Nye heh heh heh, if you just had a type system that wouldn't have happened!"

It's just really hard to argue with "this thing that would have otherwise stopped the build and told you to fix your shit is now a runtime error that manifests under specific conditions with a client" and it's just so much wasted comms 'n' work for an easily-caught problem.

This isn't meant to be type system propaganda or whatever, it just keeps smacking me in the face every time I go work in some dynamic language, and every time it just makes me mad. Like, yeah, I get it, I'm an idiot, but that's why we have the tool.

To cover me being stupid.

lx,
@lx@swiss.social avatar

@thephd My bot @xkcd was originally written in Python and I had quite a few bugs which were basically founded in the same issues you describe. Then I rewrote it in Rust as my first real Rust project. In the several years it’s been running now I’ve only had one bug and that was more of a “specification problem”, in the sense that my regex wasn’t designed to handle emojis. It was quite obvious when it happened and the fix was even easier.

flower,

@thephd It can be an problem that Python fails are run-time, so seldom used code (that's not tested) can trigger a failure later on.

I might have to Google around to see if someone has written a type-checker for Python.

stiv,

@thephd Just use MyPy. Full stop. No serious Python code should be written these days that doesn't use it.

Every now and then I see people complain about it, and sometimes they're even big figures in the Python community (IIRC the guy who wrote Flask dislikes it). But I took a fairly large Python 2 project at work I'd inherited, whose behavior was a mystery to me and used the comment-style MyPy syntax to figure it all out by type annotating everything which makes these arguments fall flat to me

stiv,

@thephd MyPy has a mode that let's you write comments for Python 2 code which is a really under-appreciated feature. This let me run MyPy in both Python 2 and Python 3 mode to make sure it worked in both before switching, which worked a hell of a lot better than simply covering everything with unit tests and using Tox with both language versions.

stiv,

@thephd MyPy can conform to most of the odd idioms that Python, in it's dynamic glory, has been able to adopt over the years. However sometimes the original code is so weird it can't do it unless there are mild changes.

For example: if there are circular dependencies between specific modules or just really shitty physical organization in general, MyPy often hits a wall. IMO circular dependencies are the devil and should be fixed but I've encountered people who dislike MyPy for this reason.

stiv,

@thephd also: there is a hard-set, irrational aversion to typing in the Python community. I used to work with a lot of "Python" developers and even though MyPy is one of the easiest large-scale language upgrades to make for any "federation of languages" (far simpler than adding TypeScript where you have to generate the code) people seemed to look for any reason to knock it. I like Python but avoid circles where the language is popular because the community is filled with hard-heads.

stiv,

@thephd ... to clarify, some very important people in Python care about MyPy, including Guido van Rossum. But there's lots of cultures within Python, and many of the people who went there have an extreme dislike of static typing due to some traumatic experience they had with Java or something and will fight attempts to introduce MyPy for any reason they can think up.

thephd,
@thephd@pony.social avatar

@stiv I think if the MyPy community was smart, they would do what TypeScript did and provide an out-of-band types registry where users could provide annotations for libraries tied to version number / git tag. That would get around the problem of having to fight upstream maintainers to add annotations that they neither want nor care about.

thephd,
@thephd@pony.social avatar

@stiv (This is partially covered by e.g. TypeShed (https://github.com/python/typeshed), but the tools I use do not automatically pull typeshed types and use them to provide type annotations; it's all just whatever the current analyzer can infer from the code/bytecode available.)

vitaut,
@vitaut@mastodon.social avatar

@thephd Makes large-scale refactoring a huge pain too.

floooh,
@floooh@mastodon.gamedev.place avatar

@vitaut @thephd I tried to convert my one big python code base (https://github.com/floooh/fips) to type hints and it was a pain in the ass TBH, because it quickly turns into a "generics-puzzle".

IMHO Python's "journey" towards a "proper" programming language is a dead end, Python shines for quick'n'dirty cross-platform scripting and sloppy glue code (and Python 2.x was just right for that).

horenmar,
@horenmar@mastodon.social avatar

@floooh @vitaut @thephd IMO the "generics puzzle" is telling you to use more types.

I am definitely guilty of doing things like returning tuple of heterogeneous lists, which is terrible to hint, but really, it should be a type.

floooh,
@floooh@mastodon.gamedev.place avatar

@horenmar @vitaut @thephd a lot of my python code 'exploits' python's duck typing (even if I didn't specifically have that in mind when writing the code). I think it's related to the fact that I typically use python for "scripting stuff" and pass data around in Lists or Dictionaries.

I had the impression that the Python type hints are less 'flexible' than what I can do with the Typescript type system (which has been specifically designed to gradually add type-hints to old JS code bases).

floooh,
@floooh@mastodon.gamedev.place avatar

@horenmar @vitaut @thephd ...in any case, it's probably easier to start a new python project with type hints than adding type hints to an existing project... but also, for the 'serious stuff' where I want a strict type system I wouldn't use python in the first place. It's nice to have a pragmatic "sloppily typed" language around for quick'n'dirty scripting stuff, and python is just that for me.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ethstaker
  • DreamBathrooms
  • mdbf
  • InstantRegret
  • ngwrru68w68
  • magazineikmin
  • everett
  • thenastyranch
  • Youngstown
  • slotface
  • cisconetworking
  • kavyap
  • osvaldo12
  • modclub
  • megavids
  • GTA5RPClips
  • khanakhh
  • tacticalgear
  • Durango
  • rosin
  • normalnudes
  • Leos
  • provamag3
  • tester
  • cubers
  • anitta
  • JUstTest
  • lostlight
  • All magazines