News for hackers. Stuff that matters.
Re:Things I Was Wrong About: Types by rswail on Sunday September 27, 2020 @11:10AM (#24607184)
A lot of people are making comments about how they can code "faster" without types.

But for the majority of the code we write, inital speed isn't that important. Understanding the code and maintaining it are orders of magnitude more important for any non-trivial code.

Types are not only a way for the compiler to understand your code and impose constraints. They're also your API to other programmers. When they see a sum type, they can understand its possible states. When they see a product type they can understand its possible values.

Understanding other people's code is at least half the job of a programmer, whether it's understanding a library or understanding code you have to maintain, or understanding your own code that you wrote 6 months ago.

Types help you do that.

Re:Things I Was Wrong About: Types by cannabis_sam on Sunday September 27, 2020 @02:04PM (#24608698)
It’s honestly embarrassing to hear all the worthless arguments against types.

The cognitive load of a dynamically typed (or unityped, or “untyped” or whatever) language is massive, yet the common argument is that types «increase» the cognitive load??? How does offloading a large majority of the trivial reasoning of a program over to a type system, ”INCREASE” the cognitive load???

It’s just so endlessly easier to program with types

Re:Things I Was Wrong About: Types by cuddlybacon on Sunday September 27, 2020 @04:42PM (#24609993)
I think there are a few reasons why people develop an impression that types are overhead:

* People who are learning to code are writing lots of code but not reading very much code. I think types do the most work when trying to understand existing code.

* Lots of people's first experience with typed languages was something like C++ or Java back when they had much worse error messages.

* The kind of mistakes you make when first learning to code make the type checker feel like a pedantic nitpicker instead of a protective ally.

* Programming instruction tends not to teach technique very much. If you invent techniques that leverage the strengths of types, then great for you. If you don't, then you might program for years until you are exposed to the benefits types can provide.

Re:Things I Was Wrong About: Types by jiggawatts on Sunday September 27, 2020 @05:45PM (#24610371)
Also, many beginner programmers work on small code bases in every sense of the word.

These days I will often have to glue together some tiny part of two or three enormous APIs, some of which are "auto generated" from some other system. Think LINQ-to-SQL or WCF.

It's amazing when you can take a 100 MB chunk of code, and simply "navigate" to the thing that you want using tab-complete, in the sense that "somefactory.sometype.someproperty.subproperty.foo" is almost self-evident when you press tab and cycle through the options at each step.

And then when you finally get "foo", if it's the exact unique type you were looking for, then you can be certain that you did the right thing! There's practically no need to reach for the debugger and start inspecting live objects. Just tab, tab, tab, tab... yup, that's it, move on.

If you're working with a "blank slate" PHP app (or whatever), where you've personally written most of the lines of code involved, typing can feel unnecessary.

If you're glueing together Enterprise Bean Factory Proxies all day, then strong typing is practically mandatory.

Re:Things I Was Wrong About: Types by cannabis_sam on Tuesday September 29, 2020 @11:25AM (#24628947)
To be honest, I disliked PHP’s dynamic typing just as much as I disliked Java’s static typing, and that’s after spending over 10 years professionally developing primarily in those two languages (and some python and javascript).

The last couple of years I’ve developed stuff in haskell and elm, but I’m currently getting back into python and javascript. And I’m sniffing around, trying to figure out how to utilize typescript and python type annotations in an ergonomic way, that doesn’t feel like too much overhead.

I’ll easily admit that it’s not as easy to reach the same kind of benefit in those languages.

The magic sauce really is (ideally as global as possible) type inference combined with programming primarily via expressions instead of primarily via statements, with appropriate language support of course.

Re:Things I Was Wrong About: Types by zeveb on Sunday September 27, 2020 @11:16PM (#24612627)
> If you're working with a "blank slate" PHP app (or whatever), where you've personally written most of the lines of code involved, typing can feel unnecessary.

> If you're glueing together Enterprise Bean Factory Proxies all day, then strong typing is practically mandatory.

Might that not be a problem, though? Shouldn't more software systems be small, elegant and well-architected rather than a spaghetti nightmare navigable only through an IDE?

I like types, I think they are great, I like editor tool, I think it is great. I even like a lot of the luxuries modern systems afford me. But … maybe we could stand a little simplification?

Re:Things I Was Wrong About: Types by jiggawatts on Monday September 28, 2020 @08:47AM (#24616036)
Have you seen the enormous scope of something like Azure Resource Manager? Amazon Web Services releases several new products or major features per day. They all have APIs.

Office and Office 365 is also a behemoth that covers entire suites of business products, front-end and back-end.

If you start to seriously talk about integrating these things with a bunch of third-party components, you're talking tens of gigabytes of binaries.

> But … maybe we could stand a little simplification?

Always. Unfortunately, that runs up against the limitations of our squishy meat brains. Especially when they're numbered in their tens of thousands. Simplification, refactoring, and code reuse requires coordination.

I too am horrified that a mere database engine no longer fits on a standard DVD disc... when compiled into a binary.

But I can download the ISO image in a matter of minutes, and use the system with a few button clicks in an IDE to produce functional software.

I know that the raw numbers should qualify as a nightmare, but at the end of the day, things get done anyway and it doesn't seem to matter that much.

I guess we're just horrified because we know how this particular sausage is made...

Re:Things I Was Wrong About: Types by marktangotango on Sunday September 27, 2020 @02:16PM (#24608819)
I agree with this 1000%. Projects (note not programs or individual source files!) are simply easier to grok (maintain, enhance, debug, refactor) with statically (and strongly) typed languages than dynamic IMO.

Five years ago when switching jobs I’d pursue “full stack” positions because I’d done a fair amount of front end dev in the past. No more, me personally, I’m backend all the way. Dynamic typing (vanilla js) is just harder; more time consuming more cognitive load, IMO.

Re:Things I Was Wrong About: Types by lolinder on Sunday September 27, 2020 @02:41PM (#24609081)
It's not perfect, but TypeScript goes a long way toward making frontend feel as safe as backend. You still have the potential for weird bugs when interacting with external JavaScript, but your internal code is pretty safe. Also, TypeScript's type system is impressively flexible, and I often find myself missing features (like unions) when working with other languages.
Re:Things I Was Wrong About: Types by MiroF on Sunday September 27, 2020 @04:42PM (#24609997)
> missing features (like unions) when working with other languages.

Which languages are missing unions? Off the top of my head, they exist in C/C++ and mypy python.

Re:Things I Was Wrong About: Types by a_humean on Sunday September 27, 2020 @05:43PM (#24610362)
Typescript allows you to have literal type discriminators in their unions, which combined with control flow based type narrowing of unions effectively gives you sum types. That is what he is talking about, because most mainstream langauges don't have sum types and you need to go to strongly typed functional langauges (haskell, scala, etc...) or modern strongly typed langauges such as Rust to get access to such features.
Re:Things I Was Wrong About: Types by lolinder on Monday September 28, 2020 @02:22PM (#24619735)
Yes, this. Sum types in most languages are approximated by something like kotlin's sealed classes. Sometimes you don't want to declare a whole new class hierarchy, you just want to say "this function can either return this or this".
Re:Things I Was Wrong About: Types by mumblemumble on Sunday September 27, 2020 @03:43PM (#24609561)
Here's my split personality:

I love love love Python for data science, in part because it's dynamically typed. I can bang things out quickly without worrying about the engineering bits, and, since I'm working in an interactive coding environment, it's generally easy enough to just inspect the values of my variables to figure out what they are.

I hate hate hate Python for ML engineering, in part because it's dynamically typed. The same features that make it so easy to hack out a quick data analysis make it absolutely awful to build for durability. For example, since stuff in production runs hands-off, you need to feel pretty confident about the return types of every function in order to feel confident you won't throw a type error at run time. Actually pinning this down can get quite complicated, though, when you're working with a library like scikit-learn that relies heavily on duck typing. Sometimes you end up having to go on a journey down a rabbit hole in order to clearly identify and document all the types your code might accept or return.

(Disclaimer: Hate aside, it's still my preferred ML engineering language. You've got to take the bad with the good, and the language gets you access to an ecosystem that is so very good.)

Re:Things I Was Wrong About: Types by scubbo on Sunday September 27, 2020 @04:06PM (#24609754)
This is absolutely it. Untyped languages are great for glue-scripts, for exploration (of an API, a dataset, whatever), for quick-and-dirty things. As soon as your logic grows beyond "what can be appropriately expressed in <5 files" and/or "this is going to have a second developer", types become helpful.
Re:Things I Was Wrong About: Types by zo1 on Sunday September 27, 2020 @06:16PM (#24610582)
I see it completely the other way around coming from the python, dynamically-typed side. For me, statically-typed languages have a benefit on the smaller-side of the scale, but absolutely bomb when the code-base grows. At that point everything is a FooFactory or an IInterface with no help from the IDE anyways because of IOC/DI/attribute reflection magic. And when it's that big, everyone argues over folder, package and inheritance hierarchies and the "right way" to refactor & reuse code, with the inevitable slide into yet another level of inheritance or interfaces. All the while peppered with Singletons, overloads and new abstract virtual base methods with complicated method override rules.

Obviously I exaggerate a bit, but we've all seen various incarnations of a lot of those issues.

Re:Things I Was Wrong About: Types by jakear on Sunday September 27, 2020 @06:56PM (#24610879)
The second you’ve “engineered” yourself into losing good IDE support half the benefit or using a strongly typed language goes out the window in my opinion. Though maybe some bias because I make an IDE! :)

Happily with TS it’s possible to have DI and IInstantiationService’s and all that and still maintain good IDE support —- in no small part because the IDE is built with all those, in TS... if it was unusable we’d fix it.

Re:Things I Was Wrong About: Types by 5n on Sunday September 27, 2020 @04:07PM (#24609764)
IMO dataframes are the reason why dynamic typing fits data science so well. It's certainly possible to represent a single dataframe as a static type; but representing all the slicing, column removal, joins, etc. is actually pretty hard without dependent tricks. So bypassing types for data frames is preferable. On your ML engineering point, the other side of it is that once your dataframe's schema is finalizes it really should be statically typed so that assumptions can safely be made about what is/isn't inside of it
Re:Things I Was Wrong About: Types by MiroF on Sunday September 27, 2020 @04:37PM (#24609959)
> representing all the slicing, column removal, joins, etc. is actually pretty hard without dependent tricks

Disagree in the strongest possible terms, tbh.

It's the lack of static typing that gets you 3/4 of the way down your experimental pipeline only for your code to fail because column "trianing_batch" can't be found. Huge productivity loss, even with rapid iteration.

Re:Things I Was Wrong About: Types by mumblemumble on Sunday September 27, 2020 @07:27PM (#24611110)
We must work very differently. I couldn't fathom that happening to me, if only because I compulsively peek at samples of the data frame every step of the way, in order to make sure the data look reasonable all the way through.
Re:Things I Was Wrong About: Types by valand on Sunday September 27, 2020 @09:52PM (#24612150)
As helpful a static type system can be, most of them do cause increased cognitive load UNTIL the FIRST RUNNABLE VERSION. Having your code running for the first time is rewarding for devs, especially those who are handling many simple codebases rather than few complex ones.

There are great type system that provide enough ramp for for first runnable version. Rust, for example, has type inference and an unusually helpful compiler.

But most languages, especially the old ones, don't have that. Because of that, coders need full-blown IDEs like Intellij/VS to write comfortably in those languages. Without full-blown IDEs or editors packed with plugins, it is quite a chore to navigate types. There's no hyperclicking, type annotation, docs preview. While dynamic-typed languages usually is runnable since the first character without having to wait for the compilation, so even notepad is acceptable to write with (though that would be really painful).

Having been in both sides, I love types in certain languages (and disdain them in others e.g. PHP). I would still pay the price of compilation and use TypeScript for scripts that lives long rather than using JavaScript. But I think both sides need to understand where the cognitive load arguments came from.

Re:Things I Was Wrong About: Types by igneo676 on Monday September 28, 2020 @10:23AM (#24616884)
I love types.

I just didn't when I was new to programming. I learned Python because that's what I saw pitched to me all the time. There was a local Python meetup, MIT's CS courses taught Python and Udacity eventually taught Python. I loved the language and learned quickly how to do a bunch of basic stuff

But I wanted to make Android apps and, ugh, Java confused the crap out of me. It wasn't so much the language, but rather "URI? Where in the world do I get one of those?! Oh, you instantiate a URI with the string. In Python this is just a String..."

Or another time, once I had mastered types, I convinced my Javascript team that Typescript was Worth It. And the ensuing chaos when nobody understood how to use Types and nothing would ever compile for anyone.

All SUPER noob-y mistakes. All because I (or my team) didn't understand how to think in Types. Furthermore, people who can Think in Types often don't know how to articulate that thought process to others.

Re:Things I Was Wrong About: Types by igneo676 on Monday September 28, 2020 @10:26AM (#24616916)
I'll also throw out there that scripting languages w/o types tend to have a lot less tooling around the language. People are used to being able to type whatever they want and things kinda just work.

Typed languages are very different. The tooling is far more robust and more able to point out errors, but also tends to be more complex than just a simple text editor.

This is changing with VS Code and LSP being a thing, but it still influences those communities in fundamental ways.

Re:Things I Was Wrong About: Types by cannabis_sam on Sunday September 27, 2020 @04:34PM (#24609946)
(Sorry for being a bit too aggressively argumentative in this comment)
Re:Things I Was Wrong About: Types by valand on Sunday September 27, 2020 @09:57PM (#24612179)
(It turned out to be a productive comment despite the aggressive wording, so upvotes!)
Re:Things I Was Wrong About: Types by vendiddy on Sunday September 27, 2020 @03:54PM (#24609644)
I agree.

And you also see many dynamic languages working around lack of types by describing the types anyway in the documentation. Like jsdoc in javascript before typescript became popular.

You are already doing the hard work of describing your types anyway, but because your compiler doesn't know the types, it can't help you out.

Re:Things I Was Wrong About: Types by cle on Sunday September 27, 2020 @05:00PM (#24610098)
There’s a continuum for sure. Type systems have their own kind of cognitive load, because you have to learn them, how to model your invariants in them, how to understand error messages, avoid common pitfalls, etc. Type systems are usually quite “general” and abstract, and that always comes with cognitive load. Quite often reading the code of a parametrically-polymorphic Python function is way easier than understanding the generalized polymorphism constructs of an advanced static type system.

There are times when the cognitive load of a particular static type system is less than that of a dynamic one, for certain classes of programs and audiences, and times when it’s not. This is fine and we should encourage development of both kinds of type systems and a shared understanding of how to pick the right ones for the job (which is a discussion nearly always missing in these debates).

Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @05:36PM (#24610315)
For the most part this cognitive load already exists in order to write correct programs. Types don’t just appear when a type checker is present. Type systems only add on the additional burden of needing to understand the formalization of that intuition. It’s not an insignificant burden, but it’s a much smaller gap than learning to intuit about programming correctly in the first place.
Re:Things I Was Wrong About: Types by cle on Sunday September 27, 2020 @07:03PM (#24610932)
It depends on what you mean by "correct". If it means "it does what I need it to do and I can move on with my life", then no, the cognitive load doesn't already exist, and formalized type theory in many cases adds an incredible amount of cognitive load.

I know that in many cases "correct" means a lot more than that, such as in proper software engineering contexts when building a program/system that needs to live and evolve for a long time among many people. I write that kind of software all the time, and I always use static type systems for it.

But I also write a bunch of ad-hoc, one-time-use programs, and I'm very glad that I don't need to reason about abstract type theory in order to parse a CSV file and add up some columns to send to a colleague.

Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @07:40PM (#24611186)
No one is talking about abstract type theory; we’re talking about the intuition you use to write maintainable, correct software including CSV munging.
Re:Things I Was Wrong About: Types by cle on Sunday September 27, 2020 @08:09PM (#24611416)
I don’t care if my throw away CSV munger is formally safe/sound or maintainable. I care if it gives me correct results, once, as quickly and effortlessly as possible. Which is why very few people fire up GHCi/rustic/javac for that, but instead use awk/shell/Python or something similar.
Re:Things I Was Wrong About: Types by zeveb on Sunday September 27, 2020 @11:18PM (#24612638)
OTOH, sometimes the CSV munger one writes today is still in use five years later, when the input CSV has a UTF-8 character for the first time, and suddenly it crashes and no-one knows where the bug could even be.
Re:Things I Was Wrong About: Types by cle on Monday September 28, 2020 @09:41PM (#24623350)
UTF-8 support is completely orthogonal to static typing. There are dynamically typed languages that handle it great, and statically typed languages which have garbage support for it.

In general I know what you mean though. “What if this CSV parser turns out to be really important?” If you think there’s a high probability of that, do it in a statically typed language then. 99.9% of data munging I’ve done have been throwaway programs to answer a question to inform some decision or help refine a mental model.

Re:Things I Was Wrong About: Types by throwaway894345 on Tuesday September 29, 2020 @08:57AM (#24627168)
Frequently that answer is important and you want extra confidence that you calculated it correctly.
Re:Things I Was Wrong About: Types by pvorb on Sunday September 27, 2020 @05:30PM (#24610281)
I don't buy this "choose the right tool for the job" thing. I'd always advise you to choose the tool that your company has the most knowledge in. If there's a problem that cannot be solved in that programming language, then you can look for a better tool. But you shouldn't pick a language that nobody else understands, just to save a few lines or some time when doing the initial implementation - just to realize that you now have to constantly keep up the knowledge to be able to support it.
Re:Things I Was Wrong About: Types by cle on Sunday September 27, 2020 @07:04PM (#24610935)
I consider that one of the most important criteria when picking the right tool for the job (if you're writing something to be maintained by other people in a company).
Re:Things I Was Wrong About: Types by pvorb on Monday September 28, 2020 @01:08AM (#24613162)
Okay, maybe. But usually this is not part of the description of "choosing the right tool for the job".
Re:Things I Was Wrong About: Types by paganel on Sunday September 27, 2020 @05:45PM (#24610372)
> It’s honestly embarrassing to hear all the worthless arguments against types.

I think this forum is written in a language that doesn't have types. My favourite though was lambda-the-ultimate.org, at some point the number one resource on the internet when it came to discussing about programming languages (maybe it still is, I haven't followed it for a while), which was written in an untyped language, PHP (Drupal, to be more exact).

Re:Things I Was Wrong About: Types by skohan on Sunday September 27, 2020 @11:44AM (#24607478)
> Understanding other people's code is at least half the job of a programmer

This was one of the pain-points when I was working more with node.js: the function signature told you nothing - like whether the function would even return or not would sometimes be a mystery.

In very, very short scripts you can get away without types (like in a notebook for example), but once a project starts to get even medium size the tiny amount of time you put into writing a type name explicitly here and there is more than made up for by the degree it helps with the structure and correctness of your program.

Re:Things I Was Wrong About: Types by bo1024 on Sunday September 27, 2020 @11:56AM (#24607588)
This kills me about python. So many times I cannot figure out what exactly a functions expects and what it returns, sometimes even from reading the documentation! Matplotlib is especially bad.
Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @01:15PM (#24608203)
Good grief, matplotlib and the whole scientific computing stack are abysmal. Every function takes dozens of arguments, but any given call only has to pass some subset, and depending on the subset and their runtime types, the function just tries to guess what the caller wanted to do. I get that this stuff was written by amateurs, but in a saner world this stuff would have been addressed by now. Anyway, I moved on from Python to Go and I’m super happy (!!performance!!, !!package management!!, editor tooling, top notch document generation, quality ecosystem, !!static binaries!!, and types—even if Go’s type system isn’t as robust as Rust’s, it still goes a long way).
Re:Things I Was Wrong About: Types by krzat on Sunday September 27, 2020 @04:14PM (#24609818)
This is the most ridiculous thing about dynamic languages, I don't understand how people can be productive in such environment. Meanwhile I just press few keys and IDE shows my all about I need to know about that function. Oh, and it also runs 100x faster.
Re:Things I Was Wrong About: Types by 6gvONxR4sf7o on Sunday September 27, 2020 @01:31PM (#24608384)
kwargs makes me so angry in docs. Pass in anything! Learn the whole library to use this function!
Re:Things I Was Wrong About: Types by mettamage on Sunday September 27, 2020 @01:30PM (#24608377)
I use a Python debugger in VSCode and hit the necessary breakpoints to figure it out.

Yes, it's bad, but it works. I hope there are better ways of doing it, but this is my way.

Re:Things I Was Wrong About: Types by arvinsim on Sunday September 27, 2020 @12:09PM (#24607694)
Didn't Python 3.5 introduce optional typings?
Re:Things I Was Wrong About: Types by dilawar on Sunday September 27, 2020 @12:25PM (#24607818)
Only annotations which can be checked by mypy or other linters. I think cpython doesn't check them at runtime.
Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @01:18PM (#24608241)
And mypy is still very immature. You can’t denote a recursive type (e.g., a JSON type) or specify a callback that takes keyword arguments. Even getting it to load type annotations from third party packages is hard in many cases. Worse, it seems to be improving at a snail’s pace if at all.
Re:Things I Was Wrong About: Types by zo1 on Sunday September 27, 2020 @06:26PM (#24610673)
A "JSON" type in Python is just an untyped dictionary. Is that not what you're looking for?

Also, python's type-hinting supports forward-references which are what you would use for recursive or "self-referencing" types.

Personally, I like the slow pace they're taking with the typing. It's touching the core usage of the language in a fundamental way and I don't think that can be rushed. We're seeing lots of community growth around the type-hinting, even using them at run-time, which is amazing to watch and marvel at.

Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @11:45PM (#24612764)
Untyped dictionaries are a superset of JSON. JSON is (more or less) precisely:

   Dict[str, JSON] | List[JSON] | str | float | int | bool | None
Re:Things I Was Wrong About: Types by ben-schaaf on Sunday September 27, 2020 @01:05PM (#24608123)
Python indeed doesn't check them. Really they're just syntactic sugar for what you'd otherwise put in documentation.
Re:Things I Was Wrong About: Types by IshKebab on Sunday September 27, 2020 @01:25PM (#24608314)
Yes but hardly any code uses them yet. Hell there's still lots of code on Python 2 (yes really, no I'm not imagining it).
Re:Things I Was Wrong About: Types by GordonS on Sunday September 27, 2020 @06:00PM (#24610473)
> the function signature told you nothing - like whether the function would even return or not would sometimes be a mystery

Yes! This drives me nuts about JavaScript! Untyped parameters are one thing, but having to read the entire function just to know if it returns anything is ridiculous.

Re:Things I Was Wrong About: Types by eyelidlessness on Sunday September 27, 2020 @06:16PM (#24610578)
To be fair, JS’s dynamic types aren’t solely to blame for this. There are dynamically typed languages that don’t require you to read an entire function body to know if it returns something. But, those are languages without statements, and all functions return something.
Re:Things I Was Wrong About: Types by thurn on Sunday September 27, 2020 @12:37PM (#24607905)
I agree with this for really large codebases, but I think you can get a surprising amount done before your program becomes "non-trivial" using a good dynamic language. For example, the website you are writing this comment on has been perfectly maintainable in lisp without any static typing for the past 15 years.
Re:Things I Was Wrong About: Types by darksaints on Sunday September 27, 2020 @12:52PM (#24608012)
It also hasn't changed much in 15 years. Now that could be (and probably is) a deliberate decision. But there are more than enough cases of projects that haven't changed because they can't...they've painted themselves into a corner, and every time they try to change something, something else breaks.

I've felt this way with Python and Ruby and Node projects (it is a major complaint in the RoR community), but have never felt that way with Scala, Java, C#, F#, Rust, or OCaml. Most of the time, when I need to make a change, I just change it, iteratively eliminate any type errors, and once the type errors are gone, the tests magically pass too.

Re:Things I Was Wrong About: Types by throwaway894345 on Sunday September 27, 2020 @01:21PM (#24608273)
I get the feeling that lisp doesn’t produce as many runtime type errors as Python or JS and I’m not really sure why that would be. Maybe there’s something to a functional style of programming that improves quality even apart from type checking?
Re:Things I Was Wrong About: Types by remexre on Sunday September 27, 2020 @04:03PM (#24609724)
Arc "feels" a lot more Scheme-like than Common Lisp-like, but pg is a CL guy afaik; my observations on the two:

Scheme avoids type errors by writing programs which could be given static types with a sufficiently powerful type-checker. If a Scheme programmer needs to define two aggregates, both of which have a property "name," they're likely to define two different functions, foo-name and bar-name, to get at them. This, though it's noisy, makes type errors more obvious.

CLOS helps avoid type errors too, since it encourages thinking not about how code interacts with a single type, but instead how it interacts with a whole _protocol_ of methods. I think multimethods in general are a powerful design tool that help avoid type errors in a dynamic setting, but I haven't had a chance to try them out in a language other than CL.

Many CL implementations also have static type-checking. For example, when I try to define a function with a type error in SBCL:

  * (defun f (x) (+ 1 x (car x)))
  ; in: DEFUN F
  ;     (CAR X)
  ;
  ; caught WARNING:
  ;   Derived type of X is
  ;     (VALUES NUMBER &OPTIONAL),
  ;   conflicting with its asserted type
  ;     LIST.
  ;   See also:
  ;     The SBCL Manual, Node "Handling of Types"
  ;
  ; compilation unit finished
  ;   caught 1 WARNING condition
CL's philosophy here differs a bit from most typed languages: SBCL will emit a warning (not an error!) for code it can statically show is impossible to run without getting a type error, while e.g. GHC gives an error for any code it can't statically show doesn't get a type error. However, in my experience, many type errors are obvious enough that SBCL warns about them (e.g. passing a vector where a list was expected, a string where a symbol was expected, nil where a non-nil value was expected, etc.), so this helps quite a bit, especially when combined with the interactive editing one gets through SLIME/slimv.

One can also attach type annotations to functions [0], and SBCL (and probably other implementations) will add a runtime CHECK-TYPE [1] unless you tell it to optimize for speed enough.

[0]: http://www.lispworks.com/documentation/HyperSpec/Body/d_ftyp...

[1]: http://www.lispworks.com/documentation/HyperSpec/Body/m_chec...

Re:Things I Was Wrong About: Types by eyelidlessness on Sunday September 27, 2020 @06:25PM (#24610662)
This is partly right. FP approaches do tend to reduce the volume of mistakes, and reduce the kinds of mistakes you can make.

But that’s not because type errors are less likely. For dynamic functional languages they’re only less likely because the implicit contracts tend to be more general and the data structures tend to support a high degree of polymorphism.

The reason FP approaches tend to reduce mistakes is mostly that managing state is hard, and pure functions are easier to reason about.

Re:Things I Was Wrong About: Types by csb6 on Sunday September 27, 2020 @05:38PM (#24610336)
I have had similar experiences with Python. What endlessly frustrated me when looking up the documentation for Python’s standard library (I was using the classes for working with emails/imap) was that what kind of thing to pass in as arguments wasn’t specified clearly. It made using the API so much harder because I had to trial/error to figure out how to construct the proper object that the API would accept.
Re:Things I Was Wrong About: Types by throwaway316943 on Sunday September 27, 2020 @08:19PM (#24611496)
The reason people argue for being able to write and run code quickly is it helps with prototyping and iterating on a concept. For a lot of people, overly verbose typed languages kill that creative cycle. Type systems are great for data validation and self documenting code when you need those things but they essentially double the work when you’re first getting something off the ground.
Re:Things I Was Wrong About: Types by joe_the_user on Sunday September 27, 2020 @05:41PM (#24610350)
For many enterprises, getting code out the door is a key win. So in an idealist conception, maintainability, correctness and good design are everything. In the practical reality of today, these often have to take a back seat to speed of implementation.

What I'd like to see is a language that allows typeless programming to start but which is designed to allow the imposition of types at a later point.

Re:Things I Was Wrong About: Types by easton on Sunday September 27, 2020 @06:33PM (#24610720)
Python’s type hinting is specifically designed for this use case: https://docs.python.org/3/library/typing.html

Also, TypeScript is designed to work the same way, as it can coexist with untyped JavaScript code as you introduce it to the code base (it still has to run through a compiler, of course).

Re:Things I Was Wrong About: Types by agumonkey on Sunday September 27, 2020 @04:59PM (#24610090)
Warning this is in 2008 context:

Types are cool but when I worked on eclipse apis (plugins) god forbid they were utterly useless. Design matter, having 32 intermediate classes to do just anything, 12 of which are totally unrelated and suddenly types don't help you much.

Also it was full of Option types disguised as potentially empty arrays.

I guess today things are better.

Re:Things I Was Wrong About: Types by higerordermap on Monday September 28, 2020 @04:51AM (#24614480)
Also these days types are important for good IDE completion support, on-the-fly error checking and refactoring.