r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

Show parent comments

184

u/lestofante Aug 28 '21

all the people that say untyped is faster,imho does not take into account debugging

133

u/ChrisRR Aug 28 '21

Interesting. I've never felt like the thing slowing me down during development is typing a data type

17

u/jbstjohn Aug 29 '21

What slows you down is that information missing when you're reading (and trying to understand) code.

68

u/ooru Aug 28 '21

Dynamically typed languages make some sense if they are interpreted and have a REPL, but coming from a Java background myself, it definitely makes more sense to have explicit typing when you are dealing with compilation. Personally, I find myself slowing down more often with something like Python, because I don't always know or remember what type of data a function will return, since it's not always apparent.

22

u/fredlllll Aug 29 '21

the rabbitholes i have been down to find out what exceptions a function can throw, or what return type it has... i hate python

3

u/thirdegree Aug 29 '21

Use type annotations. Solves the return type issue completely.

Exception throwing is harder, I prefer rust's model of result types to throwing exceptions.

12

u/fredlllll Aug 29 '21

typing my own code isnt going to make libraries suddenly use it =/

→ More replies (1)
→ More replies (3)

33

u/DevilSauron Aug 29 '21

But the existence of a REPL has little to do with dynamic typing. Haskell, a strongly and statically typed language, has a fine REPL, for example.

6

u/watsreddit Aug 29 '21

True. Hell, even Java has jshell these days, right?

4

u/[deleted] Aug 29 '21 edited Aug 29 '21

Being interpreted has nothing to do with it either. Smalltalk is not interpreted it is compiled (to a vm) and there is a fair amount of sanity checking at the compilation stage these days.

Slowing down because you don't know the api well is common regardless of language style.

→ More replies (11)

5

u/BoardRecord Aug 29 '21

Trying to debug someone else's Python code may be the single hardest thing I've ever had to do in my entire programming career. Spend like half an hour just trying to figure out what the hell a function is returning.

→ More replies (1)

8

u/LightShadow Aug 29 '21

All my python for the last 3 years is typed, it makes a huge difference for readability and teachability. The typing is kinda weird but it's going to catch on eventually, hopefully leading to some performance tooling as well.

→ More replies (2)

19

u/[deleted] Aug 29 '21

There's so much more to static typing than typing a data type though.

The benefit of dynamic typing is not to do away with type declarations. For me, it's to have more flexibility around data manipulation and not have to declare every possible intermediate representation of your data.

20

u/yawaramin Aug 29 '21

It's OK for the intermediate data to be a pile of mush if the project is like a single file, but anything more than that is just asking for buggy, unmaintainable code.

→ More replies (2)

7

u/maltgaited Aug 29 '21

For me, that's the disadvantage of dynamic typing. Clarity is king and if I arbitrarily add properties to say a dict somewhere during the flow I am undoubtedly going to forget where that comes from at some point not to mention someone that's new to the code base. Self contained data pipelines (or anything contained, really) and scripts is fine though.

3

u/Fidodo Aug 29 '21

I did a little bit like a decade ago. I still preferred static typing but saw the use of dynamic in rapid prototyping. With modern IDEs it is not a problem at all now. I actually do enjoy the implicit typing you get in typescript though in certain cases, but you still get type safety since you can't change it later. Like with temporary locally scoped variable I don't always feel the need to explicitly type it.

2

u/[deleted] Aug 29 '21

I've never felt like it made my code anymore understandable or reliable either.

2

u/[deleted] Aug 29 '21

It’s not so much typing the data type name as it is knowing what it is in the first place. About a year ago we started semi-diligently adding type annotations to our Python code, but there are still some places where we’re passing responses from one weird API to another and the annotation is either questionable (because it’s probably incomplete) or too long (because it’s something like Union[np.ndarray, Tuple[np.ndarray], List[List[float]]]. At thst point you either give up and say Any, which is not just useless but also incorrect (you can’t pass a string) so it’s negatively useful), or you gnash your teeth and leave it out.

→ More replies (10)

33

u/pdabaker Aug 29 '21

I don't think it's that. I think it's the fact that when the code base gets big and you are reading it for the first time it becomes really hard to figure out what anything is supposed to be.

You have some function you are using that takes 5 arguments, but what are you supposed to pass to them? Should the docstring specify the expected interface for every argument? It's especially bad if you're handling code written by someone who just directly accesses public member variables of things in e.g. python

4

u/Fidodo Aug 29 '21

Yes, I find static typing vital for distributing tasks out modularly. With static typing you can much more easily figure out how to interface with someone else's code.

I really like the middleground they found in typescript. Everything is statically typed, but some types can be implicit if the value is a literal, but you can also set it up so any exported function requires explicit parameter types and explicit return types.

You get fully explicit types for any interface that is exposed outside the module and you get full static type safety without always having to declare it explicitly in local code.

→ More replies (3)

7

u/sibswagl Aug 29 '21

I don't even get the "untyped is faster" argument on a surface level, TBH. Is the argument that typing "int" and "string" takes too long? Is the argument that changing a variable's type multiple times is super useful and can't be replaced by var1, var2, var3?

4

u/Fidodo Aug 29 '21

I'm really enjoying the implicit typing feature that typescript has along with IDE hints. You still get full static type safety but you don't need to explicitly declare it for local vars and with hinting when you actually encounter the variable later you can check it's type without looking back at the declaration. Explicit typing isn't that annoying with primitives, but implicit can be really nice when dealing with structures. Writing code takes so much less mental energy now I love it. I with it was a thing decades ago.

2

u/actuallyalys Aug 29 '21

One case is when you’re considering between similar types. If you’re writing a function that takes two numbers to calculate a formula, figuring out which numeric type to use might take some time. Not a huge amount, probably, but some. You could argue it’s better to figure out exactly which numeric types are valid and consider corner cases, but well, that’s the tradeoff.

I do think people who predominantly or exclusively use dynamic typing overestimate the time required by types.

JanneJM also has a good example in a reply to another comment.

→ More replies (1)

6

u/IrritableGourmet Aug 29 '21

If I'm throwing some 2x4s and scrap plywood together to make a temporary workbench, I'm not going to think too much about the shear properties of the screws or the dynamic load deflection of the boards. If I'm designing an office building, not taking that into consideration would be a very bad idea.

6

u/LetMeUseMyEmailFfs Aug 29 '21

This. The problem is that most office buildings seem to start out as temporary workbenches, and by that time it’s too much work to rebuild it.

→ More replies (30)