I'm sure this is a simple, but recurrent, problem for which I can't
hit on a totally satisfactory solution.
As an example, suppose that I want write a module X that performs
some database access. I expect that 99.999% of the time, during
the foreseeable future, the database connection parameters will
remain unchanged. The only exception that I envision for this
would be during testing or debugging.
Given all this, I am tempted to turn these connection parameters
into hard-coded module attributes that I can always override (i.e.
overwrite) when necessary.
But for as long as I can remember the dogma has been that hard-coded
values are bad, and that one should use other techniques, such as
configuration files, or parameters to a suitable constructor, etc.
This is where I begin to get confused: whose responsibility is it
to know of and read the config file? I can think of two distinct
scenarios: 1) module X is being used by a large, full-fledged
application A that already uses a config file for its own configuration;
2) module X is being used by a simple script that has no need for
a config file. In case 1 I'd be glad to let application A set
module X's connection parameters using values read from its own
(i.e. A's) config file; this minimizes the number of config files
that need to be maintained. In case 2, however, it would be
preferable for module X to read its connection params from its own
(i.e. X's) config file. In this way the script won't have to bother
setting some parameters that are in fact practically constant...
After going round and round on this, my original idea of hard-coding
the values as module attributes begins to look pretty attractive
again.
How would you handle such situations?
Thanks!
kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded. 2 1118
On Thu, 12 Jun 2008 21:32:34 +0000, kj wrote:
I'm sure this is a simple, but recurrent, problem for which I can't hit
on a totally satisfactory solution.
As an example, suppose that I want write a module X that performs some
database access. I expect that 99.999% of the time, during the
foreseeable future, the database connection parameters will remain
unchanged. The only exception that I envision for this would be during
testing or debugging.
Given all this, I am tempted to turn these connection parameters into
hard-coded module attributes that I can always override (i.e. overwrite)
when necessary.
But for as long as I can remember the dogma has been that hard-coded
values are bad, and that one should use other techniques, such as
configuration files, or parameters to a suitable constructor, etc.
This is where I begin to get confused: whose responsibility is it to
know of and read the config file? I can think of two distinct
scenarios: 1) module X is being used by a large, full-fledged
application A that already uses a config file for its own configuration;
2) module X is being used by a simple script that has no need for a
config file. In case 1 I'd be glad to let application A set module X's
connection parameters using values read from its own (i.e. A's) config
file; this minimizes the number of config files that need to be
maintained. In case 2, however, it would be preferable for module X to
read its connection params from its own (i.e. X's) config file. In this
way the script won't have to bother setting some parameters that are in
fact practically constant...
After going round and round on this, my original idea of hard-coding the
values as module attributes begins to look pretty attractive again.
How would you handle such situations?
Thanks!
kynn
I think I would just abstract it away with a "getter" for the connection,
a function that takes some optional parameters, if not supplied, it
simply fetches them from a default configuration. Ie:
def connect(params= None):
if params is None:
return dblayer.connect (conf["default"])
else:
return dblayer.connect (params)
Unless I have misunderstood you completely? Now people can change your
scripts config file, and if someone wants to use your code, they can use
the getter directly.
I hope this is of some help.
In <g2*********@ku ling.itea.ntnu. no=?iso-8859-1?q?Robin_K=E5v eland?= Hansen <ka*******@gmai l.comwrites:
>On Thu, 12 Jun 2008 21:32:34 +0000, kj wrote:
>I'm sure this is a simple, but recurrent, problem for which I can't hit on a totally satisfactory solution.
As an example, suppose that I want write a module X that performs some database access. I expect that 99.999% of the time, during the foreseeable future, the database connection parameters will remain unchanged. The only exception that I envision for this would be during testing or debugging.
Given all this, I am tempted to turn these connection parameters into hard-coded module attributes that I can always override (i.e. overwrite) when necessary.
But for as long as I can remember the dogma has been that hard-coded values are bad, and that one should use other techniques, such as configuratio n files, or parameters to a suitable constructor, etc.
This is where I begin to get confused: whose responsibility is it to know of and read the config file? I can think of two distinct scenarios: 1) module X is being used by a large, full-fledged application A that already uses a config file for its own configuration; 2) module X is being used by a simple script that has no need for a config file. In case 1 I'd be glad to let application A set module X's connection parameters using values read from its own (i.e. A's) config file; this minimizes the number of config files that need to be maintained. In case 2, however, it would be preferable for module X to read its connection params from its own (i.e. X's) config file. In this way the script won't have to bother setting some parameters that are in fact practically constant...
After going round and round on this, my original idea of hard-coding the values as module attributes begins to look pretty attractive again.
How would you handle such situations?
Thanks!
kynn
>I think I would just abstract it away with a "getter" for the connection, a function that takes some optional parameters, if not supplied, it simply fetches them from a default configuration. Ie:
>def connect(params= None):
if params is None:
return dblayer.connect (conf["default"])
else:
return dblayer.connect (params)
>Unless I have misunderstood you completely? Now people can change your scripts config file, and if someone wants to use your code, they can use the getter directly.
>I hope this is of some help.
Thanks!
Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ara.T.Howard |
last post by:
hi-
i know nada about python so please forgive me if this is way off base. i'm
trying to fix a bug in MoinMoin whereby
WordsWithTwoCapsInARowLike
^^
^^
^^
|
by: Dieter Vanderelst |
last post by:
Dear all,
I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the most
efficient language would be for our purposes. I have to admit that,
although I'm very familiar with Python, I'm complete Perl noob (and I
hope to stay one) which is reflected in my questions.
I know that the web offers a lot of resources on Python/Perl
differences. But I couldn't find a...
|
by: Brian |
last post by:
Had a unsettling conversation with a CS instructor that
teaches at local high schools and the community
college. This person is a long-term Linux/C/Python
programmer, but he claims that the install, config, and
library models for C# have proved to be less
problematic than Python. So both his courses (intro,
data structs, algorithms) are taught in C#.
I am a low-end (3-year) journeyman Pythonista, and I
was attracted to the language...
|
by: sandipm |
last post by:
Hi,
In my application, I have some configurable information which is used
by different processes. currently I have stored configration in a
conf.py file as name=value pairs, and I am importing conf.py file to
use this variable. it works well
import conf
print conf.SomeVariable
but if I need to change some configuration parameteres, it would need
|
by: Derek Martin |
last post by:
I'd like to know if it's possible to code something in Python which
would be equivalent to the following C:
---- debug.c ----
#include <stdio.h>
bool DEBUG;
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |