News for hackers. Stuff that matters.
Re:This Is What Python Beginners Have to Deal With by int_19h on Thursday September 08, 2016 @05:14AM (#12451424)
Regarding the docs layout and "having to scroll down to see which function", I also don't quite get it. From my perspective, it's a very nice trait of Python docs compared to PHP docs, that the former actually explain how to use the various parts of the API together, before giving descriptions for every specific API. It's simply a much better way to digest it and learn to use it without making a mess (speaking of which and PHP...).
Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @05:20AM (#12451458)
Coming from statically typed languages, I've really struggled with the Python docs, because they aren't really clear with what is returned from a lot of functions, and which arguments are allowed. I end up finding an example where it is being used, then deducing from what they do with the result what was actually returned.

Contrast this with the ugly-but-functional JavaDocs, which can be auto-generated, and easily shows all return types and arguments for every publicly exposed function and member variable. I understand why this can't be done automatically in Python, but at least they could put the time in to make it clear in their standard libraries.

Re:This Is What Python Beginners Have to Deal With by lqdc13 on Thursday September 08, 2016 @06:17AM (#12451694)
To provide a counterexample, it takes me forever to figure out how to do something after reading Java/Cpp docs, but I instantly know how to do it in Python after reading the docs.

Typical workflow for Java: This function takes in these object types as inputs... Then you have to wonder how to get those object types so you scour through 10 more pages of docs to figure that out. You end up creating a factory of a factory of a factory to make that input object only to find out that it has to be further preprocessed by sending it somewhere else.

Typical workflow for Python: read docs, try out an example in the interpreter by passing a basic object type to the function (such as string or dict), copy code from interpreter into text editor. You are done.

I really love Python docs. It takes me seconds to find what I want and figure out how to use it. I hope they don't change anything.

Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @06:37AM (#12451757)
That's more to do with coding style. I abhor reflection and factories, so if I write Java I don't use them. That said, you can end up writing a RandomNumberGeneratorFactory in Python just as easily if you are trying to achieve the same scaling and re-usability requirements that the Java program is.

The issue I run into in Python is that I need to call something which takes * args or * * kwargs, and the only way I know any of the arguments exist at all is because of some snippet of code on github, probably by the person who implemented the feature in the first place. Even if the argument is named I don't know if it should be a magic number which is defined in some enum-like class, a boolean, or a string to describe the name of what I want and pray that the library maintainers used the same capitalisation and localisation that I think is most logical. In fact, without looking at example code, I literally have no clue how to do anything.

As such, with Python I end up doing copy-paste programming which is dependant on my internet speed and how many other people had the same problem already. With C/C++/Java I tend to do a more build-it-from-scratch style programming, driven mostly I think by the style of the documentation.

Re:This Is What Python Beginners Have to Deal With by int_19h on Thursday September 08, 2016 @03:28PM (#12456445)
> I abhor reflection and factories, so if I write Java I don't use them.

But factories etc are idiomatic Java. You can avoid it in the code that you write, sure, but how do you avoid it in the third-party libraries that you use?

Re:This Is What Python Beginners Have to Deal With by snovv_crash on Friday September 09, 2016 @06:18AM (#12460821)
I've been lucky enough to use Java for fun, not work, and as such I have the time to write things the way I feel they make the most sense.
Re:This Is What Python Beginners Have to Deal With by d0mine on Thursday September 08, 2016 @08:03AM (#12452181)
The advantage of Python is that you do not need to think about type labels: "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck."

For example, the builtin print() function accepts any object with write(string) method as the file parameter. There are ABCs classes that capture the "duck" essence but it would be an unnecessary pessimization to require a io.TextIOBase instance as the file parameter in this case. Don't write Java in Python. Go's io.Writer would work in this case (the type label as the documentation and the exact specification) but if you don't mind thinking about type labels and/or believe that the type of bugs that can be found by a compiler worth the trouble instead of just writing tests and expressing directly what you want the code to do then using a statically typed language make sense.

Though there are type hints (proposed by BDFL) in the recent Python (to enable better static analysis, IDEs code completion and refactoring) https://docs.python.org/3/library/typing.html If its usage is not limited (e.g., through Python culture convention); it could be a regression in Python evolution. If your API is so enormous that you need type labels; you should split it. Python code should communicate the intent to a human first over a compiler/static analysis tool.

Here's a static typing programmer perspective (how it feels) on dynamic languages "What is the appeal of dynamically-typed languages?" https://gist.github.com/non/ec48b0a7343db8291b92

Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @08:29AM (#12452338)
Wholly agreed about not writing Java in Python, and I do write idiomatic Python. The problem is that I don't know what methods the returned objects have available, and as such whether they are a duck or a tiger. The examples show that it has a mouth and eyes, but I need to know whether it has wings or claws, and Python's docs don't make that clear.

Can I index the returned object, or only iterate over it? Is it mutable? Is it a dict or a tuple of (key,value) tuples? Did the author think it was worth it to make its own class for the return type, because they want the indexes where the value was found as well as the metadata?

Python, to a degree, brushes over these problems by being able to print out most types of data and then figure out where the problem is, but TBH I'd prefer to write the correct code to begin with, and the docs don't give me enough information to do so. As such, Python turns into a dodge-the-error-driven-programming, and I feel much less productive than I could be.

Yes, duck-typing gets you part of the way, but it doesn't let you pretend type doesn't exist entirely.

I feel like using Go's interfaces would be more powerful for a duck-typing language than having type-annotations.

Re:This Is What Python Beginners Have to Deal With by d0mine on Thursday September 08, 2016 @12:56PM (#12454756)
If you don't know whether a method returns an iterator or a mutable/immutable sequence (regardless of the specific type) then the documentation is incomplete (it is a bug). If it is in stdlib; you could submit a documentation patch for a *.rst file on https://bugs.python.org/ See https://docs.python.org/devguide/docquality.html
Re:This Is What Python Beginners Have to Deal With by lqdc13 on Thursday September 08, 2016 @08:54AM (#12452472)
"The problem is that I don't know what methods the returned objects have available, and as such whether they are a duck or a tiger."

I don't get this... Why not do the following:

    In [1]: import requests
    In [2]: resp = requests.get('http://www.google.com')
    In [3]: resp.
    resp.apparent_encoding     resp.iter_lines            
    resp.close                 resp.json                  
    resp.connection            resp.links                 
    resp.content               resp.ok                    
    resp.cookies               resp.raise_for_status      
    resp.elapsed               resp.raw                   
    resp.encoding              resp.reason                
    resp.headers               resp.request               
    resp.history               resp.status_code           
    resp.is_permanent_redirect resp.text                  
    resp.is_redirect           resp.url                   
    resp.iter_content          
Now you can try each of those things and explore their methods.
Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @03:23PM (#12456393)
Because I'm not always scripting - sometimes the work I'm doing takes 10 minutes of runtime to get to the end and I want to know what I'm writing before I run it.

If Python wants to remain a scripting language forever then the docs are sufficient. But if it wants to graduate, and it seems a lot of people think it already has, then the libraries need to be better documented.

Re:This Is What Python Beginners Have to Deal With by natch on Thursday September 08, 2016 @11:51AM (#12454135)

    >>> import requests
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named 'requests'
Now, what was your question?
Re:This Is What Python Beginners Have to Deal With by vbernat on Thursday September 08, 2016 @05:45AM (#12451546)
Python also uses autogeneration for most of the documentation, but the documentation itself is not fully autogenerated. You write your documentation and you say to Sphinx: put the generated documentation for this module here.

IMO, this is something positive. You can decide the structure of your documentation and include only the most relevant references.

For example, this part of the documentation for the re module is autogenerated from code: https://docs.python.org/2/library/re.html#module-contents

Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @05:59AM (#12451618)
Agreed, but my point is that argument and return types are badly documented, and in Python autogen doesn't help this.
Re:This Is What Python Beginners Have to Deal With by nitely on Thursday September 08, 2016 @06:45AM (#12451788)
Usually there are examples for everything. Sometimes you have to scroll down, though. What the function returns is usually stated in the description. But I know what you are saying, actually most 3-party libs do document types.

IMHO, python docs are ok. If you struggle with them as a beginner I don't see what would change as an advanced programmer.

Re:This Is What Python Beginners Have to Deal With by snovv_crash on Thursday September 08, 2016 @08:00AM (#12452162)
I am an advanced programmer.

I shouldn't have to read code snippets to figure out if a function returns a tuple or a 'group' which can be iterated over, but can't be indexed. This is something which would be fixed if the documentation included types, because then I could check what all the allowable operations on 'group' are directly without searching for a code snippet which does what I want or just running it and praying I got it right.

Re:This Is What Python Beginners Have to Deal With by philipov on Thursday September 08, 2016 @05:42AM (#12451536)
The author has a vested interest in making people believe they can't figure it out themselves. The article is an advertisement for their book/videos.
Re:This Is What Python Beginners Have to Deal With by Flimm on Thursday September 08, 2016 @05:55AM (#12451593)
The author also has experience teaching beginners (presumably), giving them a perspective that experienced programmers very easily forget and/or ignore.
Re:This Is What Python Beginners Have to Deal With by thewhitetulip on Thursday September 08, 2016 @05:59AM (#12451621)
On the contrary, I learned python starting with the docs, and I am very picky, if something is difficult to understand I am the first to complain, but I did find python docs to be okay, considering I started learning the language from the docs itself.

They might not be the best, but they aren't what the author says like 'we just can't understand shit'

Re:This Is What Python Beginners Have to Deal With by dkersten on Thursday September 08, 2016 @06:43AM (#12451776)
I learned python purely from an offline copy of the official docs, back in 2001 or so. It was obviously doable, since I did learn Python, but it wasn't particularly easy and I remember starting to really like Microsofts documentation (eg their VB docs).

Python's docs have improved, but they're not amazing. Then again, neither are the docs for many other languages. For example, I'm a big fan of Clojure, but many of the docs there have me really appreciating Python's docs ;-)

I think once you get used to Pythons docs, they're pretty easy to follow, although I agree that type information on arguments/return values would be great and I also largely work from examples unless I'm already familiar with a library and am just looking for reference material.

Re:This Is What Python Beginners Have to Deal With by thewhitetulip on Friday September 09, 2016 @12:17AM (#12459599)
That's what my point it, the author, in my opinion is wrong about the docs, since even I learned the language entirely from an offline html copy of the docs.
Re:This Is What Python Beginners Have to Deal With by dkersten on Friday September 09, 2016 @04:48AM (#12460512)
Yeah, I wasn't disagreeing with you. Just adding my own anecdote.
Re:This Is What Python Beginners Have to Deal With by thewhitetulip on Friday September 09, 2016 @12:10PM (#12463529)
Yes, I know that :-) Sorry for being unclear in my comments!!