Page 1 of 2 [ 24 posts ]  Go to page 1, 2  Next

mouthyb
Deinonychus
Deinonychus

User avatar

Joined: 5 Aug 2013
Age: 46
Gender: Female
Posts: 323
Location: Somewhar dusty and hot.

07 Feb 2014, 5:47 pm

Does anyone else find it.... very difficult.... to work with code they've inherited and/or otherwise received from other persons? I'm in a coding class now and the stuff the professor is handing us to work with is eyewateringly difficult to comprehend the purpose of, as well as to work with the logic for organization and implementation. There are things grouped together that I cannot imagine a reason for grouping, and it appears to me that what she tells us she wants us to write and what's actually there are so different as to make the instructions only partially helpful.

I'm spending more time trying to figure out the rationale for the code we're not allowed to change than I am writing it. Is this an AS thing?


_________________
RAADS-R: 181
Eye Expression Test: 19
Alexithymic: Please explain conclusions if asked

The feels are shipped in by train once a week--Friday, I'm in love.


linuxdude314
Butterfly
Butterfly

User avatar

Joined: 5 Feb 2014
Gender: Male
Posts: 11

07 Feb 2014, 5:50 pm

I don't think its so much an AS thing, aside from looking for order when there may actually be none. I think that when you encounter things in code that you can't find a reason for its just easier to assume that the person did not have a good reason, and just did it arbitrarily. Keep it simple!



mouthyb
Deinonychus
Deinonychus

User avatar

Joined: 5 Aug 2013
Age: 46
Gender: Female
Posts: 323
Location: Somewhar dusty and hot.

07 Feb 2014, 7:48 pm

My brain segfaults when there's not a discernible order and it's hard to recover. I tend to panic a little because I assume there must be an order, but for some reason I'm not seeing it, which makes me wonder what else I'm not seeing.

It's a.... weird..... personality flaw. Things that have no underlying order make me feel like bits of my brain are on fire.


_________________
RAADS-R: 181
Eye Expression Test: 19
Alexithymic: Please explain conclusions if asked

The feels are shipped in by train once a week--Friday, I'm in love.


Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 35
Gender: Male
Posts: 4,132
Location: Scandinavia

07 Feb 2014, 8:24 pm

This is why you should use comments, and why it's important for code to be orderly, and important for it to make sense (i.e. a class that represents a list structure should be named "myList" rather than "marklar" or "ivejackedupuntilibleed").

The fact of the matter is that this is a problem a lot of people struggle with, which is why golden handcuffs are very efficient (allthough in the EU/EEA, you can sue employees if they program nonsensical code).



ruveyn
Veteran
Veteran

User avatar

Joined: 21 Sep 2008
Age: 87
Gender: Male
Posts: 31,502
Location: New Jersey

07 Feb 2014, 9:23 pm

Working with un commented code is difficult. If the code is not commented and you do not have a clear notion of what the code was supposed to do, then it is damned near impossible.

Here is an example Suppose I handed you a machine level code for the solution of a quadratic equation.
ax^2 + bx +c = 0 The code executes the well known formula x = (-b +- sqrt (b^2 -4ac))/2a.

The code could be beautiful and clean but without comments and without a statement of what the code was supposed to do, 99 out of 100 good programmers would not be able to tell you what the code was and if it were correct.

ruveyn



Shatbat
Veteran
Veteran

User avatar

Joined: 19 Feb 2012
Age: 31
Gender: Male
Posts: 5,791
Location: Where two great rivers meet

07 Feb 2014, 9:38 pm

Is it undocumented? It is bad form to hand out undocumented code and expect others to understand it.

When it is documented, my issues are mainly with understanding the overall structure, and what each attribute and method are supposed to do when looked at as a whole. UML diagrams are good for that.


_________________
To build may have to be the slow and laborious task of years. To destroy can be the thoughtless act of a single day. - Winston Churchill


TallyMan
Veteran
Veteran

User avatar

