News for hackers. Stuff that matters.
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