News for hackers. Stuff that matters.
Re:Practical Python Programming by the_af on Thursday June 18, 2020 @09:28PM (#23570101)
This.

My experience with Python goes like this:

"I have to write a really small script... ok, not so small that I can do it with bash. I know, I'll use Python! This is going to be a small, throwaway utility anyway"

(Some weeks later, it's turned into a large monstrosity and I need to refactor something, and everything breaks because refactoring anything nontrivial written in Python is a dangerous proposition)

"Ouch! Python: never again!"

(Repeat a few weeks later)

Re:Practical Python Programming by ghostwriter on Friday June 19, 2020 @06:31AM (#23573030)
You can try Turtle next time, if you prefer fully type-checked shell scripts

https://hackage.haskell.org/package/turtle-1.5.19/docs/Turtl...

Re:Practical Python Programming by the_af on Friday June 19, 2020 @09:41AM (#23574416)
That's awesome. I love Haskell. Will definitely try Turtle next time!
Re:Practical Python Programming by disgruntledphd2 on Friday June 19, 2020 @06:01AM (#23572896)
I mean, you need to write tests before you refactor, but that's true in all languages.

I do agree (and have the scars to prove it) that this isn't a panacaea but it does help, a lot.

That being said, one of the worst bugs I had in python was in passing in the wrong types to a constructor function, and my tests didn't catch that. To be fair, Mypy would have, but I hadn't annotated that part. At the end of that debugging situation, I would have gladly killed somone for enforced static types in Python.

That being said, the data model is a work of art, and a core reason why I enjoy coding in Python. It's just a shame that pandas kinda sucks.

Re:Practical Python Programming by the_af on Friday June 19, 2020 @09:39AM (#23574402)
I find the problem with writing tests for Python is twofold:

- Most Python programs I write start their life as tiny scripts, always with the certainty they'll never grow (Narrator: they always grow). I don't know many people who write tests for their scripts...

- Testing in Python means too much effort in the wrong places. Consider that most refactoring problems would have been caught for free by a language with static typing. I've experienced runtime errors because I changed the return type of a function from a single value to a list (or viceversa). A statically typed language would have let me know of my mistake for free, so that I could focus on tests that really matter.