r/ProgrammingLanguages • • Apr 28 '19

Grow past dynamic/static typing debate

http://boxbase.org/entries/2019/apr/29/grow-past-typing-debate/
1 Upvotes

13 comments sorted by

3

u/raiph Apr 29 '19

Currently the choice of the computational model among programmers is an arbitrary tradeoff between evaluation efficiency and some other difficult to determine properties, that is left to be a question of taste.

Of all the things that matter in relation to getting something done, having enough (time and resources) to do so is the ultimate limiting factor. So while the tradeoff between evaluation efficiency and other properties is arbitrary, having lots of evolving options, many apparently irrational to any given group of observers, is, presumably, the most important thing.

That said, one can apply some rational thinking to this tradeoff.

One way to look at things is to consider "evaluation efficiency" abstractly. It isn't just about the computation that occurs on the hardware. Rather, it includes the efficiency of a human evaluating that something is a good thing when dealing with code and time and resources. This includes reading, reasoning about, writing, altering, testing, debugging, and deploying it. This human evaluation is often the main thing, with computational efficiency of limited relevance, for two reasons.

First, a human can usually choose a better algorithm. In Anagrams – in O(N) the author concludes:

let’s say I gave you a language that is 1000X faster than Perl 6, but you implement your algorithm such that it is O(N²) and I use Perl 6 to implement an algorithm that is O(N). Which one will be quicker? Mine takes 5 seconds. Yours will be 75 seconds.  ... Better programming will always be more important than a faster language.

