Skip to main content
edited body
Source Link
Jens
  • 73.3k
  • 16
  • 134
  • 186

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

string fooBar(string s, int? i) { string ret = ""; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

string fooBar(string s, int? i) { var ret = ""; if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiacarchaic point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

string fooBar(string s, int? i) { string ret = ""; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

string fooBar(string s, int? i) { var ret = ""; if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

string fooBar(string s, int? i) { string ret = ""; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

string fooBar(string s, int? i) { var ret = ""; if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archaic point of view these days.

Correcting code
Source Link
ljs
  • 37.9k
  • 36
  • 110
  • 124

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

void string fooBar(string s, int? i) { string ret;ret = ""; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

void string fooBar(string s, int? i) {  var ret = ""; if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

void string fooBar(string s, int? i) { string ret; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

void string fooBar(string s, int? i) { if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

string fooBar(string s, int? i) { string ret = ""; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

string fooBar(string s, int? i) {  var ret = ""; if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

improved formatting
Source Link

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

void string fooBar(string s, int? i) { string ret; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

void string fooBar(string s, int? i) { if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

void string fooBar(string s, int? i) { string ret; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

void string fooBar(string s, int? i) { if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

I would say it would be incredibly unwise to decide arbitrarily against multiple exit points as I have found the technique to be useful in practice over and over again, in fact I have often refactored existing code to multiple exit points for clarity. We can compare the two approaches thus:-

void string fooBar(string s, int? i) { string ret; if(!string.IsNullOrEmpty(s) && i != null) { var res = someFunction(s, i); bool passed = true; foreach(var r in res) { if(!r.Passed) { passed = false; break; } } if(passed) { // Rest of code... } } return ret; } 

Compare this to the code where multiple exit points are permitted:-

void string fooBar(string s, int? i) { if(string.IsNullOrEmpty(s) || i == null) return null; var res = someFunction(s, i); foreach(var r in res) { if(!r.Passed) return null; } // Rest of code... return ret; } 

I think the latter is considerably clearer. As far as I can tell the criticism of multiple exit points is a rather archiac point of view these days.

fixed broken formatting
Source Link
Matt Ball
  • 360.9k
  • 102
  • 655
  • 725
Loading
Added code language hints
Source Link
Simon Cowen
  • 1.9k
  • 17
  • 20
Loading
Post Made Community Wiki by CommunityBot
fixed *stupid* typo
Source Link
ljs
  • 37.9k
  • 36
  • 110
  • 124
Loading
deleted 1 characters in body
Source Link
David
  • 14.1k
  • 25
  • 85
  • 102
Loading
Source Link
ljs
  • 37.9k
  • 36
  • 110
  • 124
Loading