common practice for creating utility functions?

J

John Salerno

Bruno said:
At least someone reading this may learn about the max_split param of
str.split() !-)

LOL. The first thing I did was scramble to the docs to see what that
second parameter meant! :)

But I was a little confused about why you included it. Just to insure
that only two elements are returned? I plan on making either a text file
or a database with quotes in that format (quote|author), so maybe the
maxsplit isn't needed?
 
B

bruno at modulix

John said:
LOL. The first thing I did was scramble to the docs to see what that
second parameter meant! :)

But I was a little confused about why you included it. Just to insure
that only two elements are returned?

Yes. It may or not be a wise choice. Depends on the context, your
design, etc...
I plan on making either a text file
or a database with quotes in that format (quote|author), so maybe the
maxsplit isn't needed?

It's up to you.
 
E

Edward Elliott

BartlebyScrivener said:
QOTW

"Programming is not just creating strings of instructions for a
computer to execute. It's also 'literary' in that you are trying to
communicate a program structure to other humans reading the code." Paul
Rubin

I take it you've never heard of Donald Knuth or literate programming:

"The main idea is to regard a program as a communication to human beings
rather than as a set of instructions to a computer."

"So you need somebody who's not afraid to write an essay, as well as not
afraid to write a computer program. They work together perfectly, but you
have to be able to communicate to the computer, and you have to be able to
communicate to the human being, and if you don't do both, then you can't
expect your program to be as successful. Literate programming is just the
best way I know to do both at the same time."

"My schtick is to promote the idea that humans, not computers, read
programs.... I ask programmers to think of themselves as writers, teachers,
expositors. When you're programming, the very act of trying to explain it
to another human being forces you to get more clarity. And then later on,
you can maintain, modify, and port your programs to other platforms much
more easily. Even if your only audience is yourself, everything gets
better."

http://www-cs-faculty.stanford.edu/~knuth/
http://www-cs-faculty.stanford.edu/~uno/lp.html
 
E

Edward Elliott

Bruno said:
Then it would be better to just alias it:

# def convert_quote(quote):
# return make_code(quote)
convert_quote = make_code

The former makes sense if you're planning to do more with the calling
function later.
About the "fine to do" part, remember that Python's function calls are
rather expansive...

Indeed, their expansiveness makes them great. Unfortunately they're
somewhat expensive too. ;)
 
B

bruno at modulix

Edward said:
Bruno Desthuilliers wrote:




The former makes sense if you're planning to do more with the calling
function later.

Then it will be time to uncomment the def block and comment out the
binding !-)
Indeed, their expansiveness makes them great. Unfortunately they're
somewhat expensive too. ;)

Lol !-)

Please have mercy, I learned English a long long time ago - and mostly
with the lyrics of my favorite rock bands...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,525
Members
48,249
Latest member
reactnativeexpert

Latest Threads

Top