News for hackers. Stuff that matters.
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Monday May 29, 2017 @09:40AM (#14439030)
One under-appreciated aspect of static types is that they make certain classes of stupidity a little more difficult, for example, overloading the permissible types on an object's member variable such that every bit of code that uses it needs to do an `isinstance()` check to see if it has the type that particular bit of code wants. Doing this would be tedious in a statically typed language where the sane solution is often the easier solution. This doesn't mean it's hard to write bad code in a static language, just that it's harder to do by accident.
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by panic on Monday May 29, 2017 @10:46AM (#14439349)
Although it'll always be tempting to provide isinstance() type checks in your dynamic language, there's no reason you have to have them!
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by crdoconnor on Monday May 29, 2017 @12:32PM (#14439913)
Over the last few years I've started using them a lot simply because it means you get simpler, clearer and more actionable errors more quickly.

They're especially useful when you are writing libraries for use by somebody else.

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by panic on Monday May 29, 2017 @06:54PM (#14441953)
Yeah -- a dynamic language could provide an assertinstance() operation, which throws an error if the types don't match, without going all the way to a boolean isinstance() check.
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Monday May 29, 2017 @05:31PM (#14441554)
This is basically the "correctness" argument for static typing. That you do this in a dynamic language is a liability.
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by crdoconnor on Monday May 29, 2017 @05:52PM (#14441672)
Placing a small number of sanity (hint: it's not always type that needs checking) checks on border code is not any kind of argument for static typing.

I'd do the same thing in most languages - in fact, I'd end up doing way way way more of it in C because it's very weakly typed.

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Monday May 29, 2017 @11:00PM (#14442787)
> it's not always type that needs checking

I think type theorists would disagree.

> Placing a small number of sanity checks on border code is not any kind of argument for static typing.

Yes it is if any of those checks are for types.

> I'd do the same thing in most languages - in fact, I'd end up doing way way way more of it in C because it's very weakly typed.

C doesn't have type checks, unless you're using some runtime type system (like GObject) on top of it. At any rate, C may not be completely type safe, but it's better than dynamic languages which are completely type unsafe; even if you could do type assertions, you would do them far less frequently in C than, say, Python. Further, C is not the canonical statically typed language, and you would be laughed out your workplace if you proposed adding a runtime type check on your function parameters.

Even if you're using Python (assuming you have the good fortune to use a modern version), you can just use type annotations and the static type checker rather than littering the code and slowing your program. Albeit your point stands about writing library code for another's consumption.

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by crdoconnor on Tuesday May 30, 2017 @06:11AM (#14444160)
>C doesn't have type checks, unless you're using some runtime type system (like GObject) on top of it. At any rate, C may not be completely type safe, but it's better than dynamic languages which are completely type unsafe

And worse than dynamic languages which have greater type-safety. Point being that it's type safety, not static typing that helps cut down on the need for sanity checking.

>you can just use type annotations

Type annotations are both unchecked and render any code that you write unusable in python 2.

>rather than littering the code

Type annotations DO litter the code.

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Tuesday May 30, 2017 @10:55AM (#14445786)
> And worse than dynamic languages which have greater type-safety

I think you're confusing strong typing with type safety. Strong typing doesn't preclude errors; you just don't see the error until you hit the code, which might be all the time for a happy path, or almost never for an error path. Static typing, on the other hand, completely eliminates the need for sanity type checks (and depending on your language's notion of 'type' this can include virtually all forms of sanity checks).

> Type annotations are both unchecked and render any code that you write unusable in python 2

Static type checking is supported for both Python 2 and 3. If you need to write Python 2/3, you could probably just use the Python 2 annotations.

> Type annotations DO litter the code.

They don't. They're a small annotation that tells you what the variable actually is/does. Much neater than Sphinx docs, etc. And you do need to know the type, whether you like it or not.

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by crdoconnor on Saturday June 10, 2017 @11:01AM (#14527580)
>I think you're confusing strong typing with type safety.

Check the wikipedia page for strong typing. Type safety is one of the ~11 or so different definitions. It's one reason I try to avoid using the term - because it's more emotional than meaningful.

>Static typing, on the other hand, completely eliminates the need for sanity type checks

You've not programmed in C have you?

Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Monday May 29, 2017 @05:34PM (#14441568)
I agree; but there's nothing enforcing it either, and I always prefer rails for enforcing best practices rather than code review (where egos tend to be bruised, feedback takes longer, etc etc).
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by panic on Monday May 29, 2017 @06:57PM (#14441966)
I'm saying you could enforce it at the language level by not providing that operation in the first place.
Re:Bracha v Felleisen “Types for an Untyped World” (2015) [v... by weberc2 on Monday May 29, 2017 @10:49PM (#14442756)
Fair point; my criticism wasn't levied against the idea of dynamic languages so much as the many popular implementations which do include the likes of `isinstance()`.