wc exclude . and .. directories and empty or commented lines
# Although, that's language dependent... Examples can be found below...
cat foo.c | sed '/^s*$/d' | wc -l
And if you consider comments blank lines:
cat foo.pl | sed '/^s*#/d;/^s*$/d' | wc -l