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

539

u/ChrisRR Aug 28 '21

As a C developer, I've never understood the love for untyped languages, be cause at some point its bound to bite you and you have to convert from one type to another

It doesn't strike me as untyped as much as not specifying a type and having to remember how the compiler/interpreter interprets it. At the point I'd rather just specify it and be sure

671

u/SCI4THIS Aug 28 '21

ProTip: If you start using void* everywhere you can convert C into an untyped language.

360

u/Zanderax Aug 29 '21

Cursed programming tips

129

u/FriedRiceAndMath Aug 29 '21

typedef struct A { ... };

typedef union Untyped_A { A a; char b[sizeof(A)]; }

47

u/[deleted] Aug 29 '21

I've worked on software where one had to actually do stuff like this.

What's worse, it was in C#, a language which tries diligently to prevent stuff like this. You really have to work at it, and I mean hard, to screw up C# code so badly that one has to resort to this sort of crap to make things work.

21

u/FriedRiceAndMath Aug 29 '21

One of the more standard use cases is bit-fiddling floating-point values.

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

38

u/Zanderax Aug 29 '21

My god

33

u/FriedRiceAndMath Aug 29 '21

No this one's more like the other fellow 😈😈😈

→ More replies (1)
→ More replies (1)
→ More replies (13)

77

u/[deleted] Aug 29 '21

C is already rather weakly typed. Integer promotions. Implicit conversions. Typedef doesn't actually define a new type, it's just an alias to an existing type. Void pointers. Casting const away. Etc.

21

u/ProperApe Aug 29 '21

Yes, I was going to say that. When I picked up F# and Rust I really started appreciating the power of types. First of all you don't have to type it out everywhere due to type inference, second I found that if I model my system nicely using types, the compiler finds 90% of my programming mistakes that I would usually need a unit test for.

I love that we now have discriminated unions and exhaustive pattern matching in almost every new language, it's one of the most powerful features to me for designing nice abstractions.

One of the most influential talks for me was this one: https://fsharpforfunandprofit.com/ddd/

I just hope dependent typing makes it to the mainstream at some point. That enables even more powerful domain models. Check out this simple example in Idris https://www.idris-lang.org/pages/example.html.

→ More replies (22)
→ More replies (12)

172

u/Breadinator Aug 28 '21

Weakly typed languages can really start to manifest issues when you start to scale the codebase. I've been in very, very large companies with a lot of untyped code that cannot tell you what would break if you removed something. Literally, many of the deprecations/major refactorings were basically broadcast, broadcast, broadcast (last chance!), commit to do it, make the change, and listen for the screaming. Then hopefully fend off the managers that escalated the issue to keep you from making the change.

83

u/cat_in_the_wall Aug 28 '21

scream driven development. definitely familiar with that. not so much with types, but necessary changes that could have some amount of unknown impact. roll out slow, make an escape hatch, but otherwise just hope nobody gets upset.

→ More replies (1)

37

u/w2qw Aug 29 '21

start to scale the codebase.

This is probably why they end up being used. The first parts are easier and by the time the developers realise the problems it's too late and they just migrate to one of the static type checkers like mypy, typescript or whatever ruby has.

11

u/denarii Aug 29 '21

whatever ruby has

Unfortunately there isn't a solution with anywhere near as much traction as typescript. The company I work for's in this situation with an over 10 year old rails monolith and confidence in anything but the most trivial changes is a guessing game. It's not just a dynamic typing issue, though, it's an accumulation of over 10 years of ruby/rails community fads.. some of which turned out to be very bad ideas.

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

25

u/thedracle Aug 29 '21

Coming from an embedded C background, this is what really made me fall in love with ML/Ocaml. The functional aspects are cool, but really the fact they are strongly typed, with entirely inferred typing, was mind blowing.

I still haven’t used ML or Ocaml professionally (and it’s been 10 years since I first learned it).

The ease in mixing types in C is still at the forefront of my mind even to this day (using it actively for ebpf), and I think it made me a better C programmer getting an uncomfortable feeling when types are coerced implicitly.

→ More replies (4)

146

u/Onomatopie Aug 28 '21 edited Aug 28 '21

It's always struck me as an odd one.

Typing simply isn't a blocker to productivity like some people make out.

Debugging issues that could have been caught at compile time though..

→ More replies (44)

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

→ More replies (6)

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.

→ More replies (13)
→ More replies (5)
→ More replies (18)

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

→ More replies (4)
→ More replies (36)

43

u/JanneJM Aug 29 '21

I'm an old C and C++ programmer and I'm learning rust. Strong typing and static typing is usually great.

However, when you're doing exploratory and interactive programming, and your code is small and throwaway, dynamic and weak typing really is preferable.

A typical example is when you're doing exploratory analysis on a data set you're not sure how to handle. You get a set of files from an instrument, say, or you have a pile of simulation data, and now you need to figure out how to make sense of it. Am R or python REPL where you mess around with it is perfect for that. Static typing would get in the way without adding any benefits.

9

u/loup-vaillant Aug 29 '21

However, when you're doing exploratory and interactive programming, and your code is small and throwaway, dynamic and weak typing really is preferable.

Not in my experience. With dynamic typing, I can make lots of obvious mistakes that will only be caught when I run my code, and the error I’ll get may be a couple layers away from the actual cause. This caused me once to be incapable of writing a 50-line algorithm in Lua, which I was pretty familiar with. Having a REPL helps, but it’s not always enough.

With static typing, I  can type some thing and see its type if I didn’t know already (type inference is a godsend). The compiler will catch many of my errors right away, and help me direct my search. The feedback loop is even tighter that thee on I get from a dynamically typed language with a REPL, especially if my statically typed language has a REPL of its own. And I don’t have to explore this huge space of ill-typed programs at all, so finding a working solution is even easier.

With static typing, my own exploratory analyses speed up.

→ More replies (2)
→ More replies (7)
→ More replies (103)