473,385 Members | 1,645 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,385 software developers and data experts.

Crucial tests in Main()

This is a very general question of style. I'm often writing console
programs that takes one input file and returns an output file. They use
to look something like this:

class Program
{
public static int Main(string[] args)
{

// 1. See if we got the right number of arguments...
// 2. Parse arguments further...
// 3. Check if the input file exists...

}
}

Each of these steps must of course be passed successfully for the program
to do its real work. If any test fails, the program should exit with an
error message. I use to implement the tests this way:

class Program
{
public static int Main(string[] args)
{
// See if we got the right number of arguments
if (args.Length != 2)
{
Console.WriteLine("Usage: program <input> <output>");
return 1;
}
...
}
}

This is why I use "int" and not "void" as return type in Main(). This
works, but I wonder if it's the best practice? Maybe I'm putting too many
things in Main()? Any opinions?

Thanks,

Gustaf
Nov 15 '05 #1
2 1021
"Gustaf Liljegren" <gu*****@algonet.se> wrote in message news:Xn*********************@127.0.0.1...
This is a very general question of style.


This has nothing to do with Main, if any function gets too big it should be broken down into functions.

--
Michael Culley
Nov 15 '05 #2
"Gustaf Liljegren" <gu*****@algonet.se> wrote in message
news:Xn*********************@127.0.0.1...
This is why I use "int" and not "void" as return type in Main(). This
works, but I wonder if it's the best practice? Maybe I'm putting too many
things in Main()? Any opinions?


Refactor the argument checking out of Main:

static int CheckArgs(char[] args)
{
...
}

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com
Nov 15 '05 #3

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

Similar topics

12
by: Paul Moore | last post by:
One of the things I really dislike about Unittest (compared, say, to a number of adhoc testing tricks I've used in the past, and to Perl's "standard" testing framework) is that the...
0
by: A. B., Khalid | last post by:
Hello all. After the effort of getting most of Python 2.3.4 Final compiled in MinGW (see: http://mail.python.org/pipermail/python-list/2004-June/225967.html, and get the patch and read more...
7
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
51
by: Matt | last post by:
Hello, I'm a hiring C++ developer employer looking for existing, online C++ aptitude tests. I have not yet extensively researched this yet, but as an example, I thought this test looked...
1
by: travislspencer | last post by:
Hey All, I am trying to write a script that runs all of my pyunit tests for me. Ideally, I would like to be able to drop a new module into my project's test subdirectory, and the testing script...
0
by: Chuck | last post by:
Sorry for the advertisement but I think this is something that people could actually use. I am creating a new product called Simple Load Testing and I thought I would see if anyone would be...
16
by: Greg Roberts | last post by:
Hi I want to place the tests needed in the code using attributes. There seems to be enough code snippets around for me to cover this. e.g. // Test cases, run these here on the function and...
1
by: Chris Burgess | last post by:
I'm starting a small application to get my feet wet with Test Driven Development. I understand the mechanics of setting up NUnit, but I'm not sure what types of tests I should be writing. The...
1
by: Chris Fonnesbeck | last post by:
I have a module for which I am trying to code a unit test. However, when I run unittest.main(), I get: In : import PyMC In : PyMC.unittest.main() ...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.