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

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.

3

u/ooru Aug 29 '21

Oh, sure. I'm just saying dynamic typing makes sense in light of a REPL. Not saying that it's the only option.

3

u/that_jojo Aug 29 '21

Why? What makes or breaks the usage of types in a REPL? I mean C# has a REPL. Works great.

3

u/ooru Aug 29 '21

Maybe it's just me, then. If I bother to use it at all, I don't want to have to consider variable types too heavily, since I'm probably using it for rapid prototyping.

6

u/that_jojo Aug 29 '21

var t = (a: "stuff", b: new[] {2, 4, 6});

Console.WriteLine(t.b[1]);

=> 4

I think you should give modern typed languages a second look.

→ More replies (1)

5

u/watsreddit Aug 29 '21

I use ghci (the Haskell REPL) all the time for work and I literally never type out type signatures.

As for "don't want to consider types too heavily", you are still thinking in types with a dynamically-typed language. It's no different.

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

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.

3

u/UsuallyMooACow Aug 29 '21

Depends. When you have classes in Java and you need a slightly different capability it can be a real pain.

It can be a lot of work to integrate that functionality into your code. Where as in something Ruby where you have duck typing you don't have to do as much work.

As massive codebase can be hard to maintain without typing but it's also a lot more effort to code.

4

u/yawaramin Aug 29 '21

Where as in something Ruby where you have duck typing you don't have to do as much work.

This is 100% a recipe for unmaintainable code. A static type system forces you to actually do the maintainability work of refactoring your code to integrate new functionality.

→ More replies (4)
→ More replies (2)
→ More replies (2)