6 ms·
Type Wars
- echelon 11y agoWithout those pesky types, how does one do automated refactoring in a large codebase? By hand? Types are one of the hallmarks of large scale engineering. Any codebase of appreciable size without types is difficult to work in, at least in my own experience. It takes a little bit more effort writing the types, but doing so saves so much time in the long run that it's absolutely worth it.
- mpweiher 11y ago> Without those pesky types, how does one > do automated refactoring in a large codebase? > By hand? Dunno. One could use the RefactoringBrowser. The first automated refactoring tool. Ever. In Smalltalk. A dynamically typed programming language. The authors even talked about the tradeoffs of using a dynamic language. They thought the problems would be bigger than they turned out to be. http://dl.acm.org/citation.cfm?id=280610 http://dl.acm.org/citation.cfm?id=280610 http://www.refactory.com/tools/refactoring-browser http://www.refactory.com/tools/refactoring-browser http://c2.com/cgi/wiki?RefactoringBrowser http://c2.com/cgi/wiki?RefactoringBrowser
- efnx 11y agoIt's disappointing to see this post makes no mention of any ML style functional language or even Rust. It's hard to take a post with this kind of title (and predictions) seriously when it doesn't even mention the big (relatively) new players in the "Type Wars".
- giaour 11y ago> Why am I wasting time satisfying the type constraints of Java when my unit tests are already checking everything? Couldn't you invert the question for Java and instead ask, why am I wasting my time chasing 100% test coverage when the type constraints of the language guarantee a certain degree of correctness? I've always found that dynamic language projects require twice as many tests as a Java project to get a similarly reliable test suite.
- formula1 11y agoI whole heartedly agree with this sentimate
- josephmoniz 11y agoThis reminds me of a talk from StrangeLoop 2012 by Paul Snively and Amanda Laucher "Types vs Tests". Well worth the watch. https://www.infoq.com/presentations/Types-Tests https://www.infoq.com/presentations/Types-Tests
- JoshTriplett 11y agoExactly. Types are a class of tests, checked by the compiler at compile time.
- mpweiher 11y agoRight. They are one class of tests that happens to be checked at compile time. But what about all the other tests that you still have to do? Which typically also coincidentally check the types (if I check that a value is > 2, I am also checking that its type is number (or int or whatever your particular numeric tower or non-tower says). And what is the value of "compile time", if the all this type checking makes the compiler so slow that just compiling is slower than compiling + running unit tests in a simpler language? What if it catches 10% of errors (optimistic estimate) but due to constraints in reusability makes my code 20% bigger (conservative estimate)? Likely around 10% more bugs. Don't get me wrong: I like static typing (to some degree). I just get antsy when it gets oversold.
- m_fayer 11y agoDon't underestimate the productivity boost provided by the little squiggly red line. The fact that your tooling will stop you from ever passing T when the expected parameter is Collection<T>, and that this "rescue" involves pretty much zero cognitive overhead, is invaluable. When I work in a statically typed language, I find that I pretty much never make "head-desk" type errors, and despair at their reappearance when writing... javascript.
- nercury 11y agoI don't know about what the author's goals are, but I am in favor of offloading as much work to computer as possible. To err is to be human, but compilers never forget.
- josephmoniz 11y agoGood point, the author clearly misses the point that tests themselves are code and thus can have errors in them as well. Code coverage is just a vanity metric if you're tests don't actually test the correct thing.
- crdoconnor 11y ago>I don't know about what the author's goals are, but I am in favor of offloading as much work to computer as possible. The problem is that both writing more tests and statically typing your code involve extra code you need to write. Neither one comes for free.
- m_fayer 11y ago>The pendulum is quickly swinging towards dynamic typing. Programmers are leaving the statically typed languages like C++, Java, and C# in favor of the dynamically typed languages like Ruby and Python. Even though this article is recent, it reads like it's a good several years out of date. From where I sit, Ruby and Python are incumbents and the trend is moving toward typed languages of several varieties. From ML variants to Scala to the "streamlined functional-ish" languages like Swift, Kotlin, whatever C# is morphing into, to Typescript, and so on. He presents TDD as a convenient way to escape the shackles of static-typing. I think many, myself included, would regard compiler-enforced type safety as a way to leverage a machine to ease the significant burden of writing and maintaining a huge test suite. Not to mention the productivity boost provided by the comparatively richer tooling that static typing enables.
- josephmoniz 11y ago>The pendulum is quickly swinging towards dynamic typing. Programmers are leaving the statically typed languages like C++, Java, and C# in favor of the dynamically typed languages like Ruby and Python. And yet, the new languages that are appearing, languages like go and swift appear to be reasserting static typing? The author makes the claim that the pendulum is swinging back towards dynamic typing but then follows up immediately with the contradictory evidence that the new hip languages showing up are strongly typed. I'm curious what if any evidence can be presented that this pendulum is swinging in any direction as oppose to just pulling at opposite ends as it has been for quite some time.
- knucklesandwich 11y agoHonestly, I feel like the current is going the opposite direction here. In the mid-to-late 2000s the most ascendent languages seemed to be dynamic ones. Ruby, Python, PHP, Javascript, etc. Perhaps that's web solipsism, but those are the languages I remember having the highest visibility from that time. Currently, the tide seems to be changing to towards static typing (and stronger typing). Swift, rust, go, scala, etc. Already statically typed languages seem to be borrowing ideas from their stronger typed brethren. C++ gaining concepts (similar to typeclasses from haskell), Java encouraging the use of Optional (similar to Maybe sum types) for nullable values, etc. Many dynamic languages seem to be providing type checking as an option. Clojure, python with PEP 484, various javascript dialects and type system addons, etc. Tests are important and should supplement a static type system, since there are many classes of bugs a static type system can't prevent. But the benefits of static typing as opposed to TDD for verifying the same thing are obvious to me: 1. Tests are not proofs. Unless a test is exhaustive on the set of inputs accepted, it cannot prove that a piece of code works correctly. Types can prove that certain inputs can never be received by a piece of code, which is a stronger guarantee. 2. Tests are more work. Why write tests to verify assertions that a compiler can prove for me? In practice I find this means that unit tests attempting to verify correct behavior for incorrect inputs have gaps or are imperfect because of lack of time or lack of foresight. 3. Tests are still code. Test assertions can have bugs in the same way that regular code can have bugs. True enough, a type system is also code and can also have bugs, but the code in a type system is more visible and more attended to. In practice, I have found many bugs from flawed test assertions and none from a broken type system (as far as I know).
- crdoconnor 11y ago>Tests are not proofs Neither is static typing. It's a layer of protection, much like tests. >Tests are more work I don't think that's necessarily true. You still need to write tests with or without static typing. Those tests you need to write anyway will usually catch type errors in a dynamically typed language that a statically typed language picks up at compile time. The question is whether you need to write more tests (probably you do...maybe 5% more), and whether the greater number of tests offsets the greater amount of code you need to write to statically type your code. As far as I'm concerned, that's not an easily answered question. >Tests are still code. Test assertions can have bugs in the same way that regular code can have bugs Ditto for types.
- wyager 11y ago> The language is very opinionated about type safety... For example, the fact that a variable of type X might also be nil means you must declare that variable to hold an "optional" value... The extreme nature of the type system in swift Oh boy, if he thinks that's extreme... > Why am I wasting time satisfying the type constraints of Java when my unit tests are already checking everything? Oh really? Are the unit tests testing every single 2^64 possible values of an Int? Are they testing for the existence of null everywhere you have a pointer? Strong types aren't just a little bit more info about something; they're a precise refinement of the nature of all values in a program. While very few type systems can test everything you can test with unit tests, a decent type system and good semantics can cover all causes of crash failures and many causes of logic errors. Seriously, folks; writing programs that crash is more or less optional these days. Writing correct programs is still hard, but you can make it a lot easier on yourself.
- mpweiher 11y ago> Are the unit tests testing every single 2^64 possible values of an Int? Hmm...your usual type checker is checking 0 possible values of an int. It is checking just the type. And of course if you are checking a value in a test, you ar coincidentally also checking its type. That's not to say that types can't be useful (for example they have been shown to be quite useful as machine-checked documentation for getting around unfamiliar codebases), but please let's not oversell...
- dsharlet 11y agoThe compiler can use the known bounds of a type to perform correctness checks or optimizations. It might not be testing every possible value of an int explicitly, but the compiler certainly uses the range of an int to make lots of decisions and produce warnings/errors.
- wyager 11y agoIn fact, it checks every predicate codified by the type system. The question is how powerful your type system is, because this determines what predicates you can (conveniently) test. Well-designed strongly typed languages naturally check some useful predicates (existence, the exact structure of the value, etc.). These alone are sufficient to eliminate null pointers, non-total functions, and most other failure modes that plague languages like C++ or Python. Stepping it up a notch, you can use things like GADTs and kind promotion to check much more advanced predicates (like that a vector must be non-empty or even length). With refinement types a la liquid Haskell, I can statically guarantee that e.g. my function only returns lists of even length or only returns even numbers, without even having to put this information in the type of the returned value. With full-blown dependent types a la Coq/Idris/Agda, you can encode pretty much whatever property you want into types. For example, Idris has `verifiedMonoid` which statically guarantees that an operation is associative and has an identity. See https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Classes/Verified.idr https://github.com/idris-lang/Idris-dev/blob/master/libs/con...
- joslin01 11y ago> My own prediction is that TDD is the deciding factor. If this turns out to be the case, then people would reach for statically typed languages to augment & cut-down on tests. Like everyone here is saying, the pendulum is moving toward statically typed. The next generation will probably be in higher kinded types as we continue to attempt to write more generic code that cuts down on number of lines, but still preserves type guarantees. Finally, I don't think it's appropriate to regard `Option[T]` as some mystical type. It's just a regular old generic class that wraps something. Scala programmers (and I'm sure others) have been doing this with `Either[A,B]` & `Option[A]` for awhile, but Swift was really clever in building it into the language with the `?` & `!` operators.
- paulddraper 11y ago"Clever" or "overly specialized", depending on your viewpoint.
- joslin01 11y agoAgreed, but I will say it's been a boon to my iOS development.
- paulddraper 11y agoAnd to my Scala development :) https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ https://www.lucidchart.com/techblog/2015/08/31/the-worst-mis...
- jroesch 11y agoI think they made a much better decision then everyone else even if verbose. Nearly every language has continued to repeat Tony Hoare's "billion dollar" mistake of allowing null to inhabit any type. I think approaches like Rust's and Swift's are steps to stamp out something that never should of existed in the first place.
- paulddraper 11y ago
- shasta 11y ago"On the eve of publication, Bertrand Russel wrote to Frege and pointed out that Frege's logical system allowed statements that were ambiguous -- neither false nor true." This makes it sound as though Russel showed the system to be incomplete, and the reference to Godel's theorem in the next paragraph reinforces the confusion. Russel instead showed the system to be inconsistent, which is much worse.
- paulddraper 11y agoThere are many concepts which approach equivalence, e.g. the IO monad and the C preprocessor. http://conal.net/blog/posts/the-c-language-is-purely-functional http://conal.net/blog/posts/the-c-language-is-purely-functio... Likewise, tests and type systems approach equivalence (especially with dependent types). Thus the distinctions are practical rather than purely theoretical. (1) In practice, I find the static typing approach to result in more complete "tests". (2) In practice, I don't see people writing reusable tests when they share code with others. However static types are are shared with the user's code, thus reducing the testing they need to write themselves.
- deleted 11y ago[deleted]
- Silhouette 11y agoUnfortunately, this post doesn't seem to improve on Martin's usual fundamental misunderstandings. He still doesn't seem to understand that unit tests verify single cases but strong type systems prove general cases, and that in situations that could be handled with either approach, the latter is strictly more powerful. He still seems to believe that dynamic languages are the way things are going, despite almost every successful large and complex software system still being written in the popular static languages he dismisses. He still thinks dynamic languages like Python and Ruby are great for productivity, but he's primarily comparing them to Java as the standard for productivity with statically type languages. This is the man who, somewhere around 2011 I think, claimed that we might have explored the whole programming language space, and there might not be any new programming languages left to be invented. He's also the man who, going by the very post we're discussing, seems to think that having typing so restrictive that not everything is nullable by default is some sort of radical new idea. (Compare that with Tony Hoare's conference speech in 2009, in which he called inventing the null reference his billion dollar mistake, and notice that almost every modern static language provides this kind of safeguard.) So I'm not sure we should take Robert Martin's predictions for where the programming industry is going too seriously; indeed, he should perhaps learn a bit more about what is already available today before making big public predictions about tomorrow.
- tunesmith 11y agoRuby salaries tend to be higher than JVM salaries? What?
- andy_boot 11y agoI was surprised by that statement too, I don't think it is true in London.
- matthewmacleod 11y agoReally? My experience is that while there are a number of high-end Java positions, and a number of Ruby positions in well-funded startups and such, there are VAST numbers of Java positions for mediocre engineers and mediocre companies – no fault of the language, more of the niche it has found itself in. I'm not surprised at all to find that this drags the average salary down.
- gwright 11y agoOne survey in support of this: http://qz.com/298635/these-programming-languages-will-earn-you-the-most-money/ http://qz.com/298635/these-programming-languages-will-earn-y...
- alkonaut 11y ago> "Why am I wasting time satisfying the type constraints of Java when my unit tests are already checking everything" Not only is this a straw man, it's also a really weak argument. Types prove the absence of (type) bugs. Tests can merely prove the presence of such bugs.
- agazso 11y agoModern type systems made type inference and gradual typing possible and those are making a huge difference nowadays. With type inference you can write programs almost as easily and productively as in dynamic languages. With gradual typing you can basically write the same code as in a dynamic language and still get type safety (e.g. TypeScript). Swift, Go, (Rust, Scala, C# etc. but even C++) has type inference today. Maybe dynamic languages will get type annotations and gradual typing in the future and then basically we can have the best of both worlds.
- jsmith0295 11y agoWhile it might seem like things are shifting back towards static typing, I think that is primarily happening in the development of technology now but not the use of that technology yet. I think these predictions will probably appear to be true for some period of time before these newer typed languages begin to gain larger amounts of usage. (However, I expect the testing will probably stick around. I'm highly skeptical of the idea that typing and testing are some how interchangeable.) Also, I think it'll be interesting to see what role gradual typing systems like Flow, Hack, and TypeScript might have on getting static typing into existing dynamically typed codebases.