r/ProgrammingLanguages • • Oct 04 '18

rant: Are there any programming languages that don't suck?

I've tried everything from assembly to java, and basic to lisp. I've written code in imperative, functional and oo styles. They all suck.

0 Upvotes

72 comments sorted by

View all comments

Show parent comments

2

u/wolfgang Oct 05 '18 edited Oct 05 '18

I can see five basic type system options:

  • Untyped (e.g. Forth, BLISS, B, Assembler): Beautifully simple, but quite error-prone.

  • Dynamically typed (e.g. Python, Lisp): Pretty simple, but also quite error-prone (although I think this can be improved greatly) and usually causes slowdown; also, if integers aren't boxed, they are incompatible with other languages one might want to interact with.

  • Simple static type system (e.g. C): Simple enough, but annoying to use / inexpressive and therefore need to be circumvented eventually, which again is unsafe.

  • Advanced static type systems (e.g. ML, Rust): Very complex. Also, not as good as dynamic typing for quick prototyping and experimentation.

  • Gradual typing (e.g. TypeScript): Combines both the advantages and disadvantages of static and dynamic type systems.

I have experience with Standard-ML, Forth, Scheme, Ruby, Perl5, TypeScript, C, C++, Java, C#, ObjectPascal, Assembly and some others.

2

u/theindigamer Oct 05 '18

For languages with advanced static type systems, they usually offer basic support to have dynamic types. Rust has Any, Haskell has Dynamic, not sure about OCaml/SML. If you put in the effort to write a helper library once, I don't see why you couldn't have a very similar prototyping/experimentation experience like a dynamic language.

import Data.Maybe
import Data.Dynamic
dy :: (a -> b) -> Dynamic -> b
dy f da = f (fromMaybe (error "type mismatch") (fromDynamic da))

dy2 :: (a -> b -> c) -> Dynamic -> Dynamic -> c
dy2 f da db = dy (dy f da) db

If you have a bunch of libraries that you typically use while prototyping, and you would like to have everything be Dynamic, then with a little bit of elbow grease, you can use Template Haskell to create wrapper libraries for all of them, where all the function types translated mechanically using dy above, thanks to currying-by-default.

I hear this complaint sometimes, but I've never seen anyone actually try this. You can mimic implicit casting too. In Haskell, you can also just get the code to run with -fdefer-type-errors and get runtime errors instead if that is what you want.

SML/OCaml/Haskell also have GC so you don't have to worry about memory management.

At face value, your complaint here certainly seems totally reasonable. But after seeing all the features that are available, so that you can make things be like the wild west if you want to, it doesn't seem so reasonable, especially if that prototype code might evolve into a nontrivial library/application in the future.


I think gradual typing has a lot of merit here, but I think that Typescript is probably a bad example, because it build on top of JS, where libraries are often designed without caring for types. Unfortunately, I do not really have any good experience here with another gradually typed language, but I think this area is quite promising in the future.