Joined: 30 Mar 2008
Gender: Male
Posts: 40,061

08 Feb 2014, 3:20 am

I took on an undocumented project. It was spaghetti code with no comments or documentation. Something like 30,000 lines of undocumented code. The programmer had left his employer to move on to other things and I took over the code as a private contractor. I made a nice living from doing upgrades to the software for a number of years. It adds a whole new dimension to programming when you have to work with such code. You almost have to treat the code as a series of black boxes. It isn't a task for the faint hearted though. You need to tread with great care so as not to break any existing functionality. The software was in use by hundreds of organisations all over the world and was associated with a lot of data in a highly proprietary compressed format, so maintaining compatibility with all the existing data was crucial.

Some of my own software that I wrote twenty years ago is still in use today, I'm thankful that I wrote documentation and well documented the code - nobody can remember how or why they did things several years later, especially when the language you wrote the code in is effectively obsolete and you've moved on to program in other languages. I recently got a request from a client to produce a version of some of my twenty year old software in German so I've been busy with that. Working with old code is a bit like archaeology, so the more documentation the better.


_________________
I've left WP indefinitely.


MaxE
Veteran
Veteran

User avatar

Joined: 2 Sep 2013
Gender: Male
Posts: 5,274
Location: Mid-Atlantic US

08 Feb 2014, 10:17 am

I'm a bit odd this way. I've always been confident understanding others' code. I began my programming career writing in assembler and debugging the resulting machine language, so I suppose it was a survival skill.

In fact, I often don't pay much attention to human language documentation. For me, computer languages are the most concise (if "spoken" fluently) and can't be improved on through translation into English, Spanish, or Telugu.

Of course well-written code is far more understandable than its opposite. Just as well-formed English sentences can be understood much better than what one typically encounters in social media.

Also when looking at source code, you can't know whether the comments reflect the latest 03h00 revision. Best make certain you understand the code.



ruveyn
Veteran
Veteran

User avatar

Joined: 21 Sep 2008
Age: 87
Gender: Male
Posts: 31,502
Location: New Jersey

08 Feb 2014, 10:41 am

Shatbat wrote:
Is it undocumented? It is bad form to hand out undocumented code and expect others to understand it.

When it is documented, my issues are mainly with understanding the overall structure, and what each attribute and method are supposed to do when looked at as a whole. UML diagrams are good for that.


If the purpose of the code is documented well enough, one can reverse into the code even if it is badly written and figure out ways to clean it up.

ruveyn



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 35
Gender: Male
Posts: 4,132
Location: Scandinavia

08 Feb 2014, 10:43 am

TallyMan wrote:
I took on an undocumented project. It was spaghetti code with no comments or documentation. Something like 30,000 lines of undocumented code. The programmer had left his employer to move on to other things and I took over the code as a private contractor. I made a nice living from doing upgrades to the software for a number of years. It adds a whole new dimension to programming when you have to work with such code. You almost have to treat the code as a series of black boxes. It isn't a task for the faint hearted though. You need to tread with great care so as not to break any existing functionality. The software was in use by hundreds of organisations all over the world and was associated with a lot of data in a highly proprietary compressed format, so maintaining compatibility with all the existing data was crucial.

Some of my own software that I wrote twenty years ago is still in use today, I'm thankful that I wrote documentation and well documented the code - nobody can remember how or why they did things several years later, especially when the language you wrote the code in is effectively obsolete and you've moved on to program in other languages. I recently got a request from a client to produce a version of some of my twenty year old software in German so I've been busy with that. Working with old code is a bit like archaeology, so the more documentation the better.


