by retrogradeorbit · 12y ago · 0 comments
No, no, no! This always frustrates me. This is not 'coding' (maybe it is, and we should be doing less of it, and more programming). This is gluing together pre-coded snippets and trying to make it work. Continuing to do this is an impediment to getting better. Thinking that somehow this is what 'coding' is, is missing the point.
I will read a stack overflow page perhaps in a search for some direction, look at all the 'solutions' like surveying a landscape of others approaches to the problem. Then I'll throw them all away and code my own. Possibly it will share a lot with one of the answers, what I would consider a good approach. But a literal copy and paste just doesn't happen. I would consider a copy and paste a recipe for inviting trouble, because you haven't really reasoned through the problem yourself, and thus don't really understand the solution intimately.
Programming is a process of mental reasoning around your problem with an eye on the form of reasoning computers use, so you can express that reasoning to the computer in the language you're using. Because computers don't reason like humans 'reason' (ie. humans don't really 'reason'...), knowing how a computer reasons and behaves is alien and takes time to understand and learn and it takes time to become quicker at comprehending this. This is the path of becoming a better programmer. Gaining that experience so the process is less alien and you more easily can fathom how a computer will respond and behave with a certain approach of laying out of the logic you are trying to express.
Copy and paste doesn't help you at all with this. In some cases it may prevent you learning essential lessons and hinder your improvement.
Generally I agree with this, but there is a way to use copy-pasta as a learning tool. If I find a code sample that does what I want but don't understand it, here is what I do:
1. Add a comment with a link to the source for reference.
2. Rename the variables.
3. Comment the parts that I understand.
4. Flag the parts I don't understand with a simple // ? comment.
5. Research the parts of #4 until I understand them, and then update each comment accordingly.
#2 is incredibly important to me. I've been doing some walk-through tutorials lately (e.g., http://learn.knockoutjs.com), and if I use the same variable names as the tutorials suggest, then I'm just transcribing. The code doesn't stick in my head, and I'm not really learning as much. But once I start changing the variable names, then it sticks.
#3 might seem like a waste of time, but I've found with conceptually difficult code, having the #3 comments helps keep me grounded if my brain gets too muddled.
6. Make changes to it so that it does the same thing, but in a better way -- faster, smaller/more concise, etc.
I think that being able to do this (correctly) is to truly understand, since then you are "thinking beyond the code" and can see the problem that it solves, not just an implementation that solves it.
I personally learned (as I think many people did) by copying code out of books. Whenever something went wrong, I had to figure out whether it was my typo or the book's typo or my conceptual error or the book's conceptual error. That process helped me to learn a lot, and quickly. If everything went perfect, I got to play some creative game which I loved and gave me a sense of acheivement that helped me to progress.
I no longer do this, because it's not relevant to me at this stage of my learning, but I view that as an important part of my early learning process. If you reflect on your own early learning process, I would be extremely surprised if you didn't copy and paste code. Frankly, you are surely still dependent on other people's code now, you just might call it a 'library' instead.
I agree if you're saying professional developers should avoid copy-paste (there are also legal consequences), but new learners can make great progress by using copy-paste. I would say it's an essential part of studying what other people have done.
Rather than take a boring example from my programming career I'd rather draw from my brief mathematical studies in college. In undergrad I was taking a course on Real Analysis. The course redefined, much more rigorously, certain concepts that I had understood at a much higher level--think the limit, derivatives and the Riemann Integral. Suffice it to say that these new concepts challenged my understanding of introductory Calculus, and when I was tasked with writing proofs based on the underlying concepts (e.g. neighborhoods), I struggled.
In what can only be described as frustration I decided I was going to start copying the proofs over and over. I repeatedly transcribed half a doze proofs for a few days straight (I did each one a few times each night). A strange thing happened. I began to understand the proofs. By that I mean I started to understand the intuition required to make the transition between each step of the proofs. At that point I found the material much more accessible. Reading the book was easier, the lectures made more sense, I could do homework, and consequently I could complete the exams.
I like this example because there is no copy-paste alternative. I had to engage with the material, but I chose to engage at a very mechanical level. Still, there was something about the process of reading and writing that aided in understanding the material.
I don't believe you can get that with copy-paste unless you find some other way to engage with the code.
I personally write a lot. I certainly find it useful to do that.
However, I would not normally recommend Zed Shaw "Learn Code the Hard Way" type of method of writing out over and over again. I think it probably works and you can do it yourself, but I think it's quite inefficient. I don't need to type 10 PRINT "HELLO" 20 GOTO 10 more than once to get a good sense of what's going on.
I think you most of all benefit here from the time you're forced to put in. If you can understand nothing, there's really no other sensible thing that allows you to concentrate for the time you need to make decent progress.
However, I don't think this means transcription is pedagogically ideal. IMHO building something for yourself is more effective; getting expert tuition is more effective: in terms of time spent vs benefit received.
This is bad especially for young developers (such as myself). Not to mention jeopardizing the security and integrity of your software project.
I hear 'don't reinvent the wheel' often written in blogs etc. That is not good. The lazy developer would read that and go, 'oh, I dont need to know how these things work, it's already been done for me. I'll just slap A to B, no need to reinvent anything'
Imo how it should read instead is, 'keep reinventing the dam wheel till you understand how it was made, only then you're free from reinventing it'.
I'm not surprised.
Ever observe threads about software engineering? They're profoundly anti-intellectual. HN is not the place to get any sort of engineering advice, I'm afraid. It's tailored towards self-promotion via programming. The difference may seem small, but the motives are quite different: mastery (as a developer) vs getting it done.
It shouldn't be surprising that there is a group who feel "I'll just slap A to B" is a good idea (that's not what happens every time somebody copy-and-pastes, by the way--it's one extreme example, and it's possible to copy-and-paste with a deep and mature understanding of what one is doing). Just like it shouldn't be surprising when certain elements of other groups chime in with comments implying CS is some deeply intellectual study of the fundamental nature of mathematics and logic, and if a programmer isn't treating his Enterprise CRUD App X as a means to engage in a deeply intellectual study or application of algorithms, data structures, and complexity analysis he's doing it wrong, or he isn't a real programmer, etc.
My first job was doing Perl, after studying Java. The Perl cookbook was a godsend, and basically encouraged copy pasting BUT had a discussion on the different methods presented and advantages of each one. I personally found that a very good way to learn.
This is one thing I find nice in the Perl community. I haven't used Perl for a few years now, but I always found PeelMonks a lot better then Stack Overflow, because it encourages the discussions that Stack Overflow discourages. Essentially it encourages the bad type of copy pasting I have described.
Are you aware of the notion that expressed confidence tends toward being inversely proportional to competence? And that this is a key to insightful learning?
You've said you're a young developer, so perhaps you haven't recognized this aspect of mind yet, but there's plenty of solid science (as well as anecdotal examples such as your confidence/competence in this exchange may be) that corroborate the essential truth of this aspect of mind.
Of course, I may well be wrong about applying that knowledge to this scenario, so I'm not going to claim confidence or competence in applying it, just that it seemed apropos. :)
That's how I was schooled by senior devs, whose opinion I have profound respect for. The reasoning is sound to me, I'll stick with it. Unless, someone has better reasons why I should copy and paste code, I would consider it.
You are doing god's work, son. Thank you.
To the GP: Swizec has it, please don't stop.
For example, I have a friend who sometimes fixes bugs in compiled software running banking systems with no access to the original code and woefully out of date documentation. He gets paid some 300eur an hour in a country where the median developer salary is only about 30k eur per year (about 14eur/h)
Sure, that particular type of problem likely/hopefully isn't caused by copy-paste programming, but it is caused by the sort of endemic issues copy-paste programmers to produce.
I'm sort of in between "get shit done" and "fix other people's shit" in my work. Because I like to take pride in my work, and because I don't want to leave the full timers with yet more contractor mess, I take care to do my job as well as I can. And I prefer projects where I can be proud of everything I do.
But in the 'trenches' of unsexy work, where my ideals meet reality, neither I nor the full-timers always have the time, money, or expertise to do things right, and are sometimes even forced by management to just get it done.
And I don't always mind. I can be happy with the result because it serves its purpose, and I made both the managers and many customers happy, even though I cringe at the underlying mess we produced. I know it is likely to cause much more work down the road, and I would generally advise against 'ship first, refactor later', but I'm also okay with the idea that I provide work for specialists to fix my mess.
Can I call myself a 'programmer'? Or am I more of a 'code monkey'? Do 'real' programmers thumb their nose at my sometimes shoddy code?
I don't really care. I'm happy with my work, and with my solutions. My aim is to move towards being able to provide full, high-quality solutions, because that makes me happier. But it also makes me happy to creatively solve problems in a way that might be imperfect, or frowned upon by some.
The most important reason for me to provide good, solid, readable code is because I care about the full-timers I meet who don't enjoy fixing my mess, and because I don't want my client to get into trouble later. That's why. It's primarily (but not exclusively) because I work with humans and I don't want to abuse my 'privilege' as a contractor and (relatively) skilled communicator to give other people headaches and crying fits over having to fix my junk. I've seen that happen, and it sucks.
(sorry, not necessarily directing this at you specifically)
> whole teams grind to a halt productivity-wise because the codebase is so bad
There are more than enough APIs just on the platform I work with daily that I can imagine how much fun it must be sorting through all those available to Windows developers must not be a joy. Well Google lets me search quickly for established solutions and combined with my knowledge I can quickly identify which if any will do what I want to do and adapt if not drop into my coding style.
TL;DR
Copy/Paste might not be good for new programmers, but time savings for experienced programmers warrants its use
Everybody has their own style of learning, and not everyone is at a point in their journey where poring over API docs or dropping down into a lower level makes sense for them.
That's not fair at all. Off the top of my head, three topics I have searched StackOverflow for a lot are Android development, MongoDB, and MySQL. Each time, I would consider the task I was doing to be programming, despite the fact that I was not building a mobile phone operating system or database myself from scratch.
It annoys the heck out of me too when people apply for a programming job and cannot implement even trivial CS methods (like integer => string conversion with base N), then point out that they would just Google for a solution if they needed something like this.
But to be honest, a lot of programming wisdom is buried somewhere on the web as well as inside libraries that do not warrant reimplementation. Much of this googling and copy-pasting simply represents the fact that our traditional programming library approach isn't sufficient anymore for distributing correct implementations of particular functionality - probably too much overhead. SO is much like a large library with mediocre code, imprecise interface specification and without working imports, but it also contains many solutions to trivial problems that competent engineers should be able to implement straighforwardly...
I can fix anyone's code, even when I've never used the language before [2] and it was written by an outsourced programmer who quite obviously only read "how to write SatanScript in 28 days" and then was locked in a room for 2 years until his program kinda worked if you held it upside down while reciting the words to Annie.
I am confident I am a good coder at this point in my career, and much better than many of the programmers I have met. There are a handful I have met that I know are better than me.
I would only have a vague idea of how to do a integer => string conversion with base N without googling it. So am I shit? Am I suddenly a useless programmer because lazyjones only likes people who studied CS? Even though I can understand that code in a glance and rewrite it, often better or clearer than the SO example?
You have picked an arbitrary, and extremely rare in the programming world, standard. No-one needs to write their own string handling routines any more.
Programming is hard and there are many different flavours.
And yours is an old fashioned favour from the early 00s. Stop judging people by it.
[1] Apart from my very bad habit of making a minor last minute tweak or bug fix, not testing it, and introducing an easily fixed bug
[2] They're all pretty much the same after you've used 3 or 4.
You can jump into any codebase and solve core architectural problems like precise garbage collection, eventual consistency, or miscellaneous dead locks? I'm not making up contrived examples, these are some of the problems my friends and I are currently dealing with at work for different companies.
> I would only have a vague idea of how to do a integer => string conversion with base N without googling it. So am I shit? Am I suddenly a useless programmer because lazyjones only likes people who studied CS?
I've never had to do integer => string conversion until asked in an interview either and I still did it. It's not a difficult problem. Anyone with a basic understanding of division and string manipulation should be able to reason out a solution.
> You have picked an arbitrary, and extremely rare in the programming world, standard. No-one needs to write their own string handling routines any more.
I wrote my own C++ string library before std::string was introduced. I contribute to Rust which has its own string, big number, vector libraries and much more. The web site I work on gets >130M monthly uniques and we have extended Python's string, dictionary, iteration, and datetime modules because the standard library isn't enough.
> [Programming languages are] all pretty much the same after you've used 3 or 4.
Then you haven't used enough languages. Try functional programming via Haskell, or dependent typing via Coq, or concurrency via Erlang, or memory safety via Rust.
The world is a really big place. I know people infinitely smarter than me doing incredible things, and there are many more like them. Stop being limited by your own experiences.
But take a step back. What are you trying to say? You're better than everyone who hasn't done these things? You're somehow a real programmer and everyone else isn't?
And look how big your penis is!
Seriously, what were you trying to achieve with this comment? What have you demonstrated? You're a specialist, you know certain things other people don't. So what? It doesn't make you any more of a programmer than I am.
And seriously, don't puff up the differences between languages, in the end every language is just a different way to take some data, transform that data and emit that new data. What happens in between is nothing particularly complex, it's simply the sheer number of those steps that can happen that make it complex. The whole point of languages is to make it easier to express something. Not harder.
I honestly don't know what perceived slight you were responding to. Carry on believing only the highly specialized 0.1% of programmers are real programmers if you want. Stop being limited by your own snobbish elitism.
If you receive a programming task like the above (with a relatively clear specification, very little state to manage, defined domain of the desired function, and the input and output of the function are most likely primitives in your language, your standart library probably have lots of utility functions to work with these primitives), I will expect, that you should be able to do it without googling.
Your solution may not be the most effective/short/clean, but it should work. If you can not do it without googling, well ... yes, I do think you are a shitty (or just out of shape for the moment) programmer.
You will need more programming exercise, in order to know more algorithms and aproaches to solving problems, and/or learn better your language and its standart library.
I would probably not hire you unless you could actually back up your dubious claims ("I can fix anyone's code ..."). The funny thing is, while I am judging people by their ability to solve a particular problem (which admittedly may have an age bias), you are judging people who studied CS based on the fact that you didn't but are still full of yourself.
It's worthwhile, if you can actually program.
It's unfortunate that a lot of people have to wait till they've gone to Uni, studied CS, gone into the real world, got a job programming, and found they cannot program.
It sounds very much like it I'm afraid. This is trivial problem solving. Your overconfidence + lack of problem solving ability are big red flags. If you're as good as you claim you are then you should know foundational principles. It gives you a far greater insight into programming than just grinding away with other programmers 'snippets'.
Personally I think this example is way more reasonable than most other technical "gotcha" problems. (I say that because I could solve it despite not having studied CS and being still relatively inexperienced.) But at least they're not asking how many pickles you could eat before exploding if you were shrunk down to the size of a kitten's tongue and placed on a miniature rocking horse that may or may not be alive inside its sad plastic shell.
I would argue that the problem is not the copy/pasting but where to paste the code. As an iOS developer I download a lot of code samples from the Apple Development Website. In many cases on these samples the developers put a lot of code in Controllers to show how things are done.
Beginner developers will usually copy/paste the code as is in the controller and believe what it does by faith.
An experience developer should understand that the code was put in the controller for educational purposes and place the code where it belongs. A Model, Singleton, or leave it in the controller if it makes sense.
So basically you're in the business of reinventing the wheel all the time. I feel sorry for your employer.
I think it is actually the other way around: once you develop the skill of 'programming', you will know what to search for when you have a problem and you will understand enough of the puzzle to construct the last piece from the various results to your search query. If you don't know how to search for an answer to your problem, you do not sufficiently understand your problem.
Unless you are using a library, it's gonna be better long-term going for complete understanding. Even then, it's usually a great idea to understand what a lib does under the hood.
Sometimes I just can't help thinking that the code I maintain has been optimized, foremost, for someone's job security—even when I know that the author is actually just of ‘get-shit-done’ type, and has been paid hourly.