473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Parameter checking on an interfase

Hi all,
I am more or less new to Python, and currently am making my
first "serious" program. The application is a Clinical History manager
(for my wife) which stores its data on a sqlite database. After
googling on this newsgroup, I have read several threads where is
stated that the LBYL way of testing parameters is not a pythonic way
to work, and that is preferable catch the exceptions generated trying
to use an invalid parameter passed to a function.
Although I am generally following this approach, the problem I
see is that sqlite docs states clearly that the engine does not check
that the data types passed to the SQL sentences matches the types
declared for the column, and lets any kind of information to be put in
any column of the table. When I code the "business objects" of the
application (don't know if this is the exact term for a layer that
will isolate the application from the raw database, letting me change
it in a future if necessary), I realize that if I pass arguments of
wrong type (say, a numeric ID instead of the patient name), the DB
engine will accept that gladly, and I will finish with data that could
not be consistently retrievable if I use the DB from another program
(no one right now, but I think of, perhaps, statistical trends on
diseases and treatments).
In this case, could be reasonable add type checking LBYL style
on the methods, so if passed data is of wrong type, it generates a
adequate exception to be catched by the caller? In this way, the rest
of the app (mostly GUI) can be coded EAFP style. As programming
background, as you can guess, I have made some programming in C, VBA
and JavaScript (quite procedurally).
I hope that you can bring me some light about this kind of
design, so I can improve my coding and get the Python way faster.
Cheers!
Walter Gardella
PS: Excuse me if my english is not good enough, but is not my mother
tongue (I'm argentinian), and if my computerish is flawed (I'm only
human;))

