News for hackers. Stuff that matters.
Re:Yes, Python is Slow, and I Don’t Care by dom96 on Friday September 08, 2017 @09:00AM (#15199797)
The fact that Python is slow isn't its only problem. What I care more about nowadays is wasting my time hunting bugs that could have been avoided by a static type system.
Re:Yes, Python is Slow, and I Don’t Care by autokad on Friday September 08, 2017 @09:27AM (#15199967)
I see this stated as if its a universal fact, but it really true that static types reduce over-all bug density?

I myself have found this to not be true, and I have found the same in reading / talking to others. However, if you have found a resource that has data on the contrary, I would find it very interesting to read.

https://medium.com/javascript-scene/the-shocking-secret-abou...

Re:Yes, Python is Slow, and I Don’t Care by contravariant on Friday September 08, 2017 @09:58AM (#15200164)
A static type system doesn't protect you from choosing the wrong abstraction, and all the bugs that result from it. But if used properly I think it does help.
Re:Yes, Python is Slow, and I Don’t Care by traverseda on Friday September 08, 2017 @11:07AM (#15200751)
How? I don't think I've ever gotten a type I wasn't expecting in any of my python code. It's just not a problem for me.

That is, past the first time I run it. I've been known to pass something an x when it wanted a y, but that's a "fail early, fail loud" bug and not an actual problem.

Re:Yes, Python is Slow, and I Don’t Care by everheardofc on Friday September 08, 2017 @05:45PM (#15204172)
Unfortunately in my experience I don't know what type of x I'm supposed pass into to. I either have to guess what x is out of a infinite search space or I have to look at the implementation but unfortunately it also calls some other functions so I need to determine the possible inputs for that function and repeat this until I've read 100s of lines of code just to use a single function because someone thought that documentation is uneccessary and 10 seconds of less typing were worth the tradeoff. Static typing is statically enforced documentation. Sure you might be lucky and already have voluntary documentation available but I am not. I'm getting sick of randomly being stuck for 10 hours on some trivial problem caused by wrong incentives.
Re:Yes, Python is Slow, and I Don’t Care by contravariant on Friday September 08, 2017 @02:42PM (#15202900)
This just means that you already have an idea of what kind of object should go where, you just never wrote it down. And because you never wrote it down it becomes hard to generalise things when you eventually want to reuse some method, since you never made explicit which operations an object should support to be able to reuse that method.

Also you have no guarantee that what you think the types should be is actually consistent.

Re:Yes, Python is Slow, and I Don’t Care by newen on Friday September 08, 2017 @02:07PM (#15202564)
Well the obvious problem is that you have to test all of the code paths before deciding that your code is type safe. Static types do not have that problem.
Re:Yes, Python is Slow, and I Don’t Care by nerdwaller on Friday September 08, 2017 @09:22AM (#15199945)
Have you checked out MyPy and the optional type hinting? I've been going that route in my python recently and been liking the both/and of having an optional type checker.
Re:Yes, Python is Slow, and I Don’t Care by dom96 on Friday September 08, 2017 @09:29AM (#15199981)
I have, and I do like that Python is heading in this direction. But this feature does still feel half-baked to me, the error messages are often confusing and I do recall running into a few bugs along the way. I'm also not certain that the type hinting will ever be 100%, the dynamic nature of Python seems to prevent that. This could end up giving some people a false sense of correctness.
Re:Yes, Python is Slow, and I Don’t Care by nerdwaller on Friday September 08, 2017 @01:19PM (#15202134)
The _getting started_ part could certainly be a bit smoother, I have had a few issues as well. Generally speaking I think for in-house things you can probably alleviate a bit of the possible dynamic issues that you mention - just by discouraging too much meta-ness.
Re:Yes, Python is Slow, and I Don’t Care by ageofwant on Friday September 08, 2017 @09:23AM (#15199951)
You only pay the the price while debugging. In your static language you pay the price continually. You are wasting orders of magnitude more time fighting your language's type system every day, you have to read reams of boilerplate code that are unrelated to the problem at hand, each extra line increases the attack surface and complexity of your code.
Re:Yes, Python is Slow, and I Don’t Care by carlmr on Friday September 08, 2017 @09:55AM (#15200138)
>You are wasting orders of magnitude more time fighting your language's type system every day

I program C# a lot, I never fight the type system. It helps me. It tells me while coding that something is wrong. In Python I'll catch this as well...eventually, when I run the code. A type error in C# would be a runtime error in Python. That's very inconvenient.

The static types are also documentation showing intent. It's hard to read old dynamically typed code bases, because I have to do the type processing in my head to understand what is what. Much simpler if I have nicely defined interfaces.

Re:Yes, Python is Slow, and I Don’t Care by cup-of-tea on Friday September 08, 2017 @10:55AM (#15200639)
When I write a new function in Python I immediately evaluate it in a running REPL and test it. There's no eventually about it. A function either works or it doesn't.
Re:Yes, Python is Slow, and I Don’t Care by christophilus on Friday September 08, 2017 @09:33AM (#15200001)
Having worked in both dynamic and statically typed systems, I don't think this is true. A good statically typed language doesn't get in your way very often, and it doesn't produce any more boilerplate than doc comments do in dynamic languages. You do write doc comments, right?

In fact, I'd say that most of the time, a good statically typed language does the opposite of get in your way. It helps you w/ refactoring tools, better intellisense and editor help, self-documentation, etc. The older a codebase gets, the more helpful a static type system is.

That said, there are statically typed languages which produce a ton of boilerplate (Java used to, at least), and there are those that don't (F# comes to mind).

The only dynamically typed language I've used where I didn't regularly miss static typing is Clojure. (Elixir may fit the bill, but the jury's still out on that.)

Re:Yes, Python is Slow, and I Don’t Care by asah on Friday September 08, 2017 @09:38AM (#15200030)
This.

Let me add a radical point: static typing is often thrown out anyway, when you encode your data as strings, serialize/marshal it, create polymorphic lists and hierarchical data structures, etc etc

Meanwhile, disciplined use of python is perfectly easy to get right: - use pylint - be ruthlessly consistent in naming classes, methods and variables (which pylint helps btw,) - for large projects, consider mypy etc

Re:Yes, Python is Slow, and I Don’t Care by contravariant on Friday September 08, 2017 @09:56AM (#15200147)
If you're working in a statically typed language and cast everything to string / object you deserve all the bugs you get.
Re:Yes, Python is Slow, and I Don’t Care by gipp on Friday September 08, 2017 @09:18AM (#15199920)
Mypy / the PyCharm typechecker have come a long way. It's not the same, of course, but you can get a good bit of mileage out of the new gradual typing system these days.
Re:Yes, Python is Slow, and I Don’t Care by blumomo on Friday September 08, 2017 @09:07AM (#15199843)
Please tell me, do you write tests? I've learned that it's necessary. I do 100% code coverage and I'm enjoying TDD a lot.
Re:Yes, Python is Slow, and I Don’t Care by virmundi on Friday September 08, 2017 @09:12AM (#15199884)
The whole point of static type systems is that they give you the "type tests". 100% code coverage just to get what the compiler would give you is a waste of time. If python is supposed make developers more productive, this is just dragging them down.
Re:Yes, Python is Slow, and I Don’t Care by vog on Friday September 08, 2017 @09:34AM (#15200007)
If you haven't already tried, I recommend to port [1] a Python program to OCaml, F# or Haskell.

There are so many tests you can throw away, so many corner cases you don't need to test anymore. (I'm talking about tests that you can't even write down without getting a compiler error.) Not to mention the assertions within your functions that aren't needed anymore.

And those little type annotations are so much simpler and easier to write down than corresponding tests.

If you really head for 100% testing, not just code coverage, but also all corner cases, you will love the modern static type systems. (However, you should really use an ML type system, because doing the same with Java or C++ is cumbersome and not much fun.)

[1] I did so for my mathematics diploma thesis, starting implementing my formalism in Python, having lots of trouble when refactoring, then moving all code to OCaml and then being able to refactor the code alongside the developing formalism in the thesis.

Re:Yes, Python is Slow, and I Don’t Care by VT_Drew on Friday September 08, 2017 @09:39AM (#15200043)
>I'm enjoying TDD a lot

Meh, test are great in so far as they can help you not break things if you upgrade the framework, or langauge in the future. But other than that I have to agree with Kent Beck's sentiment of "I get paid for code that works, not for tests".

https://istacee.wordpress.com/2013/09/18/kent-beck-i-get-pai...

If I had started out trying to learn Django using TDD as in this tutorial:

http://chimera.labs.oreilly.com/books/1234000000754/index.ht...

I never would have learned Django. I would have given up with the ridiculous slow progress of results and functionality.

Re:Yes, Python is Slow, and I Don’t Care by adwn on Friday September 08, 2017 @09:15AM (#15199895)
Time/cost to locate and fix a bug: at compile time < in unit test < in integration test < in production.

Besides, tests cannot find all the bugs a good static type system can find, and vice versa. Tests, even at 100% coverage, are not a complete substitute.

Re:Yes, Python is Slow, and I Don’t Care by jsd1982 on Friday September 08, 2017 @09:41AM (#15200053)
100% coverage is meaningless with respect to correctness and the ability to prove facts about your code. 100% coverage only means that you've been able to exercise all relevant lines of code at least once, not that you've tested all possible execution paths through the code.

The idea that you could somehow replace the utility of static type checking with a suite of human written tests is laughable. Static typing systems allow you to prove facts about your code which make reasoning about correctness much easier than with dynamic type systems which practically disallow this (unless gradual typing is allowed in your language).

Re:Yes, Python is Slow, and I Don’t Care by flogic on Friday September 08, 2017 @10:56AM (#15200647)
Static types and tests check different things. Tests are for making things function as desired. Types are for making sure they actually connect sensibly where desired. Sometimes you can use them for the other purposes though that often produces ugly tests/types.