Skip to main content
Post Locked by Thomas Owens
Notice added Historical significance by Thomas Owens
added syntax-highlighting
Source Link
Deduplicator
  • 9.3k
  • 5
  • 34
  • 53

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why.

public void SomeFunction(bool someCondition)
{
    if (someCondition)
    {
        // Do Something
    }
}
public void SomeFunction(bool someCondition)
{
    if (someCondition)
    {
        // Do Something
    }
}

or

public void SomeFunction(bool someCondition)
{
    if (!someCondition)
        return;

    // Do Something
}
public void SomeFunction(bool someCondition)
{
    if (!someCondition)
        return;

    // Do Something
}

I usually code with the first one since that is the way my brain works while coding, although I think I prefer the 2nd one since it takes care of any error handling right away and I find it easier to read

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why.

public void SomeFunction(bool someCondition)
{
    if (someCondition)
    {
        // Do Something
    }
}

or

public void SomeFunction(bool someCondition)
{
    if (!someCondition)
        return;

    // Do Something
}

I usually code with the first one since that is the way my brain works while coding, although I think I prefer the 2nd one since it takes care of any error handling right away and I find it easier to read

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why.

public void SomeFunction(bool someCondition)
{
    if (someCondition)
    {
        // Do Something
    }
}

or

public void SomeFunction(bool someCondition)
{
    if (!someCondition)
        return;

    // Do Something
}

I usually code with the first one since that is the way my brain works while coding, although I think I prefer the 2nd one since it takes care of any error handling right away and I find it easier to read

Post Closed as "Opinion-based" by CommunityBot, Bart van Ingen Schenau, Ixrec
edited tags
Link
gnat
  • 20.5k
  • 29
  • 117
  • 310
retag (since the retag priviledge is gone I have to go through suggested edits)
Link
Tweeted twitter.com/#!/StackProgrammer/status/558950089184780290
Question Protected by gnat
ah, the good old days...
Source Link
yannis
  • 39.7k
  • 40
  • 185
  • 218
Loading
Post Reopened by yannis
insert duplicate link
Source Link
Loading
Post Closed as "exact duplicate" by CommunityBot
Post Reopened by CommunityBot
Post Closed as "not constructive" by Jeff Atwood
Notice removed by Jeff Atwood
Post Unlocked by Jeff Atwood
edited tags; edited title
Link
user8
user8
Loading
Notice added by Adam Lear
Post Locked by Adam Lear
edited tags
Link
Adam Lear
  • 32.1k
  • 8
  • 104
  • 126
Loading
Post Made Community Wiki
edited tags
Link
rjzii
  • 11.3k
  • 8
  • 49
  • 72
Loading
Source Link
Rachel
  • 24k
  • 16
  • 95
  • 160
Loading