Comments on: Don’t Chain Failure States in Returns https://simpleprogrammer.com/dont-chain-failure-states-in-returns/ Thu, 14 Jul 2016 19:02:23 +0000 hourly 1 https://wordpress.org/?v=7.0 By: Mike Wardle https://simpleprogrammer.com/dont-chain-failure-states-in-returns/#comment-228 Fri, 08 Apr 2016 17:49:00 +0000 https://simpleprogrammer.com/?p=964#comment-228 Would a good refactor not be to introduce line and column classes that both expose a process method. If these the expose some interface and are constructed via a factory of some sort (possibly an IOC container) the the whole thing would be a lot more SOLID.

In terms of the early exit, I likewise shy away from exceptions for anything that looks like flow control, although I do agree that the final code is very easy to follow and fairly clean.

]]>
By: Anna Lear https://simpleprogrammer.com/dont-chain-failure-states-in-returns/#comment-227 Mon, 28 Jun 2010 03:08:38 +0000 https://simpleprogrammer.com/?p=964#comment-227 That doesn’t seem like using exceptions for flow control to me. At least, not in the evil sense. Since the method with the try/catch is just returning after catching the exception, it looks more like just normal exception handling.

In my mind, using exceptions for flow control looks more like something like this obviously contrived example:

public void DoSomething()
{
int x;
try
{
x = GetValueOfX();
}
catch
{
x = 5;
}

// do something meaningful to X
}

]]>
By: handcraftsman https://simpleprogrammer.com/dont-chain-failure-states-in-returns/#comment-226 Sat, 26 Jun 2010 20:15:26 +0000 https://simpleprogrammer.com/?p=964#comment-226 Good topic. I started to respond here but then it started to get long so I turned it into post. http://handcraftsman.wordpress.com/2010/06/26/a-refactoring-exercise-printing-file-columns/

]]>
By: jsonmez https://simpleprogrammer.com/dont-chain-failure-states-in-returns/#comment-225 Fri, 25 Jun 2010 19:47:44 +0000 https://simpleprogrammer.com/?p=964#comment-225 In reply to Dan Martin.

Yeah, I kinda shyed away from 3 at first, still I had actually turned #2 into #3 and cut out so much code. (In the real implementation).
Then there was no question in my mind that even though #3 feels a little wrong, that it is the best solution.

]]>
By: Dan Martin https://simpleprogrammer.com/dont-chain-failure-states-in-returns/#comment-224 Fri, 25 Jun 2010 19:33:36 +0000 https://simpleprogrammer.com/?p=964#comment-224 I like refactor #3. I did something very similar recently and was wondering if it was an atrocity or not.

]]>