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. Code Puzzle

Code Puzzle

Scheduled Pinned Locked Moved The Weird and The Wonderful
questiondatabasedocker
28 Posts 12 Posters 1 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.
  • S Sascha Lefevre

    How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?

    public class QueryContainer
    {
    private static List<QueryContainer> Container;
    private static QueryContainer instance;

    public static QueryContainer Instance
    {
        get
        {
            if (Instance == null)
                instance = new QueryContainer();
    
            return instance;
        }
    }
    
    public int \_searchID;
    
    public int ID { get { return \_id; } }
    
    public string Query
    {
        get { return Container.Find(instance => instance.\_id == \_searchID).Query; }
        set { Container.Query = value; \_id =+ 1; }
    }
    
    private int \_id;
    private string \_query;
    
    private QueryContainer()
    { }
    

    }

    If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

    P Offline
    P Offline
    Power Puff Boy
    wrote on last edited by
    #21

    "But please - no programming questions."

    S 1 Reply Last reply
    0
    • P Power Puff Boy

      "But please - no programming questions."

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #22

      As you didn't mark your post as a joke or put a smiley into it I have to assume you're being serious: But my post isn't a programming question.

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      P 1 Reply Last reply
      0
      • S Sascha Lefevre

        How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?

        public class QueryContainer
        {
        private static List<QueryContainer> Container;
        private static QueryContainer instance;

        public static QueryContainer Instance
        {
            get
            {
                if (Instance == null)
                    instance = new QueryContainer();
        
                return instance;
            }
        }
        
        public int \_searchID;
        
        public int ID { get { return \_id; } }
        
        public string Query
        {
            get { return Container.Find(instance => instance.\_id == \_searchID).Query; }
            set { Container.Query = value; \_id =+ 1; }
        }
        
        private int \_id;
        private string \_query;
        
        private QueryContainer()
        { }
        

        }

        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #23

        1. The Instance property get will overflow the stack due to recursion. 2. The Query property set and get will both throw NullReferenceException's, since Container is never initialized. 3. The code shouldn't even compile. The Query property set assigns value to Container.Query, but since Container is a List<>, it doesn't have a Query property. I'm going to completely ignore the code's stated purpose, which I don't think what they've provided has the faintest hope of meeting.

        Software Zen: delete this;

        1 Reply Last reply
        0
        • S Sascha Lefevre

          As you didn't mark your post as a joke or put a smiley into it I have to assume you're being serious: But my post isn't a programming question.

          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

          P Offline
          P Offline
          Power Puff Boy
          wrote on last edited by
          #24

          Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.

          J S 2 Replies Last reply
          0
          • P Power Puff Boy

            Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #25

            You forgot a few: :baaaa!: :badger: :beer: :bob: :eek: :java: :jig: :vegemite:

            Wrong is evil and must be defeated. - Jeff Ello

            1 Reply Last reply
            0
            • P Power Puff Boy

              Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.

              S Offline
              S Offline
              Sascha Lefevre
              wrote on last edited by
              #26

              I'll take the second one, please. Can you wrap it as a gift? ;P

              If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

              P 1 Reply Last reply
              0
              • S Sascha Lefevre

                I'll take the second one, please. Can you wrap it as a gift? ;P

                If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                P Offline
                P Offline
                Power Puff Boy
                wrote on last edited by
                #27

                ****** * :-D * ******

                S 1 Reply Last reply
                0
                • P Power Puff Boy

                  ****** * :-D * ******

                  S Offline
                  S Offline
                  Sascha Lefevre
                  wrote on last edited by
                  #28

                  Very nice, will order again ;)

                  If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                  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