:( my mentor doesn't understand my code

Cogman

Lifer
Sep 19, 2000
10,286
147
106
So at my company before we can commit code, we have to send it through a review process. Being an intern, I send my code through my mentor. A recent assignment that I completed he approved for submission but made the passing comment "I didn't really understand it."

:( This gutted me. I've always felt my code was pretty clear, but I guess it isn't. He didn't really make the comment to say "your code sucks, you need to fix it." but rather just that the code looked to work so it must be good enough.

So, here is a snippet of my code. Please let me know what I can do to improve it or make it more readable. This is written in perl. This particular sub draws heavily off of the perl CGI library. The code works fine; there are no errors that I know of in it so don't spend too much time trying to debug it :D. I'm more interesting in comments on the form and less about comments on the function (though, the two are related).

Code:
# This sub creates an HTML table based off of a list of filenames and information strings comming in.
sub listItems {

# $index should contain the current directory index, $heading contains title of the section
# and @list contains all the different column information.
    my ( $index, $heading, @list ) = @_;
    if ( $#list >= 0 ) {
        print $index h1($heading), start_table({-class => 'navTable'}),
          Tr(
            th(
                [ 'Name', 'Last Author', 'SVN Revision', 'Last Modified Date' ]
            )
          );
        foreach my $item (@list) {

# This prints the data for each row. -class refers to the css class for each item.
            my $itemFormated = @$item[0];
            $itemFormated =~ s/\./_/g;
            print $index '<tr>',
              td(
                { -class => 'test' },
                a(
                    { href => 'http://' . $docAddr . "/$itemFormated.html" },
                    @$item[0]
                )
              ),
              td( { -class => 'author' },   @$item[1] ),
              td( { -class => 'revision' }, @$item[2] ),
              td( { -class => 'date' },     @$item[3] ),
              '</tr>';
        }
        print $index end_table;
    }
}
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
Sounds like your mentor needs a lesson on how to be less vague.

How the hell are you supposed to do anything with the feedback "I didn't really understand it?"

Kick him in the balls next time he says that to negatively reinforce his shortcommings.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Perl is not widely acclaimed for its readability.

Your mentor should give you much more detailed feedback than 'I didn't understand it'. But I don't know any Perl and I mostly understand it. Therefore, I conclude the fault is at least 90&#37; with your mentor. :)
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
Perl is not widely acclaimed for its readability.

Your mentor should give you much more detailed feedback than 'I didn't understand it'. But I don't know any Perl and I mostly understand it. Therefore, I conclude the fault is at least 90% with your mentor. :)

Still, though, my mentor has been said to be one of the better coders on the team.. If he doesn't understand it, what are the chances that someone else is going to come along that can understand it?

Luckily, this is a minor part of whole system that won't really need to be looked at all that much, but still, it bothers me that I'm potentially writing unmantainable code. I don't want to be known as the "Crap, I hate dealing with this guy's code" guy :D.

(This is an automated test development team, hence the perl usage :D)
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
You can ask he what exactly he doesn't understand and offer to explain it to him. Have you looked at his code to see how it differs from yours?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
So, here is a snippet of my code. Please let me know what I can do to improve it or make it more readable. This is written in perl. This particular sub draws heavily off of the perl CGI library.
That's the first problem. The Perl CGI library has a slightly unusual syntax. I'd never seen it before. Did you make mention of using it in the comments, and possibly provide a link to its documentation?

Otherwise, I only see little issues of style:
  • Code:
    my $itemFormated = @$item[0];
    I think you just got a slice of one. Did you mean $$item[0]? Likewise with indices 1 and 2 later. I always have to refer to perlreftut when working with references. Edit: Oh, and it's "formatted", not "formated". :p
  • Tr, not tr? Is that why you did '<tr>'...'</tr>' later? Again, I'd need to see the CGI documentation.
  • Code:
    { href => 'http://' . $docAddr . "/$itemFormated.html" },
    That's rather inconsistent. I'd go with either both variables separated out of the string or neither. Either way should work.
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
(This is an automated test development team, hence the perl usage :D)

:eek: What automated testing system uses Perl? (And what does it test?) I'd love to introduce such a system to my boss, if it tests stuff we're testing. :)
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
:eek: What automated testing system uses Perl? (And what does it test?) I'd love to introduce such a system to my boss, if it tests stuff we're testing. :)