Code:
            #include  <math.h>
           #include      <time.h>
           #include            <unistd.h>
        #include           <netinet/in.h>
          typedef            float F,A[3]; F D,M
        [999]={          LT} ,*L=NL+M,*P,b,t,*h,*i; A
      #define S(x,y,z)F  x(F*d,F z s){ F t=y; t+=y; return t+=y; }
    E,Q,U,V,C,c,I={ EY} ; unsigned char g[2414],*p=g,*e; int j,k,s,m
   ,n,x,y; S(B,*d++=*s++,*)S(o,*d+++=*s++,*)S(a,*d++-=*s++,*)S(H,*d++
      **s++,*)S(X,*d++*=s,)S(v,*d+++=s,)int w(int c){ return*p++=c; } F W(F*
     d){ return sqrt(H(d,d)); } void r(uint32_t u){ w(u>>24); w(u>>16); w(u>>
    8); w(u); } F  O(F*d){ return X(d,1/W(d));  } char*z,*f; void u(char*s){ *
   s&&w((u(1+s),*s)); } F G(F x,int p){  for(z=p*46+f; 12^*z; x+=.5){ for(D=-4;
  5>D; D++)if(9-*z++){ *P++=x; *P++=D/2; *P++=0; } } return p; } void K(){ write
  (k,g,p-g); p=g; } F*d(){ h=0; D=1e9; a(E,Q); O(E); 2[E]&&0>(t=(1+2[Q])/2[E])&&
 (D=-t,h=P); for(i=M; P>i; i+=3){ B(C,i); a(C,Q); b=H(E,C); (t=b*b-H(C,C)+(i<L?99
 :.6))>=0&&0<(t=b<t?t+b:b-t)&&D>t&&(D=t,h=i); } return h; } void Y(int N){ F*h,*i
; A p,n; if(!(h=d()))*c=1[c]=(2[c]=2[E]/2)/2; else if(h<L){ X(c,0); v(c,1); } else
{ B(p,E); X(p,D); o(p,Q); if(h-P){ B(n,p); a(n,h); O(n); } else{ X(n,0); ++2[n]; }
B(Q,n); X(Q,1e-4); o(p,Q); X(c,0); if(N<8){ B(Q,n); X(Q,2*H(n,E)); a(E,Q); o(E,p);
B(Q,p); Y(1+N); X(c,h-P?.8:.2); } for(i=M; L>i; ++i){ B(E,i); B(Q,p); d()-i||v(c,(
h-P?.1:.5)*H(n,E)); } v(c,0.05); h-P||(2[c]*=.3,c[1&lrint(*p)^lrint(1[p])&1]*=.2);
} } void Z(char*s){ K(); p+=4; u(s?s:"TADI"); } void J(){ uint32_t c=~0; e=p; p=g;
r(e-p-8); while(p!=e){ c^=*p++; for(j=0; 8>j; j++)c=c/2^c%2*3988292384; } r(~c); K
 (); } void q(int c){ w(c); m+=c; m%=c=65521; n+=m; n%=c; } void T(F c){ c=.5+255
 *c; q(0>c?0:c>255?255:c); }  struct sockaddr_in R;  int main(){ time_t i; struct
  tm*b; R.win_port=8224;  s=socket(R.sin_family=AF_INET,SOCK_STREAM,0);  bind(s,
  (void*)&R, sizeof R); listen(s,1); for(; ; ){ k=accept(s,0,0); for(; ; ){ ++j;
   read(k,p,1); if(*p=='\n')  { if(3>j)break;  j=0; } }  m=1; u("\n\032\n\rGNP"
    "\211\n\r\n\r1 :hserfeR\n\rKO 002 0.1/PTTH"); Z("RDHI"); r(800); r(600); w
     (8); r(33554433); J(); Z(0); w(120); w(1); J(); i=time(0); b=localtime(&
      i); x=b->tm_sec; *I=45<x?x-60:15>x?x:30-x; *U=-I[1]; 1[U]=*I; *V=2[I]*
   *I; 1[V]=2[I]*1[I];2[V]=-*I**I-1[I]*1[I];  O(U); O(V); X(U,D=W(I)/
    1e3); X(V,D);  P=L;y=1+(11+b->tm_hour)%12; 9<y&&G(-14,y/10); G(-
      10,y%10); G(-6,10); y=b->tm_min;  G(-2,y/10);G(2,y%10); G(6,
        10); G(10,x/10);  G(14,x%10);  for(z="xxxdtrb!  d r y ";    9[z]; ++z){
          for(y=7&8[z]; 600>y; y+=14&*z){ Z(0); w(0); p+=4; q(    0); for(x=7&9[z]; 800>x;
        x+=15&1[z]){ B(Q,V); X(Q,y-300); B(E,U); X(E,x    -400); o(E,Q); B(Q,I); Y(0);
           T(*c); T(1[c]); T(2[c]); } j=p-g-13; 12[    g]=~(10[g]=j>>8); 11[g]=~(9[g]=
           j);  J(); } }  Z(0); w(1);  r(    65535); r(n<<16|m); n=0; J(); Z(
            "DNEI"); J(); j=0;    close(k); } } char*f=

