13 ms·
As I read this, I originally disagreed with the author - for me the challenge of a new language is not the language itself but becoming familiar with the librar
by nlawalker 9y ago
As I read this, I originally disagreed with the author - for me the challenge of a new language is not the language itself but becoming familiar with the libraries that everyone uses and understanding how to get things done with them - but then I saw this:
>> packages that alter its syntax and behavior
Is this kind of thing common with Python? I'm used to C#, where libraries are just libraries. Sure, you still have to learn your way around them, but they don't change the language out from under you. Even in big frameworks that completely dictate the overarching organization of your code, it's still C# you're writing.
- SwellJoe 9y agoNo, it's not super common, IMHO. Python doesn't really even lend itself to altering syntax in significant ways (though some of the libraries he mentioned have low-level C implementations that can/do alter Python syntax). If you're doing scientific computing you're going to see some new things that don't entirely look like Python. Things like matrix math and the like have new types and (mildly new) syntax. But, I don't think it's surprising for people who know Python. I guess there may be some cognitive dissonance that comes from using projects that paper over Fortran and C++ libraries with light Python wrappers (a lot of scientific computing libraries, again...so, not often new syntax, but not very Pythonic, either). The specific example mentioned of matplotlib (and SciPy and Numeric, etc.), probably comes from the origins of the library...it was intended to make it easy for people coming from Matlab to switch to Python for the same sorts of tasks, so it's conceptually a mashup of the two. But, maybe the argument should just be "walk before you run", rather than singling out any particular library. Particularly if those libraries might be the sole reason the person is learning Python. Sounds like the person he was helping out with her matplotlib problem really wanted to be working with matplotlib and the scientific computing ecosystem Python offers. You've gotta learn them eventually if that's the kind of work you want to do with Python. They might be a little weird, but they're not a whole new language.
- paultopia 9y agoDefinitely in the data science stack though. For example: how pandas behaves with slicing, and copy vs view semantics are totally different from vanilla python, and are confusing enough coming from vanilla python. God help you if you learn pandas and python at the same time.
- vram22 9y ago>how pandas behaves with slicing, and copy vs view semantics are totally different from vanilla python, and are confusing enough coming from vanilla python Can you give a few examples of this?
- paultopia 9y agoSure thing. For slicing, see Jake VanderPlas's book: https://jakevdp.github.io/PythonDataScienceHandbook/03.02-data-indexing-and-selection.html https://jakevdp.github.io/PythonDataScienceHandbook/03.02-da...) that describes the complexities -- some kinds of pandas slicing include the last index, some kinds don't. View vs copy is even worse. There are some situations where indexing on a DataFrame yields a view, some situations where it yields a copy, and they are effectively indeterminate in a lot of situations. From the Pandas documentation https://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy https://pandas.pydata.org/pandas-docs/stable/indexing.html#i...: See that __getitem__ in there? Outside of simple cases, it’s very hard to predict whether it will return a view or a copy (it depends on the memory layout of the array, about which pandas makes no guarantees), and therefore whether the __setitem__ will modify dfmi or a temporary object that gets thrown out immediately afterward. By contrast, the vanilla python rules are much simpler: slicing always leaves off the last index, and the rules for view vs copy of mutable data structures like lists are at least determinate...
- vram22 9y agoThanks for the reply. I can see how it can be confusing, and more so for that indeterminate part.
- ameliaquining 9y agoPython has operator overloading like C#, which, if used in relatively more interesting ways, can cause code using these APIs to look pretty different from "standard" Python. Python also allows overloading (i.e., defining new semantics for) more interesting things like field lookups and class definitions. This is extremely powerful and lets you do various useful things that are impossible in C#, but it also means you can't take much of anything for granted when using someone else's API, as there might be "spooky action at a distance". And so there's a real cost to learnability and maintainability. There is something of a culture in Python of not being overly clever, which keeps this stuff in check. (Contrast Ruby, which offers equally powerful language facilities without the cultural norm of not using them for crazy things.) But for relatively all-encompassing frameworks, the ergonomic benefits are often too great to ignore, so you start to see things like Django models and class-based views, which tend to look and feel quite different from "regular" Python classes.
- falsedan 9y ago> There is something of a culture in Python of not being overly clever, which keeps this stuff in check. (Contrast Ruby, which offers equally powerful language facilities without the cultural norm of not using them for crazy things.) Have you seen namedtuple? It's part of the stdlib… and metaclasses are designed for devs to do wildly unpredictable actions when creating instances (not to mention python's OO layer is basically a clever hack).
- icebraining 9y ago"Keeping in check" is not the same as "not allowing". It has metaclasses, but they're rarely used. namedtuples are also a rare case in a large stdlib. How is the OO layer a clever hack?
- falsedan 9y agoMost other OO languages can pass self implicitly, and don't distinguish between initialization & construction. > There is something of a culture in Python of not being overly clever This is the part I disagree with. So much python I read in apps, libraries, web frameworks, and pythonista tweets is needlessly clever.
- bigiain 9y agoIt depends a lot on what you mean by "Learning Python". Is it "Learning Python as a second or third programming language", or "learning programming using Python"? Understanding libraries and idiomatic language constructs is important - but only if you're well past the "Hello World!" stage. If you can't get close to a working fizzbuzz yourself - you're probably not ready for BeautifulSoup or Numpy or Django. You _might_ be able to copy paste Stack Overflow examples, but there's some basic "learning programming" that needs to be done before you'll understand what you're doing...
- nlawalker 9y agoAh thanks, I've always looked for a way to sum up this distinction and you've captured it perfectly (particularly "learning programming using x".. I think a lot of books called "Learning X" should be called that instead). Is there any recommended material for learning Python as a second or third language?
- icebraining 9y agoThere are a few guides out there in the form of "X for Y programmers", eg. Python for Ruby programmers. Personally, I find it more helpful to use regular materials and skip the stuff I already know.
- reificator 9y agoWhen I do that, I miss the details that can catch you off guard. If I had done that with Javascript, I can assure you that function based scoping would have destroyed my brain in trying to debug. But since I read a book on Javascript[1] that assumed familiarity with other languages, I was prepared for it. [1]: https://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691 https://www.amazon.com/Professional-JavaScript-Developers-Ni...
- dagw 9y agoI disagree in the case of numpy. If you're going to be using python for numerical work almost all of your data will be numpy arrays so there is not reason to not get used to them from the beginning. You don't have to go digging into the obscure corners of numpy, but you should be familiar with basic arrays and how they work.