r/programming • • Jun 27 '18

Python 3.7.0 released

https://www.python.org/downloads/release/python-370/
2.0k Upvotes

383 comments sorted by

View all comments

-88

u/wavy_lines Jun 28 '18

Can we all take a moment to acknowledge how large numbers of people (including me) have come to realize in recent years what a bad idea dynamic typing was?

131

u/xonjas Jun 28 '18

I don't think dynamic typing is a bad idea. I think taking a tool that is useful in certain scenarios and environments and applying it broadly to problems it doesn't suit is a bad idea.

The large the codebase, and the more developers working on it, the higher the cost of dynamic typing. Architecting a system with dynamic typing is a skill also, and many devs working with dynamic languages have not learned it well. If you write python or ruby like a java or c# dev, you're going to be in for a bad time.

There are benefits to dynamic typing. Particularly for small projects, where the lack of a type system is less of a hindrance, and prototypes, where the flexibility allows for easy changes. There are also problems that dynamic typing is particularly suited to solving. There's a reason why the majority of popular webapp frameworks run on dynamic languages (rails, wordpress, django, laravel). When twitter learned the hard way that writing all their middleware in ruby was a bad idea and rewrote the majority of their software in scala, they never moved away from rails because the dynamic type system suited dynamic content generation very well.

Dynamic typing is a very sharp knife; it's important that it's not used as a screwdriver.

56

u/Homoerotic_Theocracy Jun 28 '18

I don't think dynamic typing is a bad idea. I think taking a tool that is useful in certain scenarios and environments and applying it broadly to problems it doesn't suit is a bad idea.

Dynamic typing seems like a worse and worse idea the more flexible static type systems become.

Static typing seems horrible if all you have is C or Go but when you have Idris you suddenly feel that the scope of the problem of "I know this is safe but I cannot prove this to the compiler." is a lot smaller.

I also love Racket's static type system; it's actually completely fine with giving two branches of an expression a different type altogether and the resulting type will be the union of both but of course for it to type check the consumer of that expression must be able to handle the union of both. and be able to handle both types.

But if you have a function that can print both strings and characters to the stdout there is absolutely no harm in passing it an expression that either evaluates to a string or a character and it wil statically verify that this is okay.

Of course a type system as flexible as that of Typed Racket does not give you a lot of the performance benefits of static typing as it cannot in the general case erase type info at runtime because it needs it to make branches; it only can with confidence tell you that your code does not contain type errors.

28

u/xonjas Jun 28 '18

Yeah, I agree, the more expressive your type system is, the more useful it is.

At the same time, languages like python and ruby are going to have an important and deserved place in a programmers toolbox until languages like Irdis are widely supported and mainstream.

8

u/Homoerotic_Theocracy Jun 28 '18

Well truth be told that place seems to mostly be "dealing with lack of knowledge"; in an ideal world of infinite time and knowledge the demand would probably be lower but the main niche those languages fill over powerful type systems like that of Idris is that not everyone has the type to master the somewhat complex subject matter required to grok the type system. It's not mainstream because the learning curve is too high.

5

u/xonjas Jun 28 '18

That might be correct, but I think it's hard to say at this point. Idris is very young, even if it were to become mainstream, it's way too young for it to have reached that point yet. Mainstream isn't just popularity either, it's availability of libraries, api support, job openings, etc.

I think that some of the learning curve will get sanded away eventually. The big languages with slow inertia will start integrating ideas from cutting edge type systems. That knowledge will eventually become ingrained in the 'culture' of mainstream programming languages and each idea folded in is one less hurdle.

I think we'll also see more type systems where more and more of the typing workload is handled automatically, paired with better IDE integration so that generated typing is applied as the code is being written.

7

u/Homoerotic_Theocracy Jun 28 '18

That might be correct, but I think it's hard to say at this point. Idris is very young, even if it were to become mainstream, it's way too young for it to have reached that point yet. Mainstream isn't just popularity either, it's availability of libraries, api support, job openings, etc.

It's certainly older than Rust or Go and those seem to be more mainstream.

6

u/cephalopodAscendant Jun 28 '18

In addition to what xonjas mentioned about sponsorship, I can think of another possible factor. Rust and Go both use C-like syntax and are trying to fill the niche of "C/C++ but better", which naturally attracts a lot of attention. In contrast, Idris is based on Haskell, which is already fairly niche itself, and from what I've seen, the people who use Haskell seem to be pretty content with it.

10

u/Homoerotic_Theocracy Jun 28 '18

I love how Go calls itself a "systems programming language" but has a garbage collector and absolutely no low level control and can't even fork because multithreaded garbage collecting mutexes.

