IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Good Programming Practice


kvarnerexpress
no avatar
Super Member
*********
Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



Post #1 post Mar 6 2006, 07:16 PM
I am creating a webs interface to a database which as you would imagine allows the user to search the database for soemthing, and on submitting search the results are shown. So far i have done this in just one .cgi program. I know i could have write 2 seperate programs to accomplish this task- i.e one passing parameters to another. My question is this- I'm going to have to make all the search results in a way such that you click on one and you display all the info on that particular result. But is it good practice to say have multiple .cgi files with them all linked by forms with an action that passes params to another, or have it all in one .cgi program?
Go to the top of the page
+Quote Post
tuddy
no avatar
Privileged Member
*********
Group: Members
Posts: 570
Joined: 5-July 05
From: Ballarat
Member No.: 9,042



Post #2 post Mar 7 2006, 01:01 AM
Depends, if you can handle trying to maybe debug multiple .cgi programs, its a better way to go, it has a more easy smaller flow through. It also allows for better intergration of new coding etc.
Go to the top of the page
+Quote Post
stlgoalie
no avatar
Newbie [Level 3]
***
Group: Members
Posts: 42
Joined: 21-December 05
Member No.: 16,021



Post #3 post Mar 7 2006, 02:18 AM
In one of my PERL books it states: "In PERL there is always more than one way to do it!". In terms of what is good coding practices on wether to have one cgi file or several, that really is up to you. There really is no "right" or "wrong" way to do it. It really is your personal preference.

I've heard it both ways, but to me, there is nothing worse that going through a PERL file that is 65k lines long trying to find a mistake. Sometimes I wish the main file just called subroutines from linked files. So if there is a problem with submitting, then its isolated to the few dozen/hundred/thousand lines of code in that file.

So the answer here is, what ever you want so long as it works.

Actually that's my motto to coding.
Go to the top of the page
+Quote Post
fffanatics
no avatar
Privileged Member
*********
Group: [HOSTED]
Posts: 936
Joined: 14-April 05
From: West Chester, PA
Member No.: 5,636



Post #4 post Mar 7 2006, 03:19 AM
In almost every programming language it is better to have a new file for each new task. It just allows for better data abstraction and reusability of code. Plus, since there are different files, if you need to update one task, you dont risk changing the other one and you also know exactly where to look. If it just is you editing the code, it probably doesnt matter but in the real world where most programming is done, if 100,000 line programs were in 1 file, it would be sooo hard to work with or understand the code.
Go to the top of the page
+Quote Post
Tyssen
no avatar
***********
Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



Post #5 post Mar 7 2006, 05:33 AM
QUOTE(fffanatics @ Mar 7 2006, 01:19 PM) [snapback]234253[/snapback]

If it just is you editing the code, it probably doesnt matter but in the real world where most programming is done, if 100,000 line programs were in 1 file, it would be sooo hard to work with or understand the code.

I would've thought the opposite would also be true to a certain extent. If you have a dozen 10-line functions that all do similar tasks, wouldn't it be better to group them all together in a single file rather than have 10 individual ones?
Go to the top of the page
+Quote Post
sonesay
no avatar
|||[ n00b King ]|||
*********
Group: [HOSTED]
Posts: 732
Joined: 20-June 07
From: Auckland
Member No.: 45,102
myCENT:7.62



Post #6 post Jul 3 2007, 08:20 PM
I think it can be either way depending on your preference and of those working on the project with you. There are cases where I find having all the code in one file good and others where it becomes too clutered so I would seperate them.
Go to the top of the page
+Quote Post
Tetraca
no avatar
Privileged Member
*********
Group: Members
Posts: 628
Joined: 20-May 06
Member No.: 23,968



Post #7 post Jul 3 2007, 10:01 PM
QUOTE(Tyssen @ Mar 7 2006, 05:33 AM) [snapback]234278[/snapback]
I would've thought the opposite would also be true to a certain extent. If you have a dozen 10-line functions that all do similar tasks, wouldn't it be better to group them all together in a single file rather than have 10 individual ones?


The goal in seperating code by files is to organize the functions by what they do so then you don't get confused. For example, in a CMS that I had written I have one main index.php file which passes parameters to the other PHP files. Each PHP file is organized by the task it performs - news.php dispenses news, admin.php reroutes all admin functions to their proper functions, securities.php contains all functions for security of the scripts. I couldn't manage everything if I had everything in one single file because if I did, it'd be 278 KB of text to sort through and I can't bookmark where each specific thing is.

The larger a program is, the better it is to organize it into seperate modules. If you have a small program that has 3 or so functions, there's no reason to organize your code into seperate modules.

This post has been edited by Tetraca: Jul 3 2007, 10:02 PM
Go to the top of the page
+Quote Post
apicolet
no avatar
Newbie
*
Group: Members
Posts: 8
Joined: 22-November 07
From: Antibes, France
Member No.: 53,494



Post #8 post Nov 22 2007, 01:31 PM
I totally agree with Tetraca on this. I would even go beyond : each time I write a program, even the simplest one, I separate functions and objects into distinct, coherent packages. Almost each time, it turned out later that I was right, because at least one the following thing always happens :
- somebody will have make it evolve some day (the data you store needs some special post-processing in a certain case)
- somebody will want to reuse one interesting component of it some day (writing another app that will access the same data)
- someday, you will want to migrate a part of this to another way of doing the same thing (I used to store my data in plain text file, now let's use a DB, let's even use a new complex plugin architecture for data storage, without impacting the rest of the application)
It's true that, when you have a program that would take 20 lines in a single file, it is a bit overkill to split it in 5 modules and define a whole object model and interfaces. I don't do it for throw-away scripts that I need to run only once !
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   5 KansukeKojima 450 8th December 2007 - 02:10 AM
Last post by: jlhaslip
No New Posts   0 williantg 207 16th July 2004 - 08:03 PM
Last post by: williantg
No new 17 gamefreaksl 1,127 23rd October 2004 - 07:35 PM
Last post by: sargilla
No new   16 Roly 1,154 13th August 2004 - 01:24 AM
Last post by: SilverBoarder
No New Posts   4 takato2100 272 10th June 2006 - 08:56 PM
Last post by: farsiscript
No new   17 eforumhongkong 1,267 24th August 2004 - 03:13 AM
Last post by: NuHoaXuLa
No New Posts   3 tomko 424 6th August 2004 - 11:55 AM
Last post by: triax
No new   55 LILJOHN 6,248 16th February 2008 - 01:20 PM
Last post by: saitunes
No New Posts   3 Albus Dumbledore 333 20th May 2007 - 04:46 AM
Last post by: jlhaslip
No new 19 odomike 1,509 11th December 2004 - 05:30 PM
Last post by: antitrust


 



RSS Lo-Fi Version Time is now: 4th December 2008 - 07:23 PM