"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ";


An IOCCC winning entry, "mills.c".



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 35
Gender: Male
Posts: 4,132
Location: Scandinavia

08 Feb 2014, 10:47 am

ruveyn wrote:
Shatbat wrote:
Is it undocumented? It is bad form to hand out undocumented code and expect others to understand it.

When it is documented, my issues are mainly with understanding the overall structure, and what each attribute and method are supposed to do when looked at as a whole. UML diagrams are good for that.


If the purpose of the code is documented well enough, one can reverse into the code even if it is badly written and figure out ways to clean it up.

ruveyn


You can reverse engineer almost anything, but it's very time consuming, tedious, and often has a low payoff. Nevertheless, this is the primary reason why you should never hardcode sensitive information. The most famous examples of reverse engineering being used for something useful, is the porting of closed source game engines.



mouthyb
Deinonychus
Deinonychus

User avatar

Joined: 5 Aug 2013
Age: 46
Gender: Female
Posts: 323
Location: Somewhar dusty and hot.

08 Feb 2014, 2:07 pm

It's not commented on what it does, it was commented as to what the person who wrote it would like it to do, but without saying that it was what the person wanted it to do. I figured out more or less what is going on, I just had a brain-seize looking at it because I am a) inexperienced (this is only the second class) and b) assumed that the professor would tell us what she wanted us to do with it (she said, and I quote "make it work" and was then out sick so we couldn't ask questions.)

There's literally a class made up of nothing but method stubs, and we have to write our own class that implements those method stubs. But the comments indicate that the methods work (they don't), so I couldn't figure out for a little bit if they DID work and I was just too inexperienced to figure it out, or if she intended us to write them (but we aren't allowed to change her code.)

I was just wondering if anyone else gets..... very uncomfortable.... when they encounter code that makes no damn sense.


_________________
RAADS-R: 181
Eye Expression Test: 19
Alexithymic: Please explain conclusions if asked

The feels are shipped in by train once a week--Friday, I'm in love.


ruveyn
Veteran
Veteran

User avatar

Joined: 21 Sep 2008
Age: 87
Gender: Male
Posts: 31,502
Location: New Jersey

08 Feb 2014, 2:51 pm

Kurgan wrote:
TallyMan wrote:
I took on an undocumented project. It was spaghetti code with no comments or documentation. Something like 30,000 lines of undocumented code. The programmer had left his employer to move on to other things and I took over the code as a private contractor. I made a nice living from doing upgrades to the software for a number of years. It adds a whole new dimension to programming when you have to work with such code. You almost have to treat the code as a series of black boxes. It isn't a task for the faint hearted though. You need to tread with great care so as not to break any existing functionality. The software was in use by hundreds of organisations all over the world and was associated with a lot of data in a highly proprietary compressed format, so maintaining compatibility with all the existing data was crucial.

Some of my own software that I wrote twenty years ago is still in use today, I'm thankful that I wrote documentation and well documented the code - nobody can remember how or why they did things several years later, especially when the language you wrote the code in is effectively obsolete and you've moved on to program in other languages. I recently got a request from a client to produce a version of some of my twenty year old software in German so I've been busy with that. Working with old code is a bit like archaeology, so the more documentation the better.


