top | item 36731008

(no title)

tacotacotaco | 2 years ago

> The whole point of static types (well one big reason at least) is to improve the actual code quality.

I have worked on multiple typescript projects that had terrible code quality. Types do not make you write SOLID code.

I find functional programming and well-used functional patterns do result in higher quality code. Typescript’s type system makes writing functional code more difficult. The documentation even recommends against it[1].

IMO typescript is easy to prescribe as a panacea, “just use typescript”, whereas understanding how to write SOLID code takes time.

[1] https://www.typescriptlang.org/docs/handbook/typescript-in-5...

discuss

order

IshKebab|2 years ago

> Types do not make you write SOLID code.

Of course. They are not sufficient but they are necessary.

I wouldn't see point free programming is the same as functional programming. Rust has many functional programming features and no currying.

In fact my experience of OCaml is that point free programming makes the code much harder to read.

thewix|2 years ago

My world changed when I started thinking in a strongly typed way (not just using string and number) and representing state changes as different types rather than interpreting than through property values. Once you do that then your code becomes mapping from one type to the next.

For example, if `type ShoppingCart = EmptyCart | LoadedCart` then `addToCart` is just a map from `ShoppingCart` to `LoadedCart`. It makes invalid states impossible to represent and flows become clearer. Add in good FP and composition becomes easier.

tacotacotaco|2 years ago

I am not against types but I do find typescript’s type system to be deficient. Additionally, functional programming is not incompatible with type systems but typescript’s type system in particular makes it more difficult.

Several of the terrible typescript projects I referred to still used property values to represent state (like your example). Just because every definition has a type doesn’t make it good code. Shitty typed code is still shitty code. My concern is that many in our industry conflate typescript with quality and stop there.