All the Perl that's Practical to Extract and Report

Navigation

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

Another point that I would have made is: often, novices structure code in weird ways, with procedures that aren’t very useful outside the context in which they were conceived because they are big and do too many things. They use variables that get recycled over too many intermediate calculations, or conversely fail to break calculations into intermediate steps saved in variables.

Naming is a good detector for such problems. If you can’t think of a good precise name for the variable you just declared, it’s probably because it spans several computations that should be stored in separate variables. If you have trouble giving a function a good precise and concise name, it’s probably because you made a mistake in your separation of concerns.

This is a great general principle. “If you can’t give it a name, it’s probably because it’s the wrong abstraction.”

With experience, you get a better sense for which operations to break out, and in how many distinct parts to break them out. If you have a strong sense for program structure and naming, comments become almost completely unnecessary. Nowadays, nearly all comments in my code are related to bugs or shortcomings – explanations of why the code has to do this peculiar thing to avoid such-and-such problem, FIXMEs, the works.

For arrays and hashes, I always use the singular form. The plurality is already implied by the sigil – putting it in the name as well would be repetition. Note also that there are many cases where you use the collection as a whole, which read nicer with a singular name, such as push @person, $last_record (OK, I suppose that can be argued either way) or keys %person_name.

I read in a software engineering textbook about a South African software company that went broke, because its code had been written by Portuguese speakers, who used Portuguese for their variable names. The Portuguese programmers left the company, and were replaced by Afrikaans-speaking ones, who couldn't maintain the code, because they couldn't understand Portuguese.I found this hard to believe, but I've never had the experience.The textbook writer, from South Africa, said names must be in English.