tags:

views:

106

answers:

2

I am a beginner in programming. I have a large piece of code. I want to break it up into functions, return values, pass those values to another function. I want to be an expert in doing this. Give me suggestions on where to study or how to be an expertise on these simple fundamentals. When will I use pointers in the functions and all this?

A: 

Code Complete is a good book to study for these types problems. It has one chapter of about 25 pages dedicated to writing good functions.

Code Complete provides recommendations instead of strict rules. Some of the recommendations for writing good functions are:

  • Use a good name for the function.
    • A good name describes everything the routine does.
    • Avoid using meaningless verbs, such as ProcessInput() or DealWithOutput()
  • A function should (usually) only do the one thing.
  • A function shouldn't have side effects. Ie It modifies something outside of the function not related to the function result.
  • A function should have a good layout that is easy to follow. In most cases it is better to have a single exit/result point.
  • A function should do the same thing, regardless of where the function is called from.

The above is just a small summary of some of the points made in Code Complete.

Shannon
A: 

As a beginner,

Best way to learn Perl is to read standard book e.g.; Programming Perl by the inventor itself.

This book helps you to understand lot of things like

  • Subroutines
  • Data structures
  • References etc etc.
Nikhil Jain
For a beginner, reading [*Learning Perl* (5th edition)](http://oreilly.com/catalog/9780596520113/) beforehand is advisable.
daxim
@daxim: That's true, agreed but if we know the basic of programming, then we can also read Programming Perl too.Thanks
Nikhil Jain