Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 05, 2016, 12:48:58 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Copy/pasting code and the last line effect  (Read 1976 times)

phitsc

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 1,187
    • View Profile
    • Donate to Member
Copy/pasting code and the last line effect
« on: December 03, 2015, 03:05:02 PM »
I just copy/pasted some (test) code. But never you worry, I'll pay extra attention that the last one of the pasted lines is correct ;)

Read this article today about what the author calls the last line effect.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #1 on: December 03, 2015, 03:09:37 PM »
Nice!
I've made the last line effect mistake many times -- didn't know there was a name for it!

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 7,713
    • View Profile
    • The Blog of Deozaan
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #2 on: December 08, 2015, 05:32:52 PM »
I just caught myself making a "last line effect" copy/paste error. My brain farted and I edited the last line to be exactly the same as the second-to-last line. :o


TaoPhoenix

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 4,550
    • View Profile
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #3 on: December 08, 2015, 06:36:05 PM »

I dunno, I might disagree with this line:
"Not because they are tired..."

I think the joy is *because they are tired* because depending on how many blocks they did, they are tired of tedium rather than being creative solving a new problem, but instead are cranking out copied blocks with mods.

If it was just a 4 line program, it wouldn't happen. But it's probably after a lot of OTHER hard and/or tedious stuff, and then they just get disgusted.


anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 408
    • View Profile
    • App, to help you : Overlap Wallpaper, Park Cursor Aside, Stick A Note, Merge CSV and Text and many more.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #4 on: December 09, 2015, 02:01:52 AM »
Happened with me many times. Either the compiler or the run time error points my mistake.

I think the mind really gets 'tired' of repeated copy-paste-change work and starts registering 'Oh come on, it is done' before the last line ends.  :)

TaoPhoenix

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 4,550
    • View Profile
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #5 on: December 09, 2015, 07:40:13 AM »
Happened with me many times. ...
I think the mind really gets 'tired' of repeated... work and starts registering 'Oh come on, it is done' before the last line ends.  :)

And it's not just programming, I'll expand it to tedious anything. So in the physical world besides if there's muscle fatigue, you risk injuries from getting sloppy on the last "thing to do".

And just at the end of a big project, when you're checking little stuff, all over the map, even if it's not the same thing, that last couple of things are the ones where an error creeps in.

Heh and it happens in Chess! "Hurry up and resign already I've won... oh $hit ... I just dropped a piece and now I'm about to lose!!"

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #6 on: December 11, 2015, 10:07:09 AM »
Heh. Guilty here as well.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,282
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #7 on: December 11, 2015, 10:12:14 AM »
Whatever it was must have happened to the maintainer of the page since it does not respond.  :D

Edit:  actually I get a server not found but you know what I mean.  :)

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 677
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #8 on: December 11, 2015, 06:33:31 PM »
Quote
Multi Theft Auto

class CWaterPolySAInterface
{
public:
    WORD m_wVertexIDs[3];
};
CWaterPoly* CWaterManagerSA::CreateQuad (....)
{
  ....
  pInterface->m_wVertexIDs [ 0 ] = pV1->GetID ();
  pInterface->m_wVertexIDs [ 1 ] = pV2->GetID ();
  pInterface->m_wVertexIDs [ 2 ] = pV3->GetID ();
  pInterface->m_wVertexIDs [ 3 ] = pV4->GetID ();
  ....
}

The last line was pasted mechanically and is redundant. There are only 3 items in the array.

I noticed the author of that article is actually wrong about the above one. Because it appears the array starts at 0 therefore that one is absolutely correct because it has 4 items in the way 0, 1, 2 and 3. ;)
Carroll - HamRadioUSA.net

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #9 on: December 11, 2015, 06:41:10 PM »
actually there is a bigger bug here, though it's hard to be sure exactly what the author intended.

First things first, this looks like c++ code.

my guess is that the most likely bug is the declaration WORD m_wVertexIDs[3] should probably be WORD m_wVertexIDs[4];
creating a 4 element array(vector), indexed from 0 to 3, making the lines in the function correct.  if so this is NOT an example of a last line effect, but a deadly c++ style error of declaring an array too small (which may not be flagged as an error).

It's certainly true that the Multi Theft Auto code example is incorrectly diagnosed -- that last line is not "redundant", it is an error (given the earlier declaration) -- one that would be caught in some languages or cause unpredictable memory problems in others.
« Last Edit: December 11, 2015, 06:53:53 PM by mouser »

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 677
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #10 on: December 11, 2015, 06:54:38 PM »
So instead of the last line pasted...the author of the code seems to have simply forgot to increase the array size.  Which is definitely not the last line effect anyhow.
Carroll - HamRadioUSA.net

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #11 on: December 11, 2015, 06:57:51 PM »
Yes, ONE explanation is that the last line is correct but he/she forgot to increase the array size (thats my guess).
You could also argue that the last line should not be there at all -- in which case the proper explanation is not that that last line was "redundant" -- it's certainly not -- it will cause serious problems.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 6,137
  • Slartibartfarst
    • View Profile
    • Donate to Member
Re: Copy/pasting code and the last line effect
« Reply #12 on: December 11, 2015, 10:05:54 PM »
From my experience of working as a programmer, systems analyst, IT project manager and applications development manager, there are probably few or no mistakes that one is likely to find in this or any other discussion on errors made by skilled programmers that would be statistically "uncommon", and that will likely tend to be the way of it until human error is eliminated from the process of code-writing.
One of the more moronic statements I came across in IT management was at a meeting where a senior applications development manager, who, his team having been hit with a rash of coding errors that had manifested themselves only after operational implementation, instead of saying "We need to improve pre-production release testing", said "We need to have a Zero Error target". It was a gob-smackingly ignorant statement.
(The analyses of errors in programming coding indicated that it is not a process in statistical control, and even if it were (or could be) a process in statistical control, the main source of error would still remain/be human error, which is impossible to eliminate unless you eliminate the human element.)

As @anandcoral says:
Happened with me many times. Either the compiler or the run time error points my mistake.
I think the mind really gets 'tired' of repeated copy-paste-change work and starts registering 'Oh come on, it is done' before the last line ends.  :)

- and that could well be true. We don't really know the real cause of it in our heads.
One thing for sure is that programming requires a collection of learned skills and habits of mind that are products of our socio-cultural development rather than being associated with a necessary natural survival characteristic. If programming was associated with a necessary natural survival characteristic, then there would very probably be fewer common coding errors!

For example, you would be able to observe which areas of the brain light up on an EEG (Electroencephalograph) whilst a skilled programmer was coding, and you would probably see no lighting up of those areas of the brain associated with survival, because there is no danger.
You could contrast programming with (say) a skilled juggler juggling 3 spherical objects. Juggling, like programming, is a learned skill, and, similarly, you would be able to observe which areas of the brain light up on an EEG whilst a skilled juggler was juggling 3 spherical objects, and, again, you would probably see no lighting up of those areas of the brain associated with survival.

However, using the same skilled juggler, if you then substituted 3 very sharp knives for the 3 spherical objects, the EEG will show the juggler's brain lighting up very rapidly all over the place, including  those areas of the brain associated with survival - which is what one might intuitively expect. We are designed by our DNA and evolution to survive - all those who weren't simply dropped out of the gene pool. Once a threat to survival comes into it, our brain knows very well what is at risk, and literally "takes over".
Now I haven't studied this closely, but it would be interesting to see the statistics for the same skilled juggler, showing the number of mistakes made whilst juggling 3 spherical objects versus the number of mistakes made whilst juggling 3 very sharp knives.