Code:
            #include  <math.h>
           #include      <time.h>
           #include            <unistd.h>
        #include           <netinet/in.h>
          typedef            float F,A[3]; F D,M
        [999]={          LT} ,*L=NL+M,*P,b,t,*h,*i; A
      #define S(x,y,z)F  x(F*d,F z s){ F t=y; t+=y; return t+=y; }
    E,Q,U,V,C,c,I={ EY} ; unsigned char g[2414],*p=g,*e; int j,k,s,m
   ,n,x,y; S(B,*d++=*s++,*)S(o,*d+++=*s++,*)S(a,*d++-=*s++,*)S(H,*d++
      **s++,*)S(X,*d++*=s,)S(v,*d+++=s,)int w(int c){ return*p++=c; } F W(F*
     d){ return sqrt(H(d,d)); } void r(uint32_t u){ w(u>>24); w(u>>16); w(u>>
    8); w(u); } F  O(F*d){ return X(d,1/W(d));  } char*z,*f; void u(char*s){ *
   s&&w((u(1+s),*s)); } F G(F x,int p){  for(z=p*46+f; 12^*z; x+=.5){ for(D=-4;
  5>D; D++)if(9-*z++){ *P++=x; *P++=D/2; *P++=0; } } return p; } void K(){ write
  (k,g,p-g); p=g; } F*d(){ h=0; D=1e9; a(E,Q); O(E); 2[E]&&0>(t=(1+2[Q])/2[E])&&
 (D=-t,h=P); for(i=M; P>i; i+=3){ B(C,i); a(C,Q); b=H(E,C); (t=b*b-H(C,C)+(i<L?99
 :.6))>=0&&0<(t=b<t?t+b:b-t)&&D>t&&(D=t,h=i); } return h; } void Y(int N){ F*h,*i
; A p,n; if(!(h=d()))*c=1[c]=(2[c]=2[E]/2)/2; else if(h<L){ X(c,0); v(c,1); } else
{ B(p,E); X(p,D); o(p,Q); if(h-P){ B(n,p); a(n,h); O(n); } else{ X(n,0); ++2[n]; }
B(Q,n); X(Q,1e-4); o(p,Q); X(c,0); if(N<8){ B(Q,n); X(Q,2*H(n,E)); a(E,Q); o(E,p);
B(Q,p); Y(1+N); X(c,h-P?.8:.2); } for(i=M; L>i; ++i){ B(E,i); B(Q,p); d()-i||v(c,(
h-P?.1:.5)*H(n,E)); } v(c,0.05); h-P||(2[c]*=.3,c[1&lrint(*p)^lrint(1[p])&1]*=.2);
} } void Z(char*s){ K(); p+=4; u(s?s:"TADI"); } void J(){ uint32_t c=~0; e=p; p=g;
r(e-p-8); while(p!=e){ c^=*p++; for(j=0; 8>j; j++)c=c/2^c%2*3988292384; } r(~c); K
 (); } void q(int c){ w(c); m+=c; m%=c=65521; n+=m; n%=c; } void T(F c){ c=.5+255
 *c; q(0>c?0:c>255?255:c); }  struct sockaddr_in R;  int main(){ time_t i; struct
  tm*b; R.win_port=8224;  s=socket(R.sin_family=AF_INET,SOCK_STREAM,0);  bind(s,
  (void*)&R, sizeof R); listen(s,1); for(; ; ){ k=accept(s,0,0); for(; ; ){ ++j;
   read(k,p,1); if(*p=='\n')  { if(3>j)break;  j=0; } }  m=1; u("\n\032\n\rGNP"
    "\211\n\r\n\r1 :hserfeR\n\rKO 002 0.1/PTTH"); Z("RDHI"); r(800); r(600); w
     (8); r(33554433); J(); Z(0); w(120); w(1); J(); i=time(0); b=localtime(&
      i); x=b->tm_sec; *I=45<x?x-60:15>x?x:30-x; *U=-I[1]; 1[U]=*I; *V=2[I]*
   *I; 1[V]=2[I]*1[I];2[V]=-*I**I-1[I]*1[I];  O(U); O(V); X(U,D=W(I)/
    1e3); X(V,D);  P=L;y=1+(11+b->tm_hour)%12; 9<y&&G(-14,y/10); G(-
      10,y%10); G(-6,10); y=b->tm_min;  G(-2,y/10);G(2,y%10); G(6,
        10); G(10,x/10);  G(14,x%10);  for(z="xxxdtrb!  d r y ";    9[z]; ++z){
          for(y=7&8[z]; 600>y; y+=14&*z){ Z(0); w(0); p+=4; q(    0); for(x=7&9[z]; 800>x;
        x+=15&1[z]){ B(Q,V); X(Q,y-300); B(E,U); X(E,x    -400); o(E,Q); B(Q,I); Y(0);
           T(*c); T(1[c]); T(2[c]); } j=p-g-13; 12[    g]=~(10[g]=j>>8); 11[g]=~(9[g]=
           j);  J(); } }  Z(0); w(1);  r(    65535); r(n<<16|m); n=0; J(); Z(
            "DNEI"); J(); j=0;    close(k); } } char*f=

