News for hackers. Stuff that matters.
Re:Diminishing returns of static typing by cm2187 on Monday October 02, 2017 @11:25AM (#15384507)
The benefit of static typing isn't just reliability. Tooling is another major argument. Won't appeal to certain hardcore programmers who think that even notepad has too many features. But it is great for refactoring, finding all references to a function or a property or navigating through the code at design time. Basically all the features visual studio excels at for .net languages.

And I disagree with the barrier to entry argument. Static typing, by enabling rich tooling, helps a beginner (like it helped me) a lot more by giving live feedback on your code, telling you immediately where you have a problem and why, telling you through a drop down what other options are available from there, etc. Basically makes the language way more self-discoverable than having to RTFM to figure out what you can do on a class.

Re:Diminishing returns of static typing by Eridrus on Monday October 02, 2017 @11:54AM (#15384792)
I think dynamic typing proponents get hung up on the auto-complete aspect. The real benefit is when you find someone writing a property with a common-ish name to a data structure and you want to know "who the hell uses this", you can answer that question pretty easy in statically typed languages. In dynamically typed languages you kind of just grep and hope the name is not too common.
Re:Diminishing returns of static typing by gopalv on Monday October 02, 2017 @02:08PM (#15386275)
> In dynamically typed languages you kind of just grep and hope the name is not too common.

For four days, I spent debugging a python production script because in one place I had typo'd ".recived=true" on an object and just couldn't understand why my state machine wouldn't work.

And very quickly, the whole team became fans of __slots__ in Python.

I still write 90% of my useful code in python, but that one week of debugging was exhausting & basically wouldn't have even compiled in a statically declared language. Even in python, the error is at runtime, after I got the __slots__ in place.

Re:Diminishing returns of static typing by bandrami on Monday October 02, 2017 @03:53PM (#15387344)
Is that really a typing problem, though? If I tried to use a "recived" slot on a Lisp struct that only had a "received" slot defined, I'd get a read-time error, and there's zero typing involved there.
Re:Diminishing returns of static typing by protomyth on Monday October 02, 2017 @04:05PM (#15387444)
> For four days, I spent debugging a python production script because in one place I had typo'd ".recived=true" on an object and just couldn't understand why my state machine wouldn't work

Is that really a dynamic typing problem or a language that allows you to create instance members anywhere? It seems like that is a flaw in the declaration model of the language and not a static / dynamic issue.

Re:Diminishing returns of static typing by kazinator on Monday October 02, 2017 @04:19PM (#15387549)
TXR Lisp, a dialect I created:

  $ txr
  This is the TXR Lisp interactive listener of TXR 185.
  Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet.
  1> (set a.b 3)
  ** warning: (expr-1:1) qref: symbol b isn't the name of a struct slot
  ** warning: (expr-1:1) unbound variable a
  ** (expr-1:1) unbound variable a
  ** during evaluation of form (slotset a 'b 3)
  ** ... an expansion of (set a.b 3)
  ** which is located at expr-1:1
Both warnings are static. If we put that into a function body and put that function into a file, and then load the file, we get the warnings.

The diagnostics after the warnings are then from evaluation.

Those are nothing; TXR Lisp will get better diagnostics over time. I'm just starting the background work for a compiler.

There is dynamic and then there is crap dynamic.

Don't confuse the two.

There is crap static too. Shall we use C as the strawman examples of static? Hey look, two argument function called with three arguments; and there's a buffer overrun ...

Re:Diminishing returns of static typing by lomnakkus on Monday October 02, 2017 @05:06PM (#15387949)
It seems to me that you've just invented a static type checker. (Combined with a run-time type checker.) Am I mistaken?

I mean, we can argue the semantics of what, exactly "static type checker" means, but...

Re:Diminishing returns of static typing by kazinator on Monday October 02, 2017 @10:14PM (#15389601)
Static checking doesn't make a "static language".

A "static language" occurs when we have a model of program execution that involves erasing all of the type info before run-time. Or most of it. (Some static languages support OOP, and so stuff some minimal type info into objects for dispatch.)

Note how above, my expression executes anyway; the checks produce only warnings. The warning for the lack of a binding for the a variable is confirmed upon execution; the non-existence of the slot isn't since evaluation doesn't get that far.

If we retain the type info, we have dynamic typing. There is no limit to how much checking we can do in a dynamic setting. The checking can be incomplete, and it can be placed in an advisory role: we are informed about interesting facts that we can act on if we want, yet we can run the program anyway as-is.

Re:Diminishing returns of static typing by lomnakkus on Tuesday October 03, 2017 @05:45PM (#15396485)
This really sounds like "semantics" to me (not PL semantics! :).

For example, these days it's quite possible to ask GHC to defer type errors to runtime. Does that mean that the GHC dialect of Haskell is dynamically typed? This is basically a command line switch away, btw.

Retention of type information does not "dynamic typing" make. As a trivial example, consider C++ RTTI.

You really have just reinvented static (type) checking and a good runtime. There's no shame in that, but let's not pretend that these are opposing forces.

Re:Diminishing returns of static typing by kazinator on Tuesday October 03, 2017 @11:29PM (#15398089)
C++ RTTI is only for class objects, and only useful when they are manipulated by pointer or reference. I believe I covered that sort of thing with my statement, "Some static languages support OOP, and so stuff some minimal type info into objects for dispatch.". It's a gadget which provides an alternative to the structure of doing everything via virtual functions on a base class reference.
Re:Diminishing returns of static typing by lomnakkus on Friday October 06, 2017 @04:03PM (#15419943)
Ok, fair enough, but what about e.g. "-defer-type-errors" for GHC?

I still think you're just arguing semantics.

EDIT: Incidentally, the statically typed crowd can even go the "other way", namely from runtime -> compile time. For example, it's quite possible to derive a static proof/type from a runtime value in e.g. Idris by pattern matching as long as you're meticulous about building up the proof.

Re:Diminishing returns of static typing by Guthur on Monday October 02, 2017 @05:56PM (#15388304)
Not sure it's really an invention, it's been around for awhile. Check any decent common lisp implementation.
Re:Diminishing returns of static typing by naedish on Monday October 02, 2017 @06:27PM (#15388499)
I'm pretty sure he doesn't mean invented in a literal sense. The phrasing implies a meaning of reinvented.
Re:Diminishing returns of static typing by lomnakkus on Tuesday October 03, 2017 @05:46PM (#15396493)
Correct, I was being a little bit facetious. All in good fun, obviously :).
Re:Diminishing returns of static typing by flavio81 on Monday October 02, 2017 @04:47PM (#15387795)
>There is dynamic and then there is crap dynamic. (...) There is crap static too.

Excellent. My point exactly. I have no fear of using a static or dynamic language, as long as it is a good implementation of a statically (or dynamically) typed language.

Re:Diminishing returns of static typing by passivepinetree on Monday October 02, 2017 @06:44PM (#15388622)
What would you consider good implementations of either?
Re:Diminishing returns of static typing by flavio81 on Monday October 02, 2017 @07:29PM (#15388828)
Good "statics": Haskell, ML family, maybe Rust.

Good "dynamics": All the Lisp-family languages. Smalltalk. Julia. Lua. Tcl.

Re:Diminishing returns of static typing by zzzcpan on Monday October 02, 2017 @04:45PM (#15387784)
Plus you can eliminate all typos in any language with a simple statistical linter that you can implement in like an hour or two.
Re:Diminishing returns of static typing by avip on Monday October 02, 2017 @04:07PM (#15387462)
Could you clarify - did you go over all classes in your codebase and added __slots__ attribute? Or you have some tooling to do that for you? I don't have any clear counterargument but that sounds wildly unpythonic thing to do.
Re:Diminishing returns of static typing by y4mi on Monday October 02, 2017 @02:38PM (#15386567)
> I still write 90% of my useful code in python, but that one week of debugging was exhausting & basically wouldn't have even compiled in a statically declared language.[...]

nothing stops you from using static typing with python3

Re:Diminishing returns of static typing by nightski on Monday October 02, 2017 @02:41PM (#15386604)
I haven't used optional typing in python. However, the problem I see with optional typing is that while I may choose to use it my team mates might not. Even more importantly, the 3rd party dependencies I use probably don't. So the amount of code that actually uses the types would be very limiting. Saying the choice is entirely up to you personally is a misnomer.
Re:Diminishing returns of static typing by gipp on Monday October 02, 2017 @03:07PM (#15386884)
Strict use of type annotations has to be a team decision, yes. Checking for them can be integrated into a CI build, though.

The typing spec provides for supplementary "stub files" that can be provided for third-party dependencies without their own annotations. The typeshed project provides these for a fair and quickly increasing number of common dependencies, and is plugged into pycharm and mypy by default: https://github.com/python/typeshed

Re:Diminishing returns of static typing by yawaramin on Monday October 02, 2017 @03:43PM (#15387259)
I think GP meant 'you' as in 'your team'. Anyway, Python has a type repository for popular libraries, just like TypeScript does. And mypy can still typecheck your code even without type annotations.
Re:Diminishing returns of static typing by sidlls on Monday October 02, 2017 @04:04PM (#15387436)
In fairness the hints available in Python 3 aren't really a static typing system. It would take a lot of extra work to make it one.
Re:Diminishing returns of static typing by lomnakkus on Monday October 02, 2017 @05:09PM (#15387974)
Well, nothing except almost the whole ecosystem of libraries not having type annotations, those type annotations that exist themselves being quite limited (IIRC), etc. etc.?

Can we stop pretending that adding type annotations to a 'dynamic' language solves the "good static typing" problem? It's just silly.

(About as silly as pretending that static types solve all problems.)

Re:Diminishing returns of static typing by smallnamespace on Monday October 02, 2017 @05:30PM (#15388127)
This seems like something a linter can catch though. ESLint certainly seems to give me warnings for use of undefined properties.
Re:Diminishing returns of static typing by lrem on Monday October 02, 2017 @06:46PM (#15388633)
That's a kind of error caught by the popular static analysis tools. Better add that pylint and mypy to your travis.yml as soon as possible.
Re:Diminishing returns of static typing by dkersten on Monday October 02, 2017 @12:15PM (#15385067)
For me, what I miss when using dynamic languages is good, solid refactoring tools that can inline functions/methods, rename across source files, etc. In my experience, in both Python and Clojure, the refactoring tools simply don't come close to those of languages like C++, C# and Java. And I say this as a major Clojure fanboy...
Re:Diminishing returns of static typing by joncampbelldev on Monday October 02, 2017 @03:03PM (#15386846)
Namespaced keywords can really help with refactoring your domain model.

Usually I use normal keywords for throwaway or glue code, but anything important (my actual domain entities) will be namespaced, allowing (relatively) pain free refactoring.

Cursive has a few good refactoring tools/shortcuts, but I would also like to see extract/inline/move for functions.

Re:Diminishing returns of static typing by dkersten on Tuesday October 03, 2017 @04:49AM (#15391057)
I'm not saying that I don't have facilities or tools (clj-refactor) to do refactoring, just that they are, in my opinion and experience, not as good or full featured as in the mainstream static languages (and this experience seems to translate between other dynamic languages, eg, Python: I have refactoring tools, but they're not as good as what I can do in, say, Java).

Its not a huge problem, just something I miss from the static languages.

Re:Diminishing returns of static typing by Eire_Banshee on Monday October 02, 2017 @12:02PM (#15384902)
This.

Not just, "who the hell uses this", but "where the hell is this defined" as well.

Re:Diminishing returns of static typing by flavio81 on Monday October 02, 2017 @12:11PM (#15385027)
>Not just, "who the hell uses this", but "where the hell is this defined" as well.

On Common Lisp, a dynamic language, I can also get this answered instantly. I just press a key combination on a method call and i jump to the definition.

So this isn't exclusive to statically typed languages.

Re:Diminishing returns of static typing by KMag on Monday October 02, 2017 @01:08PM (#15385688)
But if the compiler doesn't enforce that types are statically determinable, there will be cases where the tool will have to show you more potential definitions for function definitions than would be shown for a statically typed language.

Maybe good tools are able to perform some static analysis and rule out some of the methods with the same name but impossible types, but the language doesn't rule out situations where the best the tool will be able to do is show you all of the function definitions with the same name as the (dynamically dispatched) function call site you're looking at.

Let's say you have seven different type hierarchies having dynamically dispatched functions named "run", with 5 definitions in each hierarchy, for a total of 35 functions named "run". In a statically typed language, if the code compiles, it's possible to narrow down the type for a given call site to either one of the hierarchies or one definition, meaning you have to look at either 1 or 5 definitions. In a dynamically typed language, there are situations where legal code results in the tool having to throw up its hands and show you all 35 definitions.

The flip side is that if you really have a spot where you'll need to dispatch to any of the different hierarchies, then in a strong statically typed language, you'll need to either create an algebraic sum type covering all 7 hierarchies, or you'll need something like a typecase / typeswitch statement to enumerate out your possibilities.

Re:Diminishing returns of static typing by ubernostrum on Monday October 02, 2017 @01:52PM (#15386098)
there will be cases where the tool will have to show you more potential definitions for function definitions than would be shown for a statically typed language.

And even in a statically-typed language there will be cases where the tooling can only determine fairly generic things statically.

I don't see anyone advocating for abandoning static typing over that occasional limitation. Yet I do see people proposing similarly-infrequent issues as cause to abandon dynamic typing.

Re:Diminishing returns of static typing by jaggederest on Monday October 02, 2017 @02:29PM (#15386454)
When $problem happens to $language_I_prefer, it's an unavoidable difficulty that is easy to work around.

When $problem happens in $language_I_dislike, it's a clear sign that the language itself is inherently broken.

Re:Diminishing returns of static typing by caseymarquis on Monday October 02, 2017 @01:21PM (#15385817)
I had to do a decent amount of setup and wrote a quick script to run the tools which generate ctags to make this happen in CL using slimv. With top tier ides for static languages, this is built in from day 1 with no effort. You can't not have it. That said, a top tier repl for development is missing in languages like C#. I'd love to see that gap bridged.
Re:Diminishing returns of static typing by Eridrus on Tuesday October 03, 2017 @07:36AM (#15391664)
I think it's telling that while there are Lisp aficionados in this thread telling us how great it is, none of these ideas have been implemented in Python or JavaScript or Ruby, the most common dynamically typed languages.

And that's really all I care about, I'm not about to start writing production code in Lisp.

Re:Diminishing returns of static typing by dvlsg on Monday October 02, 2017 @05:20PM (#15388069)
You can even do this with Javascript, too. And without doc types. At least in vscode, anyways.

Well, usually. It gets a little confused when you start using dependency injection containers, or dynamic requires, or anything like that.

Re:Diminishing returns of static typing by Eire_Banshee on Monday October 02, 2017 @12:16PM (#15385080)
Lets be real, when we say dynamic languages, we aren't talking about niche languages like Lisp. We are talking about JS and Python almost exclusively.
Re:Diminishing returns of static typing by flavio81 on Monday October 02, 2017 @01:35PM (#15385946)
>Lets be real, when we say dynamic languages, we aren't talking about niche languages like Lisp.

How can it be a niche language, if it's an ANSI standard, has more than 8 or 10 fully feature, standard-conformant implementations, runs on most CPU types, and has been proven to work in production systems for spaceship guiding, worldwide airfare reservation and credit card transaction verification?

You use Js and Python because you choose to use it, but it's not the only choice. Not only Common Lisp, you could also be working in Clojure with many benefits.

Re:Diminishing returns of static typing by amirouche on Monday October 02, 2017 @12:35PM (#15385291)
Python has jump to definition too.
Re:Diminishing returns of static typing by catnaroek on Monday October 02, 2017 @01:10PM (#15385705)
Does it work in the presence and (ab)use of dynamic features? (e.g., when you have lots of decorated functions) Or is it just a best effort thing? (i.e., only works when your code would actually be expressible in a static way)
Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @02:27PM (#15386442)
This is a continuum... in many statically typed languages there are regularly used paths that lead outside the realm of the language-defined type system as well. Consider dynamic class loading in Java, dlopen / reinterpret_cast in C++ etc.
Re:Diminishing returns of static typing by catnaroek on Monday October 02, 2017 @03:16PM (#15386982)
> This is a continuum.

It is not. A language feature is either amenable to static analysis (not necessarily type checking) or it is not.

> Consider dynamic class loading in Java, dlopen / reinterpret_cast in C++ etc.

This actually emphasizes my point. Features that are not amenable to static analysis are problematic for tooling.

Re:Diminishing returns of static typing by adamnemecek on Monday October 02, 2017 @12:39PM (#15385341)
You mean there’s an ide with that feature? It’s never as good as with any statically type language.
Re:Diminishing returns of static typing by markbnj on Monday October 02, 2017 @12:57PM (#15385557)
Sublime Text has this feature on hover, but I am fairly certain it is based on text search of the modules in the python path.
Re:Diminishing returns of static typing by hwayne on Monday October 02, 2017 @12:49PM (#15385455)
Have you tried it? It's usually pretty good for Python.
Re:Diminishing returns of static typing by steelbird on Monday October 02, 2017 @12:53PM (#15385503)
Which IDE?
Re:Diminishing returns of static typing by hwayne on Monday October 02, 2017 @01:13PM (#15385733)
PyCharm and VSCode are both pretty good.
Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @01:06PM (#15385656)
There have been references to Clojure, Elixir, Smalltalk, Common Lisp in the comments here, what makes you think just Javascript & Python?
Re:Diminishing returns of static typing by yellowapple on Monday October 02, 2017 @01:54PM (#15386132)
It's worth noting that Elixir (by descent from Erlang) can emulate at least a basic static typing system pretty easily through pattern matching. You miss out on some features common in more traditionally-object-oriented languages (namely: subtypes), but tagged tuples and structs do provide a lot of the same safety benefits in runtime (and tools like Dialyzer can - last I check - use such pattern matching as a basis for static verification).
Re:Diminishing returns of static typing by nv-vn on Monday October 02, 2017 @05:51PM (#15388269)
Elixir and Erlang still lack the ability to typecheck any process behaviors because messages can take any type anywhere.
Re:Diminishing returns of static typing by yellowapple on Monday October 02, 2017 @09:01PM (#15389240)
You can still pattern match when receiving, though (in fact, 'receive' in both Erlang and Elixir does pattern matching already in the same vein as 'case'); just match messages based on a tagged tuple or a record (Erlang) / struct (Elixir) signature or however else you want to define your "types".
Re:Diminishing returns of static typing by hellofunk on Monday October 02, 2017 @01:56PM (#15386159)
Why would you say that? There are far more dynamically typed languages in widespread use than those 2!
Re:Diminishing returns of static typing by pvorb on Monday October 02, 2017 @12:39PM (#15385339)
IntelliJ/WebStorm is also pretty good at this (with JavaScript at least) by indexing a whole project and its dependencies. Refactoring doesn't work that well, though.
Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @01:31PM (#15385907)
PyCharm gets it right 99% of the time. That 1% is hardly worth switching the a different language.
Re:Diminishing returns of static typing by Peaker on Monday October 02, 2017 @02:48PM (#15386688)
For someone paranoid about correctness, that's 1% of lingering doubt about every single operation in the IDE.

The 99% stat is quite likely a big exaggeration.

Refactoring is far far harder to do reliably, and more straining as so much more responsibility on the programmer.

Re:Diminishing returns of static typing by kodablah on Monday October 02, 2017 @02:16PM (#15386349)
IME, add that 1% to another "1% isn't worth switching" argument with some other Python deficiency and then to another and so on, and reasonable case for choosing other languages can be made. I'm not saying Python should be abandoned for all projects, but we should be careful with "but if we make everyone use this one tool, and this one tool does it right almost all of the time, so we're good" arguments.
Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @03:24PM (#15387062)
I'm reading Type-Driven Development with Idris right now exactly because I don't think Python is always the correct choice. I just don't find slight improvements in IDE features to be relevant.
Re:Diminishing returns of static typing by sidlls on Monday October 02, 2017 @02:30PM (#15386467)
What about the time accounted for in each of those buckets? If "that 1%" accounts for more than 1% of debugging, error chasing, and related time it starts to look more important, yes?
Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @01:01PM (#15385610)
The module system makes it very easy to find definitions, because one namespace = one source file.

And the other way around: Statically typed languages without module systems, such as C, exhibit this problem too.

Re:Diminishing returns of static typing by hinkley on Monday October 02, 2017 @05:33PM (#15388152)
I work with an in-house framework written in Javascript.

You would think by looking at the code that the creators had a 30 word vocabulary, because 80% of the code uses the same six nouns and four verbs to pass data around and what you use those for depends on the context of who is calling it.

Oh, but the entire thing is written using promises, so most of your function calls have no context. It's hell, and I'm starting to worry that Node has dug itself a reputation hole it will never get out of.

Re:Diminishing returns of static typing by flavio81 on Monday October 02, 2017 @06:35PM (#15388564)
I can feel your pain, but note that this isn't a fault of dynamic typing per se. This is bad coding (for example, no good use of modules) plus the problem of Javascript itself having many issues; not to mention the wildly different levels of quality within the JS library ecosystem.
Re:Diminishing returns of static typing by Eridrus on Tuesday October 03, 2017 @07:33AM (#15391643)
I don't think Node is doomed; Typescript + async/await makes code make sense.
Re:Diminishing returns of static typing by Ace17 on Monday October 02, 2017 @01:31PM (#15385906)
Actually, refactoring browsers were pioneered by Smalltalk people.
Re:Diminishing returns of static typing by hinkley on Monday October 02, 2017 @05:44PM (#15388222)
And smalltalk had to leave trampolines in place to deal with renames that it couldn't finish deterministically. No thank you.

Nobody ever talks about that little horror when they bring up how Smalltalk could to refactoring JUST FINE without static types. It wasn't just fine, turns out.

Re:Diminishing returns of static typing by imtringued on Monday October 02, 2017 @03:33PM (#15387163)
I don't understand this argument.

In smalltalk the parameter names are part of the function name to reduce the likelyhood of name clashes. You still have the same problem when you have two functions with the same name and parameters.

Re:Diminishing returns of static typing by josephv on Monday October 02, 2017 @04:42PM (#15387757)
You understand, someone will always claim that everything was invented by smalltalk at some point.
Re:Diminishing returns of static typing by geofft on Monday October 02, 2017 @01:09PM (#15385702)
What are your favorite tools for doing this in C/C++ (which are extremely statically typed, if not very strongly typed)?

I think the best thing I've found for this personally is coccigrep, which works but I've only used it a couple of times. I'd like something I'd reach for about as often as I reach for grep. (Also I think these days you'd want it to be based on clang or something.)

One thing that does seem to be true is that the requirement to name types means that a textual grep is way more reliable than it is in C. If I want to find all places where a Python class is used in a large codebase, I might as well give up.

Re:Diminishing returns of static typing by bpicolo on Monday October 02, 2017 @01:59PM (#15386193)
I imagine CLion is a popular answer here: https://www.jetbrains.com/clion/
Re:Diminishing returns of static typing by geofft on Monday October 02, 2017 @02:07PM (#15386268)
Oooh, I've heard of people using it but for some reason I just thought it was an editor. I'll have to give it a try.
Re:Diminishing returns of static typing by stagger87 on Monday October 02, 2017 @06:03PM (#15388348)
QtCreator
Re:Diminishing returns of static typing by jcelerier on Monday October 02, 2017 @06:12PM (#15388408)
Here are the refactorings available : http://doc.qt.io/qtcreator/creator-editor-refactoring.html

Also they are backed by Clang and muuuuuuuuuuuch faster than in Visual Studio + whatever paid extension

A very nice feature it has and that I didn't see elsewhere is the optional case-sensitive renaming. eg renaming Foo to Bar will also change foo to bar and FoO to BaR.

Re:Diminishing returns of static typing by mozey on Monday October 02, 2017 @12:40PM (#15385343)
And "what the hell is this?" when you see a data structure called "options"
Re:Diminishing returns of static typing by sly010 on Monday October 02, 2017 @02:57PM (#15386781)
And "why? oh, why?" when that data structure is unvalidated json and the only way to enumerate all options is to read all the code
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @12:21PM (#15385136)
I'm so happy to see the pendulum swing the other way, because when JavaScript was becoming popular, and Ruby and Python had a popularity renaissance (around mid to late 2000s), I had a lot of online arguments about the value of static typing.

People were complaining about static typing for the dumbest reasons (it's too 'wordy'). It started as a backlash against old-school enterprise Java development (which was fair, EJB2 world sucked) but then it went completely off-the-rails. Typing in Java could be better, sure, but even with its quirks it's way better than the nothing you get with dynamic languages. There are a class of bugs you just never need to worry about when the compiler does some compile-time checks for you ... like worrying that you passed the wrong type into a function, or the wrong number of arguments.

Thank God people are coming to their senses.

Re:Diminishing returns of static typing by KMag on Monday October 02, 2017 @02:15PM (#15386341)
I've worked with, statically typed languages, dynamically typed languages, and my day job involves a dynamically typed language with optional annotations (dynamically enforced) and static analysis tools.

In my experience, the cost of static typing feels roughly constant per line of code, while the benefits of static typing feel roughly O(N log N) in lines of code or O(N) in number of cross-type interactions. These are just wild guesses based on gut feelings, but they feel about right. The constant factors are affected by individual coder preference, experience, and ability, but also specifics of thy type systems involved and the strength of type inference in the tools being used.

In any case, I think often times dynamic typing proponents and static typing proponents have vastly different notions of what a large code base is, or at least the size code bases they typically use.

One problem is that many code bases start out where the advantages of static typing aren't readily apparent, but re-factoring into a statically typed language is often not realistic, even/especially when a project starts groaning under its own weight.

I'd love to see more mainstream use of gradual typing/optional typing/hybrid typing languages, especially something like a statically typed compiled subset of a dynamically typed interpreted language, where people could re-factor portions of their quick-and-dirty prototypes into nice statically typed libraries.

Re:Diminishing returns of static typing by andybak on Monday October 02, 2017 @06:28PM (#15388512)
There are no large codebases - just insufficiently modular ones. :-)
Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @01:39PM (#15385980)
Typing in Java could be better, sure, but even with its quirks it's way better than the nothing you get with dynamic languages.

I disagree; that Java was the standard example of statically typed languages is what convinced me for a long time that I didn't want anything to do with it. Having to pollute my code with all that crap, deal with a lot of dumb restrictions and still have NPEs left me with a sour taste.

Only after I discovered Haskell (and more recently Idris), did I realize that static typing can actually be worthwhile.

Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @02:01PM (#15386215)
Agreed, every time I had to patiently explain to javac that shockingly, my new ArrayList<T> was a List<T>, my new FooBar was a FooBar, and always would be, it drove me slowly mad. Still, I was thankful for the static types when trying to understand where this strange object came from and what it was supposed to do. I’m glad we have modern languages that have the potential to do an even better job of that without a lot of the verbosity.
Re:Diminishing returns of static typing by breischl on Monday October 02, 2017 @03:42PM (#15387250)
Those things are indeed obnoxious, but they are truly _Java_ issues rather than static typing issues. For instance, C# will figure that stuff automatically in many cases using the _var_ keyword. The Lombok plugin can add something like that into Java, although it's only about 80% as good because of other Java limitations, primarily type erasure.
Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @06:36PM (#15388570)
I agree. While I have never used C# in anger I have played with enough other (non-Java staticky typed) languages to know that it doesn’t have to be this bad :D
Re:Diminishing returns of static typing by nradov on Monday October 02, 2017 @03:07PM (#15386894)
While it may be frustrating to novice programmers, the distinction between interfaces (List) and implementation classes (ArrayList) is quite valuable, especially when dealing with huge code bases that have to be maintained over decades. Those declarations help to establish an internal design contract and clarify the developer's intent. In this particular case, a future maintenance programmer could switch from ArrayList to any other class which implements the List interface without breaking the program.
Re:Diminishing returns of static typing by nicoburns on Monday October 02, 2017 @06:32PM (#15388544)
True, but there are more elegant solutions. For example, Rust's traits allow you to define a trait (somewhere in between an interface and an abstract class in Java), and then methods can be generic over any object that implements that trait. And structs and traits have a many-to-many relationship.

This allows you implement patterns like duck typing which are idiomatic in languages like javascript, but impossible to implement in java.

Re:Diminishing returns of static typing by x0x0 on Monday October 02, 2017 @05:56PM (#15388305)
Which happens exactly how often? I've been writing java code for the better part of two decades and basically never needed to swap my list/set/map types around. Also, one of the purported benefits of java's typing is your editor can find and refactor / swap all usages, so it doesn't seem to me like this distinction has much value. It instead makes me think it's a fetish for object orientedness...

In fact, the only cases I've ever swapped even a HashMap has been to trove, which implements data structures for builtin types rather than reference types. In which case using interfaces everywhere doesn't help.

Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @03:43PM (#15387267)
It’s not about having the difference, it’s about having to explain to Javac what I am using because it’s incapable of doing meaningful type inference.
Re:Diminishing returns of static typing by vkou on Monday October 02, 2017 @04:37PM (#15387709)
Only in the case of generic erasure, which is a Java wart that we will, sadly, never eliminate.
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @03:02PM (#15386841)
Generics in Java have well known limitations stemming from type erasure (a design decision made to preserve backwards compatibility). Things aren't quite as dire as you made them out to be and in the general case, they work quite well.
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @02:47PM (#15386674)
>Having to pollute my code with all that crap

What crap? Types?

>deal with a lot of dumb restrictions

Like what?

Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @03:42PM (#15387248)
What crap? Types?

Types, especially those that could easily be inferred and that provide no value to the programmer. Writing types down can be useful - Python programmers do it too. Having to tell the compiler every little thing is crap.

Like what?

Type erasure. Having to treat primitives and arrays differently from other types. No first class functions or classes. I won't go on, the arguments are easy to find.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @04:32PM (#15387675)
I won't deny that Java had some quirky design decision that the language is paying for (though some of those have been mitigated). But I can't find your criticisms very persuasive in a world where languages like JavaScript and PHP are popular. Even C and C++ have their own idiosyncrasies to contend with.

I am surprised though that you were completely ignorant of the benefits of static typing outside of Java. I would think that simply out of curiosity you would do a language survey just to get an idea of what else is out there.

Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @05:32PM (#15388145)
II can't find your criticisms very persuasive in a world where languages like JavaScript and PHP are popular.

Persuading you on the general demerits of Java wasn't really my intention; my point was that if you want get more people on the static typing train, Java is a bad ambassador and might work against you.

I am surprised though that you were completely ignorant of the benefits of static typing outside of Java. I would think that simply out of curiosity you would do a language survey just to get an idea of what else is out there.

Well, back then (early 2000s) I was a self-taught teenager with a poorer grasp of English (I'm not a native speaker), so while my curiosity did lead me to discover a few languages (JavaScript, PHP, Python, Lua and C), anything remotely approaching "academic" - Haskell, OCaml, Oberon, etc - was out of bounds for me.

Since C was the only other statically-typed language I knew, and I also knew it was much older and designed for much slower machines, I assume static typing was mostly for efficiency, like manual memory management.

Re:Diminishing returns of static typing by hellofunk on Monday October 02, 2017 @01:58PM (#15386177)
> Thank God people are coming to their senses.

There are no senses to come to. Static and dynamic typing each have their own benefits, and there are genuine tradeoffs to choosing one over the other. That we are even having this debate in 2017 shows that the world of typing is not a "solved problem" and there are still good reasons to use one over the other for various reasons.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @03:16PM (#15386990)
>Static and dynamic typing each have their own benefits,

I struggle to think of any benefits of dynamic typing on a reasonably sized code-base (e.g. 50k+ LOC).

Re:Diminishing returns of static typing by lordCarbonFiber on Monday October 02, 2017 @03:25PM (#15387069)
Cheap and plentiful dev talent. Grab any random guy (and at these shops it's always guys) off the street and bang you've got a python dev.

There's always going to be an agility multiplier so long as VC is flowing and getting an mvp and a high head count is worth more than any kind of sustainable product.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @04:20PM (#15387561)
>Grab any random guy (and at these shops it's always guys) off the street and bang you've got a python dev.

I expect any programmer to be able to transfer their skillet to a new programming language - especially when we're talking about mainstream languages with a GC.

>There's always going to be an agility multiplier so long as VC is flowing and getting an mvp and a high head count is worth more than any kind of sustainable product.

What kind of agility multiplier? Maybe it makes a difference during a hackathon where you have 24 hours to put something together or maybe if you're putting together shell scripts ... but taking something to MVP takes weeks or months - mainstream dynamic languages simply don't have any edge in development speed in those instances.

Re:Diminishing returns of static typing by crdoconnor on Monday October 02, 2017 @04:05PM (#15387447)
>I struggle to think of any benefits of dynamic typing on a reasonably sized code-base

Being able to define and initialize types at runtime offers more flexibility and it's quicker to develop in.

I'm frankly surprised nobody brings it up more often but the prototypical example of "static typing done right" - Haskell - is talked about nearly constantly but when I look for actual software I might use that's written using it.... there's so little it's almost embarrassing. One obscure window manager, one obscure VCS, facebook's spam filter and some tool for converting markup.

Given a sprinkling of asserts, a decent linter and a high level of test coverage I don't see much of a benefit to adding static typing.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @04:35PM (#15387700)
>Being able to define and initialize types at runtime offers more flexibility and it's quicker to develop in.

Quicker if you're writing shell scripts or a small single-purpose applications. Not quicker if you're adding to a codebase of any significant size.

Re:Diminishing returns of static typing by crdoconnor on Monday October 02, 2017 @05:23PM (#15388084)
Decent programmers compose code bases of "significant size" from many small, loosely coupled single purpose applications.

Yes, IME it's still quicker.

OTOH, if you're using "codebase of significant size" as code for "big ball of mud", static typing certainly helps, but integration tests are the real lifesaver.

Re:Diminishing returns of static typing by macspoofing on Tuesday October 03, 2017 @05:32AM (#15391215)
>OTOH, if you're using "codebase of significant size" as code for "big ball of mud", static typing certainly helps, but integration tests are the real lifesaver

No. I mean when the codebase is of a certain size, new features require some thought and planning. Features may span multiple-modules. They may require partial or full rewrites or the refactoring of any number of sub-components to support the new behaviour. This means that you proceed carefully because you may not want to introduce regression bugs. This costs time. At that point, you're not limited by your typing speed as you may be putting in net 10 lines of code a day. There is just no benefit to dynamic typing at that point. Worse for dynamic languages, this is where improved tooling and static type constraints start paying extreme dividends.

Re:Diminishing returns of static typing by crdoconnor on Tuesday October 03, 2017 @07:51AM (#15391738)
>No. I mean when the codebase is of a certain size, new features require some thought and planning. Features may span multiple-modules. They may require partial or full rewrites or the refactoring of any number of sub-components to support the new behaviour. This means that you proceed carefully because you may not want to introduce regression bugs. This costs time.

Yes. And all equally true for statically typed languages.

Refactoring without tests is easier in a statically typed language, but still stupid. If you assume a decent body of tests, the benefit dissipates quickly.

If you prototype faster, as you usually will in a dynamically typed language, your design mistakes cost less. Since in large software systems I tend to find that the two biggest sources of bugs are a) errors in specification and b) poorly designed APIs, not obscure edge case bugs, quicker prototyping helps in large projects too.

And, if your design is solid, you can still achieve similar benefits as static typing by "locking down" your boundary code with asserts so that future development that interacts with that boundary code will fail quickly if it interacted with in the wrong way.

>At that point, you're not limited by your typing speed as you may be putting in net 10 lines of code a day. There is just no benefit to dynamic typing at that point.

This is fallacious. You're never limited by your typing speed in any language at any point. The cost of "extra typing" is cognitive, not a finger speed limitation.

The benefit of dynamic typing is more flexibility in the code you write (especially useful for writing frameworks and such) and quicker turnaround when prototyping because you do not have to prespecify as much up front.

Re:Diminishing returns of static typing by macspoofing on Wednesday October 04, 2017 @06:42AM (#15399490)
>Yes. And all equally true for statically typed languages.

>Refactoring without tests is easier in a statically typed language, but still stupid. If you assume a decent body of tests, the benefit dissipates quickly.

We're not arguing whether dynamic language+extensive integration/unit test is better than static typing and no tests.

>And, if your design is solid ...

Yes, if you have a very solid architecture, strict coding guidelines, extensive integration and unit test coverage, experienced developers (etc. etc. etc.) you will mitigate a lot of problems with dynamic typing. So if you do everything right, avoid the pitfalls, you can have something solid. A similar argument is made to me when I assert JavaScript is a terrible language. I don't disagree with either but it doesn't prove anything.

>The cost of "extra typing" is cognitive, not a finger speed limitation.

Exactly.

Re:Diminishing returns of static typing by crdoconnor on Thursday October 05, 2017 @12:58PM (#15410679)
>We're not arguing whether dynamic language+extensive integration/unit test is better than static typing and no tests.

I am, because that's the way I'd work in any language, because I'm not a hack.

>Yes, if you have a very solid architecture, strict coding guidelines, extensive integration and unit test coverage, experienced developers (etc. etc. etc.) you will mitigate a lot of problems with dynamic typing.

Eliminate.

>A similar argument is made to me when I assert JavaScript is a terrible language.

No, javascript is different. The weird and fucked up implicit type conversions render even a high level of testing insufficient to achieve a high level of confidence in the code. There's way too many edge case behaviors where it should be throwing exceptions and it does something weird instead. C suffers from this problem too despite being statically typed.

Re:Diminishing returns of static typing by golergka on Monday October 02, 2017 @05:03PM (#15387923)
"Quick to develop in" doesn't sound as a very good thing to me - because it usually means "slow and hard to maintain for the next guy".
Re:Diminishing returns of static typing by hellofunk on Monday October 02, 2017 @06:01PM (#15388334)
> I struggle to think of any benefits of dynamic typing on a reasonably sized code-base (e.g. 50k+ LOC).

And yet, it's done all the time with great results.

Re:Diminishing returns of static typing by metaphorm on Monday October 02, 2017 @01:47PM (#15386063)
The type systems of Java and C/C++ are the most commonly encountered ones and by far the most widespread in industry programming (as opposed to academia/research) and they are actually awful and really add a lot of friction and inertia to developing. Being free of that kind of type system when using a language like Python really does feel like a big upgrade.

There is a different problem with the more powerful and useful type systems in more modern statically typed languages though: learning curve. Haskell is dysfunctionally hard to learn and other languages do a little bit better but there's still friction in the learning curve that gets in the way of widespread adoption in projects that want to be able to hire rapidly.

Re:Diminishing returns of static typing by breatheoften on Monday October 02, 2017 @08:43PM (#15389163)
I think Typescript is significantly easier to learn than JavaScript.
Re:Diminishing returns of static typing by wiremine on Monday October 02, 2017 @12:44PM (#15385396)
> EJB2.0 world sucked

This is the #1 reason I leaned away from static typing. Typescript and Swift have changed my mind. I now see typing as a helpful tool that can solve a lot of problems.

Re:Diminishing returns of static typing by enraged_camel on Monday October 02, 2017 @01:24PM (#15385840)
>>There are a class of bugs you just never need to worry about when the compiler does some compile-time checks for you ... like worrying that you passed the wrong type into a function, or the wrong number of arguments.

People always say this and it baffles me. Bugs like that should be caught immediately by your test cases. You shouldn't rely on the compiler to catch them for you.

Re:Diminishing returns of static typing by rbobrowicz on Monday October 02, 2017 @02:11PM (#15386300)
Personal anecdote:

I worked on a small Python project some years ago and we had a type error in production despite having tests.

We traced it back to a call to a third party library. It was supposed to return a list of results, and all of the test cases around it worked and always got a list back. In production however we encountered an error because if there was only one value to return, the library would not return a list of one element, as we expected, but a scalar value. So the rest of the code was expecting a list and when it encountered a scalar it blew up.

You can blame it on us for having insufficient test cases, or not coding defensively enough, or not reading the source code of the library we used, or the author of the library for bad design, but ultimately, this bug would not have been possible in a statically typed language.

So just saying "have test cases" is not good enough. Your test cases can be not exhaustive, but a good static type system and type checker is.

Re:Diminishing returns of static typing by berdario on Monday October 02, 2017 @05:11PM (#15387999)
I cannot reply to cdoconnor (probably some downvotes), so I'll write here:

That's the whole point: as it's often said "type checking keeps you honest"

I stumbled time and time again upon badly designed libraries... With a static type system, the painfulness will be obvious and felt the first time you'll try to build your code

with dynamic types, the pain might not be felt at all, until a crazy bit of code will be invoked, sometimes at the most unfortunate of times

Re:Diminishing returns of static typing by crdoconnor on Monday October 02, 2017 @04:11PM (#15387494)
>or the author of the library for bad design

That's the one. That's a damned stupid decision.

Re:Diminishing returns of static typing by UncleMeat on Monday October 02, 2017 @05:43PM (#15388216)
Yeah and a static type system refuses to let you make such a stupid decision. When interoperating with code I didn't write, knowing that the code is guaranteed to conform to some specification is valuable.
Re:Diminishing returns of static typing by andrewaylett on Monday October 02, 2017 @01:34PM (#15385934)
Why would I write test-cases for something the compiler can catch for me? Yes, I need to write tests for all the correctly-typed cases, but there are a whole class of bugs that I don't need to test for any more because I can't even write the failing case.
Re:Diminishing returns of static typing by crdoconnor on Monday October 02, 2017 @04:23PM (#15387585)
>there are a whole class of bugs that I don't need to test for any more because I can't even write the failing case.

By adding sanity checking asserts in a dynamically typed language you can achieve more or less the same result.

Re:Diminishing returns of static typing by wstrange on Monday October 02, 2017 @04:48PM (#15387809)
If you are going to add a bunch of asserts, why not just use types?
Re:Diminishing returns of static typing by crdoconnor on Monday October 02, 2017 @05:14PM (#15388029)
I don't particularly see the need to extend this approach to every single variable in my code base. I usually just stick it on boundary code.
Re:Diminishing returns of static typing by enraged_camel on Monday October 02, 2017 @01:42PM (#15386009)
You don't write test cases specifically to check types. Your existing cases, if they are robust and thorough, will simulate your runtime and check those for you as a side effect.
Re:Diminishing returns of static typing by andrewaylett on Monday October 02, 2017 @05:12PM (#15388005)
My existing test cases, robust and thorough though they are, only test what happens when I feed in a correctly typed object. Because I can't write a test that exercises my code on an incorrectly typed input: the type system prevents that.
Re:Diminishing returns of static typing by metaphorm on Monday October 02, 2017 @01:49PM (#15386084)
you're already writing the test cases to ensure correct behavior with typical input, and predictable exceptional input. putting in one more assert for predictable exceptional input (wrong type) doesn't really add a noticeable amount of overhead to writing the tests you were already writing.
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @02:52PM (#15386739)
>putting in one more assert for predictable exceptional input (wrong type) doesn't really add a noticeable amount of overhead

Yes. We call that 'typing'.

Re:Diminishing returns of static typing by discreteevent on Monday October 02, 2017 @05:58PM (#15388315)
And it takes less typing (keyboard) than the assert, and you get free documentation inline with the code!
Re:Diminishing returns of static typing by cm2187 on Monday October 02, 2017 @02:30PM (#15386464)
If you have to write a test for every line of code you write, the "chatty" argument against static typing goes away.
Re:Diminishing returns of static typing by senorjazz on Monday October 02, 2017 @03:03PM (#15386845)
and not just that, but for every possible case for the line you can think of. Like the post above, testing the results of a function returns a list for 1 item, or many items...

I see all too often, java bad, just look at how many lines you need to write to get "hello world". Who cares, the IDE generates that for you, but if you don't understand static void main as a beginner... again who cares, just put it in and ignore it until you need to understand it. Also read that dynamic languages are so productive, but they never mention you need to then write tests to detect what the compiler would catch for free. Yes good code needs tests, but the compiler IMO is a damn good built in test suite for catching many classes of errors

Re:Diminishing returns of static typing by Silhouette on Monday October 02, 2017 @04:02PM (#15387421)
Bugs like that should be caught immediately by your test cases. You shouldn't rely on the compiler to catch them for you.

What's wrong with relying on the compiler? Bugs like that will be caught immediately by a good static type system, so you don't have to rely on your test cases to catch them for you.

Relying on a test suite to verify basic properties that could be enforced automatically through a type system means you're only checking some cases instead of all cases. It also means you're cluttering your test suite with boilerplate about language mechanics instead of writing high value tests that verify the real operational behaviour of your system.

There are pros and cons to static vs. dynamic typing in general, but in this particular respect, static typing is strictly more powerful, less verbose and more efficient.

Re:Diminishing returns of static typing by dep_b on Monday October 02, 2017 @01:39PM (#15385985)
Well if you don't need to write that particular test you have more time writing tests that are actually useful, like validating your logic (and dare I say: more fun to write).
Re:Diminishing returns of static typing by AsyncAwait on Monday October 02, 2017 @06:44PM (#15388623)
Having a compiler catch this for you means having to write less test cases.
Re:Diminishing returns of static typing by 201709User on Monday October 02, 2017 @01:28PM (#15385871)
Yes, why do something automatically when you can do manual work!
Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @01:32PM (#15385915)
I think the idea is that you have to write tests anyway.
Re:Diminishing returns of static typing by whyever on Monday October 02, 2017 @01:40PM (#15385992)
No, you don't have to write tests for invariants enforced by the type system.
Re:Diminishing returns of static typing by ubernostrum on Monday October 02, 2017 @02:05PM (#15386254)
I think the bigger idea is that people who've never actually written serious code in a dynamically-typed language assume that people who do always write a bunch of extra unit tests to assert correct types, assert behavior on incorrect types, etc. etc., and that programs crashing due to type errors is a super frequent occurrence.

None of those things are true.

Re:Diminishing returns of static typing by tome on Monday October 02, 2017 @05:01PM (#15387919)
And yet there are dynamic language proponents in this very subthread suggesting that's exactly what everyone should do.
Re:Diminishing returns of static typing by cle on Monday October 02, 2017 @11:35AM (#15384604)
IMO the autocomplete argument is rather unconvincing. Every dynamic language I've worked deeply with has powerful and simple introspection capabilities, and they generally come with much more interactive development environments (shell/REPL), so I've never found API discoverability to be any worse than statically typed languages, just different.

In general though, the more you can formally reason about the program, the more you can automate program transformations (refactoring). Programmers in dynamic languages will argue that the amount of code is far less than the equivalent code in a mainstream statically-typed language, so while the cost of refactoring may be higher per unit, the number of units is less, so the overall cost is the same (or less).

I believe in using the best tool for the job...some use cases would benefit more from static typing, while others would benefit more from using a dynamic language. One of the most important factors is the team and its engineers' backgrounds, preferences, styles, etc.

Re:Diminishing returns of static typing by msla on Monday October 02, 2017 @11:46AM (#15384716)
Yeah, I agree: Two of the languages with the best autocomplete and introspection in general are Common Lisp and Smalltalk. Some of that's simple maturity, but it proves that those features can work very, very well in even the most dynamic languages around.
Re:Diminishing returns of static typing by dahauns on Monday October 02, 2017 @12:16PM (#15385078)
Sorry, but I'd contest that remark, at least for Smalltalk. It only has the best autocomplete/introspection for people who have never worked with modern statically typed languages/IDEs and/or significantly large projects. It just doesn't have the neccessary information.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @11:44AM (#15384697)
Does anyone believe in using the wrong tool for the job?
Re:Diminishing returns of static typing by cle on Monday October 02, 2017 @11:49AM (#15384754)
Yes! Many engineers use tools they like for reasons unrelated to the job they're doing or the product they're building.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @12:25PM (#15385195)
It might still, at least arguably, be "the right tool for the job." If you have a huge team of expert C# developers C# might be "the right tool for the job" even if it would be a little easier to do in a different language, given the same pool of experts in that language.
Re:Diminishing returns of static typing by cle on Monday October 02, 2017 @12:53PM (#15385504)
Agree. My point is that, if I personally dislike C# (I don't), and I'm on a team of C# experts and C# is the best choice for shipping the product given those experts and all the other use cases, then C# is the best tool for the job and I'll peruse C# documentation. I try my best to focus objectively on the product, not my ego or subjective preferences...and I often fail :(.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @02:52PM (#15386742)
I've been writing PHP for a couple months and I've been pleasantly surprised so I feel like I am moving beyond that.
Re:Diminishing returns of static typing by girvo on Monday October 02, 2017 @06:18PM (#15388443)
To be fair, PHP 7.1 with Composer is a very different language to PHP 4, for the better of course.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @06:37PM (#15388575)
Yeah, sure, and I was able to avoid the painful years. But C# pre-generics and pre-Linq is a way less appealing language too, you know? Most languages that are popular now look kind of rough to work in several versions ago.
Re:Diminishing returns of static typing by girvo on Tuesday October 03, 2017 @06:04PM (#15396618)
Oh definitely. I think that’s the case for nearly any language that’s worth the code it’s written in. C++ is an interesting case study in how to do it both right and wrong; we’re spoilt for choice and it keeps getting better every day
Re:Diminishing returns of static typing by 19873287234 on Monday October 02, 2017 @12:04PM (#15384923)
At a place I worked at once, it was "use Microsoft for everything". So yeah.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @12:26PM (#15385201)
Yeah but that's more a matter of the criteria to decide on the right tool. Nobody would say "I intend to use the wrong tool for the job."
Re:Diminishing returns of static typing by vorg on Monday October 02, 2017 @03:23PM (#15387056)
> Nobody would say "I intend to use the wrong tool for the job."

...but there's plenty of sales charlatans out there who will say "I intend to get the manager of that IT dept to make its developers use my tool for the job, and I don't care if my tool is the right one or the wrong one."

Re:Diminishing returns of static typing by disconnected on Monday October 02, 2017 @11:49AM (#15384743)
> Does anyone believe in using the wrong tool for the job?

Yes. PHP developers.

:)

Re:Diminishing returns of static typing by 19873287234 on Monday October 02, 2017 @12:03PM (#15384910)
The thing about magical refactoring though is that it often isn't a good idea. You usually don't just change the name of something, but you change it conceptually. If you just let the ide go and change the name everywhere, you create bugs because you never actually went and made sure the old code was updated for the new concept, rather than just the name.
Re:Diminishing returns of static typing by emodendroket on Monday October 02, 2017 @08:33PM (#15389118)
That's not really true.
Re:Diminishing returns of static typing by a-saleh on Tuesday October 03, 2017 @02:32AM (#15390589)
In my mind, what swayed me towards static typing languages was after I played around with Haskell and was able to use the 'deriving' clause.

The realization that with types, smart enough compiler can implement interfaces for me, was amazing.

Unfortunately, I am afraid that it will take a while for these techniques to go mainstream. A.f.a.i.k most a mainstream language can do, is to fill in the method stubs for you.

Re:Diminishing returns of static typing by drblast on Monday October 02, 2017 @11:49AM (#15384752)
Definitely. Static typing lets you turn the compiler into a hard-working friend that helps you refactor large projects without going insane.

There are no diminishing returns. Defining types is easy and enhances code readability.

Re:Diminishing returns of static typing by cle on Monday October 02, 2017 @11:57AM (#15384822)
Believing that any technology has no cost is poor engineering IMO. There are costs to that rigidity, and they're rather self-evident.
Re:Diminishing returns of static typing by cobbzilla on Monday October 02, 2017 @06:57PM (#15388697)
No one is saying there is no cost. The cost of using static types is (1) you have to think about type info when writing the code and (2) you have to fix compile-time type errors while you are developing. The poster is claiming that, over time, as code bases tend to grow large, this small investment yields increasing (not diminishing) returns; a claim I would agree with.
Re:Diminishing returns of static typing by ridiculous_fish on Monday October 02, 2017 @12:02PM (#15384905)
If you believe there are no diminishing returns, I'm interested to hear your reply to the author's question about why we don't all use Agda or Idris.
Re:Diminishing returns of static typing by Arcsech on Monday October 02, 2017 @12:40PM (#15385349)
Well, the easy answer is that dependently-typed languages like Agda and Idris aren't very mature yet. They're still missing many commonly-needed libraries, compile times are slow, the tooling isn't great, etc etc.

Getting a language to the point where it's workable for serious projects is a lot of work. Rust is getting there with the backing of Mozilla, Haskell has made some decent strides too (but still has a way to go, and I think has some pretty fundamental flaws entirely apart from the type system). It'll be probably another decade at least before we see any dependently-typed languages getting a serious foothold, but I do think they're going to become a lot more common eventually.

Re:Diminishing returns of static typing by catnaroek on Monday October 02, 2017 @01:21PM (#15385823)
It isn't just a matter of tooling. There exist hard limits on how much can be inferred about unannotated programs, and when you go past those limits, the price you have to pay is to embed (partial) proofs of correctness in your own code. For example, think about why GADTs don't play nicely with type inference.

IMO, machine assistance is useful to the extent it relieves us humans from work. In particular, types are useful to the extent they can be inferred. Beyond that, you still need to prove the correctness of your programs on your own, so there is no point to the ceremony of writing down those proofs in a machine-checkable format.

Re:Diminishing returns of static typing by Merovius on Monday October 02, 2017 @04:55PM (#15387883)
> Well, the easy answer is that dependently-typed languages like Agda and Idris aren't very mature yet.

It's also self-evidently wrong. Agda was first released in 1999, ten years before Go. If you use a wallclock interpretation of "maturity", Agda is twice as old as Go and Idris is roughly as old as Go. Both are used significantly less (by several orders of magnitude), though. Despite them having a far stronger type-system.

If you, on the other hand, you are using a "developers' time" interpretation of maturity, on the other hand, you are making a circular argument, i.e. "Agda is seeing less use, because it has been used less", as resources invested in a language ecosystem tend to be strongly correlated with it's usage.

Re:Diminishing returns of static typing by seanwilson on Monday October 02, 2017 @05:47PM (#15388240)
Have you used them? Switching to a language like Agda or Idris is entering the realm of formal verification because the types are so expressive. It's completely different to what most programmers are used to.

Essentially the types being used as so complex the type checker cannot automate the decision about two types being compatible so you have to write maths proofs to help. The types used in mainstream languages are simple enough that the type checker never needs help like that.

The cost of formal verification right now is immense but the benefit is close to bug free code. Mainstream strong statically languages require nowhere near the same amount of effort and give clear benefits over dynamic types.

Re:Diminishing returns of static typing by sacado2 on Monday October 02, 2017 @12:46PM (#15385422)
Defining types is easy and enhances code readability until you go too far. Some type declarations in Haskell or highly templated C++ are hard to read.
Re:Diminishing returns of static typing by Silhouette on Monday October 02, 2017 @02:01PM (#15386208)
While this is a valid point, it's also worth remembering that if you have a data structure of sufficient complexity that writing out its type is cumbersome, then your data is still in that structure whether you choose to be explicit about it or not. Any code reading or modifying some element within that data still needs to correctly find that element, and if writing out the types is a burden then probably finding the correct location every time is also difficult. So if anything, when you have more complicated data structures flying around, and particularly if you work with several similar but different complicated structures, that could make having the types explicit much more useful for ensuring correctness and maintainability.
Re:Diminishing returns of static typing by tome on Monday October 02, 2017 @05:05PM (#15387937)
Absolutely. Sometimes the type is too complex not to be explicit about it.
Re:Diminishing returns of static typing by kronos29296 on Monday October 02, 2017 @01:15PM (#15385759)
Highly templated C++ is the highway to hell. If you haven't heard C++ templates are turing complete and so can also have the halting problem.
Re:Diminishing returns of static typing by 19873287234 on Monday October 02, 2017 @12:06PM (#15384956)
I really don't think it does that. Most refactoring is not like that. It is about changing things at a deeper level than just the type.

I don't think they enhance code readability - I think they make it worse. I never look at the type when I am reading code, it just gets in the way.

Re:Diminishing returns of static typing by matharmin on Monday October 02, 2017 @01:32PM (#15385910)
Semi-automatic refactoring tools is just one part of what a type system enables. A much bigger benefit in my opinion is that it immediately highlights issues in your code while you are refactoring. Basically answer "What do I still need to change to finish the refactoring?". Unit testing also gives you some of this, but is typically much slower - both in execution time, and the additional time it takes to figure out where the issue is.
Re:Diminishing returns of static typing by chr1 on Monday October 02, 2017 @12:43PM (#15385383)
When using languages with static typing amount of refactoring of that type is disproportionately large, so people notice how much the ide helps, without noticing that most of the help wouldn't be even necessary without the complexity added by static types.
Re:Diminishing returns of static typing by christopheml on Monday October 02, 2017 @11:48AM (#15384742)
My main progamming language at the time is Java, and the amount of assistance my IDE provides is astonishing (to the surprise of no one, it's IntelliJ). The confidence strong automatic refactors provide is of great help when managing large codebases.
Re:Diminishing returns of static typing by amirouche on Monday October 02, 2017 @12:41PM (#15385366)
I agree that static typing helps reading comprehension and that IDEs like pycharm help getting into big code bases, that said, at the end of the day, when you know the code both the IDE and static typing are getting in the way. Actually, I never saw anybody as quick as people using simple editors like emacs and vim. GUI is getting in the way of the programmers intent. Static typing is a hindrance in front of refactoring. Unit tests is the only truth that matters, static typing or not.
Re:Diminishing returns of static typing by always_good on Monday October 02, 2017 @01:09PM (#15385698)
You're kinda damning it with faint praise when you say that you can use dynamically typed languages on small projects that fit in your head (and are also probably written by a single developer).

You can pretty much use any language in that scenario. But the chickens come to roost around day 30+ or so.

Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @01:43PM (#15386022)
A large project is a poorly decoupled set of small projects.
Re:Diminishing returns of static typing by orthecreedence on Monday October 02, 2017 @05:18PM (#15388050)
True, once my libraries get bigger than five or six assembly instructions, I tend to break them down to a more manageable size.
Re:Diminishing returns of static typing by always_good on Monday October 02, 2017 @09:19PM (#15389335)
May be.

Meanwhile real-world non-trivial projects tend to be large projects.

Nice to be prepared for that instead of gambling on "surely we'll extract out smaller projects that fall on the right abstraction boundaries in the face of unknown future requirements."

Re:Diminishing returns of static typing by ubernostrum on Monday October 02, 2017 @02:06PM (#15386259)
Personally I'd only use a language like C or C++ or Java for a tiny puny baby child's toy program. They're fundamentally unfit for real-world codebases.
Re:Diminishing returns of static typing by KMag on Monday October 02, 2017 @02:29PM (#15386458)
I'm probably being trolled, but I'll bite.

How big are the "real-world codebases" you're talking about, and how many programmers are working on the code? Once you hit 5-10 million lines of code and/or thousands of developers, static typing really helps manage complexity.

Re:Diminishing returns of static typing by ubernostrum on Tuesday October 03, 2017 @10:56AM (#15392810)
It's more that I get tired of this argument and decided to try to pre-emptively spoil it.
Re:Diminishing returns of static typing by naasking on Monday October 02, 2017 @01:50PM (#15386087)
> Unit tests is the only truth that matters, static typing or not.

Well that's provably false, because there exist properties that you can type check that literally can't be verified via unit tests, even in principle. For instance, race and deadlock freedom.

Re:Diminishing returns of static typing by tome on Monday October 02, 2017 @05:08PM (#15387962)
> Static typing is a hindrance in front of refactoring.

Are you kidding? Python programming's my day job but Haskell is an order of magnitude easier to refactor.

Re:Diminishing returns of static typing by sacado2 on Monday October 02, 2017 @12:43PM (#15385382)
There's not only tooling and reliability. Don't forget performance, too. Knowing at runtime that a memory word represents, for instance, an integer rather than a reference to a struct that contains both a type tag and a reference to the actual value, makes a huge difference. And I'm not even mentioning the inlining possibilities.
Re:Diminishing returns of static typing by petters on Monday October 02, 2017 @01:44PM (#15386042)
This is really true. I was a complete Java newbie and knew some Python when I joined Google. Yet I found working in an unfamiliar Java code base much, much easier here.

Large Python code bases are really hard to understand and work in (here).

Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @11:31AM (#15384573)
Dynamic languages support this kind of tooling too - you can even have seamless data completion (eg. map/dictionary keys). The original Refactoring Browser was written for Smalltalk. Etc.

Of course there are cases where dynamic languages do worse, but it balances out I think.

Re:Diminishing returns of static typing by igouy on Monday October 02, 2017 @12:46PM (#15385416)
> The original Refactoring Browser was written for Smalltalk.

Unless you think original means Bill Opdyke's thesis work, where the tooling was written for C++ and written in CLOS.

http://www.laputan.org/pub/papers/opdyke-thesis.pdf

Re:Diminishing returns of static typing by cm2187 on Monday October 02, 2017 @11:57AM (#15384833)
But how can you offer any refactoring or auto-complete inside a function if you don't know what type to expect as an argument?
Re:Diminishing returns of static typing by actsasbuffoon on Monday October 02, 2017 @12:26PM (#15385211)
You can, but you may start to run into some limitations. Many languages have some version of type inference, which allows them to figure out the type of a thing, even though the programmer didn’t specify it.

C# has a very weak version of this with the auto keyword. Languages like Crystal take it much further by tracing the flow of data through the entire program. It generally works quite well, though there are a few edgecases that require explicit type annotations.

As for auto-completion, some languages feature designs that make it easy to offer auto completion even without type information. For instance, Elixir doesn’t have methods. You only have functions defined on modules, and it’s trivially easy to know what functions are defined on a module.

So it’s possible, but there are some limitations.

Re:Diminishing returns of static typing by TheDong on Monday October 02, 2017 @01:42PM (#15386014)
Type inference goes hand-in-hand with static typing. Those are not opposite things.

> C# .... Crystal

Both are fully statically typed languages with type inference. Those are unrelated to the argument the parent comment is making.

Re:Diminishing returns of static typing by andybak on Monday October 02, 2017 @06:54PM (#15388684)
> Type inference goes hand-in-hand with static typing.

That would imply there's no type inference possible with dynamic languages - either at "compile" time or run time.

(Wouldn't it also imply that static typing and strong typing are synonymous?)

Re:Diminishing returns of static typing by jaggederest on Monday October 02, 2017 @02:34PM (#15386515)
They still both allow generic arguments, in reduction, this means that they still have uncertainty.

I can and have built a totally untyped language within a fully statically typed language - nostrademons' Scheme-in-haskell exercise is a lot of fun.

You just have to define a Universal type and then back out of all that nasty compile-time nonsense. Everything is Univ and Univ is everything.

Re:Diminishing returns of static typing by bjz_ on Monday October 02, 2017 @01:25PM (#15385851)
Yes! If your language allows you to put constraints on those types you can specify what specific types have access to. For example in Rust:

    fn foo<T: Positioned>(x: &T) -> Point {
       x.position()
    }
Note that this doesn't work in languages that use templates for generics, like C++, where templates work more like compile-time duck typing.
Re:Diminishing returns of static typing by cm2187 on Monday October 02, 2017 @02:35PM (#15386527)
But, if I may, you are effectively statically typing your code.
Re:Diminishing returns of static typing by bjz_ on Monday October 02, 2017 @03:00PM (#15386820)
Oh wait, I misread the comment you were responding to. Oops!
Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @12:12PM (#15385031)
In dynamic languages functions aren't typically overloaded by argument type.

For OO languages and methods it does get a little guesswork-y, and tools often offer a wider range of guesses than is correct for completion. But you can show the class along with the offered completion, so it's not too bad.

Re:Diminishing returns of static typing by DavidWoof on Monday October 02, 2017 @12:07PM (#15384961)
If Visual Studio is your example, then you're making the same argument as the author: there's a sweet spot. From the python world, c# may look statically typed, but from the Haskell/Idris point of view, the java/c# type systems look really sloppy and ambiguous.
Re:Diminishing returns of static typing by ruskimalooski on Monday October 02, 2017 @11:37AM (#15384626)
Agreed. Although other comments claim that their dynamically typed languages have this same property, inherently in dynamic languages the auto complete will fail out unless you effective write code as if you were using static types.
Re:Diminishing returns of static typing by gnaritas on Monday October 02, 2017 @11:50AM (#15384763)
I can do all of those things in Smalltalk, which is dynamically typed; these things are not byproducts of static typing, they're simply byproducts of mature tools. So no, these are not arguments in favor of static types.
Re:Diminishing returns of static typing by igouy on Monday October 02, 2017 @12:31PM (#15385255)
>> finding all references to a function <<

Yes, you can find all references to a method in Smalltalk -- but those references are not separated-out from all the references to other methods that happen to have the same method name but are defined on a different class.

With type information for the receiver and method arguments, we can find just the references we're looking for.

Re:Diminishing returns of static typing by gnaritas on Monday October 02, 2017 @04:32PM (#15387681)
Which is why Smalltalk's refactoring browser has a manual intervention step to allow you to see what it proposes to do, and remove any steps you don't agree with, as well as the ability to scope your refactorings to a package or class to limit the scope to more relevant data. Either way, it's sufficient to get 99% of the benefits of automated refactorings without the 100% guarantee static typing provides; good enough for me.

Automated refactoring was invented in Smalltalk, claiming it's a benefit only static typing provides is to not know history.

Re:Diminishing returns of static typing by igouy on Monday October 02, 2017 @04:46PM (#15387789)
> Automated refactoring was invented in Smalltalk, claiming it's a benefit only static typing provides is to not know history.

History: In Bill Opdyke's thesis work, the tooling was written for C++ and written in CLOS.

http://www.laputan.org/pub/papers/opdyke-thesis.pdf

Re:Diminishing returns of static typing by gnaritas on Monday October 02, 2017 @05:29PM (#15388119)
Ralph Johnson, a prominent Smalltalk'er, was advisor on that paper and was the creator of the first Smalltalk refactoring browser and that paper is littered with references to how things are done in Smalltalk. I was unaware a C++ was involved, but I still think Smalltalk had the first commercial refactoring browser. A research paper is not a product, however, thanks for the ref.
Re:Diminishing returns of static typing by igouy on Tuesday October 03, 2017 @10:34AM (#15392660)
Do you think having "the first commercial refactoring browser" is the same as "[a]utomated refactoring was invented in Smalltalk" ;-)

Incidentally, what's your source for "Ralph Johnson… was the creator of the first Smalltalk refactoring browser" ?

Re:Diminishing returns of static typing by gnaritas on Tuesday October 03, 2017 @10:48AM (#15392755)
Don't be a douche, obviously I don't think it's the same hence my comment. And I'm willing to bet, same as you, my source was Google to verify my memory of something I read long ago.
Re:Diminishing returns of static typing by igouy on Tuesday October 03, 2017 @04:39PM (#15395974)
If I'd read it as obvious I wouldn't have made that comment: your name-calling is unhelpful.

We still don't know if you simply confabulated your other claim.

Re:Diminishing returns of static typing by gnaritas on Tuesday October 03, 2017 @09:39PM (#15397679)
I didn't name call, saying don't be something isn't remotely the same as saying you are something. If someone tells you don't be a jerk, they're not calling you a jerk, they're warning you you're nearing that point. We're done, good will has exited the building, there's no point in continuing.
Re:Diminishing returns of static typing by KingMob on Monday October 02, 2017 @01:35PM (#15385948)
I can't speak to Smalltalk, but any namespaced Lisp system can figure out what references what. The key is that the searches happen through the REPL, not grep/ag. So if I tell CIDER to find all instances of a Clojure symbol, it can use the namespace to avoid false positives.
Re:Diminishing returns of static typing by igouy on Monday October 02, 2017 @04:48PM (#15387808)
Are you saying that reduces the number of false positives or are you saying that eliminates false positives?
Re:Diminishing returns of static typing by KingMob on Monday October 09, 2017 @02:12PM (#15436126)
Assuming there's no ambiguity, it can eliminate false positives.
Re:Diminishing returns of static typing by lispm on Monday October 02, 2017 @01:25PM (#15385844)
I can ask my Lisp IDE to find callers for methods based on the sub/class of arguments.
Re:Diminishing returns of static typing by igouy on Monday October 02, 2017 @01:41PM (#15386003)
Does it work better if you use type-specifiers in your code :-)
Re:Diminishing returns of static typing by gwbas1c on Monday October 02, 2017 @01:08PM (#15385686)
Isn't static typing a requirement when writing an algorithm and data structures for "every bit and clock cycle counts" situations? How can a 0-compute overhead for dynamic typing exist in a dynamic typed environment?

I always thought dynamic typing is a feature for situations where the code needs an extreme amount of flexibility to adapt to a wide variety of data; even at the expense of performance.

Re:Diminishing returns of static typing by catnaroek on Monday October 02, 2017 @01:26PM (#15385853)
For optimal performance, the absence of unnecessary dynamic checks is a requirement. The presence of static checks is not, although they are useful for your sanity's sake.
Re:Diminishing returns of static typing by golergka on Monday October 02, 2017 @05:07PM (#15387955)
Dynamic languages can actually be quicker in some cases because of virtual machine optimizations based on how your code actually runs with live data.
Re:Diminishing returns of static typing by fulafel on Monday October 02, 2017 @01:33PM (#15385922)
Advanced compilation techniques can transform (input data, input program) into a statically typed program, so the at the limit the answer is strictly "no". See partial evaluation, futamura projections, etc- or JS JITs for more down to earth stuff (though sidestepping data transformations).
Re:Diminishing returns of static typing by chriswarbo on Monday October 02, 2017 @01:39PM (#15385981)
> Isn't static typing a requirement when writing an algorithm and data structures for "every bit and clock cycle counts" situations?

Not necessarily. The phrase "dynamic language" actually bundles together a lot of related but distinct ideas: some of those add performance overhead, others don't. "Dynamic" features which are most notable for performance overhead are tagged unions and dynamic dispatch.

Imagine a dynamically typed language which provides types like int, bool, list, functions, etc. and we're free to assign (and reassign) any of those values to any variable we like:

    x = 5              # An int
    y = true           # A bool
    y = 3              # An int
    z = square(x + y)  # An int
It's very common to store such values as a tagged union: a "union" meaning that the data could represent an int, or a bool, or whatever, and "tagged" meaning that there's some extra data which tells us which one it is. For example, we might store `5` as a pair of machine words: `1` to indicate that it's an int, and `5` to represent the data. The boolean `true` might be the pair `2` to indicate bool and `1` for the data. And so on.

This tagging adds overhead. We can reduce it in some cases, e.g. using "tagged pointers" where we use some of the bits in a word for the tag and some for the data. But it's still overhead.

However, there's nothing fundamental about using tagged unions. We could just as easily use 'unboxed' values, i.e. store the int `5` as the machine word `5`; the bool `true` as the machine word `1`; etc. There is no overhead, no metadata, etc. Whilst this is a perfectly reasonable implementation strategy, it means that we cannot tell what type a value is intended to have: e.g. if a value is stored as the machine word `1`, we have no way of knowing if that's the boolean `true`, or the integer `1`, or the character `SOH`, or whatever. This would probably lead to very buggy programs, since we have no type checker to enforce correct usage, and (since there's literally no difference between data of different types) we can't even do runtime assertions like `assert(isInt(x))`.

Likewise, many dynamic languages use dynamic dispatch to choose which functions to call based on the type of data we have. In the above example, we might have `x + y` running an integer addition function when `x` and `y` are integers, or a string concatenation function when `x` and `y` are strings, and so on. That's what Python and Javascript both do. Yet, again, there is no fundamental reason to do this! We can have a dynamic language which uses static dispath everywhere: consider that in PHP, `+` is only used for numerical addition, whilst `.` is only used for string concatenation. Dynamic dispatch adds overhead, since we need to chase pointers, etc. whilst static dispatch doesn't. This is simply a question of programmer convenience: do we want every function to have a distinct name, and write them out in full each time?

Note that both of these features: tagged unions and dynamic dispatch, can be used in static languages too. It's just that, historically, they tend to be default (and hence unavoidable) in dynamic languages, and something we must explicitly create in static languages. Hence when we compare static languages to dynamic ones, we tend to compare statements like `x + y` in Python to `x + y` in C, which are actually quite different semantically. A fairer comparison would be to compare `x + y` in Python with `callWith(lookUpSymbolFromType("+", lookUpType(x)), x, y)` in C (I've made up those function names, but the point is that the same functionality is there if we want it, but it will be just as slow as if we'd used Python)

Re:Diminishing returns of static typing by bjz_ on Monday October 02, 2017 @01:18PM (#15385780)
A good static type system will give you the ability to be able to control the level of dynamism in various parts of you code. For example you could create tagged unions to create mini dynamic type systems within parts of your codebase.
Re:Diminishing returns of static typing by tonyg on Monday October 02, 2017 @01:22PM (#15385827)
Not unless you think assembly language or machine code are statically typed.
Re:Diminishing returns of static typing by naasking on Monday October 02, 2017 @01:52PM (#15386103)
Assembly is typed. The types are machine words and usually floating point types are also available. Basically, the machine types are the types of data that the register files can hold.
Re:Diminishing returns of static typing by tom_mellior on Monday October 02, 2017 @05:16PM (#15388040)
That's not a useful notion of type. If I cannot tell statically by inspecting a register name nor dynamically by inspecting a bit pattern whether a given register holds a pointer or an integer or a floating-point value, that's pretty much the definition of "untyped".
Re:Diminishing returns of static typing by naasking on Tuesday October 03, 2017 @12:41AM (#15390203)
Dynamic type testing or introspection is not an essential feature of type systems. The fact is, your computing machine is typed. You can not deference a floating point register as an address, for instance.
Re:Diminishing returns of static typing by tom_mellior on Tuesday October 03, 2017 @02:55AM (#15390679)
> Dynamic type testing or introspection is not an essential feature of type systems.

I didn't say so. An essential feature of type systems is being able to determine the types of (many) values, statically or dynamically.

> You can not deference a floating point register as an address, for instance.

So you'd agree that architectures that don't make a distinction between integer and floating point registers are untyped? But sure, call this a type system if you must. It's just a very very weak one, so weak as to be almost entirely useless. (And the reason floating point registers are often separate from integer registers is not to provide this kind of "type safety", it's due to history and architecture.)

Re:Diminishing returns of static typing by naasking on Tuesday October 03, 2017 @09:38AM (#15392290)
> It's just a very very weak one, so weak as to be almost entirely useless.

Weak and strong aren't meaningful terms. A machine ISA might have an inexpressive type system and/or an unsound type system (because it conflates addresses and integers).

> And the reason floating point registers are often separate from integer registers is not to provide this kind of "type safety", it's due to history and architecture.

No, the reason is performance. And we get performance by making statically known distinctions between datatypes, which is what the original poster asked about.

Intermingling the integer and floating point circuitry so they access the same register file would never improve performance over keeping them separate. You'd need longer wires to place them both near the same register files to minimize signal latency, an the added signal delay alone ensures lower performance.

Re:Diminishing returns of static typing by tom_mellior on Tuesday October 03, 2017 @04:02PM (#15395646)
>> It's for architectural reasons.

> No, it's for architectural reasons.

You win, I guess?

Re:Diminishing returns of static typing by naasking on Tuesday October 03, 2017 @09:51PM (#15397725)
I'm not sure who you're quoting, but I never even used the word "architecture". I don't even know what that's supposed to mean.
Re:Diminishing returns of static typing by tom_mellior on Wednesday October 04, 2017 @12:59AM (#15398354)
You try to explain CPU architecture to me, then claim you don't know what CPU architecture is? OK, maybe you don't win, in any case I'll stop here.
Re:Diminishing returns of static typing by naasking on Thursday October 05, 2017 @11:33AM (#15409994)
"Architectural reasons" is nonsense. "Architecture" isn't a set of reasons justifying anything, rather it's the other way around: we design architecture for specific reasons. Your claims that we do things for "architectural reasons" don't have any clear meaning. I said the actual reasons are performance. I don't think I'm the one being unclear.
Re:Diminishing returns of static typing by tonyg on Monday October 02, 2017 @02:45PM (#15386654)
Yep. You can, of course, make a similar argument for Scheme. But you don't get a very interesting type system out of it.

Perhaps I should have written "... nontrivially statically typed."

Re:Diminishing returns of static typing by naasking on Monday October 02, 2017 @02:50PM (#15386709)
Sure, but to bring it back to the original question, the fact that you can trivially distinguish floating point from word types already means statically typed languages are easier to optimize than dynamically typed languages for numerical programs.

And there are all sorts of optimizations like this that simply aren't available to dynamically typed languages. Tracing JIT can only take you so far.

Re:Diminishing returns of static typing by tonyg on Monday October 02, 2017 @02:55PM (#15386759)
OK, but that wasn't the original question.

(There are also all sorts of optimizations that can't be done statically, so I guess there's that.)

Re:Diminishing returns of static typing by naasking on Monday October 02, 2017 @03:15PM (#15386972)
The original question asked whether static typing is needed when maximal performance is required. If we understand "maximal" to mean literally, "no more performance can possibly be squeezed out", then it simply is. Static typing might not be sufficient for this case, but it is necessary.
Re:Diminishing returns of static typing by tonyg on Tuesday October 03, 2017 @06:43AM (#15391454)
I think those few, crucial pieces of hand-written assembly language one sees from time to time disagree with you. (Modulo your observation that assembly languages are trivially statically typed.)
Re:Diminishing returns of static typing by naasking on Tuesday October 03, 2017 @09:39AM (#15392295)
> I think those few, crucial pieces of hand-written assembly language one sees from time to time disagree with you.

I still don't think so. For example, plenty of silicon is spent on branch predictors simply because addresses and integers aren't distinguished, in general, thus permitting more expressive but costlier code.

Execution would be much faster if integers and addresses were forced to be distinct. Static typing pretty much always improves performance.

Re:Diminishing returns of static typing by taeric on Monday October 02, 2017 @11:29AM (#15384555)
Live coding environments are amazing at this, as well. Often without the need for as extensive static typing, since it can just use reflection.

This isn't to say that static typing isn't good at this. Just, even with that, there is a lot of effort that goes into making the rich tooling. A lot of very smart and capable folks work hard to make Visual Studio.

Re:Diminishing returns of static typing by 19873287234 on Monday October 02, 2017 @12:00PM (#15384868)
>Tooling is another major argument.

vscode seems to figure out the types in javascript without any static typing.

>But it is great for refactoring

Searching for strings isn't that much worse. Also, when it comes to web development, you cross into the client-side and suddenly you can't refactor. So you can only refactor the server-side and end up with a mismatch.

>finding all references to a function or a property or navigating through the code at design time

You can do that without static typing in many cases as well.

>Basically all the features visual studio excels at for .net languages.

When I was working in c# on the server and javascript on the client, I really hated having to go back into c#.

>telling you through a drop down what other options are available from there

vscode seems to be able to figure this out most of the time as well.

I think static typing is necessary when you need performance because all of the fast languages are statically typed.

I think a lot of these things are about organisational complexity and making sure new and average programmers don't screw up the software. It is about large companies trying to manage their organisation, it isn't about the complexity of the code itself.

There are a ridiculous amount of tech companies that have used dynamic languages to go from nothing to the biggest companies in the world and only switched to static languages well and truly after that occurred.

Re:Diminishing returns of static typing by matharmin on Monday October 02, 2017 @01:17PM (#15385772)
> vscode seems to figure out the types in javascript without any static typing.

It is actually using TypeScript's engine for this. It uses TypeScript's type definitions where it is available (e.g. most popular libraries and built-ins), and some inference rules where it has to work with plain JavaScript.

While this does give you decent auto-complete in a lot of cases (and still getting better), it's not quite as good as using TypeScript directly.

> Searching for strings isn't that much worse.

I'm busy with a large refactoring project, and TypeScript has been amazing for this. After restructuring code, you can just keep on fixing things until there's no more red. This is not just about reducing bugs - it removes almost any thinking/mental overhead required for the refactoring process.

> Also, when it comes to web development, you cross into the client-side and suddenly you can't refactor. So you can only refactor the server-side and end up with a mismatch.

TypeScript also works very well for client-side. Of course, if you change the API between the client and server, that's a different story.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @12:24PM (#15385180)
>vscode seems to figure out the types in javascript without any static typing.

There are limits to type inference. And if you're going to rely on type inference to prevent runtime bugs you might as well double-down on static typing since you're giving up on some of the 'features' (insanity) of dynamic languages anyway.

Dart 2.0 now mandates strict typing but will allow you syntactic shortcuts as long as the compiler can infer the type (if it can't, you get a compile-time error) - that's a great compromise. I wish more people would love Dart. It's such a great, well-designed, language.

>Searching for strings isn't that much worse.

There are very real limits with what you can do with 'strings'. And yes, it is that much worse.

>When I was working in c# on the server and javascript on the client, I really hated having to go back into c#.

I do not understand that view. You are an alien to me. C# is a beautiful language that fixes a lot of syntactic problems in Java. It is much more pleasurable to write C# code than JS code (outside of dinky 50 line programs).

>I think static typing is necessary when you need performance because all of the fast languages are statically typed.

That's not the only reason but it is one of them. JIT and AOT compilers can do more with strongly typed code.

>There are a ridiculous amount of tech companies that have used dynamic languages to go from nothing to the biggest companies in the world and only switched to static languages well and truly after that occurred.

Sure. PHP (pre-5) and JavaScript made a ton of money for a ton of people. Both languages were integral in the Web revolution. Doesn't change the fact that PHP was a terrible language and JavaScript is still a terrible language.

Re:Diminishing returns of static typing by valuearb on Monday October 02, 2017 @12:51PM (#15385485)
The vast majority of development time is spent finding and fixing bugs. Small startups got huge often because they hit the sweet spot of features before anyone else, not because their code was high quality. Once they get large installed bases (and large valuations) they get religion about the value of more strict typing.

The unknowable question is, would they have hit that sweet spot anyways by engineering their product more rigorously, and had less pain later? Or would it have impeded them in the exploratory phase of writing and rewriting their code until they hit that spot?

Re:Diminishing returns of static typing by cwyers on Monday October 02, 2017 @12:14PM (#15385053)
> vscode seems to figure out the types in javascript without any static typing.

Doesn't it do this by treating Javascript as a statically-typed language (Typescript) and using type inference?

Re:Diminishing returns of static typing by 19873287234 on Monday October 02, 2017 @12:17PM (#15385085)
No it works without using typescript. I just figures it out through... I have never thought about it. I mean, var p = new Cat();. I am sure it can find the cat definition easy and read the properties and so on. It probably can't prove things 100% but it can guess very well at what things are.
Re:Diminishing returns of static typing by cwyers on Monday October 02, 2017 @12:59PM (#15385581)
> I just figures it out through... I have never thought about it.

https://github.com/Microsoft/TypeScript/wiki/JavaScript-Lang...

> Visual Studio 2017 provides a powerful JavaScript editing experience right out of the box. Powered by a TypeScript based language service, Visual Studio delivers richer IntelliSense, support for modern JavaScript features, and improved productivity features such as Go to Definition, refactoring, and more.

It works off Typescript type annotations for packages and the Typescript compiler's type inference. VS Code's Javascript editing does not seem to be evidence for tooling around dynamic languages so much as it's evidence that if you have a lot of money and Anders Hejlsberg you can write a compiler for a statically typed language with type inference that looks like a specific dynamic language.

Re:Diminishing returns of static typing by DanRosenwasser on Monday October 02, 2017 @01:09PM (#15385694)
Our team (TypeScript) powers this experience.
Re:Diminishing returns of static typing by FLUX-YOU on Monday October 02, 2017 @12:49PM (#15385464)
>I just figures it out through... I have never thought about it.

Are there not definitions written by someone or a tool that vscode looks at?

That is what I saw using some npm packages with typescript: http://definitelytyped.org/

Re:Diminishing returns of static typing by yawaramin on Tuesday October 03, 2017 @12:26AM (#15390146)
> There are a ridiculous amount of tech companies that have used dynamic languages to go from nothing to the biggest companies in the world and only switched to static languages well and truly after that occurred.

This is a biased sample though. You're saying 'ridiculous number', but the truth is most startups (using static or dynamic languages) fail and we don't actually know if their language choice had much impact on their success or failure.

Re:Diminishing returns of static typing by walshemj on Monday October 02, 2017 @01:03PM (#15385630)
Also the article does not take into account the much higher cost fixing a bug in live compared to development
Re:Diminishing returns of static typing by Merovius on Monday October 02, 2017 @05:14PM (#15388025)
It does (though admittedly not very explicitly), it just rolls it into the "benefit" (i.e. not shipping broken code is a benefit) and the "weight given to stability". If a bug discovered in prod (or even qa/canary) has a significantly higher cost than a bug discovered early, that will influence the weight you are putting on stability. In that way, this factor is subsumed in one of the other graphs.

As you might've noticed, I have been intentionally light on the details and only talked pretty abstractly about the specific scales and factors involved.

Re:Diminishing returns of static typing by walshemj on Monday October 02, 2017 @06:40PM (#15388594)
Ty I take the point and it depends on the sort of project your working on a celphone app is different to say a major telcos billing system.
Re:Diminishing returns of static typing by kuon on Monday October 02, 2017 @06:00PM (#15388329)
I have been doing some elm, and refactoring is a MAJOR bonus. You can refactor your entire project, and when it compiles it usually works. It's funny how dynamic languages are seen as beginner friendly, while in reality they are not (ruby, js, python...).
Re:Diminishing returns of static typing by yogthos on Monday October 02, 2017 @05:53PM (#15388279)
A lot of the same refactoring is possible in dynamic languages as in static ones. I recommend reading up on Term to see what's possible to do with JavaScript http://marijnhaverbeke.nl/blog/tern.html

I use Cursive https://cursive-ide.com/ for working with Clojure, and it can do safe refactoring for symbols by doing static analysis of the source. It can show all usages of a symbol, rename it, do automatic imports, and so on.

Another piece of tooling that's not available in any statically typed languages at the moment is REPL integration with the editor seen here http://vvvvalvalval.github.io/posts/what-makes-a-good-repl.h...

I find that the REPL driven workflow found in Lisps is simply unmatched. When you have tight integration between the editor and the application runtime, you can run any code you write within the context of the application immediately. This means that you never have to keep a lot of context in your head when you're working with the application. You always know what the code is doing because you can always run and inspect it.

Having the runtime available during development gives you feedback much faster than the compile/run cycle. I write a function, and I can run it immediately within the context of my application. I can see exactly what it's doing and why.

The main cost of static typing is that it restricts the ways you can express yourself. You're limited to the set of statements that can be verified by the type checker. This is necessarily a subset of all valid statements you could make in a dynamic language.

Finally, dynamic languages use different approaches to provide specification that have different trade offs from static typing. For example, Clojure has Spec that's used to provide runtime contracts. Just like static typing, Spec provides a specification for what the function should be doing, and it can be used to help guide the solution as seen here https://www.anthony-galea.com/blog/post/hello-parking-garage...

Spec also allows trivially specifying properties that are either difficult or impossible to encode using most type systems. Consider the sort function as an example. The constraints I care about are the following: I want to know that the elements are in their sorted order, and that the same elements that were passed in as arguments are returned as the result.

Typing it to demonstrate semantic correctness is impossible using most type systems. However, I can trivially do a runtime verification for it using Spec:

    (s/def ::sortable (s/coll-of number?))

    (s/def ::sorted #(or (empty? %) (apply <= %)))

    (s/fdef mysort
            :args (s/cat :s ::sortable)
            :ret  ::sorted
            :fn   (fn [{:keys [args ret]}]
                    (and (= (count ret)
                            (-> args :s count))
                         (empty?
                          (difference
                           (-> args :s set)
                           (set ret))))))
The above code ensures that the function is doing exactly what was intended and provides me with a useful specification. Just like types I can use Spec to derive the solution, but unlike types I don't have to fight with it when I'm still not sure what the shape of the solution is going to be.
Re:Diminishing returns of static typing by rbobrowicz on Monday October 02, 2017 @08:11PM (#15389022)
For someone only passingly familiar with Spec, what's the benefit of Spec over just using a property based testing framework like Haskell's QuickCheck (and I think Clojure's test.check)?

I can encode all those invariants as QuickCheck properties and have them automatically tested against random inputs on every test run. It's still all runtime verification, but with random inputs I actually have more confidence of hitting a corner case than with just asserting during regular program runs or hand written example tests.

Also, with enough heavy lifting you can actually encode all of that in the types in a dependantly typed language like Idris [1]. And while a machine checked proof of your sorting algorithm is nice, it might be hitting the diminishing returns point the article mentions over just using property tests.

[1] https://github.com/davidfstr/idris-insertion-sort

Re:Diminishing returns of static typing by sheepmullet on Monday October 02, 2017 @09:44PM (#15389452)
Think of QuickCheck/test.check but with better integration into the language.

This makes it much more likely to be used but it's fundamentally the same set of ideas.

A really cool idea I'm playing with at the moment is using fuzzing/static analysis based generators to feed spec/test.check.

I think it will help get past the, imo, biggest issue with generators in that they can miss exceptional cases in the code.

E.g. If (x=="jack and Jill) {exceptional case} is unlikely to be triggered with standard generators but "easy" for static analysis tools to solve.

> Also, with enough heavy lifting you can actually encode all of that in the types in a dependantly typed language like Idris [1]

In theory. In practice it is multiple orders of magnitude harder to prove properties in Idris than it is to spec them using property based testing.

Re:Diminishing returns of static typing by yogthos on Tuesday October 03, 2017 @09:29AM (#15392232)
To add to what sheepmullet said, I think the insertion sort example is exactly the problem with advanced type systems. It takes nearly 300 lines of code to provide the specification.

Somebody has to be able to read that specification and understand that it's correct in a semantic sense. Ultimately, the specification itself becomes a full blown program that the type checker executes. So, now you run a program to try and verify aspects of your original program, but how do you verify that the specification itself is correct?

At some point a human has to be able to read the code and decide that it matches the intent. This step can't be automated, and I certainly don't think the Idris example improves things. I'd argue that it's far easier to tell that this version is correct:

    fun insertionSort(arr, int n)
    {
       var i, key, j;
       for (i = 1; i < n; i++)
       {
           key = arr[i];
           j = i-1;
           while (j >= 0 && arr[j] > key)
           {
               arr[j+1] = arr[j];
               j = j-1;
           }
           arr[j+1] = key;
       }
    }