Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 18th, 2011, 06:00 AM
Authorized User
Points: 135, Level: 2
Points: 135, Level: 2 Points: 135, Level: 2 Points: 135, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2007
Location: , , .
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Default Novice logic question.

I am writing an application which performs a series of steps in the order specified:
1. Read a file (xml)
2. Create Directory
3. Create files in that directory
4. Some other step
5. Some more steps
If any step fails none of the remaining steps are performed.
All the steps listed will be methods of a Perform class which will be instantiated in the Main method.
A straightforward way to do this is make all the methods in the Perform class as bool and check their return value in a if loop like so:
  // And so on ...
This loop will grow when more steps are added.
Can someone suggest/guide in implementing this in any other way?

  #2 (permalink)  
Old November 18th, 2011, 06:53 AM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts

If the methods return false when they fail, you could do
if (!CreateFilesInThatDirectory())
if (!SomeOtherSteps())
This way you immediately return from the method in case and don't have nested if.

However, having errors from these methods should be some "exceptional" cases. You should throw exceptions in case of an error. That's a better way to deal with this.
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
codehelp (November 18th, 2011)

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Novice in C# -Incrementing Employee Class GoBlue C# 4.0 aka C# 2010 General Discussion 2 May 1st, 2014 01:38 AM
What is AJAX novice looking for? daxianjin Ajax 0 January 13th, 2008 10:13 PM
novice to ado.net ganeshshmg ADO.NET 2 October 13th, 2006 05:33 PM
Novice User - Please Help, no-one else to ask! KarenWilliams Dreamweaver (all versions) 2 October 25th, 2005 05:29 AM
Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM

All times are GMT -4. The time now is 01:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.