file read program
am 01.12.2007 17:17:00 von Rahul
Hi Everyone,
I have a task to read a file and perform some file operations. Now i
have two options, i could do this in C (File system) or unix shell
scripts. I would like to know which one is best suitable for this
problem and based on what factors? and generally too, how to conclude
on which language is to be used to solve the problem.
Re: file read program
am 01.12.2007 19:28:57 von Icarus Sparry
On Sat, 01 Dec 2007 08:17:00 -0800, Rahul wrote:
> Hi Everyone,
>
> I have a task to read a file and perform some file operations. Now i
> have two options, i could do this in C (File system) or unix shell
> scripts. I would like to know which one is best suitable for this
> problem and based on what factors? and generally too, how to conclude on
> which language is to be used to solve the problem.
There are a lot of factors.
How well does this fit into your environment? If everything else is a C
program then it may take some effort to get a shell script accepted
(which is usually a mistake, but we have to live in the real world).
How easy is it to write? Shell scripts are usually faster to write as
they are a higher level than C.
How often will it be run?
How fast does it need to run? These two are interlinked. If a program is
only going to be run once, and it will take 5 mins to write as a shell
script and 20 to write as a C program, then the shell script can take 15
minutes longer to run and it will still be worthwhile. If the task is
going to be done the same way once a day for a year, then it might make
sense to spend the extra 15 mins on writing the C program (or it might
not, CPU time is usually considered to be cheap compared to person time).
How often will it be modified? Shell scripts tend to be shorter, and
hence easier to change.
There are more languages than just shell and C, one of those might be
better for the task. Perl is very successful because it fits inbetween
the two.
Re: file read program
am 03.12.2007 17:58:14 von Maxwell Lol
Rahul writes:
> Hi Everyone,
>
> I have a task to read a file and perform some file operations. Now i
> have two options, i could do this in C (File system) or unix shell
> scripts. I would like to know which one is best suitable for this
> problem and based on what factors? and generally too, how to conclude
> on which language is to be used to solve the problem.
Use the shell first.
Only use C if there is a reason.
Normally one discovers that 90% of the time is spent in 10 percent of
the code. While you might think that the 10$ should be done in C,
it is better to redesign the approach to fix the problem,
than to tune that 10 percent.
As an example, if your code is using nested loops, and takes a long
time, it's fater to use a single loop. Or perhaps do the processing
and filtering before sorting.
There are other scripting languages, such as ruby, perl, etc. You
can do amazing things in perl that is very similar to what you can do
in C, with much less time in coding.
I use C as a last resort.