On Tue, 20 Feb 2018 10:17:12 -0700, Ian Kelly wrote: > On Tue, Feb 20, 2018 at 8:38 AM, Steven D'Aprano > <steve+comp.lang.pyt...@pearwood.info> wrote: >> On Tue, 20 Feb 2018 15:23:44 +0100, Antoon Pardon wrote: >> >>>> Okay. Now create a constraint on a name in C++ such that it can only >>>> accept integers representing A.D. years which, on the Gregorian >>>> calendar, are leap years. (Using a dedicated integer-like type is >>>> permitted.) It must accept all multiples of four, except those which >>>> are multiples of one hundred, unless they're also multiples of four >>>> hundred. >>>> >>>> That's what Steve asked for. Can you do it? Or is the C++ type system >>>> not flexible enough for that? >>> >>> Steve had multiple contributions in this thread. I didn't react to the >>> one where he asked for that. >> >> Yes you did: you refused to meet the challenge, stating (and I quote): >> >> "Why should this be done at compile time?" >> >> https://mail.python.org/pipermail/python-list/2018-February/730995.html > > I really don't understand what point you're driving at here, Steven.
To be perfectly frank, neither do I any more. I fear I've been suckered into taking a position I didn't intend to, as often happens when I reply to Antoon Pardon. Obviously both statically and dynamically typed languages are Turing Complete, so any constraint you can apply at run-time in one you can apply at run-time in the other. How *easy* that is depends on the language features, and particularly for older languages, statically typed languages tend to be harder and less convenient to write in. There's typically more boilerplate, and more time spent placating the type- checker. Do I need to justify this or can we take it as a given? So I didn't think I was taking a controversial position to say that dynamic languages are good for writing constraints that are enforced at run-time, *as opposed to trying to do so within the type-system* which was the topic under discussion. I have argued in the past that the hard distinction between static and dynamic languages has been gradually worn away (if it ever existed at all!) as statically-typed languages add dynamic features, and dynamically- typed languages add static features. For example, Java supports run-time method dispatch; Python added type annotations to standardise on syntax for static type testing. Antoon's example of Pascal range checking is another run-time feature (a form of dynamic typing, in a fifty year old statically typed language no less!), as are Eiffel pre- and post-condition assertions (although the compiler can optimize them away if it can determine that they always hold). I've linked to Steve Yegge a lot, e.g.: https:// steve-yegge.blogspot.com.au/2008/05/dynamic-languages-strike-back.html so I certainly know that there's a certain amount of convergence between static and dynamic features and it was never my intention to suggest that statically-typed code can't validate values at run-time. That would be a ludicrous position to take. If Antoon was arguing in good faith surely he must have realised I couldn't have meant that. By all means call me out on factual inaccuracies, but do so in good faith. Don't assume I mean something ludicrous. If you look back at my reply to Bart: https://mail.python.org/pipermail/python-list/2018-February/730943.html you will see that the context is a discussion comparing: compile-time static analysis versus run-time dynamic checks strategies. Hence my challenge to perform the same kind of check at compile-time using an actual, existing type-system. (Not merely say a sufficiently clever type-system can do it and handwave away the practical difficulties.) Of course we can perform arbitrarily complex run-time checks in a language with static typing (it might not be as convenient or easy, especially if you have to declare every single temporary variable, do a lot of explicit casts, never re-use any variable, and use a lot of verbose boilerplate, but it can be done). > The > original claim (by you) was that dynamic languages excel at "enforcing > constraints at run-time which are hard to enforce at compile-time". The > counter-argument, as I understand, it was that while the constraints may > be hard to enforce at compile-time, they are just as easy to enforce at > run-time in a static language as in a dynamic language, so that can't > really be considered a *strength* per se of dynamic languages. Fair enough -- I acknowledge there's something to what you say, even if I wouldn't say it that way. But in which case, if dynamically typed languages are no easier to use than statically typed ones, and no faster, and no more secure, why do people use them? The conventional answer is that they are easier to use, hence more rapid prototyping and application development. But if we say that static typed languages are *just as easy to use* then the existence and popularity of Python, Ruby, Javascript, Perl, Smalltalk, Lisp, Scheme etc become a mystery. Why do we bother? > You then > followed this up by issuing a challenge to enforce this as a > compile-type check in C++. [Pedant: I never said C++, I said the choice of his language.] Looking back, I see that I misinterpreted Antoon's response. He is not disagreeing with me in the way I thought. I feel that Antoon has a long history of what *seems to me* to be petty point scoring, where he will make statements which seem carefully crafted to appear to be more extreme than they really are, so as to encourage misinterpretation and set off a response. He and I have a long history where I will make a statement which is not absolutely 100% pedantically correct, and Antoon will respond in a curt, peremptory fashion using language which can be read as taking a more extreme position than a more literal, careful reading will show. And I keep falling for it :-( To sketch a caricature of the process, *as I see it*: Me: "... and as we all know, the world is spherical, not flat." Antoon: "What are you talking about? The world isn't spherical." Me: "Of course it is! If not, how do you explain the observation that the hull of sailing ships disappear from sight before their sails?" Antoon: "I don't have to explain that. It has nothing to do with my argument." Me: "WTF???" [and finally, twenty posts later...] Me: "Wait a second... you didn't actually say the world was flat. Are you talking about the world being an oblate spheroid?" Antoon: "No." Me: *penny drops* "Do you mean the world is within 0.001% of an oblate spheroid?" Antoon: "Of course. What did you think I meant?" (If you search the archives, you'll find other examples of this, but what you won't see are the many, many, many draft posts I've written in response to Antoon which I've never sent because I decided there was simply no point arguing.) I'm a pedant myself, and I don't mind being corrected when I'm wrong if the correction is justified by the facts. But I cannot help interpreting Antoon's style of discourse as petty point-scoring, for the sake of disagreement rather than for the sake of education. A nanometre short of trolling. If I have misinterpreted Antoon's intentions, I apologise, but I can only be honest about the impression I am getting. Antoon, if you're reading this, and if you are *not* trying to point- score, then you ought to work on your communication skills. -- Steve -- https://mail.python.org/mailman/listinfo/python-list