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
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Guess His Experience Level

Guess His Experience Level

Scheduled Pinned Locked Moved The Weird and The Wonderful
30 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pete OHanlon

    Tristan Rhodes wrote:

    * Only one return per function (no short circuit conditions), leading to horrendous nesting.

    Not bad advice - just keep your functions short or you're in trouble.

    Tristan Rhodes wrote:

    * Don't use Data Access layers, they're a waste of time, just use inline SQL and bind to a DataReader.

    COBOL

    Tristan Rhodes wrote:

    * Don't create lots of objects, it's slow.

    COBOL

    Tristan Rhodes wrote:

    * Don't break things into sub functions, it's harder to read and slower.

    COBOL

    Tristan Rhodes wrote:

    * Don't use constants, it's hard to read the literal representation.

    COBOL

    Tristan Rhodes wrote:

    * Don't use wrappers, ever, as you will just end up with wrappers in wrappers.

    COBOL

    Tristan Rhodes wrote:

    * Don't use Inheritance, it's complicated.

    COBOL

    Tristan Rhodes wrote:

    * Don't use Interfaces, they're unescessary.

    COBOL

    Tristan Rhodes wrote:

    * Don't use Serialization (Xml or otherwise - My understanding of serialization is object state persistence so I'm not sure how to persist without it).

    COBOL

    Tristan Rhodes wrote:

    * Don't make custom controls

    COBOL

    Tristan Rhodes wrote:

    * Don't use design patterns, they just complicate things.

    COBOL

    Tristan Rhodes wrote:

    * Don't use code generators, they generate slow / too much code.

    COBOL

    Tristan Rhodes wrote:

    * Don't bother with resources until we need to globalize the app.

    COBOL

    Tristan Rhodes wrote:

    * Don't make unit tests, waste of time, we can just user test it.

    COBOL

    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

    T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #21

    Pete O'Hanlon wrote:

    Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

    I'd rather see this

    MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

    if (child == null)
    return;

    MenuItemNode parent = child.Parent as MenuItemNode;

    if (parent == null)
    return;

    MenuItemNode swap = child.PrevNode as MenuItemNode;

    if (swap == null)
    return;

    //Code Here

    Than This

    MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

    if (child != null)
    {
    MenuItemNode parent = child.Parent as MenuItemNode;

      if (parent != null)
      {
            MenuItemNode swap = child.PrevNode as MenuItemNode;
    
            if (swap != null)
            {
                  //Code Here
            }
      }
    

    }

    I just find the second option ugly, and it really isn't any easier to read.

    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

    modified on Sunday, April 5, 2009 7:33 AM

    J L K P OriginalGriffO 5 Replies Last reply
    0
    • T Tristan Rhodes

      Pete O'Hanlon wrote:

      Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

      I'd rather see this

      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

      if (child == null)
      return;

      MenuItemNode parent = child.Parent as MenuItemNode;

      if (parent == null)
      return;

      MenuItemNode swap = child.PrevNode as MenuItemNode;

      if (swap == null)
      return;

      //Code Here

      Than This

      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

      if (child != null)
      {
      MenuItemNode parent = child.Parent as MenuItemNode;

        if (parent != null)
        {
              MenuItemNode swap = child.PrevNode as MenuItemNode;
      
              if (swap != null)
              {
                    //Code Here
              }
        }
      

      }

      I just find the second option ugly, and it really isn't any easier to read.

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

      modified on Sunday, April 5, 2009 7:33 AM

      J Offline
      J Offline
      jayart
      wrote on last edited by
      #22

      I think the same. But no one in my team thinks this way and they have managed to make this as a coding rule.

      D 1 Reply Last reply
      0
      • J jayart

        I think the same. But no one in my team thinks this way and they have managed to make this as a coding rule.

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #23

        Will they let you get away with stuffing all the nested initialization/validation crap into a separate method? eg something like this (I know it needs a bit more fiddling to compile):

        bool IntializeAndvalidate (out MenuItemNode child, out MenuItemNode parent, MenuItemNode swap)
        {
        MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

          if (child != null)
          {
                MenuItemNode parent = child.Parent as MenuItemNode;
        
                if (parent != null)
                {
                      MenuItemNode swap = child.PrevNode as MenuItemNode;
        
                      return  (swap != null);
                }
          }
        

        }

        if (IntializeAndvalidate (child, parent, swap)
        {
        // do stuff
        }

        Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

        1 Reply Last reply
        0
        • T Tristan Rhodes

          Pete O'Hanlon wrote:

          Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

          I'd rather see this

          MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

          if (child == null)
          return;

          MenuItemNode parent = child.Parent as MenuItemNode;

          if (parent == null)
          return;

          MenuItemNode swap = child.PrevNode as MenuItemNode;

          if (swap == null)
          return;

          //Code Here

          Than This

          MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

          if (child != null)
          {
          MenuItemNode parent = child.Parent as MenuItemNode;

            if (parent != null)
            {
                  MenuItemNode swap = child.PrevNode as MenuItemNode;
          
                  if (swap != null)
                  {
                        //Code Here
                  }
            }
          

          }

          I just find the second option ugly, and it really isn't any easier to read.

          ------------------------------- Carrier Bags - 21st Century Tumbleweed.

          modified on Sunday, April 5, 2009 7:33 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #24

          The official solution to avoid multiple returns is throwing exceptions all over the place, especially on input validation. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          D T 2 Replies Last reply
          0
          • L Luc Pattyn

            The official solution to avoid multiple returns is throwing exceptions all over the place, especially on input validation. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #25

            :rolleyes:

            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

            1 Reply Last reply
            0
            • T Tristan Rhodes

              Pete O'Hanlon wrote:

              Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

              I'd rather see this

              MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

              if (child == null)
              return;

              MenuItemNode parent = child.Parent as MenuItemNode;

              if (parent == null)
              return;

              MenuItemNode swap = child.PrevNode as MenuItemNode;

              if (swap == null)
              return;

              //Code Here

              Than This

              MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

              if (child != null)
              {
              MenuItemNode parent = child.Parent as MenuItemNode;

                if (parent != null)
                {
                      MenuItemNode swap = child.PrevNode as MenuItemNode;
              
                      if (swap != null)
                      {
                            //Code Here
                      }
                }
              

              }

              I just find the second option ugly, and it really isn't any easier to read.

              ------------------------------- Carrier Bags - 21st Century Tumbleweed.

              modified on Sunday, April 5, 2009 7:33 AM

              K Offline
              K Offline
              kfoster
              wrote on last edited by
              #26

              The 'one return per function' rule is a bit old school (early 90's :) ). IBM had it as a requirement when I was contracting there. It's not so much about style and readability as it is about introducing subtle bugs. If a maintenance programmer has to put some code in the function that has to take place before the function ends, he may place it right before the final 'return' near the end of the code block. And if he was working fast, or just working stupid he may not know of the other return points. Anyway, OOP guidelines of very short (7 +- 2) meaningful lines of code per method made this a moot point.

              1 Reply Last reply
              0
              • L Luc Pattyn

                The official solution to avoid multiple returns is throwing exceptions all over the place, especially on input validation. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                T Offline
                T Offline
                Tristan Rhodes
                wrote on last edited by
                #27

                I've used that method before, but i was always told by my teacher to not use exceptions to control application flow, so it's something I'm reluctant to do unless I'm out of options. Still, if you want a short circuit validation routine with no input or output, guess that's the only way. What's the performance hit like for exceptions in ASP.Net? I thought exceptions were super bad at crippling servers?

                ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                L 1 Reply Last reply
                0
                • T Tristan Rhodes

                  I've used that method before, but i was always told by my teacher to not use exceptions to control application flow, so it's something I'm reluctant to do unless I'm out of options. Still, if you want a short circuit validation routine with no input or output, guess that's the only way. What's the performance hit like for exceptions in ASP.Net? I thought exceptions were super bad at crippling servers?

                  ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #28

                  Hi, there is no performance hit for testing and throwing exceptions; what is slow is catching exceptions, especially so for the first one caught inside Visual Studio. But then exceptions should be used to deal with exceptional circumstances only, which does *not* mean they should be used rarely. It would be a bad idea to use them like so:

                  int[] numbers=new int[100];
                  for (int i=0; ; i++) numbers[i]=i; // break with IndexOutOfRangeException

                  :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                  1 Reply Last reply
                  0
                  • T Tristan Rhodes

                    Pete O'Hanlon wrote:

                    Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

                    I'd rather see this

                    MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

                    if (child == null)
                    return;

                    MenuItemNode parent = child.Parent as MenuItemNode;

                    if (parent == null)
                    return;

                    MenuItemNode swap = child.PrevNode as MenuItemNode;

                    if (swap == null)
                    return;

                    //Code Here

                    Than This

                    MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

                    if (child != null)
                    {
                    MenuItemNode parent = child.Parent as MenuItemNode;

                      if (parent != null)
                      {
                            MenuItemNode swap = child.PrevNode as MenuItemNode;
                    
                            if (swap != null)
                            {
                                  //Code Here
                            }
                      }
                    

                    }

                    I just find the second option ugly, and it really isn't any easier to read.

                    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                    modified on Sunday, April 5, 2009 7:33 AM

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #29

                    You could always do this as:

                    if (child != null && child.Parent != null && child.PrevNode != null)
                    {
                    }

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    • T Tristan Rhodes

                      Pete O'Hanlon wrote:

                      Tristan Rhodes wrote: * Only one return per function (no short circuit conditions), leading to horrendous nesting. Not bad advice - just keep your functions short or you're in trouble.

                      I'd rather see this

                      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

                      if (child == null)
                      return;

                      MenuItemNode parent = child.Parent as MenuItemNode;

                      if (parent == null)
                      return;

                      MenuItemNode swap = child.PrevNode as MenuItemNode;

                      if (swap == null)
                      return;

                      //Code Here

                      Than This

                      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;

                      if (child != null)
                      {
                      MenuItemNode parent = child.Parent as MenuItemNode;

                        if (parent != null)
                        {
                              MenuItemNode swap = child.PrevNode as MenuItemNode;
                      
                              if (swap != null)
                              {
                                    //Code Here
                              }
                        }
                      

                      }

                      I just find the second option ugly, and it really isn't any easier to read.

                      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

                      modified on Sunday, April 5, 2009 7:33 AM

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #30

                      I sort of agree, but rather than:

                      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;
                      if (child == null)
                      return;
                      MenuItemNode parent = child.Parent as MenuItemNode;
                      if (parent == null)
                      return;
                      MenuItemNode swap = child.PrevNode as MenuItemNode;
                      if (swap == null)
                      return;
                      //Code Here

                      I would prefer:

                      MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;
                      if (child == null)
                      {
                      return;
                      }
                      MenuItemNode parent = child.Parent as MenuItemNode;
                      if (parent == null)
                      {
                      return;
                      }
                      MenuItemNode swap = child.PrevNode as MenuItemNode;
                      if (swap == null)
                      {
                      return;
                      }
                      //Code Here

                      Just to remind me if I add a statement before the return.

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

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