Talk:Guard (computer science)

Add non-Haskel language example
The guard clause topic should inclue the real world and cross-language pattern of returning from a method/function at the beginning if the boolean condition is met. This reduces the number of nesting levels.

C# example

bool A(int X, int Y, int Z) { if (X > Y) return; if (X > Z) return;

code to process X, Y and Z }

Just another name?
Is this just Haskell's name for a switch statement? —Preceding unsigned comment added by 130.76.32.15 (talk • contribs)


 * Guard is a way more general concept, and any switch, case, or cond statement that uses guards in choosing the branch to take is more expressive than the alternative statements that use equality or set containment tests. --TuukkaH 20:51:12, 2005-09-07 (UTC)


 * I know nothing about Haskell beyond what is written here, but reading this article it looks like a guard is basically a conditional in Haskell, as covered by the the section Guard (computer science). In contrast, in most language is refers to a way of writing the code to avoid some levels of nesting, as covered by Guard (computer science).  If that is the case, this should be made clear.  If that isn't the case, we need to do a much better job of explaining what is the case.  Yaris678 (talk) 15:20, 3 August 2023 (UTC)

Guard vs conditional
Is there a good reason to discuss Guard (computing) separately from Conditional (programming)? --Abdull (talk) 13:23, 5 October 2010 (UTC)

External links modified
Hello fellow Wikipedians,

I have just modified 2 external links on Guard (computer science). Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
 * Added archive https://web.archive.org/web/20050408114902/http://documents.wolfram.com/mathematica/book/section-2.3.5 to http://documents.wolfram.com/mathematica/book/section-2.3.5
 * Added archive https://web.archive.org/web/20051129140339/http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html to http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

Cheers.— InternetArchiveBot  (Report bug) 22:42, 24 October 2017 (UTC)

Needs first example to be in a language with simpler grammar
Including python's isInstance in the first example requires special knowledge of Python. Use something more generic with typed and named parameters without relying on a language feature, library call or exception throw.

int Foo(int x) { if (x < 0) return 0; return X + 1; } 107.197.56.204 (talk) 13:54, 9 November 2022 (UTC)