May 9 '07 #1
3 2438
<w.******************@gmail.comwrote:
...
In this case, could be reasonable add type checking LBYL style
on the methods, so if passed data is of wrong type, it generates a
adequate exception to be catched by the caller? In this way, the rest
As maybe one of the first popular authors to use LBYL and EAFP in this
sense, I think I should comment here. First, I don't agree with
SQLite's design decision to be typeless -- I believe types are important
in RDB's in a very different way to their limited importance in programs
(where Python's "duck typing almost everywhere" suits me just fine,
though some intermediate approach like Boo's might be even better).
Nevertheless, SQLite is a good job and I use it happily... when I
_don't_ particularly care for type issues.

When I _do_ care -- I go back to PostgreSQL. It may not be quite as
handy as SQLite, if you want a self-contained program to deploy as a
unit... but in just about all other respects, it's got huge advantages.
Do consider it -- it will do a better job protecting your data's
integrity (among which type-checking of specific fields is just a
beginning). For _valuable_ data, where integrity really matters, that's
really a big point. ((Oracle, IBM DB2, SAP/DB, Firefly, and no doubt
others, might be just as good as PostgreSQL... but I have a sweet spot
for the latter; for MySQL, even though I do have to use it sometimes for
work purposes, my sympathy on the other hand is pretty low indeed)).

If you decide PostgreSQL is not worth the bother, then I think that's a
good sign that you should avoid type-checking in your code anyway, as it
indicatres that SQLite's "typeless data" approach may be OK for you.
Alex
May 9 '07 #2
w.******************@gmail.com a écrit :
Hi all,
I am more or less new to Python, and currently am making my
first "serious" program. The application is a Clinical History manager
(for my wife) which stores its data on a sqlite database. After
googling on this newsgroup, I have read several threads where is
stated that the LBYL way of testing parameters is not a pythonic way
to work, and that is preferable catch the exceptions generated trying
to use an invalid parameter passed to a function.
Although I am generally following this approach, the problem I
see is that sqlite docs states clearly that the engine does not check
that the data types passed to the SQL sentences matches the types
declared for the column, and lets any kind of information to be put in
any column of the table. When I code the "business objects" of the
application (don't know if this is the exact term for a layer that
will isolate the application from the raw database, letting me change
it in a future if necessary),
business objects and databases are not necessarily related. And business
objects are much more than a "database abstraction layer" - they are the
"model" part of the MVC triad, and are the heart of your application's
logic. As such, they are of course in charge of validating their own
state wrt/ business rules.
I realize that if I pass arguments of
wrong type (say, a numeric ID instead of the patient name), the DB
engine will accept that gladly, and I will finish with data that could
not be consistently retrievable if I use the DB from another program
(no one right now, but I think of, perhaps, statistical trends on
diseases and treatments).
In this case, could be reasonable add type checking LBYL style
on the methods, so if passed data is of wrong type, it generates a
adequate exception to be catched by the caller?
This is more a problem of validation/conversion of values than strictly
a typing problem IMHO. As someone said : "be liberal about what you
accept and strict about what you send".

In this way, the rest
of the app (mostly GUI) can be coded EAFP style. As programming
background, as you can guess, I have made some programming in C, VBA
and JavaScript (quite procedurally).
I hope that you can bring me some light about this kind of
design, so I can improve my coding and get the Python way faster.
I strongly encourage you to have a look at SQLAlchemy (a hi-level
RDBMS/python interface and an ORM) and Elixir (an ActiveRecord-like
declarative layer on top of SQLAlchemy), and FormEncode (an in/out
validation/conversion package).

http://www.sqlalchemy.org/
http://elixir.ematia.de/

FWIW, I'm actually working on using the second to add
validation/conversion to the first:
http://groups.google.com/group/sqlel...7b2d0b87613482
May 9 '07 #3
On 9 mayo, 17:42, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
w.m.gardella.samb...@gmail.com a écrit :
Hi all,
I am more or less new to Python, and currently am making my
first "serious" program. The application is a Clinical History manager
(for my wife) which stores its data on a sqlite database. After
googling on this newsgroup, I have read several threads where is
stated that the LBYL way of testing parameters is not a pythonic way
to work, and that is preferable catch the exceptions generated trying
to use an invalid parameter passed to a function.
Although I am generally following this approach, the problem I
see is that sqlite docs states clearly that the engine does not check
that the data types passed to the SQL sentences matches the types
declared for the column, and lets any kind of information to be put in
any column of the table. When I code the "business objects" of the
application (don't know if this is the exact term for a layer that
will isolate the application from the raw database, letting me change
it in a future if necessary),

business objects and databases are not necessarily related. And business
objects are much more than a "database abstraction layer" - they are the
"model" part of the MVC triad, and are the heart of your application's
logic. As such, they are of course in charge of validating their own
state wrt/ business rules.
I realize that if I pass arguments of
wrong type (say, a numeric ID instead of the patient name), the DB
engine will accept that gladly, and I will finish with data that could
not be consistently retrievable if I use the DB from another program
(no one right now, but I think of, perhaps, statistical trends on
diseases and treatments).
In this case, could be reasonable add type checking LBYL style
on the methods, so if passed data is of wrong type, it generates a
adequate exception to be catched by the caller?

This is more a problem of validation/conversion of values than strictly
a typing problem IMHO. As someone said : "be liberal about what you
accept and strict about what you send".
In this way, the rest
of the app (mostly GUI) can be coded EAFP style. As programming
background, as you can guess, I have made some programming in C, VBA
and JavaScript (quite procedurally).
I hope that you can bring me some light about this kind of
design, so I can improve my coding and get the Python way faster.

I strongly encourage you to have a look at SQLAlchemy (a hi-level
RDBMS/python interface and an ORM) and Elixir (an ActiveRecord-like
declarative layer on top of SQLAlchemy), and FormEncode (an in/out
validation/conversion package).

http://www.sqlalchemy.org/http://elixir.ematia.de/

FWIW, I'm actually working on using the second to add
validation/conversion to the first:http://groups.google.com/group/sqlel...thread/af7b2d0...
Hi all:
First of all I give Bruno many thanks for the definition of
business objects, because plugs a big hole on my concepts. And after
reading your messages, I reach to the conclussion that the best I can
do with my program is to unittest more (against my own dumbness) the
classes that will call the interfase, and take out all the type
checking code from the callees. And in the event that the program
could grow/evolve in something more serious, change the RDBMS to
another more fit to the task.
Thank you very much and May Entropy be benevolent with you.

Walter

May 10 '07 #4

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

Similar topics

7
by: Sharon | last post by:
Hi, Is it possible to check parameters against other parameters, as in: <xsl:variable name="tableData"> <xsl:apply-templates select="general/data/rows/row/fvalues" mode="tableData" />...
5
by: DataB | last post by:
Hi everyone, I have this piece of VBA script: ' checking the DOB field to see if we constrain on the date If Len(Me.EmpDOBTxt & "") > 0 Then strWhere = strWhere & " AND . <= #" & Me.DOBTxt &...
1
by: Vit | last post by:
Hi. I'd like to pass as a parameter of class method reference to ListControl (ListBox or ComboBox). Here is my call: public DoSomething(ListControl lc){} It's ok with that, but lc does not have...
2
by: Christoph Wienands | last post by:
Hello everybody, a while ago on one of the "big" DotNet websites (like GotDotNet) I stumbled across a description of a tool that enables developers to work with features like "Declarative...
0
by: Davide | last post by:
Hi We have a stored procedure for inserting data into a table and another for Updating that table. For the Insert SP we use a LastModifiedDateTime output parameter and for the Update SP we...
3
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this...
2
by: Alan Silver | last post by:
Hello, I have been trying the DataSet in VS2005, to see if it will simply some basic data access. So far it seems very useful, but I have run into a problem when trying to use a parameter for...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
5
by: puzzlecracker | last post by:
C++ standard says the following: I am reading through c++ standard and have a difficulty understanding the difference between these two terms. Thanks, puzzlecracker
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.