Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

S Donovan

@S Donovan
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Multiple returns from methods or clean code flow
    S S Donovan

    Single ``return`` or multiple ``return`` I think is a potential code smell - based on design and code format agreements. I like the concept of having the guard statements and their ``return`` or ``throw`` exception small and tight at the beginning of a function/method. Putting the error handling into an ``else`` block can destroy the readability. We recently found a method in a work project where we were setting a ``results`` variable to ``true``, and then calling ``return false``. The last line of the method was to ``return results``. (Of course, no comments what team member that is no longer with the company was thinking.) This was in the logic and processing, not in guard statements. I think using negation logic can also be a code smell

    void doSomething(var a)
    {
    if (a == null)
    {
    throw new Exception("a == null");
    // or return with no meaningful "why"
    }
    else
    {
    //...
    }
    }

    is more readable than

    void doSomething(var a)
    {
    if (a != null)
    {
    //...
    // Many lines so that the error handling is separated from the test
    //...
    }
    else
    {
    throw new Exception("a == null");
    // or return with no meaningful "why"
    }
    }

    The Lounge question discussion cryptography collaboration help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups