News for hackers. Stuff that matters.
Re:Why Is Python Growing So Quickly? by monkmartinez on Thursday September 14, 2017 @12:28PM (#15249577)
> Why Is Python Growing So Quickly?

Really easy to answer: It is stupid fun to program with Python. There are libraries for everything you can imagine and they are generally very easy to use. Once you grok the virtual environment thing, writing apps/programs/scripts is just a matter of creating a new env and installing the libs you need. Testing ideas with Jupyter notebook is fun, fast and rewarding. Pycharm is awesome. VSCode with Python just works. You can automate tons of boring stuff (Thanks Al!)... and the list goes on... and on...

Re:Why Is Python Growing So Quickly? by rpazyaquian on Thursday September 14, 2017 @12:37PM (#15249682)
You're listing off tooling, libraries, and frameworks written with or targeting Python, which isn't Python itself. As soon as you want to go off the rails in any of those things, Python gets as complicated as any other language.

My take on the matter is that Python is gaining traction due to its market share of the Data Science/Machine Learning field, which is what's really gaining traction and growing quickly. Had Perl or Ruby been the premier language to use for DS/ML, they would be growing instead of Python.

Re:Why Is Python Growing So Quickly? by andrewflnr on Thursday September 14, 2017 @12:52PM (#15249879)
Come on, we all know a language and its library ecosystem go hand in hand. Trying to separate them from the standpoint of adoption is pointless. TFA comes to its conclusion by looking at libraries. In your hypothetical where Perl or Ruby take Python's place, that would manifest as Perl or Ruby having better data science libraries. The causality would probably be just as cyclical as it is for any "best language/library for task X" question.
Re:Why Is Python Growing So Quickly? by schneems on Thursday September 14, 2017 @12:46PM (#15249803)
This. Most schools are moving away from C or Java being their primary language. Most comp sci professors acknowledge the usefulness of a scripting language and so when they need to pick one, they pick one they have the most familiarity with. Due to numpy and scipy this tends to be Python over Ruby.

Also many things about python that I don't like such as `len` being a function rather than a method on a list are very trivial when coming from a language like C which has hordes of tiny inconsistencies.

The whitespace thing in python is pretty gimmicky but does also hold a certain amount of pedantic appeal.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @01:41PM (#15250432)
The Python design FAQ explains why Len is a built-in function instead of a method. Guido wanted a guarantee that whenever he called it, it'd return a whole number. As just another method, you might find a new type that defines a length in fractional terms, which would break any code wanting to use that as a list index, etc.
Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @02:42PM (#15251126)
But that would be on your for misusing the length method. All the built-in and popular libraries would still define length properly.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @07:09PM (#15253234)
Perhaps, but "your" mistake might impede the popularity of the language. A wide range of well-designed community libraries are a major reason to choose Python.

Take a look at the design rationale for the new __matmul__ magic method. It's not for the standard library, it's for the community.

Re:Why Is Python Growing So Quickly? by antonvs on Thursday September 14, 2017 @03:51PM (#15251906)
The need to do that reveals a couple of weaknesses (or more charitably, tradeoffs) of Python: lack of type constraints, and (related) lack of well-defined, invariant interfaces on objects.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:17PM (#15252946)
Trade-offs indeed. Magic methods indicate the use of interfaces defined by traits rather than formal types. Duck Typing. It's flexible.

But you can also see that Guido has been into types lately. He's been pushing the development of mypy and the new optional type system.

Re:Why Is Python Growing So Quickly? by dom0 on Thursday September 14, 2017 @02:05PM (#15250734)
Ruby is just used rarely outside RoR, realistically speaking.
Re:Why Is Python Growing So Quickly? by trcollinson on Thursday September 14, 2017 @03:09PM (#15251456)
Actually, you should qualify that a bit more. Ruby is rarely used outside of Ruby on Rails in North America. In Japan, it is widely used and Ruby on Rails is fair less common.
Re:Why Is Python Growing So Quickly? by ksec on Thursday September 14, 2017 @03:14PM (#15251526)
What were Ruby used for in japan?
Re:Why Is Python Growing So Quickly? by trcollinson on Friday September 15, 2017 @12:04AM (#15254542)
Ruby is a very versatile language in its own right. While the other poster is correct that it is used for anything that perl and python are used for it's also taking a large chunk from the Java and C# crowd in Japan. Everything from server side applications to command line tools and even GUI based desktop applications can be written in Ruby. Using FFI I have made some quite amazing applications with Ruby.

Rails is amazing and I personally love it. But it's not the only thing Ruby is good for.

Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @04:08PM (#15252036)
Probably anything that Perl and Python are used for.
Re:Why Is Python Growing So Quickly? by rpazyaquian on Thursday September 14, 2017 @03:12PM (#15251503)
Well, true, you have a point. Ruby is rarely used outside of Rails. Which is a shame, really.
Re:Why Is Python Growing So Quickly? by schneems on Thursday September 14, 2017 @04:09PM (#15252048)
Go to Japan.
Re:Why Is Python Growing So Quickly? by submeta on Thursday September 14, 2017 @02:33PM (#15251032)
Whitespace is no issue with a good editor (Sublime, vim, emacs...).

I dislike the many inconsistencies in Python. You mentioned one. Others: sort vs sorted (destructive vs non destructive). Also: not being able to chain methods because many don't return a value. (Scheme, Elixir or even Ruby are imho much more elegant.)

But all in all Python is a very useful programming language with a rich eco system.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:41PM (#15253086)
The Python design FAQ explains that .append and .sort return None to remind you they are mutation methods. I find this more elegant than Ruby, etc., where many things look like pure functions but aren't.

https://docs.python.org/2/faq/design.html#why-doesn-t-list-s...

Re:Why Is Python Growing So Quickly? by submeta on Friday September 15, 2017 @04:07PM (#15260338)
I know the reasons why and how mutating methods work in Python.

Nevertheless I find this here much more elegant:

data.sort.tail.first # or this data.append(7).append(3)

More elegant than this:

sorted(data)[1:][0]

data.append(7) # and then

data.append(3)

I love method chaining in Elixir or Javascript. In Python I have to create temp variables here and there to capture / further process intermediate results.

Having said that: Python has it's strengths. I use it more than any other programming language.

Re:Why Is Python Growing So Quickly? by xapata on Friday September 15, 2017 @06:28PM (#15261333)
I understand the preference and the difficulty created by methods and operators that are essentially statements instead of expressions. However, when making that criticism we should also acknowledge the benefit of requiring or encouraging multiple lines for those actions.

    if (x=42) {}
Has burned many people. Append having a useful return is comparable, though probably not as much of a trap.

> sorted(data)[1:][0]

I don't want to get into the weeds, but shouldn't that just be

    sorted(data)[1]
Or if you like unpacking for clarity

    first, second = sorted(data)[:2]

?
Re:Why Is Python Growing So Quickly? by kbenson on Thursday September 14, 2017 @01:10PM (#15250076)
> Had Perl or Ruby been the premier language to use for DS/ML, they would be growing instead of Python.

Well Perl was the premiere data science language for a while. Python made inroads and eventually took over. I think you're mostly right through, it's just a matter of other factors affecting the communities at the time causing Perl to not grow nearly as quick as Python, and Python getting a good numeric library. Had Perl not lost a lot of community in the early 2000's, it might have retained this area.

Re:Why Is Python Growing So Quickly? by cutler on Thursday September 14, 2017 @01:47PM (#15250512)
Perl just lost the plot. I think BioPerl was ahead of the game before the Python scientific libraries stole the show so they only have themselves to blame. Perl's successor Ruby seems to be headed in the same direction by failing to diversify which is a shame because Ruby is much better language than Python.
Re:Why Is Python Growing So Quickly? by empath75 on Thursday September 14, 2017 @12:48PM (#15249818)
You still have to explain why python is the premier language for that.
Re:Why Is Python Growing So Quickly? by pletnes on Thursday September 14, 2017 @01:09PM (#15250072)
Libraries. And to build them you need certain language features. 2 big ones: complex numbers and operator overloading. The lack of these meant that everyone doing simulation and data analysis skipped Java altogether.
Re:Why Is Python Growing So Quickly? by msla on Thursday September 14, 2017 @01:05PM (#15250023)
The reason C is so popular is because it's the scripting language of Unix. C++ is the scripting language of Windows. Objective-C, Macs and iOS.

Well, Python is the scripting language of a ton of useful libraries which are relevant to a lot of very interesting fields.

R sits in a similar spot, but Python is a better, friendlier language, which means actual programmers are more apt to recommend it as an offhand solution to a simple problem someone who isn't seen as a programmer is having: "Oh, that's easy. Just copy and paste this Python code, and maybe hack at it until it does something." You can get scientists programming with recommendations like that.

Re:Why Is Python Growing So Quickly? by SimbaOnSteroids on Thursday September 14, 2017 @02:06PM (#15250740)
"It's psuedo-code that works"
Re:Why Is Python Growing So Quickly? by lou1306 on Thursday September 14, 2017 @02:56PM (#15251291)
This. I took the habit of writing very Python-like pseudocode while taking lecture notes, and having it run almost verbatim at home was a blast.
Re:Why Is Python Growing So Quickly? by SimbaOnSteroids on Thursday September 14, 2017 @05:18PM (#15252595)
Honestly if other languages had the ability to use words like and, or, not, foreach <thing> in <thing> it would make learning to code that much more accessible. Even a language like C could do this. I understand that obviously you're not going to change something like a bit-wise (>>/<<) operator into something that flat says what it does (drop bit right/left), and I appreciate a good use of a ternary operator, you'd think it would be fairly trivial to de-codify some of the more basic operations.
Re:Why Is Python Growing So Quickly? by gaius on Thursday September 14, 2017 @02:06PM (#15250744)
Python has super-easy bindings to C too, that's another reason it's popular in scientific computing
Re:Why Is Python Growing So Quickly? by msla on Thursday September 14, 2017 @04:57PM (#15252454)
And because it has bindings to C, it has bindings to a lot of other languages traditionally compiled to machine language, such as Fortran and C++, making SciPy possible, because that optionally depends on LAPACK, which is written in Fortran.

https://www.scipy.org/scipylib/building/linux.html

Of course, the people who just install and run SciPy don't need to know that, but the fact Python has a nice C FFI means it can run literally decades' worth of software across a fair number of languages.

Re:Why Is Python Growing So Quickly? by dekhn on Thursday September 14, 2017 @03:50PM (#15251897)
I'd be using lua if it had python's library breadth. Or maybe julia. Not python.
Re:Why Is Python Growing So Quickly? by CJefferson on Thursday September 14, 2017 @12:38PM (#15249709)
I have come to the conclusion that part of the reason python is so fun is because it is slow.

There are so many lovely and easy to use libraries in Python. I took a couple and tried to be inspired by them to write a C++ library, maybe for addition to boost.

However, if you are writing C++, people expect your library to be fast and memory efficient -- you can't go around sticking the entirety of a parsed file in a std::string. Also, people then start saying your code better interoperate with their templated classes well, and they want to replace the memory management entirely, and it goes on...

Of course, the resulting libraries are very fast and very clever, but they have lost the joy. They also take much longer to write, maintain and use.

Re:Why Is Python Growing So Quickly? by barrkel on Thursday September 14, 2017 @12:52PM (#15249880)
Watch out for conflating abstraction level with speed. Coding at a low level of abstraction means sweating the small stuff, but it's easy to fool yourself into thinking you're making things fast - when actually, you're micro-managing.

Painting with broader brushstrokes with less concern for micro-efficiencies lets you block out a solution faster. Another part of the problem with C++ is that the components come with so many rough edges that need to be filed down that you can't help getting swamped in a certain level of detail, unless you start with a large toolbox or framework that lets you work back at a higher level again.

You ought to have the equivalent of Java's file stream, buffer and text decoder as three separate bits that you can compose, so that putting a whole file in a string is never even a temptation. But if you start out with a sparse toolbox, it's a slog.

Re:Why Is Python Growing So Quickly? by yongjik on Thursday September 14, 2017 @01:16PM (#15250135)
On the other hand, there were times when I had to get a piece of paper and draw diagrams to construct a twenty-line sequence of numpy calls, when the same would have been achieved by several completely straightforward double (or triple) loops in C++. Writing the same loop in Python was out of question because it would be too slow.

Performance grants you some freedom.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @01:34PM (#15250350)
Use Numba (http://numba.pydata.org). Have your cake and eat it too.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @01:32PM (#15250332)
One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond. That's a big win.

Python encourages readable code, which enables smarter algorithms, which ultimately swamps all those little memory optimizations. Oh, and PyPy/Numba/Cython let you get those little optimizations, too.

Re:Why Is Python Growing So Quickly? by dna_polymerase on Thursday September 14, 2017 @01:38PM (#15250400)
In addition to that there are loads of libraries for Python which are written in C, which gives you speed in the right moments.

I think the readable code thing is really really important, too. I can understand other peoples code quicker and learn more about the actual algorithm unlike in C++ where I wonder half of the time about syntactical non-sense and optimizations for certain compiler targets.

Then again, Python and C++ target very different groups and I like both languages for certain things.

Re:Why Is Python Growing So Quickly? by Sohcahtoa82 on Thursday September 14, 2017 @02:00PM (#15250685)
> One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond.

I'd really like to know what they were doing and how they could do it so wrong that the C++ version took hours while the Python version was faster than a blink of the eye.

Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @02:47PM (#15251181)
Good question. I did have a situation where looping over a fairly large Pandas dataframe took 12 minutes, but using the underlying numpy values took only 3 seconds. The looping was required to do complicated row and column operations.

Similarly, naybe the C++ code was using an inefficient data structure for a large dataset compared to using something like Numpy.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:20PM (#15252967)
It had to do with the number of dimensions and combinations that were being looped over. That kind of scale difference generally comes from combinatoric explosion -- exponential or high polynomial time vs linear or log-linear time.

The rewrite realized an approximation was reasonable in place of a more "correct" algorithm.

Note that I'm not saying Python was the cause, but the ease of reading and writing code may have helped the programmer come to this algorithm. Instead of stressing about bugs and deadlines. Algorithm choice seems correlated with language choice, in my experience.

Re:Why Is Python Growing So Quickly? by amelius on Thursday September 14, 2017 @01:49PM (#15250547)
> One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond.

Code rewrites are often more than a literal translation. They often eliminate old code, and allow to rethink the architecture. So it's really not a surprise that Python code would be faster here. A rewrite to C++ would probably be much faster still.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @07:14PM (#15253263)
Perhaps a C++ rewrite would be faster, but it depends on how many of the dependencies you revise to be optimal for this particular task and how much more clever you are than the NumPy authors and a jit-compiler.
Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @04:10PM (#15252052)
Depending on how heavily the Python code leveraged Numpy.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:31PM (#15253027)
Oops, typo: sub-second, not sub-millisecond.
Re:Why Is Python Growing So Quickly? by paulddraper on Thursday September 14, 2017 @12:41PM (#15249746)
It's a funny way of phrasing it, but you're not wrong.

C++ libraries should allow people to squeeze every bit of performance juice out of them (e.g. custom allocator).

Python libraries should be intuitive to use.

---

Naturally, there are exceptions, like numpy.

Re:Why Is Python Growing So Quickly? by fencepost on Thursday September 14, 2017 @01:01PM (#15249980)
C++ may let you "squeeze every bit of performance," but in a lot of cases it does so by handing you a lot of rope.

You might use it to make a rope bridge across that performance gap, but how good your bridge is depends a lot on you - and if you just manage to hang yourself with it, well, that's on you as well.

With Python it may take longer to get across because you detour a mile over to a more solidly constructed bridge, but you still get there and for most cases you get there fast enough.

Re:Why Is Python Growing So Quickly? by fsloth on Thursday September 14, 2017 @02:04PM (#15250724)
"you can't go around sticking the entirety of a parsed file in a std::string"

Sure you can. C++ is at best programmed like python. Just throw the working first version together - and once you hit a performance gap, you can optimize it.

Using a profiler.

Premature optimization is mostly pointless because for most non-trivial performance critical apps the bottleneck wont be where you expect it.

The faster you find the actual problematic hotspots with production content the better. The way to get there fast is to treat C++ like filthy python.

Don't trust anyone trying to goad you into premature optimization unlesa they understand the specific problem you are trying to solve, and only then with skepticism.

Re:Why Is Python Growing So Quickly? by CJefferson on Thursday September 14, 2017 @02:57PM (#15251316)
Well, in my own code I would, but you would never get some file handling / parsing library into boost, or the standard, that did that. And then (another C++ issue), installing libraries can be fiddly.
Re:Why Is Python Growing So Quickly? by fsloth on Thursday September 14, 2017 @08:50PM (#15253735)
"but you would never get some file handling / parsing library into boost, or the standard, that did that."

Why would anyone want to write code that would go into either of those? In the general sense, I mean.

Good production code is simple and is implemented preferably verbosely and understandably than cleverly.

Speaking of good software patterns, I'm not sure boost nor STL are great examples of good software architecture. Boost especially is very templatey-bloatey. The biggest merit of STL is that is exists.

"installing libraries can be fiddly."

Does anyone really need to do that? Install C++ specific libraries I mean. In 10+ years I've never developed C++ software that would not store all of it's dependencies part of the project hierarchy or sub-structure, except for the standard library.

The worst part of C++ is that is has these warts that subtly guide developers into copying all sorts of patterns for their own sake because they are seen "as the standard way to do it". Object orientation and templates should not be considered the basic building blocks of the archictecture of a C++ program, but rather escape valves when some usage pattern would end up more complex without them.

For example, when someone spends long production time creating an elegant template based solution for whatever, generally it is an indication that something is wrong somewhere. There are of course exceptions to this rule, but just saving some boilerplate is never a good reason to do it.

Re:Why Is Python Growing So Quickly? by nly on Thursday September 14, 2017 @09:43PM (#15253947)
> The biggest merit of STL is that is exists.

The STL is a library of common algorithms and data structures that are decoupled from one another, and the complexity of operations in the STL has been enshrined in to the C++ standard. These two achievements alone warrant granting it huge respect. Imho, it's the essence of great design and it should be the very first thing taught to programmers new to C++.

> copying all sorts of patterns for their own sake because they are seen "as the standard way to do it".

Yeah, Python programmers would never do anything like that. If they did they might all run around calling it being 'Pythonic' or something.

> Object orientation and templates should not be considered the basic building blocks of the archictecture of a C++ program

Just tools in the toolbox, and the amount of mileage you can get out of just these two features, along with other staples like RAII and function overloading is pretty astounding.

Re:Why Is Python Growing So Quickly? by drewrv on Thursday September 14, 2017 @02:20PM (#15250905)
Part of it is just that Python has an awesome, supportive community. Sounds like the C++ community is kinda critical and demanding, in your experience.
Re:Why Is Python Growing So Quickly? by shalabhc on Thursday September 14, 2017 @01:48PM (#15250529)
> python is so fun is because it is slow

C++ pushes you to conflate optimization with the higher level meaning of what you're trying to implement. In Python you can write the higher level meaning in a more 'pure' way, which is fun of course. The really interesting question is if you can program at the higher level while still running fast, perhaps by specifying optimizations separately?

(BTW, for Python code that can be as fast at C++ see https://kratzert.github.io/2017/09/12/introduction-to-the-nu... - it doesn't sacrifice clarity, but is limited to a subset, for now).

Re:Why Is Python Growing So Quickly? by harshgupta on Thursday September 14, 2017 @12:47PM (#15249807)
Part of the reason is same side network effect. It makes sense to create new libraries in languages having great existing libraries.
Re:Why Is Python Growing So Quickly? by RivieraKid on Thursday September 14, 2017 @03:49PM (#15251881)
Julia is fast and more fun than Python.
Re:Why Is Python Growing So Quickly? by gdulli on Thursday September 14, 2017 @12:48PM (#15249815)
> It is stupid fun to program with Python

Around 2009 I started questioning if I even enjoyed coding anymore. I was primarily using PHP and Java. Rather than quit the profession I tried Python and suddenly it was fun again. 8 years later, it still is. Python just spoke my language.

My career is based around using Python because it's the way I enjoy the work. Everything else, like the actual properties of Python relative to other languages, is irrelevant to me if using another language would make the work unenjoyable again. (Though if Python didn't measure up very well compared to other languages it wouldn't have become my go-to in the first place.)

Re:Why Is Python Growing So Quickly? by Daishiman on Thursday September 14, 2017 @04:32PM (#15252257)
Same thing here. I worked with PHP and Java apps and it was just pain having to deal with the awkwardness of PHP's designs and Java's boilerplate. I actually went into sysadmin roles because of that. Python gave me hope that there's fun development roles to be had.

Nowadays the panorama for good languages, thankfully, is much better. PHP is no longer that much of a dumpster fire with modern frameworks, and Java has decided to adopt better defaults and drop the XML madness. Not to mention all the good languages that have come up (Elixir, Clojure, Rust, etc).

Re:Why Is Python Growing So Quickly? by cutler on Thursday September 14, 2017 @01:48PM (#15250536)
Try Clojure and I promise you will have even more fun.
Re:Why Is Python Growing So Quickly? by alvivar on Thursday September 14, 2017 @03:57PM (#15251946)
Maybe you should try F#, to me both are kind of fun compatible (plus the functional focus that is kind of fun by itself).
Re:Why Is Python Growing So Quickly? by guelo on Thursday September 14, 2017 @12:38PM (#15249701)
Are you suggesting that we ignore the article's data-driven conclusion that it is because of pandas and the rise of data science and machine learning?
Re:Why Is Python Growing So Quickly? by njharman on Thursday September 14, 2017 @01:43PM (#15250475)
No they're explaining why Pandas was written in Python and why data science and machine learning projects choose Python over R or Java or Haskell, etc.
Re:Why Is Python Growing So Quickly? by rpazyaquian on Thursday September 14, 2017 @12:39PM (#15249720)
That is exactly what I am thinking myself.
Re:Why Is Python Growing So Quickly? by fish_fan on Thursday September 14, 2017 @12:51PM (#15249874)
I think you're reading the article wrong—pandas is a symptom, not a cause.

That said, it seems foolish to ignore the clear data science use case. But that's also been a theme for at least five years now.

Re:Why Is Python Growing So Quickly? by vturner on Thursday September 14, 2017 @01:08PM (#15250059)
This is an honest question, what's the size of projects you have written in Python? For me, once a project gets beyond some size, the aggravation only grows of debugging old code and adding new. Mostly, I see this is as a lack of compilation and types in Python. How do others overcome this and enjoy large Python projects?
Re:Why Is Python Growing So Quickly? by andybak on Thursday September 14, 2017 @01:17PM (#15250147)
OK. Bear with me here. This might be overstating my case...

In some sense - there are no large projects. Only projects that have failed at being modular.

Maintainability involves keeping clear boundaries between functional units so that you can keep enough code in your head at any one time to reason about it.

If we assume that Python is capable of handling more code than you can keep in your head at any given time, then surely the problem is simply one of making sure your modules are nicely self-contained from each other.

Re:Why Is Python Growing So Quickly? by vturner on Thursday September 14, 2017 @01:27PM (#15250265)
Agreed, modularity definitely helps us minimize the mental load of understanding all the objects at once. But how does it handle this situation:

Write function in module A that expects some complex data structure that comes in. In a static typed language, you put a type on the argument and thus guarantee, to some degree, the data in the object can be safely manipulated.

Over in module B we call that function. Because Python doesn't enforce types, I can pass in some type of data structure that might behave well in many situations, but in some that function is going to fail because I didn't properly construct the data structure.

How do other Python projects avoid this? Do they avoid large data structures of multiple fields?

Re:Why Is Python Growing So Quickly? by outworlder on Thursday September 14, 2017 @01:57PM (#15250646)
> Write function in module A that expects some complex data structure that comes in. In a static typed language, you put a type on the argument and thus guarantee, to some degree, the data in the object can be safely manipulated.

Let's question some of the assumptions. Do you NEED the entire thing to be passed around? If your functions are small and only do one thing, can't they be fed the portion of the data they need and only manipulate that? If they are getting unnecessary data, soon someone will like the convenience and that piece of data will now become necessary.

I have seen Java projects with humongous "DAO" objects being passed across all apps. Even if Java had Haskell's type system, at some point it breaks down.

So, you do not enforce that on Python itself. Rather, you have to apply due diligence and ensure your data structures are clean, and functions do what they are supposed to do and no more.

> I can pass in some type of data structure that might behave well in many situations, but in some that function is going to fail because I didn't properly construct the data structure.

Then you construct the structure in a single place, and that should have some sanity checks and sane defaults.

Even if you are using a static typed language, there's no guarantee that what's inside the data structure even makes sense, only that the right type of structure is being passed on. That's helpful, but not as much as people would think.

And you write tests. Lots of tests. It is amazing the amount of Python code that gets written without proper testing. And Java, for that matter. Only Python programmers have less excuses, it's easier to replace what you need for testing.

Re:Why Is Python Growing So Quickly? by simion314 on Thursday September 14, 2017 @02:55PM (#15251285)
>Even if you are using a static typed language, there's no guarantee that what's inside the data structure even makes sense.

You should always put validation in constructor so you are 100% sure that the object created is valid.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:46PM (#15253108)
How can you be sure your validation covered all cases?
Re:Why Is Python Growing So Quickly? by simion314 on Friday September 15, 2017 @01:13AM (#15254813)
Say you have a Circle class, you need a center point so you validate that the center is not null and you check that radius is greater then zero. Do you have an example where is impossible to validate all cases? if so how will your unit tests validate/test all those cases?
Re:Why Is Python Growing So Quickly? by xapata on Friday September 15, 2017 @04:18AM (#15255524)
In your example, you can't anticipate that center points approximately but not quite equal to pi will cause a ... whatever bug in ... whatever downstream use of the class. One can never really know what states are acceptable.
Re:Why Is Python Growing So Quickly? by simion314 on Friday September 15, 2017 @06:47AM (#15256041)
The circle is valid, what you say is a bug in other section that crashes with valid circles,so types could prevent invalid inputs to functions. What you describe is a bug in an algorithm I don't think that is possible for a compiler to prevent bugs in algorithms, division by zero or precision errors
Re:Why Is Python Growing So Quickly? by xapata on Friday September 15, 2017 @12:54PM (#15258637)
Type systems can do some pretty miraculous things. For example, you could distinguish between a connected and disconnected socket with types so that you don't accidentally send on a disconnected socket.

I guess I'm arguing both sides now. My point is that one needs to root out the weird cases somehow and that it's often hard to have "100%" validation of inputs. One's initial understanding of what is the valid and invalid state space is often incorrect.

Re:Why Is Python Growing So Quickly? by asddddd on Thursday September 14, 2017 @02:18PM (#15250887)
Twisted is a massive codebase, and uses zope.interface. There are definitely options for stricter guarantees, but it's optional, and generally you'd rather be treating input as ducks.

Also, even without actual type checking (mypy), IDE support + type hinting (PEP 484 or reST et al) means you can find most issues before the interpreter/compiler is involved. PyCharm is fantastic at this.

Re:Why Is Python Growing So Quickly? by crdoconnor on Friday September 15, 2017 @09:49AM (#15257105)
>How do other Python projects avoid this?

https://github.com/jonathanslenders/pymux/blob/master/pymux/...

Here's one way. Those asserts will typically pick up on errors during spikes, development and tests and turn a head scratching problem into a straightforward issue.

A couple of times on a disastrously tech debt ridden project I used it to pick up obscure configuration errors in prod, too (shouldn't see it in prod on a relatively well written project tho).

Re:Why Is Python Growing So Quickly? by andybak on Saturday September 16, 2017 @06:46AM (#15264011)
You might consider this too much of an edge case but what if I want to pass something that quacks like an EventLoop to Process init ?
Re:Why Is Python Growing So Quickly? by crdoconnor on Saturday September 16, 2017 @10:21AM (#15264756)
Unless it's a subclass (which would pass), I don't imagine that would be at all likely.

Never been much of a fan of duck typing. It only really makes sense when you have objects that approximate built in types.

Take a random object with a .run() method, for example, and you don't have a fucking clue what it might be doing so there's no point interpreting that as a quack.

Re:Why Is Python Growing So Quickly? by abc_lisper on Thursday September 14, 2017 @02:09PM (#15250768)
Re:Why Is Python Growing So Quickly? by mring33621 on Thursday September 14, 2017 @01:58PM (#15250658)
Everything's a server, er, microservice, passing JSON back and forth!
Re:Why Is Python Growing So Quickly? by marcosdumay on Thursday September 14, 2017 @02:31PM (#15251011)
Microservices are great, because you can enforce static typing within their interfaces. \s
Re:Why Is Python Growing So Quickly? by flavio81 on Thursday September 14, 2017 @01:48PM (#15250530)
> Mostly, I see this is as a lack of compilation and types in Python. How do others overcome this and enjoy large Python projects?

Divide code into modules.

If you are worried about types, use object oriented programming to define the classes you want and then use the assert() instruction to check variables to comply with said classes/types.

A good IDE like PyCharm will take advantage of such assert() statements.

Re:Why Is Python Growing So Quickly? by crdoconnor on Friday September 15, 2017 @09:37AM (#15257008)
A combination of:

* Realistic integration tests that cover as many user stories as possible.

* Raise exceptions ASAP for any kind of invalid data or state (could be checking types, but could also be checking for file/directory existence). Could also be pip installing and using 'schema'.

* Do not build on poor quality modules and strive to decouple and uninvent poorly reinvented wheels.

* Just in general: loosely couple everything.

I don't see this as a static typing issue at all. Static typing only helps with a small part of the problem and it usually does that at some expense (usually more verbose & less flexible code).

I'm a little skeptical that super-strong type systems like haskell necessarily help all that much either. They clearly help eliminate classes of bugs, but the overhead is very high (the amount of everyday software written in haskell is seemingly small relative to its apparent popularity).

Re:Why Is Python Growing So Quickly? by tw1010 on Thursday September 14, 2017 @12:38PM (#15249711)
That description doesn't explain why there has been such a sudden growth in recent years. Python is an old language. The real reason it is growing so much just recently is of course due to ML.
Re:Why Is Python Growing So Quickly? by dwaltrip on Thursday September 14, 2017 @02:02PM (#15250711)
> The real reason it is growing so much just recently is of course due to ML.

This is certainly a potential explanation. But I don't think it is self-evident that the trend of recent growth is entirely due to this.

Edit: The article supports the claim - I should have read it before commenting.

Re:Why Is Python Growing So Quickly? by euyyn on Thursday September 14, 2017 @02:23PM (#15250942)
It doesn't need to be self-evident, as it's what the article is showing with data.
Re:Why Is Python Growing So Quickly? by dwaltrip on Thursday September 14, 2017 @02:50PM (#15251215)
My bad, this is what I get for not reading the article. I added a note to my comment, thanks.
Re:Why Is Python Growing So Quickly? by jdc0589 on Thursday September 14, 2017 @12:44PM (#15249775)
> Once you grok the virtual environment thing

it's incredible how hard it is to get some people on board with this. I've gotten used to good project-local package management in other langauges, I can't imaging working with anything that depended on stuff happening to be available in a global namespace ever again.

Re:Why Is Python Growing So Quickly? by whipoodle on Thursday September 14, 2017 @12:48PM (#15249820)
It is a bit more of a pain to work with than similar features in other languages. Like as far as I know you can't just move a venv, you have to rebuild it in the new place. Whereas `node_modules` is just a dir. Also, there is a weird layering where venv abstracts away installed eggs/wheels/whatever they're calling them these days, but then since that's still painful to work with, you need another layer on top like virtualenvtools or burrito or whatever it is. (Sorry, it's been a couple years so my memory is fuzzy)
Re:Why Is Python Growing So Quickly? by qaq on Thursday September 14, 2017 @01:31PM (#15250312)
"a bit"? honestly I would say it's much closer to a lot more pain
Re:Why Is Python Growing So Quickly? by whipoodle on Thursday September 14, 2017 @01:49PM (#15250539)
I was being kind. :)
Re:Why Is Python Growing So Quickly? by Zaak on Thursday September 14, 2017 @12:58PM (#15249954)
Yeah, Python's environment/import logic is really convoluted. It evolved organically with little forethought, and only got a minimal pruning with Python 3.
Re:Why Is Python Growing So Quickly? by chrshawkes on Thursday September 14, 2017 @05:33PM (#15252696)
It was essentially created by one dude no?
Re:Why Is Python Growing So Quickly? by gilrain on Thursday September 14, 2017 @01:08PM (#15250061)
As someone who has largely moved from Python to Node: it's not the concept of project-local packages that is the problem. It's virtualenv's awful implementation and UI.
Re:Why Is Python Growing So Quickly? by andybak on Thursday September 14, 2017 @01:18PM (#15250155)
Maybe I've got Stockholm Syndrome but I never have any trouble with pip. I don't find it any worse than npm for my usage patterns.
Re:Why Is Python Growing So Quickly? by jplatte on Thursday September 14, 2017 @03:04PM (#15251407)
I'm one of those people who are really confused about the whole Python project management situation. Is there a resource where I can learn the equivalent of common operations found in other project management tools such as npm / yarn / cargo?

E.g. is there something like 'cargo run' that just checks that the required python version is installed (I got the impression that this can be specified somewhere), installs deps if they're not installed yet and then runs the main module? Or something like 'npm install --save' that adds the latest version of a package you already know the name of as a dependency and installs it?

Re:Why Is Python Growing So Quickly? by pletnes on Thursday September 14, 2017 @01:12PM (#15250103)
Tried conda or pipenv?
Re:Why Is Python Growing So Quickly? by wooly_bully on Thursday September 14, 2017 @12:50PM (#15249852)
Have them try Pipenv!

https://github.com/kennethreitz/pipenv

While virtualenv management isn't that difficult, Pipenv is VERY intuitive.

Re:Why Is Python Growing So Quickly? by dom0 on Thursday September 14, 2017 @02:11PM (#15250802)
There are still widely used packages that don't work with pip, like PyQt.
Re:Why Is Python Growing So Quickly? by pvg on Thursday September 14, 2017 @12:37PM (#15249681)
I think a big part of the answer for SO is the popularity and inscrutable nature of pandas. 'Popular, useful and incomprehensible' make for excellent Stack Overflow growth.
Re:Why Is Python Growing So Quickly? by newen on Thursday September 14, 2017 @04:23PM (#15252184)
Got to agree. I used to google pandas problems for remotely complex stuff because it wasn't really intuitive how to do it in pandas. Now I have a better context for how simple such things can be because of data.table in R.
Re:Why Is Python Growing So Quickly? by blauditore on Thursday September 14, 2017 @01:04PM (#15250005)
I recently worked with Python for a couple of months, for the first time. Even though reading code and writing simple parts is fairly easy, I found several details to be quite confusing, like variable scope, or the various underscore conventions/variables. Also, I struggled to find a good free IDE (there was no money for PyCharm), which made debugging a hassle. Also, dependency management with pip feels a bit quirky compared to e.g. Maven or npm.

All in all, I found it neither much more or less fun to program with than e.g. Java, C# or TS. It might be a better fit for small projects than others, though.

Re:Why Is Python Growing So Quickly? by NoahTheDuke on Thursday September 14, 2017 @01:39PM (#15250415)
> variable scope

Which parts did you find confusing? Was it the lack of a block-level scope, such as within for loops and if statements? I personally find the LEGB (Local, Enclosing, Global, Builtin) system to be pretty intuitive.

[0]: https://stackoverflow.com/a/23471004/3023252

Re:Why Is Python Growing So Quickly? by blauditore on Thursday September 14, 2017 @03:18PM (#15251567)
I think one thing I found particularly confusing is how class and instance variables relate to each other. It takes a while to understand how they get masked and in what case which one is referenced.
Re:Why Is Python Growing So Quickly? by chrshawkes on Thursday September 14, 2017 @05:41PM (#15252753)
Free excellent Python IDE is Visual Studio Code with a Python Extension installed by Don Jayamayne. VS Code is a solid Python experience.
Re:Why Is Python Growing So Quickly? by pletnes on Thursday September 14, 2017 @01:11PM (#15250093)
Pycharm and visual studio have free editions. Vim, emacs, Atom, VS Code, sublime - there are many options.
Re:Why Is Python Growing So Quickly? by blauditore on Thursday September 14, 2017 @03:09PM (#15251463)
I think it was the remote debugger I was missing, and as far as I could tell there was no such feature in any free editor/IDE, probably because it's not a language-native feature afaik.
Re:Why Is Python Growing So Quickly? by wslh on Thursday September 14, 2017 @01:06PM (#15250041)
IDE? Visual Studio Code.

Python is not perfect but the final code is simple to write and understand years later.

Re:Why Is Python Growing So Quickly? by bedros on Thursday September 14, 2017 @01:44PM (#15250481)
I use sublime for python development, don't use fancy debug features, just print statements
Re:Why Is Python Growing So Quickly? by cableshaft on Thursday September 14, 2017 @02:43PM (#15251135)
I generally use Notepad++. Python lets you get away with it, for the most part. Other languages would be a pain in the butt to write whole programs in it.
Re:Why Is Python Growing So Quickly? by mixmastamyk on Thursday September 14, 2017 @02:49PM (#15251205)
> Once you grok the virtual environment thing

I wish this would die, it just scares off newbies. In my twenty years of Python I encountered conflicting reqs once or twice. It's easy to direct folks to the documentation in those circumstances rather than cramming it down every newbie's throat---YAGNI.

Now that pip can install with --user and containers are popular, the problem isn't even possible in production in many circumstances.

Re:Why Is Python Growing So Quickly? by donarb on Thursday September 14, 2017 @03:17PM (#15251565)
Virtual environments are not just for conflicting requirements. I write code for clients on my laptop and don't want to clog up my packages directory with project specific libraries that I'll never use myself. Once the project is done and I turn code over to a client, I can delete the virtual env and all the installed libraries. Virtual envs also allow me to have multiple versions of Python installed on my machine.

This discussion is a lot like version control. How many people made daily (hourly) duplicates of project folders before learning the benefits of version control?

Re:Why Is Python Growing So Quickly? by mixmastamyk on Thursday September 14, 2017 @06:48PM (#15253121)
A use case that newbs need not concern themselves with.

You normally won't get a version control lecture during every programming language tutorial either.

Re:Why Is Python Growing So Quickly? by hyperpallium on Thursday September 14, 2017 @02:30PM (#15251005)
Java could have libraries almost as easy to use as python, but doesn't.

However, some things can't be as easy as in Python, such as sympy, which does symbolic processing of in-python expressions (differentiation, integration etc).

I actually don't find python easy to use - every time I use it, I have to look up how to do for loops (what? range? zero-based? does it include the last one?), and the docs don't have links for arguments (even though they require specific types), because no static types.

But the libraries absolutely are easy to use. And because many are written in C (unlike most of Java's librries), you're arguably running C.

Re:Why Is Python Growing So Quickly? by IamNotAtWork on Thursday September 14, 2017 @02:16PM (#15250857)
I haven't overcome the virtual env thing. There are a few virtual environment libraries, not sure which one to use. Then it is awkward to have to change your entire environment over by activating it and for it to be global. What if I want to work on two different projects in two different terminals? Why can't I activate an environment by just CDing into a directory with my project?

Then there is the GIL. I still don't know if multithreaded python apps are really MT or just faking it. And yes, I know you can do event driven stuff and that does look very interesting.

Re:Why Is Python Growing So Quickly? by orf on Thursday September 14, 2017 @02:21PM (#15250919)
Use "python3 -m venv"

You can activate two different environments in two different terminals. Why wouldn't you be able to?

You can automatically activate venvs when you cd into a directory with virtualenvwrapper.

Rule of thumb: if a thread goes into C it's releasing the GIL. Not always, but often. Like reading a file, or a library like like numpy or Pillow.

Re:Why Is Python Growing So Quickly? by mmagin on Thursday September 14, 2017 @01:53PM (#15250593)
I actually love forcing people into a fairly consistent coding style, but everything else about the language irks me compared to my previous extensive use of Perl (on a large enterprise software product).

One particularly big thing, that it doesn't have much of a distinct compilation phase. You'll write some script you want to run to do some one-off task that will take the next hour, only to find it crashed after 20 minutes when it hits some boneheaded syntax error you made.

Re:Why Is Python Growing So Quickly? by makecheck on Thursday September 14, 2017 @01:54PM (#15250616)
For that though you can use linting tools such as "pylint"; catches a lot of errors that might otherwise be runtime exceptions.
Re:Why Is Python Growing So Quickly? by shalabhc on Thursday September 14, 2017 @02:12PM (#15250821)
Take a look at mypy and pytype - there is a drive in the Python community to add a verification system to the language.
Re:Why Is Python Growing So Quickly? by dwaltrip on Thursday September 14, 2017 @01:59PM (#15250670)
For this reason, I generally test scripts like that with a small slice of the data, or small set of dummy data. Then one can also verify that the output is reasonable -- which is good to do even with a compiled language that would catch all syntax errors ahead of time.
Re:Why Is Python Growing So Quickly? by cbr on Thursday September 14, 2017 @02:13PM (#15250829)

    only to find it crashed after 20 minutes when it hits
    some boneheaded syntax error you made
I find mypy to be pretty useful for this.
Re:Why Is Python Growing So Quickly? by submeta on Thursday September 14, 2017 @02:36PM (#15251062)
+1 for PyCharm. With it I realized how much I was missing with Vim/Emacs/Sublime (even though I configured a lot in those editors).
Re:Why Is Python Growing So Quickly? by pageandrew on Thursday September 14, 2017 @12:36PM (#15249665)
for whatever reason, the word "grok" annoys me to no end
Re:Why Is Python Growing So Quickly? by mark-r on Thursday September 14, 2017 @12:41PM (#15249742)
The origin of the term is fascinating: https://en.wikipedia.org/wiki/Grok
Re:Why Is Python Growing So Quickly? by castis on Thursday September 14, 2017 @12:37PM (#15249678)
In other words, you don't grok "grok"?
Re:Why Is Python Growing So Quickly? by drcongo on Friday September 15, 2017 @10:26AM (#15257395)
I thought it was just me.
Re:Why Is Python Growing So Quickly? by Zarath on Thursday September 14, 2017 @04:35PM (#15252277)
For me it's the fact that no English words end in "ok".
Re:Why Is Python Growing So Quickly? by antod on Thursday September 14, 2017 @03:44PM (#15251837)
Heh. There was a python web framework called grok.
Re:Why Is Python Growing So Quickly? by walterstucco on Thursday September 14, 2017 @01:07PM (#15250045)
The real answer is: data scientist everywhere

They usually don't know better

Re:Why Is Python Growing So Quickly? by copperx on Thursday September 14, 2017 @01:31PM (#15250314)
What would they be using if they knew better? R?
Re:Why Is Python Growing So Quickly? by walterstucco on Thursday September 14, 2017 @01:50PM (#15250558)
It's ok

They'd make a mess with every language...

A beautiful mess, don't get me wrong

There are better languages but there isn't enough "science cargo cult" around them

And honestly there aren't as many code snippets to copy from

My hopes are in luna[1]

p.s. distributing load or using multi cores is still shitty in python, the more dataset will grow in size, the more python will struggle

[1] http://www.luna-lang.org/

Re:Why Is Python Growing So Quickly? by wwarner on Thursday September 14, 2017 @01:28PM (#15250275)
zing!