Talk:Guard (computer science)

Latest comment: 1 year ago by Yaris678 in topic Just another name?

Add non-Haskel language example

edit

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?

edit

Is this just Haskell's name for a switch statement? —Preceding unsigned comment added by 130.76.32.15 (talkcontribs)

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)#Mathematics. 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)#Flatter code with less nesting. 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)Reply

Guard vs conditional

edit

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

edit

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:

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

This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template {{source check}} (last update: 5 June 2024).

  • If you have discovered URLs which were erroneously considered dead by the bot, you can report them with this tool.
  • If you found an error with any archives or the URLs themselves, you can fix them with this tool.

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

Needs first example to be in a language with simpler grammar

edit

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)Reply