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.
views:
394answers:
14How to explain to a high school hacker that indenting and verbose variable names are good things?
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...
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.
Write a bunch of "his" code and ask him to find a particular piece of code.
Give him some badly written code with a bug in it and ask him to find the bug.
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.
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.
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.
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.
Maybe he's not ignorant, maybe he's just inspired by Kernighan & Pike.
i,j,k is fine for loops.
I personally prefer using 1 letter vars in iterations...
foreach ($test as $t)
{
}
beautiful :D
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.