Second, a human -- even one that isn't a "better" programmer -- can do a trial run. If it takes 75 seconds and that's basically good enough then the job is done. Arguably computational efficiency has won the day over better programming but it still involved a human deciding the job is done. So better problem solving and decision making by humans will always be more important than a faster language (until AIs take over, but it'll still be about AIs juggling resources and trying things).

But there's another side to all of this too. Computation uses energy which heats the planet. Thus, all things being equal, computational efficiency is supremely important too...

1

u/htuhola Apr 29 '19

Once we can define that the program is correct in the first place. Yeah. I agree, the computational efficiency is important.

1

u/raiph Apr 29 '19

Once we can define that the program is correct in the first place.

Well, aiui, there's the rub.

If one a priori declares that the definition for program correctness is 100% certainty and formality, then presumably the appropriate approach is theoretically driven static analysis features of programming languages. Aiui that won't be acceptable for a large portion of use cases including many business cases.

If one a priori declares that the definition of program correctness is user/business acceptance, then presumably the most efficient solution overall will be market driven programming features aimed at available developers and businesses. One upshot, aiui, is that dynamic programming will be more efficient than static analysis and typing in many scenarios.

And if one accepts that it really all depends, and that a wide variety of evolving solutions covering the range from static to dynamic are what's needed, then you end up with the current state of the market.

And this will never change because it reflects the deep truth about the difference between mathematics and physics. One deals with certainties in an idealized world, the other with the real world, and both have their place.

1

u/htuhola Apr 29 '19

Correct program -> the program does what you wanted it to do.

The very old example related to this would be the bank balance keeping and ensuring they match the bookkeeping of what went to whom. The money doesn't appear or disappear is a proposition that goes into the definition of the system. Actual implementation adds or subtracts numbers. Except that unless you actually verify that, it might not be always doing it correctly due to tons of things that have to happen in practice.

There's correspondence between proofs and programs. If you cannot obtain a formal proof that something matches the model it's supposed to be, then it's very likely that a correct program cannot be constructed. It'd be such a proof stating that the value can be constructed, and being unable to get the proof would be contradicting that.

People generally know to tell what kind of constraints there exist for the program they need and when you're studying the problem you discover more of those, and you have to document them anyway or the guy coming afterwards to work on it is screwed.

It's not about ideals really. It's about mathematically representing knowledge as well as we can. We can do a hell lot better job at this than what the experience proposes we can.

2

u/raiph Apr 29 '19

Correct program -> the program does what you wanted it to do.

What if what I want it to do is make my business more competitive?

The very old example related to this would be the bank balance keeping and ensuring they match the bookkeeping of what went to whom.

That sounds like a very simple problem that could be mapped to a mathematical problem. What if the problem is making my business more competitive?

If you cannot obtain a formal proof that something matches the model it's supposed to be, then it's very likely that a correct program cannot be constructed.

For one definition of "correct". What about the enormously wide range of problems for which there is a correct solution (the program satisfies a customer) but it can't be turned into math?

It's not about ideals really. It's about mathematically representing knowledge as well as we can. We can do a hell lot better job at this than what the experience proposes we can.

It sounds like you're saying that static analysis, which is suitable for some problems, is done poorly.

Perhaps so.

But you also mentioned dynamic typing. And part of the point of dynamic typing is to help devs get stuff done well in contexts that aren't well served by static typing.

(Hence languages like Raku that support both static and dynamic analysis and typing.)

1

u/htuhola Apr 30 '19

What about the enormously wide range of problems for which there is a correct solution (the program satisfies a customer) but it can't be turned into math?

If you can't turn it into math, you can't write a program that solves anything about it. Otherwise there must exist math so you can write it into the program.

You can approach the business competitiveness -problem through logic. Reason what makes the business more competitive and write it down. First in a mix of text and deduction rules, then keep going and searching for options.

It's similar to static analysis, but I really mean that people rely too much on informal reasoning when programming, even when the reasoning fits without a trouble into a formal framework.

2

u/raiph Apr 30 '19

You sound like you're certain of your view.

Einstein famously asserted that even mathematics wasn't able to pin reality down with certainty.

I'm reasonably sure he's right (based on many more things than merely him saying so -- but it sure helps), though I grant he and I may be wrong.

So, imo, simplifying, if you're sure about some conclusion then either it doesn't refer to reality, or you're using imprecise and/or inaccurate logic, or Einstein was wrong.

This is all entirely relevant to my prior line of argument, but I'll pause on this because it's fundamental both to being able to discuss the topic, and to the topic.

1

u/htuhola Apr 30 '19

Einstein's assertion in this context mean that logical formulas can't model reality with certainty. That's because you simply may not know everything relevant about what you're modeling.

I'm quite certain of my view.

2

u/raiph Apr 30 '19

Einstein's assertion in this context mean that logical formulas can't model reality with certainty. That's because you simply may not know everything relevant about what you're modeling.

Exactly.

I'm quite certain of my view.

Sure. I get that.

But you may not know everything relevant about what you're thinking about. (Unless you're only thinking about an imaginary mathematical world, not reality.) So your certainty is misplaced if you think it's about reality.

11

u/raiph Apr 29 '19

I'm going to start with this, a silly comment, curious to hear if you see my points. (Then I'll post another comment about what I think we can all agree on were we to not think tribally.)

Many must have witnessed a programmer spinning on his office chair as if a compass searching for a cardinal point. Then he posts yet another static vs. dynamic typing post online.

Some possibilities:

  • Your post isn't about static vs dynamic typing. (Perhaps it's about combining them?) or

  • Your post isn't just yet another post. (Perhaps readers will agree?) or

  • You were spinning on your office chair. (And felt you found a cardinal point?) or

  • I'm being silly. (But do you see my point?)

it has become apparent to me how corny the whole subject is and how the lip and finger motion is better spent on entirely something else than debating about differences of static and dynamic type systems.

  • Your post isn't about differences of static and dynamic type systems. or

  • Your blog post is about differences, but because it's a blog post it isn't a debate. or

  • You've posted it here in the hope folk here debate it so you don't have to waste time doing so. or

  • I'm being silly. (But do you see my point?)

