views:

394

answers:

14

He is good programmer (won some competitions) but he absolutely ignores formatting. He consider i, j, k beautiful... I hope he won't find out about existence of goto keyword.

+6  A: 

tell him about python :)

SilentGhost
that would only teach him about indentation. it wouldn't enforce verbose variable names
Nathan Fellman
+11  A: 

Write some code in his "style" and then ask him to read it and explain to you what it is doing.

What's good for the goose and all...

Really good idea, thanks.
Łukasz Lew
and do it in perl...
annakata
http://www.reverseshot.com/files/images/pre-issue22/texas-chainsaw-massacre_28.preview.jpg
Justice
This may work, but if he is really that good, he may not have a real problem. Then you have just reinforced his conceptions. Formatting does help an individual, but the real benefit is for a team and maintenance coders.
EBGreen
@EBGreen, in my experience when people can read messy code it's because they have an internal model of what is going on and the syntax elements just cues into that model. Throw something that is messy at them for which they have no mental model and it's not so easy.
I agree that this is generally true, however someone that has been looking at crap for a long time will usually see the corn before someone that hasn't been. Script kiddies are often well versed in quickly looking at another kiddies code and grokking it.
EBGreen
A: 

Well, if he plans to do this for a living just explain that he will have a very rough life on a real team if he doesn't at least make some effort to follow the team standards. If he doesn't plan to do it for a living, don't worry about it.

You also might determine if there is anyone(s) that he admires. If there is then there is a pretty good chance that they follow standards.

EBGreen
+1  A: 

Code maintainability

Stuff I didn't care in high school neither :)

total
+1  A: 

Write a bunch of "his" code and ask him to find a particular piece of code.

Dacto
+1  A: 

Give him some badly written code with a bug in it and ask him to find the bug.

Jim Blizard
+6  A: 

Make him maintain somebody else's code that's written the way he writes. Then make him maintain somebody else's code that was written with good style.

Paul Tomblin
The second step is nice, but should not be necessary on the path to enlightenment. ;-)
Konrad Rudolph
@Konrad, some people need more a kick in the head than others.
Paul Tomblin
A: 

You probably can't. Some people just don't get it. I use self-describing variable names both at work and in private where noone tells me to. I also got some appreciation at work for using long and understandable names.

If a guy does not do it neither for himself or for your project then you've got that kind of guy. Show him some docs on the source code style policy. Explain why this is important.

You begin to use the right naming convention after you've got some experience and you see how and why this was useful. Without experience it's just an abstract talk.

P.S. Sometimes I get stuck with variable names because I'm not sure if this particular name does conform to the common linguistic style I use in the current project or how would the name scale on the high litterature language. The problem of using bool b1 vs. bool IsSomePropertyAvailable has never come up since the first university years.

User
A: 

I would point out that having clean code is a sign of a organized and intelligent mind. However, the real killer will be when he writes a large amount of code. I doubt you will be able to convince him because more than likely he is getting excited about the logic of the app and not the process. It will take experience to teach him a harsh lesson. So here are my suggestions.

  • Give him a project full of messy unformatted poorly named code and let him suffer.
  • Encourage him to work on a project with a large code base and let him see how well he remembers his own variable names after the 1,000th source file.
  • Elijah
    +3  A: 

    A combination of FORTRAN77 and Python should sort him out.

    Ian Hopkinson
    A: 

    I'm pretty sure you can misconfigure a code beautifier to present such horrible output. Obfuscaters are common, and do essentially the same thing (short useless variable names, no indenting, poor use of whitespace).

    Give him the assignment of taking an existing program with his style and adding a trivial feature.

    Also, take code he wrote 6 months or more ago and give the same assignment.

    Adam Davis
    A: 

    Maybe he's not ignorant, maybe he's just inspired by Kernighan & Pike.

    kotlinski
    A: 

    i,j,k is fine for loops.

    I personally prefer using 1 letter vars in iterations...

    foreach ($test as $t) 
    {
    }
    

    beautiful :D

    Mario
    +7  A: 

    I told my students (post-secondary) that they had the choice of writing code well or of me writing their assignments in the same sort of way that they wrote their code. I told them I would write the following program:

    • take the text of the assignment
    • lookup a number of the words in a thesaurus and replace them with obscure versions
    • remove all punctuation
    • remove all whitespace
    • convert everything to lower case
    • insert random whitespace
    • capitalize random letters

    They could then have the assignment... hey its "right" (all of the words are there) good luck understanding what the assignment is though.

    Oddly the complaints stopped at that point :-)

    I also compared it to English. We use paragraph breaks, capitalizations, etc... as a convention. When someone chooses not to follow the conventions it makes reading much harder.

    TofuBeer