Re: [web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
How about you show me couple (say 5) of the database structures of the applications that you have already written? I can go through it and get some practical ideas.
Re: [web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
General request for comments corrections from the more experienced (than me) programmers in this group please. I really don't want to be giving bad advice. Anyway, on to the advice... Rupesh, In the end, it doesn't matter what scheme you use, as long as you find it easy your practices are consistent. If you are working on shared code (i.e. working with somebody else), then you should both agree on a set of coding practices. If you are working on multiple applications within the same database, then it makes sense to prefix application-specific tables with something which easily describes it (in case you have to examine the back-end database, or have to make cross-application queries). That being said, I suggest that at the very least, you take a look at Python PEP http://www.python.org/dev/peps/pep-0008/ guidelines, in order to standardise your coding practice. As far as database naming goes, if you are building applications from scratch, try to ensure that you have memorable names (or ones which are logical easy to recreate). If there is the possibility of more than one app being stored in your database backend, and the possibility exists for table name collisions (tables called 'name' or 'address' are very common). It is, in my opinion, good practice to prefix your application-specific tables with something to separate them from the other applications tables. Let's call your app *Contacts List.* We now have a nice, 2-prefix addition to our table names: CL # Storing our address types in a list as opposed to # devoting a full table to them: address_types=['permanent', 'temporary', 'postal', 'additional'] db.define_table('cl_contact', Field('name'), ) db.define_table('cl_address', Field('contact', db.cl_contact), Field('address_type', 'string', requires=IS_IN_LIST(address_types)) Field(' ) For small values of the list (i.e. less than a dozen items, which are unlikely to change), you may as well store them in a list (as above) and let web2py deal with the lookup. If you need a lookup table, then prefix it with whatever is easy enough to remember. The important part (*and trust me on this* :) is consistency. At the end of the day, as long as your methodology is consistent, logical and easy to follow, then just go with whatever's easiest for you. Martin. On 31 January 2011 21:58, Rupesh Pradhan rupeshkrprad...@gmail.com wrote: I am trying to standardize my naming schemes for my database, table and fields. I am trying to follow the one given below. Please share with me your scheme. Standard Database Table Naming Scheme = Table name: --- small caps with underscore look-up table prefixed with 'lu_' link table prefixed with 'lk_' (should i do this?) eg. contact lu_address_type Field names: small caps with under score primary key suffixed with '_id' eg. name address_text contact_id Table Field access notation: --- table name DOT field name eg. contact.name contact.contact_id lu_address_type.name lu_address_type.address_type
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
i try to use pythonic naming conventions in my database. i prefer: db.define_table('address_type', Field('name')) db.define_table('contact', Field('name')) db.define_table('address', Field('contact', db.contact), Field('type', db.address_type), Field('text')) but perhaps mainly because i don't like to type all those extra characters. :)
Re: [web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
I'd be cautious about some of those field names. I'm not about to look them up, but they look suspiciously like they may collide with reserved words. I'm looking particularly hard at 'type' and 'text'. You may want to check that. Martin. I don't mind typing the extra characters now that work bought me one of these http://www.kinesis-ergo.com/advantage_pro.htm :) On 1 February 2011 23:08, howesc how...@umich.edu wrote: i try to use pythonic naming conventions in my database. i prefer: db.define_table('address_type', Field('name')) db.define_table('contact', Field('name')) db.define_table('address', Field('contact', db.contact), Field('type', db.address_type), Field('text')) but perhaps mainly because i don't like to type all those extra characters. :)
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
The wizard convention is the following: - table and field names are lower case - table names have a t_ prefix - field names have a f_ prefix - reference fields have the same name as the table being referenced (but with f_, not t_) you can then use shortcuts: Person = db.define_table('t_person',Field('f_name')) It can be ugly but causes no ambiguities and it is easy to read. You can also compute labels from fields names automatically label = ' '.join(x.capitalize() for x in field_name[2:].split('_')) On Feb 1, 10:12 pm, Martin Barnard barnard.mar...@gmail.com wrote: I'd be cautious about some of those field names. I'm not about to look them up, but they look suspiciously like they may collide with reserved words. I'm looking particularly hard at 'type' and 'text'. You may want to check that. Martin. I don't mind typing the extra characters now that work bought me one of these http://www.kinesis-ergo.com/advantage_pro.htm :) On 1 February 2011 23:08, howesc how...@umich.edu wrote: i try to use pythonic naming conventions in my database. i prefer: db.define_table('address_type', Field('name')) db.define_table('contact', Field('name')) db.define_table('address', Field('contact', db.contact), Field('type', db.address_type), Field('text')) but perhaps mainly because i don't like to type all those extra characters. :)
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
I am trying to standardize my naming schemes for my database, table and fields. I am trying to follow the one given below. Please share with me your scheme. Standard Database Table Naming Scheme = Table name: --- small caps with underscore look-up table prefixed with 'lu_' link table prefixed with 'lk_' (should i do this?) eg. contact lu_address_type Field names: small caps with under score primary key suffixed with '_id' eg. name address_text contact_id Table Field access notation: --- table name DOT field name eg. contact.name contact.contact_id lu_address_type.name lu_address_type.address_type
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
I like the python style guide here: http://www.python.org/dev/peps/pep-0008/ has tips on naming conventions and such. i personally don't prefix table names or field names. and i let web2py name the primary key id. most of the time my reference fields share the same name as the table they reference.
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
I have seen that before. Its about python coding style. I am trying to discuss database table and field naming style here. Care to comment on the following table structure, please: db.define_table('lu_address_type', Field('name')) db.define_table('contact', Field('name')) db.define_table('address', Field('contact_id', db.contact), Field('lu_address_type_id', db.lu_address_type), Field('address_text')) Note: lu_address_type will contain four entries i.e. permanent, temporary, postal and additional since these are the different types of addresses a person may have. Since it is used as a lookup, i have given it a prefix 'lu_' lu_address_type_id is a reference field referring to the primary key of the lu_address_type table.
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
On Jan 27, 4:09 am, Rupesh Pradhan rupeshkrprad...@gmail.com wrote: I have made enough of mistakes in learing how to code and analyse software coding properly and now my application are basically a bloatware and increasing in complexity year after year. Good! That application is probably your greatest source of learning. I am trying to standardize the way I code, the way i name my variables, table, fields etc. Basically, i need help in standardizing my programming techniques. PLEASE FEEL FREE TO COMMENT ON ANY OR ALL OF MY CODING. Very good to ask for critique: that's a great sign of maturity. However, naming of things, or indent level, or capitalization have very little to with good coding. They are simply good manners. I read this somewhere once: - A novice understands the difference between data and code. - An expert understands that all code is data. - A master understands that all data is code. (If you find that last one difficult to understand, here is a hint: I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships.--Torvalds, Linus (2006-06-27). Message to Git mailing list. )
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
Thanks a lot for sharing the philosophy behind coding!!! I get the point. Now for some *real* help by nitpicking at my coding!
[web2py] Re: Need help in standardizing my coding and naming schemes before I start my main project
Thanks a lot MARTIN for the nitpick. REALLY needed that! Inspite of what you mentioned that you are relatively new to web2py, that was a lot of help. I don't know if other are going to help me out as much as you did. But since you did take the trouble to pore through my code, I was hoping that you would help me out a little bit more till such time you feel that you can spare time for it. I do have a lot more queries and would like to tackle them one at a time. Can I request you to subscribe to this post so that you get a notification of any posts that I make so that you can reply to it? Also, I don't know how the code from the db.py was missing. I will fix my code as per your guidelines and post it again. Rupesh