If someone ever used Go for something that person used C for prior it was either a terrible idea to use C for it or a terrible idea now to use Go for it and if someone is seriously switching from C to Go I'm inclined to think both.

Go has nothing to do with C or C++; it's a worse Java.

6

u/xonjas Jun 28 '18

I thought Idris 1.0 was released last year (although I could very well be wrong). Rust and Go also both have the benefit of very large organisations pushing them forward.

5

u/Homoerotic_Theocracy Jun 28 '18

Yes, 1.0 was but the actual language is far older. Idris was already used long before either Go or Rust were unveiled to the world.

→ More replies (29)

9

u/[deleted] Jun 28 '18

There are also problems that dynamic typing is particularly suited to solving.

Mind naming a couple?

→ More replies (1)

4

u/yawkat Jun 28 '18

I mean I don't disagree with you, dynamic typing is nice for small projects, but

Architecting a system with dynamic typing is a skill also, and many devs working with dynamic languages have not learned it well.

is not a very good argument. If people are worse at architecture in a language, that means a language has failed in its goal (or is being used for the wrong domain, as you say).

4

u/redditthinks Jun 28 '18

I don't think there's any significant benefit to dynamic typing if you have inferred types which is the case in many languages now. I would not use a dynamic language in anything that isn't a single-file script nowadays.

→ More replies (8)

17

u/Yubifarts Jun 28 '18

I love dynamic typing so long as it's also strongly typed, but that's my preference.

23

u/wavy_lines Jun 28 '18

I've already argued this in another thread, but allow me to repeat myself.

Python's typing is not "strong" in any meaningful sense. You can create an instance of any object and then just randomly start adding and remove attributes to it in runtime.

Say you have a class called Point and in the constructor it defines self.x and self.y and documents them to be numbers.

Now somewhere in the code you can check any object to see if it's an instance of Point using isinstance(obj, Point). Do you think you can guarantee that obj.x and obj.y are present and set to numbers? No! Because anyone can just take any object and remove the attributes you're looking for and add new attributes you weren't expecting.

That's hardly 'strong' typing.

>>> obj1 = Point(10, 5)
>>> obj1
<__main__.Point object at 0x101b15da0>
>>> obj1.x
10
>>> obj1.y
5
>>> delattr(obj1, 'x')
>>> obj1.x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Point' object has no attribute 'x'
>>> 

11

u/caramba2654 Jun 28 '18

Not that anyone sane would do that. Just because it can be done it doesn't mean it should be done.

And if you try searching Github for any code that does what you described, I don't think you'll find any instances of it.

15

u/wavy_lines Jun 28 '18

Why are you assuming it to be insane? How do you think ORM libraries work?

I'm not saying anything here about weather it's good or bad. I'm just pointing out that Python is not strongly typed because the type almost means nothing and you can do whatever the hell you want to the object.

You don't have to call delattr or setattr. Just simply take any instance and assign fields to it:

some_object.some_field_1 = <Some-Value>

It doesn't even have to be malicious. It could be an honest mistake. You thought some_object was an instance of some class that does have some_field_1 and nothing about the language runtime would even warn you that you're doing anything wrong.

27

u/caramba2654 Jun 28 '18

But strong typing doesn't reflect what attributes an object has. Strong typing means that there's no automatic coercion of a value of type A to a value of type B. And Python works exactly like that. So by definition Python is strongly typed.

What you should be claiming instead is that Python is dynamically typed, which is the property that allows you to add and remove attributes to an object.

→ More replies (15)

2

u/THeShinyHObbiest Jun 28 '18

What about in a language like Ruby? If :some_field_1= isn't defined on that object, then the example you've given will explode.

2

u/wavy_lines Jun 28 '18

I haven't used Ruby but if it's you say then that's a good thing.

It would be much better though if there was a compile to catch the problem at compile time.

2

u/[deleted] Jun 28 '18

Not that anyone sane would do that. Just because it can be done it doesn't mean it should be done.

But you can't do any useful static analysis because of such things.

→ More replies (3)

4

u/[deleted] Jun 28 '18

Why, exactly? It'd be interesting to see all the arguments for dynamic typing, out of the actual experience, not parroting some weird gurus.

12

u/woztzy Jun 28 '18

I don't think the people downvoting you have any real experience with a statically-typed language with an expressive type system (i.e., pretty much any typed functional programming language).

People who keep parroting that dynamic and static type systems are just "different tools to have in your toolbox" and that they're beyond comparison are insulting the field of programming language theory, and we could extend that argument to using assembly where we would otherwise use C.

This answer addresses a few misconceived notions people seem to have about static type systems.

→ More replies (5)
→ More replies (21)