Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74829 > unrolled thread

Re: What's the proper style for a library string function?

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2014-07-19 12:56 -0600
Last post2014-07-19 12:56 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: What's the proper style for a library string function? Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-19 12:56 -0600

#74829 — Re: What's the proper style for a library string function?

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-07-19 12:56 -0600
SubjectRe: What's the proper style for a library string function?
Message-ID<mailman.12057.1405796265.18130.python-list@python.org>
On Sat, Jul 19, 2014 at 12:24 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> Besides that I wouldn't write the function on one line, the first.  Once you
> return your data you can do what you want with it.  The second you can only
> write by default to stdout.  The third is really horrible in my book, YMMV.

I agree. Optional flags that alter the behavior of functions are
considered unpythonic; usually it's better to let the alternative
behavior have its own function, particularly if they can share
implementation.

With that in mind, I would suggest to the OP that you might want to
have *two* functions:

def format_completed_time(start, end):
    return "Time completed: " + str(end - start)

def print_completed_time(start, end):
    print(get_completed_time(start, end))

Also notice that I changed the function naming style from mixedCase to
lower_case_with_underscores. This is the style recommended for Python
by PEP 8, which you should read if you haven't already.
http://legacy.python.org/dev/peps/pep-0008/#naming-conventions

I also changed the verb from "get" to "format".  "get" suggests to me
that it will retrieve the completed time as a processable value, not
as a part of a formatted string.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web