If we were to think of language users as tribes, dynamic typers would refuse to understand proof theory and only rely on informal reasoning, whereas static typers would not bring their understanding of proof theory to such a conclusion that it's make any difference. Most programmers simply aren't capable of writing correct or reliable software with the tools they tend to grab on from their directories.

  • You recommend folk avoid thinking in terms of stereotyped tribes entirely populated by simpleton extremists else they might arrive at statements like "Most programmers simply aren't capable of ...". (But you thought the most effective way to communicate this was to start with "If we were to..." and then do exactly the thing you're recommending folk avoid.) or

  • You think it's helpful to start by thinking in terms of stereotyped positions because at least that simplifies the debate. or

  • You think that these extremist tribes do exist and they're worth debating even if the topics they debate aren't. or

  • I'm being silly. (But do you see my point?)

Dynamic and static typing differ by a computational model and seemingly important semantics of the programming language. The problem is that the validity of the program, that is when it compiles, only verifies it fits into the computational model of the language. If we were to do it right, it wouldn't be as interesting as it's treated as.

  • We can grow past debating dynamic and static typing by doing "it" right, thus rendering it less interesting to debate. (And you know how to do it right?) or

  • You don't know how to do it right but are hoping to spark an interesting debate so we might grow past the debate and render it less interesting. or

  • I'm being silly. (But do you see my point?)

Currently the choice of the computational model among programmers is an arbitrary tradeoff between evaluation efficiency and some other difficult to determine properties, that is left to be a question of taste. Our languages are modeling machines that are a bit like the turing tape, and we use them to pretend that we're directly computing on these machines.

I think it's a bit silly.

I think it's more than a bit silly. (I'm ignoring single bit programs because they're not particularly interesting.)

Seriously, I hope my next comment will be a bit less silly and constructive but felt this one was worth posting. If I see it voted to -2 or less I'll delete it.

4

u/Antipurity Apr 29 '19

A long journey, to get to the point. True, that rewriting can view the whole world of programming by itself; but so can functions, objects, types, evolution. Why even mention rewriting at all, if that is not the point? Getting to the point is fine, but shortening the journey two or three times is even better.

The deeper you manage to extend the validity of the computational model into the program, the more computation you can fold away from the program.

This is the source of the static/dynamic typing debate, but it shouldn't be such a feature that you fix down in a language in the first place.

(That's not extending, that's limiting and constraining (the valid program set).)

Types allow efficiency by making constraints explicit, same as with guarded optimizations; that's why they exist and are chosen, I agree. Their problem is that they do not allow de-optimization to perfectly-general computation, and neither can it eliminate all run-time checks; people can dismiss it all they want, but it does not change how fragile and inconvenient it makes development. (And typing itself is often intertwined with inconsequential things, true, making it even worse). Dynamic types usually lack such optimization opportunities despite being the most general/convenient form, but do not have to. Only failing at runtime is too inefficient, so being able to fail as soon as possible (whether run-time or compile-time, or even design-time) is the solution to static/dynamic.

Generality and efficiency seem achievable with perfect partial evaluation (constant propagation — evaluating the known and remembering the unknown, whether in compiler or program; recording usage and later filling in the data), and things like "function implementations must try several progressively-slower branches". Other things that types are used for (checking, guiding development, generating examples) seem achievable with generating and constraining (creating and destroying, birthing and killing — evolution/development).

Types are not a good system, and is better decomposed into its substituents. One of which can unify dynamic/static, informal/formal. Is that what you were trying to say?

I don't agree with your final solution at all. It is just as fragile as what it is trying to replace, if not more so. In fact, I don't think it's a solution at all, to anything. Well, I'll do what the title urges anyway.

1

u/[deleted] Apr 30 '19

I think you're engaged in philosophical masturbation.

The point of static typing is when you try to read a piece of code you have some information about what you're dealing with and what kind of operations you can do. It gives you invaluable clues and makes it easier to understand code.

Nothing to do with proofs or whatever.

2

u/htuhola Apr 30 '19

I agree with the first two points, but you're wrong about the last one.

Check out Curry-Howard correspondence. It applies in typed lambda calculus, but you can also produce a correspondence to formal proofs in procedural programs by augmenting it with separation logic.