We are currently testing HP's Superdome 2 firmware. The testing system is inhouse (sorry) and really wouldn't be very useful for anyone outside of HP anyways.

Though, for the inhouse stuff we do, it is pretty useful.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
That's the first problem. The Perl CGI library has a slightly unusual syntax. I'd never seen it before. Did you make mention of using it in the comments, and possibly provide a link to its documentation?

Otherwise, I only see little issues of style:
  • Code:
    my $itemFormated = @$item[0];
    I think you just got a slice of one. Did you mean $$item[0]? Likewise with indices 1 and 2 later. I always have to refer to perlreftut when working with references. Edit: Oh, and it's "formatted", not "formated". :p
For the CGI library. Most of the older scripts I've seen here don't use it, but many of the newer ones do use it. So, I figured I would use it. for no other reason than to save on my typing. (the "start_html" is pretty nice as it does all the W3 stuff while still being pretty readable.

With the $$ stuff, yeah, you are probably right.. Dang it, just when you think you're getting use to the differences between $ &#37; and @...

Thanks.. I'll have to comb though the code and make sure there aren't other mistakes like that.. It is sort of surprising that it worked Perl is a bit crazy that way.

  • Tr, not tr? Is that why you did '<tr>'...'</tr>' later? Again, I'd need to see the CGI documentation.
tr is a perl keyword that came before the CGI library. There are few other nuances with the CGI library like that. However, the reason I did the '<tr>' stuff is because in order for the string to be built properly, I would have to have used the "start_tr" and "end_tr" tags.. well, for consistencies sake I probably should have done it, however I figured the tag itself was a pretty small and unlikely to change tag that the few extra characters for the start_tr really didn't serve any purpose.

  • Code:
    { href => 'http://' . $docAddr . "/$itemFormated.html" },
    That's rather inconsistent. I'd go with either both variables separated out of the string or neither. Either way should work.

:), lol, good point there was no reason to do that other than the fact that I keep forgetting that perl allows you to put variables in strings like I did. :D even right after doing it.... duh!
 
Last edited:

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
coding != mentoring

One of the better Coders = Lots of experience with good code.

Which I understand Cogman's concern but with the minimal feedback the mentor gave, I'm gonna assume he is a mumbling red-stapler guy programmer.
 

quikah

Diamond Member
Apr 7, 2003
4,227
769
126
I can see a few possibilities.

- your mentor is not that good, all the good people left HP long ago. :)
- your mentor has so much stuff to do because all the good people left HP long ago that he doesn't have time to really review your code
- your mentor just doesn't know perl
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Pretty useless comment from your mentor, imho. I wouldn't read much into it at all. If he can't read that and ultimately figure out approximately what it's doing then he probably isn't very good at what he does. If he is good at what he does, then he probably doesn't give a shit. Seeing as how he didn't bother to come see you and ask you to explain it to him, I'm going with doesn't give a shit.
 
May 11, 2008
23,331
1,575
126
I have heard of perl, but i never used it and i do not know the syntax.
But i think i can grasp what you try to do. (mainly because of the comments) which (yay , for once i can be the grammar nazi :biggrin: ) have some typing errors in it.

But if someone who is a good perl coder gives you such a comment, ask what he means. Because that is a useless comment. Why is he not more specific ?
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
I was probably just overreacting. The tone of the comment sounded more like "I didn't have enough time to really look over your code" and less of "Your code is terrible and no mortal can ever understand it." It really was more of a side comment.
 

Bryanatkinson

Junior Member
Jun 27, 2011
12
0
0
cornershelfshop.com
I was probably just overreacting. The tone of the comment sounded more like "I didn't have enough time to really look over your code" and less of "Your code is terrible and no mortal can ever understand it." It really was more of a side comment.

+1

I also don't have any experience in pearl, but your code is very readable.

There is high chance that your mentor will gives different answer when he has more time.