473,834 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

common practice for creating utility functions?

Just a quickie for today: Is it common (and also preferred, which are
two different things!) to create a function that has the sole job of
calling another function?

Example: for fun and exercise, I'm creating a program that takes a quote
and converts it into a cryptogram. Right now I have four functions:

convert_quote -- the main function that starts it all
make_code -- makes and returns the cryptogram
make_set -- called from make_code, converts the quote into a set so each
letter gets only one coded letter
test_sets -- makes sure a letter isn't assigned to itself

So my first question is this: should I make a Cryptogram class for this,
or are functions fine? If the latter, then back to my original point:
can I do something like this:

def convert_quote(q uote):
return make_code(quote )

Or does it not make sense to have a function just call another function?
May 15 '06
25 1876
Bruno Desthuilliers wrote:
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?
May 16 '06 #21
John Salerno wrote:
Bruno Desthuilliers wrote:
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?


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.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
May 16 '06 #22
BartlebyScriven er wrote:
QOTW

"Programmin g 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

--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
May 17 '06 #23
Bruno Desthuilliers wrote:
Then it would be better to just alias it:

# def convert_quote(q uote):
# 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. ;)

--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
May 17 '06 #24
Hey, thanks. I got the writing thing down:

http://dooling.com

Now I'm trying to pick up the programming part.

Thanks for links.

rick

May 17 '06 #25
Edward Elliott wrote:
Bruno Desthuilliers wrote:

Then it would be better to just alias it:

# def convert_quote(q uote):
# return make_code(quote )
convert_quo te = make_code

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 !-)
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. ;)


Lol !-)

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

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
May 17 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1801
by: D Witherspoon | last post by:
What is the accepted method of creating a data class or business rules object class with properties that will allow the returning of null values? For example... I have a class named CResults with the following properties. TestID int QuestionID int AnswerID int So, this is a simple example, but I want to be able to know if AnswerID is
6
1677
by: Don Wash | last post by:
Hi All! I'm developing ASP.NET pages using VB.NET language. My background is VB6 and ASP3. Right now, I'm evaluating strategies on creating reusable and common functions and methods for ASP.NET. In ASP 3, it was nothing more than functions and methods coded in #Include Files. Now ASP.NET offers features such as Page Inheritance and full software development support. So I'm just wondering, what should I do if I have 5 functions, that...
5
3204
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. 1. I can create a common module like common.vb in my project and put all the functions in there. 2. Create a utility class and create the common functions as shared
22
2519
by: David Mathog | last post by:
One thing that keeps coming up in this forum is that standard C lacks many functions which are required in a workstation or server but not possible in an embedded controller. This results in a plethora of "don't ask here, ask in comp.x.y instead", for queries on functions that from the documentation available to the programmer appear to be part of the C language. I think largely because of this "least common denominator" C language...
0
10789
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10504
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7755
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3079
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.