Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Commenting, was: Inline POD vs. EOF POD

by Abigail (Deacon)
on Jul 11, 2001 at 02:43 UTC ( #95519=note: print w/ replies, xml ) Need Help??


in reply to Re:{2} Commenting, was: Inline POD vs. EOF POD
in thread Inline POD vs. EOF POD

translate_buffer_to_normalized_image might sound as it's a self-explaining variable name that doesn't need documenting, but is it really that practical? Too long variable names don't "stick". And long variable names make that expressions need more than one line, making programs harder to understand.

As for names having info about pre/post conditions, could you give a convincing example? I do have a hard time believing you.

-- Abigail


Comment on Re: Commenting, was: Inline POD vs. EOF POD
Re:{4} Commenting, was: Inline POD vs. EOF POD
by jeroenes (Priest) on Jul 11, 2001 at 03:54 UTC
    I ment that translate-name to be a function, as it has a verb and should do something, rather than be something.

    About the length of the names and code-lines. How understandible a block of code is does not really relate to the length of expressions, but also to the formatting and the names. If the names are well-chosen but long, the formatting should be clear. Together with the way the program is broken up in functions, that determines the accesibility of some code, not whether expressions fit in one line or not.

    For example, nested or sequential maps are a pain to read when put on a single line. Spread out over several lines the code often becomes clear. And we are talking about expressions with very short names. In this example it doesn't really matter whether your names are 10 or 30 characters, the code still gobbles up the same number of lines.

    From another point of view, lines with more than say three or four variable names are probably hard to read anyway. Spreading it out over multiple lines can help than.

    When browsing code like some linux kernel or whatever GPL program I need to tweak a bit to compile, I encounter C consisting of lots of comments intertwingled with short code. (And I wouldn't dare to claim that those are really well written examples) I find these things hard to read as well. The flow of logic in the comments is done by the authors, and is not the programming logic. There already is enough freedom in how to write code, the different ways to comment make code in general harder to read. I'd rather have to code spanning somewhat more lines than having those flexible comments in the way.....

    About pre/post conditions. Tough topic, when I think of it. A condition is a circumstance before/during/after a function. I would say that such beasts belong to the interface anyway. They can or should be named in the function-name, or be explicitly mentioned in the parameter lists. Let us for example consider code that retrieves some user-information, and count the ocurrence of a 'p'. Pretty useless of course. Depending on a condition (eg are we running under windowz?) the list has to be pulled from the builtin functions or from an user file:

    if ( $^O =~ /win32/) { get_userinfo_by_id_from_txtfile( $userid ); } else { get_userinfo_by_id_from_perlfunction( $userid ); } my $p_count_in_userinfo = count_p_in_array; report_p_count_at_interface( $p_count_in_userinfo, $reporting_interfac +e);
    Depending on the remainder of the program, these interface choices may be a Good or a Bad idea. If we bury the win32 condition a bit further in the interface, which may well be a Good Thing for programs in general:
    get_userinfo( $userid ); my $p_count_in_userinfo = count_p_in_array; report_p_count_at_interface( $p_count_in_userinfo, $reporting_interfac +e); sub get_userinfo{ my $userid = shift; my $is_this_gnix = get_gnixiness_system; get_userinfo_on_system( $userid, $is_this_gnix ); }
    This can be extended forever, I think the idea is clear by now. With this naming convention, the conditions automatically get into the naming of functions and variables.
      How understandible a block of code is does not really relate to the length of expressions, but also to the formatting and the names. If the names are well-chosen but long, the formatting should be clear. Together with the way the program is broken up in functions, that determines the accesibility of some code, not whether expressions fit in one line or not.
      But the length of an expression determines how it's formatted. Long, multiline expressions are usually harder to understand than smaller expressions fitting on one line. There's a reason why in Python and shell newlines are end of statement indicators! People break up large blocks of code into smaller segments; they do that for some reason. Don't assume that for expressions those reasons no longer hold.
      For example, nested or sequential maps are a pain to read when put on a single line.
      I don't think nested maps score high on readability, regardless whether done on one line or more.
      From another point of view, lines with more than say three or four variable names are probably hard to read anyway. Spreading it out over multiple lines can help than.
      Assigning the result of a binary operator where both operands are single variables to a third variable is very common in programming languages like C and Perl. Typically such expressions are one a single line. People are used to that. You cannot convince me easily that splitting them out over multiple lines increases readability. But if your variables are 25 characters, you have the option of either using lines over 80 characters (even if you don't use whitespace around your operators, leave the semi-colon off and don't use identation) or use multiple lines. I'd say, try it out. Write a program that way, and then ask someone else if (s)he wants to maintain it.
      About pre/post conditions. Tough topic, when I think of it. A condition is a circumstance before/during/after a function. I would say that such beasts belong to the interface anyway. They can or should be named in the function-name, or be explicitly mentioned in the parameter lists.
      Pre- and postconditions belong in the interface, sure. But do you really think that binary_search_on_a_sorted_nonempty_array_containing_integers_floats_or_doubles is a good function name? And what are you going to do if you weaken your precondition? Rewrite every program using the function? How are you going to do that in an OO environment where such things should be hidden from the user? Preconditions can easily take several lines to describe. Do you advocate using names over 80 characters?

      -- Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-07-14 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls