Live data from Hacker News

Tests aren’t enough: Case study after adding type hints to urllib3

sethmlarson.dev

31–40 of 205 posts

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#31
post #6

Earlier quoted context omitted.

It's $current_year and there's still debate whether checking stuff at compilation time is better than at runtime?

People who don't think types are a good thing need to work in a statically typed language for a year or two and then see what a difference it makes in reality. Unproductive Java bureaucracy != static typing. I think the people debating it never tried it seriously.

After using TypeScript for even a little bit I find it painful to go back to JavaScript for anything more complex than white-boarding.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#32
post #17

Earlier quoted context omitted.

I’ve done everything from Haskell to Java and I still strongly prefer Clojure and Common Lisp-style dynamic types.

I have to agree, I've done over 5 years of C# and then went to ruby and never looked back. Static type checking raises the floor on incompetence, but also lowers the ceiling on excellence. I have to admit I don't have experience with the extremes which would be Haskell and Clojure. The amount of cruft I had to type in C# just to get shit done... It's all implicit in ruby thank god for that. I never EVER have to check…

How in the world does type checking lower the ceiling on excellence?

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#33
post #25
post #20

Earlier quoted context omitted.

I've been alive long enough to see that most things are useful, and all things are oversold. More, the nice easy things to build with major restrictions pretty much gets thrown out the window for complicated things that have constraints that most efforts don't have. This isn't just a software thing. Building a little shed outside? Would be silly to use the same rigor that goes into a high rise. Which would be crazy t…

Not that I disagree, but I feel like you are overselling the simplicity of [building a shed]( https://en.wiktionary.org/wiki/bikeshedding ).

My point is that all methods and techniques probably have worked for someone doing something.

And I should have leaned in on how much is still left to implementation in terms of "shed." From weather, to what is being stored. It isn't like there is a universal shed design that will make everyone happy.

Nor is this saying that some things aren't truly valuable. Just recognize that some places they don't help as much as you would like. This isn't saying they are bad or worthless. Just acknowledging that they are oversold.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#34

I love static typing/type hints if for only 1 thing - code maintenance. Even code I wrote six months ago. Not having to dig through 6 functions deep to try to figure out whether "person" is a string, or an object, and if it's an object what attributes it has on it etc. is huge. And not to mention that some clever people decide - hey, if you pass a string I'll look up the person object - so you can pass an object or a…

The main argument for dynamic typing is speed in prototyping but I find that's opposite for me. I'm much more comfortable rapid prototyping and ripping stuff apart when I have a strongly static typed environment telling me what I just broke.

Doing radical refactoring often involves just making those changes and then fixing all the IDE or compiler errors until it runs again.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#35
post #7

Honestly will never go back to languages without type checking, it prevents so many bugs and is a huge help in understanding code you haven’t worked with previously.

I feel the same way but wonder if I'm right when the majority of jobs are JS and Python.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#36
post #6

Earlier quoted context omitted.

It's $current_year and there's still debate whether checking stuff at compilation time is better than at runtime?

People who don't think types are a good thing need to work in a statically typed language for a year or two and then see what a difference it makes in reality. Unproductive Java bureaucracy != static typing. I think the people debating it never tried it seriously.

A lot of people grew up with Java -- especially early Java -- as their primary language. It was taught heavily in schools.

I think it ruined a lot of people to static typing and exceptions because Java is/was terrible for both of those things.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#37
post #28

I love static typing/type hints if for only 1 thing - code maintenance. Even code I wrote six months ago. Not having to dig through 6 functions deep to try to figure out whether "person" is a string, or an object, and if it's an object what attributes it has on it etc. is huge. And not to mention that some clever people decide - hey, if you pass a string I'll look up the person object - so you can pass an object or a…

I never understood this argument. In what kind of shop are you working that passing a string named person to a method expecting an object is tolerated. Or even passing different types that don't share a common interface. This would never fly in a code review in any of the companies I've worked for.

I've seen essentially this code in so many organically grown codebases (when they grew up without types). It's usually close the the UI, because someone had to quickly add an alternate path to support some new user interaction

    function find_user(person) {
        if user is string {
            query_by_name(person)
        } else {
            query_by_name(person.name)
        }
    }
and yeah, we all know it's kinda messy, but also that logic has to live somewhere and we need this feature asap so it passes code review. I wrote a test for it, ship it.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#38
Even though I had previously learned some rudimentary C, C++, and Java, I really came-of-age with Python. Now, having written (and maintained) nontrivial code bases in statically typed languages including D and Rust (and dabbling in others with contributions in C, OCaml, etc.), I am never going back — except perhaps in a few cases when a library like PyTorch or Pandas has no good substitute.

(edit: corrected "Linda's" to "Pandas" heh, mobile kbd)

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#39

I love static typing/type hints if for only 1 thing - code maintenance. Even code I wrote six months ago. Not having to dig through 6 functions deep to try to figure out whether "person" is a string, or an object, and if it's an object what attributes it has on it etc. is huge. And not to mention that some clever people decide - hey, if you pass a string I'll look up the person object - so you can pass an object or a…

> I hate having to waste time figuring out the type of every variable and hold it in my head every single time I read a piece of code.

If a codebase doesn't have static types, it damn well better be set up to be highly grep-able. Including dependencies and frameworks.

This is why Rails pisses me off so much. No static types to help you out, and you can't grep (can barely google, even!) methods and properties that aren't defined anywhere until runtime. Is this from core? Is it from some 3rd party gem? Well fuck me, this file doesn't even tell me which gems it's relying on, so it could be literally anything in the entire goddamn dependency tree.

Re: Tests aren’t enough: Case study after adding type hints to urllib3

#40
post #17

Earlier quoted context omitted.

I’ve done everything from Haskell to Java and I still strongly prefer Clojure and Common Lisp-style dynamic types.

I have to agree, I've done over 5 years of C# and then went to ruby and never looked back. Static type checking raises the floor on incompetence, but also lowers the ceiling on excellence. I have to admit I don't have experience with the extremes which would be Haskell and Clojure. The amount of cruft I had to type in C# just to get shit done... It's all implicit in ruby thank god for that. I never EVER have to check…

> also lowers the ceiling on excellence

> I never EVER have to check the type of a variable at runtime.

> I always know its type just by looking at its name

I guess you've only ever written web backends and menial things like that?

Post reply on HN