"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ";


An IOCCC winning entry, "mills.c".


Aieeee! The Blob!! !!



TallyMan
Veteran
Veteran

User avatar

Joined: 30 Mar 2008
Gender: Male
Posts: 40,061

08 Feb 2014, 2:51 pm

mouthyb wrote:
I was just wondering if anyone else gets..... very uncomfortable.... when they encounter code that makes no damn sense.


I don't get uncomfortable but sometimes it irritates the hell out of me. One of the worst offenders is Microsoft. I sometimes find myself in need of somewhat advanced or newer Microsoft tools / methodology and they provide inadequate information on how to use or implement them. Their documentation is often incomplete or lacking examples. Many times I've had to implement MS features without adequate documentation and it is a case of trial and error finding the appropriate methodology and parameters by guesswork to make the technology work. I can't be the only developer to hit this problem... In fact I know I'm not because my Google searches regarding obscure/new Microsoft tools reveals a hoard of other programmers with the same problems as me... sometimes I figure stuff out myself or someone else has. For the sake of someone at Microsoft spending a few minutes writing adequate documentation many hours are wasted by many developers fumbling around guessing how to use the latest Microsoft technology and likely introducing instabilities or bugs as a result. There have been times I've given up and not been able to use Microsofts latest and greatest and I've had to fall back on old technology and old API calls in brand new software developments.


_________________
I've left WP indefinitely.


GivePeaceAChance
Veteran
Veteran

User avatar

Joined: 10 Jan 2014
Age: 61
Gender: Female
Posts: 806
Location: USA

09 Feb 2014, 6:06 am

I was working on a project in the defense industry (a compiler, fixing bugs)

had on involving going back and changing some basic things in very old modules and I came across several of them which were just masses of code written in a way against protocol and zero comments. I took it to my boss and just asked "who does this?"

1 ) someone who is incompetent

B ) wants you to think you can't get rid of them.

best reaction to this type of employee - kick them to the curb - fix their stuff - find decent people who work together and competently

conclusion of discussion - I got 2 extra weeks to work out the bug.


_________________
?The first duty of a human being is to assume the right functional relationship to society--more briefly, to find your real job, and do it.? - Charlotte Perkins Gilman
"There never was a good war, or a bad peace." - Benjamin Franklin


Marky9
Veteran
Veteran

User avatar

Joined: 4 Mar 2013
Gender: Male
Posts: 1,625
Location: USA

09 Feb 2014, 9:13 am

Yep, working through someone else's code can be frustrating, with the level of frustration depending largely on how well documented it is.