4 ms·
I'm sure there's lots of beginners to programming but most of the time when I find myself asking basic questions like "how to duplicate array Python" isn't beca
by Spivak 8y ago
I'm sure there's lots of beginners to programming but most of the time when I find myself asking basic questions like "how to duplicate array Python" isn't because I couldn't spend 2 minutes writing a function to do it but because there already exists a generally accepted best way to perform this operation that leverages the standard library and there is seemingly no other way to discover what that is.
Like for this specific example:
https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list https://stackoverflow.com/questions/2612802/how-to-clone-or-...
Knowing the right thing to do requires you be informed about the history of Python language design. Like you could just read the documentation and see that lists have a copy method but it doesn't give you a good grasp of what the alternatives are and why you might choose them. And prior to Python 3.3 you're expected to know that the best practice way to do this is to leverage an edge case in the slicing syntax or the list function. Doesn't matter if you're the best computer scientist in the world, sifting through the massive corpous of documentation and historical knowledge required to write good Python is nigh impossible unless you're willing to dedicate yourself Python.
This is something that languages need to tackle because the gap between doing a thing and doing that same thing in a way that follows language conventions and best practices is too damn high.
- tempguy9999 8y ago> and there is seemingly no other way to discover what that is Yes there is, it's called reading a goddamn book. > Knowing the right thing to do requires you be informed about the history of Python language design Bullshit, it requires you knowing the language. Perhaps by reading a book. Knowing the history is of little value. > sifting through the massive corpous of documentation and historical knowledge required to write good Python is nigh impossible unless you're willing to dedicate yourself Python Total crap, just read a decent book. About 3 years ago I learnt python from 'Learning Python' by Mark lutz (5th ed) for a new job. I spent 3 weeks going through ~1000 pages and reading stuff on the web. I amazed a guy there when he found out I'd just learnt python, ie. wasn't a veteran at it. He'd used it for years. Difficult, right, putting in all that work? Well that's called doing your job as a programmer. Happens I'm about to return there so I'm brushing up on it by going through it again. I would have some sympathy with your position if you hadn't made it out to be such a terrible task. It's not. It's called doing your due diligence as a programmer. And I have real sympathy with the guy who posed the question you gave from StackOverflow, but the key is once you've learnt about object references, say in delphi, you carry across that understanding to scala/java/python/everything else. 90% of stuff will carry between programming languages. Once you learn OO, functional, procedural, logical langs you recognise and underlying commonality. And most of all, programming is not about a specific language but problem solving and general principles, so getting hung up on a particular lang is missing the point. My first year out at university I worked at an engineering company and got the best advice ever: first thing to do is pick up the docs and start reading. It's stood me well ever since. If there are too many options (ie. your comment on slicing vs other stuff), yes, I see but the answer's simple: pick one way and stick to it; either slicing syntax or list methods. You're there to deliver results correctly to the business, not deliver idiomatically perfect code. There's NO shame in not crawling into the furthest, darkest corners of a language. Excuse the rant. It'll come with experience, just trust yourself and ask questions to any experts you can find.
- mattmanser 8y ago1990 is calling and wants you back... But seriously, many of us simply don't remember that sort of book learning. If it comes to you naturally, fine, just realise that people are different and have different skills, memorization techniques and care about different things. Some programmers are like you (a tiny minority afaik) and can read a dry spec or a book and remember all the intricacies and gotchas. It takes a certain type of mind to do that. And I would note that none of the people I knew who could do that were particularly good programmers. Others, most as far as I've seen in my more than a decade career, learn by making, experimenting and adapting examples. This is made worse now in some ways because back in the day many editors used to have fantastically well written and edited help, and that has generally disappeared. Press F1 on a type or function and you'd get reams of well written examples and explanations. Now most programming languages don't, the documentation is sparse and they simply rely on Stack Overflow and Google to provide all the examples for them. However, that means that old ways of writing things can stick around as often no-one edits a SO answer to correct it.
- tempguy9999 8y ago> many of us simply don't remember that sort of book learning. You mean you haven't heard of books, or can't read, or can't be bothered? Presumably none of these so what are you saying? > just realise that people are different and have different skills, memorization techniques Fine, I agree totally, use those! But here's what the original poster said "generally accepted best way to perform this operation that leverages the standard library and there is seemingly no other way to discover what that is". If you can find the answer on SO, that's fine - you have your answer! But that's not what he said. He said there's no way of finding it. I said it's in books, you say it's on SO, so there clearly is. > Some programmers are like you and can read a dry spec or a book and remember all the intricacies and gotchas Which I can't and don't. Please re-read my penultimate sentence where I said it's ok not to, nor was there need to. Kind of twice in fact ("You're there to deliver results correctly to the business, not deliver idiomatically perfect code." -and- "There's NO shame in not crawling into the furthest, darkest corners of a language.") > And I would note that none of the people I knew who could do that were particularly good programmers Oh noes, I haz been trolled :) > Now most programming languages don't, No language I've ever used ships with a tutorial (oh wait, delphi's did. Rather crap but it was there). Python's online docs are ok (not great, ok). So pick a book. I already recommended one. Reading is the same whether it comes from paper or phosphor. Just don't complain it needs work. It does. Sorry. From experience: not knowing how your tools work is a recipe for vastly increasing your workload. Reading a book is a boring, tedious shag but will give you the greatest savings of time overall. > learn by making, experimenting and adapting examples Yup, that too. Books AND that. You're quite right. I should not have overlooked that.
- belorn 8y agoThe best way to perform a specific action can sometimes change depending on what method is currently fastest. Copy, slice, instancing a new list object, the copy module, each can have their own code base. It would not be surprise me at all if which one is the fastest method has shifted several times between 2.7 and latest version. That said, copying is in this case the end result of distinct different methods. In the stackoverflow answer, the only redundant way to copy is the .copy method list has. If I understand right it is just a convenient method in order so new programmers don't need to import the copy module. list() is a common way to create a new list, and the constructor can take a initial sequence. Lists are sequences, so list can take a list, but that is just a side effect. Slicing is very useful for taking the first or last objects of a list. if you take all the first and all the last objects, you get a copy. Its not the primary function of slicing, but a useful side effect. The copy module is a lower level interface to work with python objects. As any other lower level interface it mostly used in exception cases when you really want a "deep copy". I have used that trick once in my whole programming career, and it was to work around a restriction in a third-party module for a corner case which they clearly didn't consider.
- diminoten 8y agoPython documentation is some of the best of any language, a lot of times you'll be able to find your answer quickly if you just look. The SO questions are almost all answerable with links directly to the docs. This, above many other things, keeps me coming back to Python year after year.